- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using PayPal Express checkout Client-side REST for our eCommerce solution. I am wondering how I can pass shipping address from our website to PayPal, so we can have the shipping address confirmed by PayPal and be eligible for Seller Protection. For your reference I am using below code:
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
paypal.Button.render({
env: 'production', // Or 'sandbox'
client: {
sandbox: 'xxxxxxxxx',
production: 'xxxxxxxxx'
},
commit: true, // Show a 'Pay Now' button
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '1.00', currency: 'USD' }
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
// The payment is complete!
// You can now show a confirmation message to the customer
});
}
}, '#paypal-button');
</script>
Thanks for your help in advance.
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Finally It is worked. The issue is redirection is not working, So I replaced the redirection with HTML message. i.e.
Instead of:
window.location="https://mydomain.com/success.php";
Replaced code:
$("#message").html("Payment Successful!");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to add the shipping_address node to the transactions node in your JSON request. PayPal's API doc for creating a payment shows an example of this.
curl -v -X POST https://api.sandbox.paypal.com/v1/payments/payment \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token" \
-d '{
"intent": "sale",
"payer": {
"payment_method": "paypal"
},
"transactions": [
{
"amount": {
"total": "30.11",
"currency": "USD",
"details": {
"subtotal": "30.00",
"tax": "0.07",
"shipping": "0.03",
"handling_fee": "1.00",
"shipping_discount": "-1.00",
"insurance": "0.01"
}
},
"description": "The payment transaction description.",
"custom": "EBAY_EMS_90048630024435",
"invoice_number": "48787589673",
"payment_options": {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
"soft_descriptor": "ECHI5786786",
"item_list": {
"items": [
{
"name": "hat",
"description": "Brown hat.",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "USD"
},
{
"name": "handbag",
"description": "Black handbag.",
"quantity": "1",
"price": "15",
"tax": "0.02",
"sku": "product34",
"currency": "USD"
}
],
"shipping_address": {
"recipient_name": "Brian Robinson",
"line1": "4th Floor",
"line2": "Unit #34",
"city": "San Jose",
"country_code": "US",
"postal_code": "95131",
"phone": "011862212345678",
"state": "CA"
}
}
}
],
"note_to_payer": "Contact us for any questions on your order.",
"redirect_urls": {
"return_url": "https://example.com/return",
"cancel_url": "https://example.com/cancel"
}
}'
PayPal Partner and Certified Developer - Kudos are Greatly Appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your help, however a small problem. I modified the code and added shipping_address to my code. Now I am able to pass the shipping address to PayPal page.
Now the problem is: On success or Failure onAuthorize, onCancel, onError functions are not working/fired. PayPal popup is closed and my old page is displayed without PayPal button and without any redirection.
Below is my modified code:
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
paypal.Button.render({
env: 'production', // Or 'sandbox'
client: {
sandbox: 'xxxxxxxxx',
production: 'xxxxxxxxx'
},
commit: true, // Show a 'Pay Now' button
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: { total: '1.00', currency: 'USD' },
invoice_number: '48787589673',
item_list: {
items: [
{
name: 'hat',
description: 'Brown hat.',
quantity: '5',
price: '3',
tax: '0.01',
sku: '1',
currency: 'USD'
},
{
name: 'handbag',
description: 'Black handbag.',
quantity: '1',
price: '15',
tax: '0.02',
sku: 'product34',
currency: 'USD'
}
],
shipping_address: {
recipient_name: 'Brian Robinson',
line1: '4th Floor',
line2: 'Unit #34',
city: 'San Jose',
country_code: 'US',
postal_code: '95131',
phone: '011862212345678',
state: 'CA'
}
}
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
// The payment is complete!
// You can now show a confirmation message to the customer
window.location="https://mydomain.com/success.php";
});
},
onCancel: function(data, actions) {
/*
* Buyer cancelled the payment
*/
window.location="https://mydomain.com/failure.php";
},
onError: function(err) {
/*
* An error occurred during the transaction
*/
window.location="https://mydomain.com/failure.php";
}
}, '#paypal-button');
</script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Finally It is worked. The issue is redirection is not working, So I replaced the redirection with HTML message. i.e.
Instead of:
window.location="https://mydomain.com/success.php";
Replaced code:
$("#message").html("Payment Successful!");

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Selected Shipping Method amount not updating to cart for card payment in SDKs
- Error payment in PayPal Payments Standard
- PayPal Express Error #10413 when people use a discount code on my Magento2 store in PayPal Payments Standard
- ExpressCheckout to REST API - Is Partner Program Now Required to Host Simple 3rd Party Transactions? in REST APIs
- permission_denied response in call to patch order when paying by Card in Braintree Client-side Integration (JS, iOS, Android SDKs)