我正在努力将CinetPay集成到React本地应用程序中。他们正在用Node包或CDN javascript提供解决方案。我已经从https://www.npmjs.com/package/cinetpay-nodejs安装了节点包。现在,我需要将这个节点包转换为使用React本机应用程序。
节点_模块/cinetpay/index.js代码
var cdn = document.createElement('script');
cdn.setAttribute('src','https://cinetpay.com/cdn/seamless_sdk/latest/cinetpay.prod.min.js');
document.head.appendChild(cdn);
module.exports = require('./lib/cinetpay');如何将此代码转换为反应本机代码?
发布于 2022-11-20 23:15:40
如果您希望在React本地应用程序中集成cinetpay,则需要使用axios并执行如下请求:
var axios = require('axios');
var data = JSON.stringify({
"apikey": "YOUR_APIKEY",
"site_id": "YOUR_SITEID",
"transaction_id": Math.floor(Math.random() * 100000000).toString(), //
"amount": 100,
"currency": "XOF",
"alternative_currency": "",
"description": " TEST INTEGRATION ",
"customer_id": "172",
"customer_name": "KOUADIO",
"customer_surname": "Francisse",
"customer_email": "harrissylver@gmail.com",
"customer_phone_number": "+225004315545",
"customer_address": "Antananarivo",
"customer_city": "Antananarivo",
"customer_country": "CM",
"customer_state": "CM",
"customer_zip_code": "065100",
"notify_url": "https://webhook.site/d1dbbb89-52c7-49af-a689-b3c412df820d",
"return_url": "https://webhook.site/d1dbbb89-52c7-49af-a689-b3c412df820d",
"channels": "ALL",
"metadata": "user1",
"lang": "FR",
"invoice_data": {
"Donnee1": "",
"Donnee2": "",
"Donnee3": ""
}
});
var config = {
method: 'post',
url: 'https://api-checkout.cinetpay.com/v2/payment',
headers: {
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});您可以在此链接文档中显示更多的内容。
https://stackoverflow.com/questions/72702476
复制相似问题