1

I am using PayPal checkout for my angular 4 project.I want to make an API call after PayPal payment gets success, but actions.payment.execute().then not allowed to access any outside object.

Can I get any event for successful ??


onAuthorize: function (data, actions) {

    return actions.payment.execute().then(function () {
      //want to make an api call
                    });
                }
        }, '#paypal-button-container');
Zeeshan Arif
  • 509
  • 5
  • 15

1 Answers1

0

Based on the answer here Processing Paypal onAuthorize callback in Angular 4, you can dispatch CustomEvent:

document.querySelector('#paypal-button').dispatchEvent(new CustomEvent('onPaymentCompleted', { detail: {payment: JSON.stringify(payment)},bubbles: true }));

on Paypal buttom:

<div id="paypal-button" (onPaymentCompleted)="addNewContract($event)"></div>

and then you have an access to original context again:

addNewContract(event) {
    console.log(event.detail.payment);
    }
David Zencak
  • 137
  • 1
  • 10