Reactjs -无现金集成(无现金没有定义)



我在后台使用reactjs前端和django,我正试图将Cashfree无缝基本支付网关与我的网页集成。我已经尝试了在此https://dev.cashfree.com/payment-gateway/integrations/web-integration/seamless-basic#response-verification中提到的相同步骤,但我得到Line35:18: 'CashFree'未定义no-undef这个错误。我也附上了代码片段。

1。创建了一个表单来存储数据{

"orderId" : "Test6", 
"orderAmount" : "500", 
"orderCurrency" : "INR", 
"orderNote" : "", 
"customerName" : "Test", 
"customerPhone" : "9900012345", 
"customerEmail" : "example@mail.com", 
"returnUrl" : "http://example.com/", 
"notifyUrl" : "http://example.com/",
"paymentOption" :"" ,
"paymentCode" : ""
}
  1. 附在index.html
  2. 文档中的脚本

3。生成签名。

4。

const Pay = ()=>{
useEffect(()=>{


const config = {};
config.layout = {};
config.checkout = "transparent";
config.mode = "TEST";
let response = CashFree.init(config);
console.log(response);
if (response.status !== "OK") {

}

},[])
var pc = (data)=>{
data.paymentOption = "card";
data.card = {};
data.card.number = "4444333322221111";
data.card.expiryMonth = "07";
data.card.expiryYear = "23";
data.card.cvv = "123";
CashFree.paySeamless(data, postPaymentCallback());
return false;
};
const postPaymentCallback = (event) => {
console.log(event);
if (event.name == "PAYMENT_RESPONSE" && event.status == "SUCCESS") {
} else if ( event.name == "PAYMENT_RESPONSE" && event.status == "CANCELLED") {
} else if (event.name == "PAYMENT_RESPONSE" && event.status == "FAILED") {
} else if (event.name == "VALIDATION_ERROR") {
}
};

const payCard = ()=>{
CashFree.initPopup(); // This is required for the popup to work even in case of callback.
axios.get("https://reqres.in/api/users?page=2") // This is an open endpoint.
.then((response)=>{
console.log(response);
pc();

})
};
const payBank = (data)=> {
CashFree.initPopup();
data.paymentOption = "nb";
data.nb = {};
data.nb.code = "3002";

CashFree.paySeamless(data , postPaymentCallback);
return false;
};
const payWallet = (data) =>{
data.paymentOption = "wallet";
data.wallet = {};
data.wallet.code = 4001;

CashFree.paySeamless(data, postPaymentCallback);
return false;
};
const payUpi = (data) => {
data.paymentOption = "upi";
data.upi = {};
data.upi.vpa = 3244;

CashFree.paySeamless(data, postPaymentCallback);
return false;
};
}
return(
<button onClick={Pay()}>PAY</button>
)

我在这一步遇到错误35:18: 'CashFree'未定义no-undef我已经尝试安装cashfree-sdk,但我仍然得到'CashFree.init()'不是一个函数

通过添加script标签加载SDK后,您需要从窗口对象访问CashFree

所以window.CashFree代替CashFree

最新更新