Issue
I'm making a Paypal checkout button with ngx-paypal for Angular that shows up when I get to the cart and proceed to the checkout, but I don't know how to "give" the shipping address to the button instead of the default one, so when someone clicks on the Checkout Paypal button they get the address that I choose to pass in my typescript. I want to to the same thing as shippingAddressOverride. This is the code to show how I configure the Paypal button:
this.payPalConfig = {
currency: 'EUR',
clientId: this.parameters.clientidpaypal,
createOrderOnClient: (data) => <ICreateOrderRequest>{
intent: 'CAPTURE',
purchase_units: [{
amount: {
currency_code: 'EUR',
value: this.item.total.toString().replace(",", "."),
breakdown: {
item_total: {
currency_code: 'EUR',
value: this.item.total.toString().replace(",", ".")
}
}
}
}],
}
};
Solution
An Orders create request body is documented here.
Here's some example JSON.
{
"payer": {
"name": {
"given_name": "John",
"surname": "Doe"
},
"email_address": "customer@example.com"
},
"purchase_units": [
{
"shipping": {
"address": {
"address_line_1": "2211 N First Street",
"address_line_2": "Building 17",
"admin_area_2": "San Jose",
"admin_area_1": "CA",
"postal_code": "95131",
"country_code": "US"
}
},
Customers can override the provided information if they choose a different address during checkout, so you must store the address received in the response and use that if it is different.
If you need to force a particular address you pre-collected to be used, there is a SET_PROVIDED_ADDRESS parameter for that -- but such forcing will cause the checkout to fail with an error if the address you are attempting to force is not valid.
Ideally, the PayPal option should be presented earlier in a flow before a shipping address is collected, so that you can potentially collect the shipping address from something that's already stored in the PayPal account, rather than the other way around and having the user type one manually into your site. This is the best flow for normal e-commerce, as it allows payers to complete their checkout more quickly (with less manual entry) and thus results in more conversion (more completed sales, less drop-off / mind-changing)
There is an onShippingChange callback you can implement to check a newly-selected address in real time, return whether it is okay or not (for example if you don't ship to the selected country), and patch the order details if necessary. This is more complex to integrate, but is necessary if you need to perform such adjustments based on a selected address.
Answered By - Preston PHX
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.