I am using @paypal/react-paypal-js to display the PayPal button and create an order. I am specifically interested in processing credit card payments. Once my Django backend receives the payment capture completion event from PayPal, it needs to store information about a particular user owning a particular product. Hence, the notification has to contain both the user ID (i.e. email) and the product ID.
This is how I am trying to pass these two pieces of information in my frontend:
createOrder={(data, actions) => {
return actions.order.create({
purchase_units: [
{
amount: {
value: course.price,
currency_code: course.currency,
},
custom_id: course.title,
},
],
payer: {
email_address: userEmail,
}
});
}}
Here is my onApprove:
onApprove={(data, actions) => onSuccess(data, actions)}
where onSuccess is implemented as follows:
const onSuccess= (data, actions) => {
return actions.order.capture().then(
function (details) {
toast.success('Payment completed. Thank you, ' +
details.payer.name.given_name,
{duration: 6000})
}
);
}
The user email address is automatically filled into the form. However, the webhook_event event in the server does not contain this information. That is, there is no payer field inside resource in webhook_event.
I also tried adding payee: {email_address: userEmail} into purchase_units, but then there was no option to pay with credit card after pressing on the PayPal button. That option got replaced by the option to create a PayPal account.
How can I pass the two pieces of information so as to get them in webhook_event? (I would like to avoid the ugly solution of concatenating both pieces into custom_id)