简体   繁体   English

.then(result) 块在 paytm 支付成功后不执行。 在反应原生

[英].then(result) block not executing after paytm payment successful. in react native

I am integrating paytm transaction in react native app.我正在React Native 应用程序中集成paytm交易。 and I have successfully integrated it.我已经成功地集成了它。 I am able to do successful transaction.我能够进行成功的交易。 but after transaction successful.但交易成功后。 some data from server API is showing over there.来自服务器 API 的一些数据显示在那里。 like this = "[{"message":"success","is_payment_done":"Y"}]" .像这样 = "[{"message":"success","is_payment_done":"Y"}]"

But the problem is .then(result) block is not executing.但问题是.then(result)块没有执行。 Please help.请帮忙。

Here is the code:这是代码:

export default class payment extends Component {
  constructor(props) {
    super(props);
    this.state = {
      order_id: "",
      mid: "xxxxxxxxxxxxxxxxxxxxxxxx",
      tranxToken: "",
      amount: "20",
      // callbackUrl:
      //   "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=TESTORDER_1",
      isStaging: true,
      appInvokeRestricted: true,
    };
  }

  call_api = () => {
    fetch("https://xxxxxxx.in/App_API_CI/xxxxxxxxxx", {
      method: "POST",
      headers: {
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
      },

      body: JSON.stringify([
        {
          mobile_no: "xxxxxxxxx",
          user_id: "xx",
          patient_name: "xxxxxxx",
        },
      ]),
    })
      .then((returnValue) => returnValue.json())

      .then((response) => {
        console.log(
          "this checksum api esponse" +
            JSON.stringify(response[0].data.txnToken)
        );

        this.setState({ order_id: response[0].data.order_id });
        this.setState({ tranxToken: response[0].data.txnToken });

        this.handleTransaction();
      });
  };

  handleTransaction = () => {
    AllInOneSDKManager.startTransaction(
      this.state.order_id,
      this.state.mid,
      this.state.tranxToken,
      this.state.amount,
      "https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=" +
        this.state.order_id,
      this.state.isStaging,
      this.state.appInvokeRestricted
    )

      .then((result) => {
        () => console.log(result);
        //AsyncStorage.setItem("is_payment_done", "Y");
        this.props.navigation.navigate("MyDrawerRP");
      })
      .catch((err) => {
        console.log(err);
        Toast.show("Something went wrong");
      });
  };

  render() {
    return (
      <View style={{ alignSelf: "center", flex: 1, justifyContent: "center" }}>
        <TouchableOpacity
          onPress={this.call_api}
          style={{
            height: 90,
            width: width / 1.2,
            backgroundColor: "#7DF8F8",
            justifyContent: "center",
            elevation: 20,
          }}
        >
          <Text style={{ alignSelf: "center", fontSize: 35, color: "#000080" }}>
            PAY 20/-
          </Text>
        </TouchableOpacity>
      </View>
    );
  }
}


For some async activity like getting data from server (the server take a little time to return data ) it's necessary to use async/await to not fail the returned data For your code try it like this :对于一些异步活动,比如从服务器获取数据(服务器需要一点时间来返回数据),有必要使用 async/await 来避免返回的数据失败对于您的代码,请像这样尝试:

call_api =  async () => {
await fetch("https://xxxxxxx.in/App_API_CI/xxxxxxxxxx", {
    method: "POST",
    headers: {
        Accept: "application/json, text/plain, */*",
        "Content-Type": "application/json",
    },

    body: JSON.stringify([
        {
            mobile_no: "xxxxxxxxx",
            user_id: "xx",
            patient_name: "xxxxxxx",
        },
    ]),
})
    .then((returnValue) => returnValue.json())

    .then((response) => {
        console.log(
            "this checksum api esponse" +
            JSON.stringify(response[0].data.txnToken)
        );

        this.setState({ order_id: response[0].data.order_id });
        this.setState({ tranxToken: response[0].data.txnToken });

        this.handleTransaction();
    });

}; };

Well you need to have few checks here那么你需要在这里进行一些检查

  1. Check whats the result printed for below code before calling handleTransaction在调用 handleTransaction 之前检查下面代码打印的结果是什么

    console.log( "this checksum api esponse" + JSON.stringify(response[0].data.txnToken) );
  2. Check if the handleTransaction block is called检查 handleTransaction 块是否被调用

  3. () => this wont execute console.log(result) and print the log , remove this from below code () => 这不会执行 console.log(result) 并打印日志,从下面的代码中删除它

    .then((result) => { ()=> //remove this console.log("result", result) })
  4. If the handleTransaction is executed there might be some issue in startTransaction block, debug and check or wrap the code inside handleTransaction in try catch如果执行了 handleTransaction,则 startTransaction 块中可能存在一些问题,请在 try catch 中调试并检查或包装 handleTransaction 中的代码

For the 4th step asked, place the below code and check the logs对于询问的第 4 步,放置以下代码并检查日志

 handleTransaction = () => {
 console.log("handleTransaction Called")
 try{
 AllInOneSDKManager.startTransaction(
 this.state.order_id,
 this.state.mid,
 this.state.tranxToken,
 this.state.amount,
"https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=" +
 this.state.order_id,
 this.state.isStaging,
 this.state.appInvokeRestricted
 )
.then((result) => {
  console.log("startTransaction Result ",result);
  this.props.navigation.navigate("MyDrawerRP");
 })
 .catch((err) => {
  console.log("startTransaction error", err)
 });
 } catch (error) {
 console.log("handleTransaction error", error)
  }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 paytm付款交易成功后如何导航到下一个屏幕。 在反应原生 - how to navigate to next screen after successful of paytm payment transaction. in react native 在 React Native 中打开 paytm 的付款屏幕后屏幕立即关闭 - screen immediately closing after opening payment screen of paytm in react native 如何在我的反应本机应用程序中通过 api 制作 paytm 的付款链接而不添加服务器 - How to make a Payment link of paytm through api in my react native app without adding a server 在try / catch块中成功执行异步请求后执行语句 - Executing statements after a successful asynchronous request in a try/catch block 在 react native 中的 paytm 集成中重定向回应用程序 - redirecting back to the app in paytm integration in react native @philly25/react-native-paytm Paytm.Events.PAYTM_RESPONSE 响应未定义 - @philly25/react-native-paytm Paytm.Events.PAYTM_RESPONSE reponse is undefined 付款成功后重定向到仪表板 - Redirect to dashboard after successful payment 成功登录后如何重定向? 在本机+博览会 - How redirect after successful login? in react-native + expo Ajax调用成功,但是错误块正在执行 - Ajax call successful, but error block is executing 无效:checksumhash 的语法不正确……在 PayTM Checksum Utility 中的本机反应中 - invalid: syntax of checksumhash is incorrect… in react native in PayTM Checksum Utility
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM