将节点程序包转换为React Native

bweufnob  于 2022-11-25  发布在  React
关注(0)|答案(1)|浏览(134)

我正在努力将CinetPay集成到React原生应用程序中。他们在节点包或CDN javascript中提供解决方案。我已经从https://www.npmjs.com/package/cinetpay-nodejs安装了节点包。现在我需要转换此节点包以与React原生应用程序一起工作。
用于节点模块/电影付费-节点js/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');

如何将此代码转换为React Native代码?

qjp7pelc

qjp7pelc1#

如果你想在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);
    });

您可以在this link中的文档中指定更多内容

相关问题