I'm integrating the new Smart Buttons into my website. I want to specify a no_shipping option, so that the user would not be prompted for their address on PayPal pages
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: '0.01'
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
How do I implement it? I do not get it.
The v2/orders application_context object is documented here.
purchase_units: [{
amount: {
value: '0.01'
},
}],
application_context: {
shipping_preference: 'NO_SHIPPING'
}
Related
Can somebody tell me why? This is a simple integration of paypal sdk for javascript. And It is working fine except that the event bellow onShippingChange is never fired. I've searching this for 2 days now. I need to update my price according to the user address.
src="https://www.paypal.com/sdk/js?client-id=XXXXXXXXX"> // Required. Replace SB_CLIENT_ID with your sandbox client ID.
</script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
console.log('createOrder ' + data);
return actions.order.create({
application_context : {
shipping_preference: 'SET_PROVIDED_ADDRESS'
},purchase_units: [{
shipping: {
address: {
address_line_1: '555 example bs',
admin_area_2: 'San bastard',
admin_area_1: 'CA',
postal_code: '95111',
country_code: 'CA'
}
},
amount: {
value: '0.01'
}
}]
});
},
onApprove: function(data, actions) {
console.log('onApprove ' + data);
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
},
onClientAuthorization: (data) => {
console.log('onClientAuthorization - you should probably inform your server about completed transaction at this point', data);
this.showSuccess = true;
},
onShippingChange: (data, actions) => {
// this event is never fired no matter what I do
console.log('onShippingChange - Shipping information have changed', data, actions);
},
onCancel: (data, actions) => {
console.log('OnCancel', data, actions);
},
onError: err => {
console.log('OnError', err);
},
onClick: (data, actions) => {
console.log('onClick', data, actions);
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
here is the solution of this question first of the shippings fees can only be managed after you enable it on your account (Login to PayPal >> Hover over to the profile name >> Account Settings >> Shipping >> Here you can create shipping profiles as per your requirements.) it will be available only for customer who pay from a paypal account. For any other payment you won't be able to manage it.
Regards
I am using PayPal smart button for payments in JavScript. Currently, I am using sandbox accounts to test.
This code gives an error
function addPaypal()
{
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
currency_code:'USD',
value: '30.00'
}
}]
});
},
onApprove: function(data, actions) {
return actions.order.capture().then(function(details) {
console.log(details);
});
},
onCancel: function (data) {
},
onError: function (err) {
console.log(err)
}
}).render('#paypal-button'); // Display payment options on your web page
}
The error I am getting is
details.purchase_units.amount is undefined
I am using two sandbox accounts. One from which I created an app and using its credentials. And other one from which I am paying the amount for testing.
I checked both accounts. I am not getting more details of the error.
I'm trying to integrate PayPal and I get the error below
You can test the code here with any PayPal sandbox buyer account:
Codepen
Here is the code I'm using
paypal.Buttons({
createOrder: function (data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: '5.00'
}
}]
});
},
onApprove: function (data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(details => {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');
more about the error
Testing your Codepen from the Network tab, you are getting a COMPLIANCE_VIOLATION -- probably due to the country of the account you are testing with not being properly set up in sandbox.
Try simply using a different country for your testing within sandbox. Create a new business account at https://www.paypal.com/signin?intent=developer&returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Faccounts%2F , and then create a new REST app with a new ClientID/Secret for it.
Here is my code. I want to use fixed integer value instead of "package_select". How can I do this...
<script>
paypal.Buttons({
createOrder: function(data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: document.getElementById("package_select").value
}
}]
});
},
onApprove: function(data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
// This function shows a transaction success message to your buyer.
alert('Transaction completed by ' + details.payer.name.given_name);
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
amount: {
value: REPLACE_WITH_FIXED_INTEGER_VALUE
}
See a full demo at https://developer.paypal.com/demo/checkout/#/pattern/client
I am new to PayPal integration. I need to get the order Id for getting the details of the transaction and wants to display the transaction details to the customer on another page.
Following is the javascript code. The following code shows OrderId = 0.
<script>
paypal.Buttons({
createOrder: function (data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
application_context: {
return_url: 'https://example.com',
cancel_url: 'https://example.com'
},
purchase_units: [{
amount: {
currency_code: 'USD',
value: '<%=bookingAmount%>'
}
}]
});
},
onApprove: function (data, actions) {
// Capture the transaction funds
return actions.order.capture().then(function () {
// Show a confirmation to the buyer
alert('Transaction complete!' & data.orderID);
});
}
}).render('#paypal-button-container'); //This function displays Smart Payment Buttons on your web page.
</script>
Question: The above code does not work as required. How to resolve this?
Using the following line of code, I was able to retrieve details of the transaction. -
"return actions.order.capture().then(function (details)"
Following is the complete running code -
paypal.Buttons({
createOrder: function (data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
currency_code: 'USD',
value: '<%=bookingAmount%>'
}
}]
});
},
onApprove: function (data, actions) {
// Capture the transaction funds
return actions.order.capture().then(function (details) {
console.log(JSON.stringify(details));
});
}
}).render('#paypal-button-container');