Home:ALL Converter>How to Use Angular HTTP instead of Ionic Native HTTP

How to Use Angular HTTP instead of Ionic Native HTTP

Ask Time:2018-10-04T00:39:39         Author:Vineet Mehra

Json Formatter

I was integrating a payment gateway page in my Ionic 3 application. I was successful in integrating it using ionic native http but the problem is that it sometimes works and sometimes doesn't. I have heard that angular http works better.

Can anyone please make the changes in below code and tell me how can I fix it so it works.

import {Component} from '@angular/core';
import Instamojo from 'instamojo-nodejs';
import {InAppBrowser} from '@ionic-native/in-app-browser';
import {HTTP} from '@ionic-native/http';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import 'rxjs/add/operator/map';
import { LoadingController } from 'ionic-    angular/components/loading/loading-controller';
import { ContactusPage } from '../contactus/contactus';
//import { ProfilePage } from '../profile/profile';

@Component({
  selector: 'page-new-transaction',
  templateUrl: 'new_transaction.html'
})
export class NewTransactionPage {
  amount;
  instamojoClient;

  constructor(public navCtrl: NavController, public navParams: NavParams, private iab: InAppBrowser, private http: HTTP,public loadingCtrl:LoadingController) {
    this.instamojoClient = new Instamojo(http, iab, 'http://xxxxx.com/access_token.php');
  }

  contactNow() {
    this
    .navCtrl    
    .push(ContactusPage);
  }

  payNow() {
    let loading = this.loadingCtrl.create({
      spinner: 'hide',
      content: `
        <div class="custom-spinner-container">
          <div class="custom-spinner-box"><img src="assets/imgs/loading.gif"></div>
          </div>`,
      duration: 5000
    });
    var data = this.instamojoClient.getPaymentFields();
    data.purpose = "Account";            // REQUIRED
    data.amount = 750;                  // REQUIRED
    // do not change this
    data.redirect_url = "http://localhost";
    loading.present().then(res=>{
      this.instamojoClient.payNow(data).then(response => {
        // alert("Payment complete: " + JSON.stringify(response));
        loading.dismiss();
      }).catch(err => {
        loading.dismiss();
        // alert("Payment failed: " + JSON.stringify(err));
        throw err;
      });
      //call the Safari View Controller

      // end of safari view controller

    })


  }



 }

Author:Vineet Mehra,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52631863/how-to-use-angular-http-instead-of-ionic-native-http
yy