反应-本土-制作-支付
使用 W3C 付款请求 API 给您的 React Industrial app. 目前支持谷歌支付Android.
安装
npm install @google/react-native-make-payment
也可以通过从此 repo 根运行以下命令来尝试示例 :
yarn && yarn example
配置
为了生产,你需要定义
GOOGLE_PAY_ENVIRONMENT 在您的工程中的财产
gradle.properties 文件( 通常为 android/gradle.properties:
GOOGLE_PAY_ENVIRONMENT=PRODUCTION
使用量
下面是一个极小的例子。 一个完整的例子是
发现于 example/src/App.tsx。 。 。 .
import { PaymentRequest, type W3CGooglePayPaymentMethod, type GooglePayPaymentDataRequest } from '@google/react-native-make-payment';
const paymentDetails = {
total: {
amount: {
currency: 'USD',
value: '14.95',
},
},
};
const googlePayRequest: GooglePayPaymentDataRequest = {
// Google Pay API JSON request object, see:
// https://developers.google.com/pay/api/android/reference/request-objects
};
const paymentMethods: W3CGooglePayPaymentMethod[] = [
{
supportedMethods: 'google_pay',
data: googlePayRequest,
},
];
const paymentRequest = new PaymentRequest(paymentMethods, paymentDetails);
paymentRequest.canMakePayment().then((canMakePayment) => {
if (canMakePayment) {
paymentRequest.show().then((response) => {
// Handle PSP response
});
} else {
// Google Pay unavailable
}
});
谷歌付费按钮
添加本地 Google 付费按钮的例子 :
<GooglePayButton
style={styles.googlepaybutton}
onPress={checkCanMakePayment}
allowedPaymentMethods={googlePayRequest.allowedPaymentMethods}
theme={GooglePayButtonConstants.Themes.Dark}
type={GooglePayButtonConstants.Types.Buy}
radius={4}
/>