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:
A successful response returns confirmation of the transaction, with the approved state and a transaction ID. See the complete list of response values in the Payments API Reference.
Have a look at the response docs specifically:
id string
The ID of the payment. Read only.
intent enum
The payment intent. Value is: sale. Makes an immediate payment. authorize. Authorizes a payment for capture later. order. Creates an order. Possible values: sale, authorize, order.
payer object
The source of the funds for this payment. Payment method is PayPal Wallet payment or bank direct debit.
application_context object
Use the application context resource to customize payment flow experience for your buyers.
transactions array (contains the transaction object)
An array of payment-related transactions. A transaction defines what the payment is for and who fulfills the payment. For update and execute payment calls, the transactions object accepts the amount object only.
state enum
The state of the payment, authorization, or order transaction. Value is:
created. The transaction was successfully created.
approved. The customer approved the transaction. The state changes from created to approved on generation of the sale_id for sale transactions, authorization_id for authorization transactions, or order_id for order transactions.
failed. The transaction request failed. Read only.
Possible values: created, approved, failed.
experience_profile_id string
The PayPal-generated ID for the merchant's payment experience profile. For information, see create web experience profile. note_to_payer string A free-form field that clients can use to send a note to the payer. Maximum length: 165.
redirect_urls object
A set of redirect URLs that you provide for PayPal-based payments.
failure_reason enum
The reason code for a payment failure. Read only.
Possible values: UNABLE_TO_COMPLETE_TRANSACTION, INVALID_PAYMENT_METHOD, PAYER_CANNOT_PAY, CANNOT_PAY_THIS_PAYEE, REDIRECT_REQUIRED, PAYEE_FILTER_RESTRICTIONS.
create_time string
The date and time when the payment was created, in Internet date and time format. Read only.
update_time string
The date and time when the payment was updated, in Internet date and time format. Read only.
links array (contains the link_description object)
An array of request-related HATEOAS links. Read only.
You'll definitely be looking for the state
to be approved
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With