- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am struggling to get "discount" to work in the "breakdown" field when I am creating an order via the Javascript SDK (smart payment buttons).
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
description: "My awesome product",
amount: {
currency_code: "USD",
value: "4.99",
breakdown: {
item_total: {
currency_code: 'USD',
value: "3.76"
},
discount: {
currency_code: "USD",
value: "1.23"
}
}
},
custom_id: "ORDER-0001234"
}],
application_context: {
shipping_preference: "NO_SHIPPING"
}
});
},
The error I see is "AMOUNT_MISMATCH".
According to the API documentation
https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
And this Github ticket
https://github.com/paypal/paypal-checkout-components/issues/1016
The functionality should be available since 1 April 2020.
Any suggestions on what I am doing wrong?
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Rubber ducking really is a thing. I just managed to solve my own problem, which was that the line-item is the original price (4.99) and the amount value should be the original price (4.99) minus the discount (1.23), which is 3.76
This code works:
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
description: "My awesome product",
amount: {
currency_code: "USD",
value: "3.76",
breakdown: {
item_total: {
currency_code: 'USD',
value: "4.99"
},
discount: {
currency_code: "USD",
value: "1.23"
}
}
},
custom_id: "ORDER-0001234"
}],
application_context: {
shipping_preference: "NO_SHIPPING"
}
});
},
And for anyone else wanting to know how to get discounts working for subscriptions, you are able to specify some plan details to override the specified plan:
createSubscription: function(data, actions) {
return actions.subscription.create({
/* Creates the subscription */
plan_id: 'MY PLAN ID',
custom_id: "ORDER-00001234",
plan: {
billing_cycles: [
{
frequency: {
interval_unit: "MONTH",
interval_count: 1
},
tenure_type: "REGULAR",
sequence: "1",
pricing_scheme: {
fixed_price: {
value: "10",
currency_code: "USD"
}
}
}]
},
application_context: {
shipping_preference: "NO_SHIPPING"
}
});
},
See: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create
An inline plan object to customise the subscription. You can override plan level default attributes by providing customised values for the subscription in this object.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Rubber ducking really is a thing. I just managed to solve my own problem, which was that the line-item is the original price (4.99) and the amount value should be the original price (4.99) minus the discount (1.23), which is 3.76
This code works:
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
description: "My awesome product",
amount: {
currency_code: "USD",
value: "3.76",
breakdown: {
item_total: {
currency_code: 'USD',
value: "4.99"
},
discount: {
currency_code: "USD",
value: "1.23"
}
}
},
custom_id: "ORDER-0001234"
}],
application_context: {
shipping_preference: "NO_SHIPPING"
}
});
},
And for anyone else wanting to know how to get discounts working for subscriptions, you are able to specify some plan details to override the specified plan:
createSubscription: function(data, actions) {
return actions.subscription.create({
/* Creates the subscription */
plan_id: 'MY PLAN ID',
custom_id: "ORDER-00001234",
plan: {
billing_cycles: [
{
frequency: {
interval_unit: "MONTH",
interval_count: 1
},
tenure_type: "REGULAR",
sequence: "1",
pricing_scheme: {
fixed_price: {
value: "10",
currency_code: "USD"
}
}
}]
},
application_context: {
shipping_preference: "NO_SHIPPING"
}
});
},
See: https://developer.paypal.com/docs/api/subscriptions/v1/#subscriptions_create
An inline plan object to customise the subscription. You can override plan level default attributes by providing customised values for the subscription in this object.
![](/skins/images/BC6528466832E4059F46B7B785A17D7B/responsive_peak/images/icon_anonymous_message.png)
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Android WebViews issue when doing seller onboarding in REST APIs
- How to get the merchant-id or how do i get the id that connects my user to get paid via Paypal in REST APIs
- PayPal debug id: f95202622d65cI in Sandbox Environment
- Javascript SDK throws 400 when trying to create order using Debit or Credit card in PayPal Payments Standard
- component into a button and use 3D Secure in the javascript SDK in SDKs