Get PayPal Transaction ID on Ionic

0

I'm using PayPal in my project following this documentation .

My question is: how do I get the transaction ID after my payment? My code is:

this.payPal.init({
      PayPalEnvironmentProduction: ''
      PayPalEnvironmentSandbox: 'mySandbox',
    }).then(() => {
      this.payPal.prepareToRender('PayPalEnvironmentSandbox', new PayPalConfiguration({
        acceptCreditCards: false,
        languageOrLocale: 'pt-BR',
        merchantName: (this.produto.nom_produto),
        merchantPrivacyPolicyURL: '',
        merchantUserAgreementURL: ''
      })).then(() => {
        let detail = new PayPalPaymentDetails('1.00', '0.00', '0.00');
        let payment = new PayPalPayment('1.00', 'BRL', 'Produto', 'Sale', detail);
        this.payPal.renderSinglePaymentUI(payment).then((response) => {
          console.log('pagamento efetuado');
          this.createCode();
          let toast = this.toastCtrl.create({ duration: 3000, position: 'bottom' });
          toast.setMessage('Pagamento efetuado com sucesso');
          toast.present();
        }, () => {
          console.log('erro ao renderizar o pagamento do paypal');
        })
      })
    })
  }

In the documentation says:

this.payPal.renderSinglePaymentUI(payment).then(() => {
      // Successfully paid

      // Example sandbox response
      //
      // {
      //   "client": {
      //     "environment": "sandbox",
      //     "product_name": "PayPal iOS SDK",
      //     "paypal_sdk_version": "2.16.0",
      //     "platform": "iOS"
      //   },
      //   "response_type": "payment",
      //   "response": {
      //     "id": "PAY-1AB23456CD789012EF34GHIJ",
      //     "state": "approved",
      //     "create_time": "2016-10-03T13:33:33Z",
      //     "intent": "sale"
      //   }
      // }
    }, () => {
      // Error or render dialog closed without being successful
    });

But I'm not exactly sure how to add these details ( id , create_time , etc) to my project.

    
asked by anonymous 03.12.2018 / 16:11

1 answer

0

Since the response is in the JSON format, you can capture the id as follows:

this.payPal.renderSinglePaymentUI(payment).then((res) => {
  console.log('pagamento efetuado');
  this.createCode();
  let toast = this.toastCtrl.create({ duration: 3000, position: 'bottom' });
  toast.setMessage('Pagamento efetuado com sucesso');
  toast.present();

  let id = res.response.id;
  console.log(id);

}, () => {
  console.log('erro ao renderizar o pagamento do paypal');
})
    
05.12.2018 / 20:50