Skip to content

Instantly share code, notes, and snippets.

@enappd
Created May 9, 2019 18:05
Show Gist options
  • Save enappd/b196c8ce705b776c898be341974c56b9 to your computer and use it in GitHub Desktop.
Save enappd/b196c8ce705b776c898be341974c56b9 to your computer and use it in GitHub Desktop.
Ionic 4 PWA Paypal payment implementation
import { Component } from '@angular/core';
@Component({
selector: 'app-paypal',
templateUrl: 'paypal.page.html',
styleUrls: ['paypal.page.scss'],
})
export class PaypalPage {
paymentAmount: string = '3.33';
currency: string = 'USD';
currencyIcon: string = '$';
constructor() {
let _this = this;
setTimeout(() => {
// Render the PayPal button into #paypal-button-container
window.paypal.Buttons({
// Set up the transaction
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: _this.paymentAmount
}
}]
});
},
// Finalize the transaction
onApprove: function (data, actions) {
return actions.order.capture()
.then(function (details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
})
.catch(err => {
console.log(err);
})
}
}).render('#paypal-button-container');
}, 500)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment