【发布时间】:2021-08-21 08:11:50
【问题描述】:
我想将flutterwave 集成到我的react native 应用程序中。我下载了他们名为 flutterwave-react-native 的 npm 包并按照他们的教程进行操作,但仍然无法做到。我在Github 上使用他们的示例 sn-p,我收到一条错误消息:
this.usePaymentLink 不是函数
我到处搜索,但找不到 this.usePaymentLink 的定义位置。您可以查看我的 sn-p 并告诉我我错过了什么以及 this.usePaymentLink 的样子。
import React from 'react';
import {View, TouchableOpacity} from 'react-native';
import {FlutterwaveInit} from 'flutterwave-react-native';
class MyCart extends React.Component {
abortController = null;
componentWillUnmout() {
if (this.abortController) {
this.abortController.abort();
}
}
handlePaymentInitialization = () => {
this.setState({
isPending: true,
}, () => {
// set abort controller
this.abortController = new AbortController;
try {
// initialize payment
const paymentLink = await FlutterwaveInit(
{
tx_ref: generateTransactionRef(),
authorization: '[merchant public key]',
amount: 100,
currency: 'USD',
customer: {
email: 'customer-email@example.com',
},
payment_options: 'card',
},
this.abortController
);
// use payment link
return this.usePaymentLink(paymentLink);
} catch (error) {
// do nothing if our payment initialization was aborted
if (error.code === 'ABORTERROR') {
return;
}
// handle other errors
this.displayErrorMessage(error.message);
}
});
}
render() {
const {isPending} = this.state;
return (
<View>
...
<TouchableOpacity
style={[
styles.paymentbutton,
isPending ? styles.paymentButtonBusy : {}
]}
disabled={isPending}
onPress={this.handlePaymentInitialization}
>
Pay $100
</TouchableOpacity>
</View>
)
}
}
【问题讨论】:
标签: react-native payment-gateway payment flutterwave