【问题标题】:how to redirect back to my ionic app from a payment site如何从支付网站重定向回我的 ionic 应用程序
【发布时间】: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);
    });
  });

}

【问题讨论】:

    标签: angular ionic-framework


    【解决方案1】:

    几天前,即使我也面临同样的问题,从技术上讲,当移动/智能手机上运行的 ionic apk 文件没有运行任何端口号时,即 http://localhost/dashboard 而不是 http://localhost:8100/dashboard。

    所以将重定向 url 指定为 redirect_url: "http://localhost/home"

    或返回到付款开始的同一窗口/页面,指定为 redirect_url:window.location.href,

    然后您将能够重定向回 ionic 应用程序。

    【讨论】:

      【解决方案2】:

      我认为你做错了;当交易成功时,支付网站将在 webhook URL 上通知您,该 URL 应该在您的服务器上,因为它们是一个发布请求。您不能将发布请求直接发送到您的客户端(浏览器/IONIC 客户端),因为它们不应该充当 Web 服务器。 一个简单的解决方案是在您的服务器上创建一个接收响应的 URL,然后将用户重定向到您的 Web 应用程序(不确定它是否与 IONIC 一起使用):否:

      http.post('/rave-callback',function(req,res){ 
      // you can store the payment details in the db if you need to
         res.redirect('http://localhost:8100/home')
      })
      

      在您的 IONIC 应用中,您必须将 redirect_url 更改为 redirect_url: "http://my-server-url.com/rave-callback

      更多信息在这里:https://medium.com/@jake_parkers/3d-secure-guidelines-9e17f9a6cf32

      【讨论】:

      • 感谢您的回答先生,我实际上使用 WordPress 作为我的后端,我希望在付款后重定向,以便可以将下订单的客户发送到我的 woocommerce。让我更新我的问题
      【解决方案3】:

      我们没有完整的故事,所以我主要是猜测,所以我想这是你的问题:

      if (event.url.indexOf('http://localhost:8100/home') != -1) {
        if (event.url.includes("payment_successfull")) {
        }
      }
      

      你怎么知道支付网关会重定向到http://localhost:8100/home?它不起作用,因为这只是您的本地服务。如果您在支付网关提供商中配置它,则需要更改它。

      你最好的选择(我所做的)是把它留在它已经有的任何成功页面,这个页面应该有一些关键字,你可以使用这个功能来检查event.url.includes("your keyword here")

      或者,如果您必须填写一个值,请使用他们的页面并在末尾添加一个带有关键字的参数:www.url.com?status=payment_successfull

      【讨论】:

      • 感谢您的回答先生,我已经更新了我的问题。我实际上想要重定向到我的应用程序,然后我会在将客户订单发送到 WordPress 之前向用户显示成功警报。但我总是在支付网关网站上支付成功后重定向股票,但是当我使用网址时,它会成功重定向。
      • @GabrielGeelario 你不能按照这个词的常识重定向到你的应用程序。如果您使用应用内浏览器打开支付网关,您应该能够监听 url 的变化并关闭浏览器(因此应用程序将再次处于活动状态)。或者您可以使用深度链接插件,但设置需要更多时间。
      • 感谢先生的支持
      猜你喜欢
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2014-10-27
      • 2016-10-29
      • 2017-07-26
      • 2020-05-17
      相关资源
      最近更新 更多