paytm_allinone_react_native 或@philly25/react-native-paytm 如何使用

问题描述

我从 Youtube 复制了以下代码。但现在我有一些问题。关于此代码。我没有完全理解这段代码..

这是我的一些问题(在 apirequest.js 文件中)

  1. 我应该在 var baseURl = "" 中写什么
  2. 我应该在 var Token = "" 中写什么

这里是问题(在 payment.js 文件中)

  1. 我应该在校验和哈希键中写什么
  2. orderid key 应该写什么

这是我尝试过的=我在payment.js文件中使用react-native-sha256生成哈希键并将其放入check checksumhash键中。 在 orderid 中,我提供了任何随机数,例如 123。 通过做这个。我收到 paytm 屏幕,但在底部错误。我收到这样的错误 = 无效:校验和哈希的语法不正确。

请帮忙。

这是我的payment.js

import stuff....

export default class Test extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      processing: false,payment_text: "Requesting payment",hash: "",};
  }

  componentDidMount() {
    Paytm.addListener(Paytm.Events.PAYTM_RESPONSE,this.onPayTmResponse);
  }

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

  onPayTmResponse = (resp) => {
    console.log("hi " + resp); // here getting undefined+

    const { STATUS,status,RESPMSG,response } = resp;
    this.setState({ processing: false });

    if (STATUS == "TXN_SUCCESS") {
      console.log("success");
      this.setState({ payment_text: RESPMSG });
    } else {
      console.log("fails");
    }
  };

  pay = () => {
    this.setState({ processing: true });

    order_req({ orderItems: "20" })
      .then((responseJson) => {
        console.log("order_req",responseJson);

        if (responseJson.ok) {
          this.setState(
            {
              processing: false,},() => {
              this.hitchecksum(responseJson.data.order_gateway_id);
            }
          );
        } else {
          alert("he" + responseJson.problem);
        }
      })
      .catch((error) => {
        console.error(error);
        this.setState({ processing: false });
      });
  };

  hitchecksum = (orderid) => {
    sha256("Test").then((hash) => {
      console.log("thi sis hash" + hash);
      this.setState({ hash: hash });
    });

    checksum_req({
      MID: "XXXXXXXXXXXXX",INDUSTRY_TYPE_ID: "Retail",WEBSITE: "APPSTAGING",CHANNEL_ID: "WAP",TXN_AMOUNT: "1",// String
      ORDER_ID: "32546",// String //yaha kya dalna hai

      CUST_ID: "CUSTOMER_1",// String

      // CALLBACK_URL:
      //   "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=" + "1",CALLBACK_URL:
        "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<1>",})
      .then((responseJson) => {
        console.log("checksum_req",() => {
              const details = {
                mode: "Staging",// 'Staging' or 'Production'
                MID: "XXXXXXXXXXXXXXXX",// String
                ORDER_ID: "32546",// String
                // EMAIL: email,// String
                // MOBILE_NO: mobile,// String
                CUST_ID: "CUSTOMER_1",// String
                //CHECKSUMHASH: responseJson.data.checksum,//From your server using PayTM Checksum Utility
                CHECKSUMHASH: this.state.hash,//From your server using PayTM Checksum Utility
                // CALLBACK_URL:
                //   "https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=" +
                //   "1",CALLBACK_URL:
                  "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=<1>",};
              console.log(details);
              Paytm.startPayment(details);
              console.log(details);
            }
          );
        } else {
          //  console.log(responseJson.problem);
        }
      })
      .catch((error) => {
        // console.error(error);
        this.setState({
          processing: false,});
      });
  };

  render() {
    return (
      <View>
        <TouchableOpacity
          onPress={this.pay}
          style={{ height: 90,width: 100,backgroundColor: "red" }}
        >
          <Text>philly full</Text>
        </TouchableOpacity>
      </View>
    );
  }
}

这是我的 apirequest.js

import { create } from "apisauce";

var baseURL = " what should I provide here ( at for testing I provide some random API";
var token = " what should I provide here";

const api = create({
  baseURL: baseURL,headers: {
    Accept: "application/json",Authorization: "Bearer" + token,});

export let order_req = (body) =>
  api.post("/prepareOrder",body).then((response) => response);

export let checksum_req = (body) =>
  api.post("/getChecksum",body).then((response) => response);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)