I'm using Paypal Plus in my angular Project. Everything thing works fine.
How can I recognize that the payment was made successfully? Which data must I save in my database. In short which data am I waiting for in success?
<div id="payments-container"></div>
export class PaypalComponent implements OnInit {
paypalConfig = {
env: 'sandbox',
client: {
sandbox: 'ATvgtyEZznsHf...',
production: '<insert production client id>'
},
style: {
layout: 'vertical',
label: 'pay',
size: 'responsive',
shape: 'rect',
color: 'gold'
},
commit: true,
payment: (data, actions) => {
return actions.payment.create({
payment: {
transactions: [{
amount: {
total: 10.5,
currency: "EUR",
}
}]
}
});
},
onAuthorize: (data, actions) => {
return actions.payment.execute().then((response) => {
console.log('response', response);
console.log('data', data);
console.log('actions', actions);
});
},
onCancel: (data, actions) => {
console.log('Canceled!');
}
};
ngOnInit() {
paypal.Button.render(this.paypalConfig, '#payments-container');
}
}
From docs:
Have a look at the response docs specifically:
You'll definitely be looking for the
state
to beapproved
.Depending on your auditing needs, you may wish to save any or all of the other fields. id, intent, payer, transactions, and failure_reason at minimum are all probably worth considering.