[英].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那么你需要在这里进行一些检查
Check whats the result printed for below code before calling handleTransaction在调用 handleTransaction 之前检查下面代码打印的结果是什么
console.log( "this checksum api esponse" + JSON.stringify(response[0].data.txnToken) );
Check if the handleTransaction block is called检查 handleTransaction 块是否被调用
() => 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) })
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.