Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70435

How redirect back to my ionic App from external service

$
0
0

.Good day everyone one. Please I need your help. I am implementing a payment gateway in my app and when the pay_Now button is clicked it redirects users to the payment gateway site to fill in their debit card credentials but the issue I am currently having is how to redirect users back to my app after successful or failed transaction. Also, what will be my ionic callback URL. Here is my code below. Thanks


     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_phone: this.user.billing_phone,
                      currency: "NGN",
                      txref: "rave-123456",
                      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("loadstop")
                            .subscribe((event: InAppBrowserEvent) => {
                              if(event.url.indexOf('https://your-callback-url') != -1) {
                                if(this.rave.paymentStatus('url') == 'failed') {
                                  console.log("failed Message");
                                }else {
                                  console.log("Transaction Succesful");
         
                                  // Place order after payment successfully
         
                                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((respData) => {
                                  this.storage.clear();
                                  this.storage.set('currentOrderData', respData);
                                  console.log(orderObj);
                                  //navigate after successful placing of other
                                  this.route.navigate(['/menu/order'])
         
                                  }).catch((error) => {
                                    console.log('Problem with placing order', error);
                                  });
                                });
              
                                }
                                browser.close()
                              }
                            })
                      }).catch(error => {
                        // Error or invalid paymentObject passed in
                        console.log ("error", error);
                      })
                  });
                  }

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 70435

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>