Get Paypal Transaction ID on Ionic

Asked

Viewed 145 times

0

I am using Paypal in my following project this documentation.

My question is: how do I receive the transaction ID after payment made? 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 it 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 don’t know exactly how to add these details (id, create_time, etc) in my project.

1 answer

1


Whereas the answer is in the informed 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');
})
  • Thanks for respoonder, I can receive transaction ID which is like: PAY-72J79963NM5333513WLQVCVNHOW but when I check the transaction history of Paypal Developer, the transaction ID looks like: 3CC23774TG6379823 . How can I sync these different amounts? to confirm a payment via QR Code? Ids are different.

  • I never used the Paypal api, but from what I understand, to receive the transaction details, you need to use this method: https://developer.paypal.com/docs/api/payments/v1/#payment_get, informing the code "PAY-....". I believe the value you are seeking is the authorization id.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.