【问题标题】:What is razorpay orders api and how to integrate it with react native?什么是razorpay orders api以及如何将它与react native集成?
【发布时间】:2020-08-04 12:56:52
【问题描述】:

我正在尝试在我的 react 本机应用程序中实现支付模块并尝试使用 Razorpay。根据文档,有两个主要内容,结帐和订单 API。两者有什么区别?订单 API 到底是什么,它如何用于本机反应?他们在文档中提供了许多选项来集成订单 API,如 java、ruby 等,但没有用于 react native。所以任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: react-native razorpay


    【解决方案1】:

    Razorpay 集成了 react-native 的结账功能,这意味着它会导致调用payment API,它的作用是接受任何用户直接转账而无需任何细节的付款。通过orders API,Razorpay 使您能够创建可链接到付款的订单。这意味着无论您的钱包收到什么付款,都会用与付款相关的内容来描述。例如,假设您必须展示您希望销售的产品。

    首先,您必须通过在服务器端调用订单 API(即 Node.JS 或其他带有请求参数(如金额)、自行生成的收据编号以及关于用户身份的可选注释来创建订单是。然后在收到 order_id 后,您将传递到移动应用程序并启动 react-native-razorpay 提供的结帐功能。

    这是我如何使用 react-native-razorpay 的示例。

    在服务器端 - node.js:

    const Razorpay = require("razorpay");
    //...
    
    let rzp = new Razorpay({
      key_id: "", // your `KEY_ID`
      key_secret: "" // your `KEY_SECRET`
    });
    
    //Inside Create Order Function
    
    rzp.orders
      .create({
        amount: price * 100,
        currency: "INR",
        receipt: "", // Add receipt string
        payment_capture: 1, // auto capture payment config
        notes: { username, planId: id }
        // custom notes, you can use this in received response as key-value pair
      })
      .then(data => { // created order response
        let sendToApplicationResponse = { // Creating the response send to mobile app
          username,
          orderId: data.id,
          receipt: data.receipt
        };
        return sendToApplicationResponse;
      })
    

    在 react-native 应用端:

    import RazorpayCheckout from 'react-native-razorpay';
    
    //.....
    
    onPress={async () => {
    //Call my server to create an Order 
    // passing userId and price and plan selected as request parameters
    // and waiting for the response
    const response = await .....
    // You can add parameters given in payment API
    var options = {
      currency: 'INR',
      key: '', // add your razorpay key here
      amount: price * 100,
      order_id: response.data.orderId, // using the orderId which 
      prefill: { // add prefill details if you want
        contact: "",
        name: "",
      },
      payment_capture: 1,
    };
    // Call the razorpay checkout
    RazorpayCheckout.open(options)
      .then(data => {
        console.log('RazorpayCheckout', data);
        Alert.alert('Payment Successful!');
      })
      .catch(error => {
        Alert.alert('Something went wrong!');
        // Alert.alert(`Error: ${error.code} | ${error.description}`);
      });
    }}
    

    【讨论】:

      猜你喜欢
      • 2020-10-16
      • 2017-08-01
      • 2019-01-12
      • 2022-10-20
      • 1970-01-01
      • 1970-01-01
      • 2019-06-29
      • 1970-01-01
      • 2020-01-26
      相关资源
      最近更新 更多