如何在React Native中添加Paytm付款

时间:2020-03-27 15:36:30

标签: react-native paytm

import React from 'react';
import { Platform } from 'react-native';
import Paytm from 'react-native-paytm';

// Data received from PayTM
const paytmConfig = {
    MID: 'Value from PayTM dashboard',
    WEBSITE: 'Value from PayTM dashboard',
    CHANNEL_ID: 'WAP',
    INDUSTRY_TYPE_ID: 'Retail',
    CALLBACK_URL: 'https://securegw.paytm.in/theia/paytmCallback?ORDER_ID='
};

export default class Test extends React.Component {
    componentWillMount() {
        Paytm.addListener(Paytm.Events.PAYTM_RESPONSE, this._handlePaytmResponse);
    }

    componentWillUnmount() {
        Paytm.removeListener(Paytm.Events.PAYTM_RESPONSE, this._handlePaytmResponse);
    }

    _handlePaytmResponse = (resp) => {
        const {STATUS, status, response} = resp;

        this.setState({processing: false, payment_text: ''});
                console.log(JSON.stringify(resp));
      };

    runTransaction(amount, customerId, orderId, mobile, email, checkSum, mercUnqRef) {
        const callbackUrl = `${paytmConfig.CALLBACK_URL}${orderId}`;
        const details = {
            mode: 'Staging', // 'Staging' or 'Production'
            MID: paytmConfig.MID,
            INDUSTRY_TYPE_ID: paytmConfig.INDUSTRY_TYPE_ID,
            WEBSITE: paytmConfig.WEBSITE,
            CHANNEL_ID: paytmConfig.CHANNEL_ID,
            TXN_AMOUNT: `${amount}`, // String
            ORDER_ID: orderId, // String
            EMAIL: email, // String
            MOBILE_NO: mobile, // String
            CUST_ID: customerId, // String
            CHECKSUMHASH: checkSum, //From your server using PayTM Checksum Utility 
            CALLBACK_URL: callbackUrl,
            MERC_UNQ_REF: mercUnqRef, // optional
        };

        Paytm.startPayment(details);
    }
}

我想在我的应用程序中添加paytm。我已经检查了很多代码,但是找不到该模块的工作方式。我如何在按钮上单击。如果有人对此有所了解,请指导我。我已经收到了此代码,但是请检查我如何在单击按钮时调用上面的代码。以及在何处添加paytm帐户详细信息。

0 个答案:

没有答案