【发布时间】:2020-06-06 21:49:52
【问题描述】:
大家好。请我需要你的帮助。我使用的支付网关需要在交易成功后重定向回我的 ionic 应用程序。但在成功交易后,我收到此错误消息“无法发布到 localhost:8100/home”,但是当我使用站点 URL 例如(https://siteurl.com)时,它通过重定向到指定站点来工作。我不知道我在哪里弄错了,我的应用程序的回调 URL 是什么。这是我的代码。谢谢。
completePurchase() {
this.loadingCtrl.create({
message: "Order Processing...",
showBackdrop: true
}).then((overlay) => {
this.loading = overlay;
this.loading.present();
let currentCustomerId = localStorage.getItem('currentUserId');
if (this.paymentGatwayId == "tbz_rave") {
this.rave.init(false, "PUBLIC_KEY") //true = production, false = test
.then(_ => {
var paymentObject = this.ravePayment.create({
customer_email: this.user.email,
amount: this.totalPrice,
customer_firstname: `${this.user.first_name}`,
customer_lastname: `${this.user.last_name}`,
customer_phone: `${this.user.billing.phone}`,
currency: "NGN",
txref: "rave-1234550",
redirect_url: "http://localhost:8100/home",
meta: [{
metaname: "flightID",
metavalue: "AP1234"
}]
})
this.rave.preRender(paymentObject)
.then(secure_link => {
secure_link = secure_link + " ";
const browser: InAppBrowserObject = this.rave.render(secure_link, this.iab);
browser.on("loadstart")
.subscribe((event: InAppBrowserEvent) => {
if (event.url.indexOf('http://localhost:8100/home') != -1) {
if (event.url.includes("payment_successfull")) {
browser.close();
console.log("Transaction Succesful");
// Place order after payment successfull
let orderObj = {};
orderObj['payment_method'] = this.paymentGatwayId;
orderObj['payment_method_title'] = this.paymentGatewayTitle;
orderObj['customer_id'] = currentCustomerId;
this.platform.ready().then(() => {
this.address = {
first_name: this.user.first_name,
last_name: this.user.last_name,
address_1: this.user.billing.address_1,
city: this.user.billing.city,
address_2: this.user.billing.address_2,
phone: this.user.billing.phone,
}
orderObj['billing'] = this.address;
orderObj['line_items'] = this.baseProducts;
this.WC.placeOrder(orderObj).then(async (respData) => {
this.storage.clear();
this.storage.set('currentOrderData', respData);
console.log(orderObj);
//navigate after successful placing of other
const alert = await this.alertCtrl.create({
cssClass: 'my-custom-class',
header: 'Status',
message: ' <strong>Transaction successful</strong>!',
buttons: [
{
text: 'Okay',
handler: () => {
this.route.navigate(['/menu/order']);
}
}
]
});
await alert.present()
this.route.navigate(['/menu/order']);
}).catch((error) => {
console.log('Problem with placing order', error);
});
});
} else {
browser.close();
console.log("Transaction fail");
}
browser.close()
}
})
}).catch(error => {
// Error or invalid paymentObject passed in
console.log("error", error);
})
});
}
});
setTimeout(() => {
this.loading.dismiss();
}, 5000);
}
交易成功后下单服务页面
placeOrder(orderDataObj){
let headers = new HttpHeaders ({
'Content-Type': 'application/x-www-form-urlencoded'
});
let orderData = this.JSON_to_URLEncoded(orderDataObj);
this.apiUrl = `${this.siteUrl}${this.woocommercePath}orders?consumer_key=${this.consumerKey}&consumer_secret=${this.consumerSecret}`;
console.log('API URL for order: ', this.apiUrl);
return new Promise ((resolve) => {
this.orderResp = this.http.post(this.apiUrl,orderData, {headers});
this.orderResp.subscribe((responseData) => {
resolve(responseData);
});
});
}
【问题讨论】: