- 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.

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Paypal subscription Api in REST APIs
- Selected Shipping Method amount not updating to cart for card payment in SDKs
- ExpressCheckout to REST API - Is Partner Program Now Required to Host Simple 3rd Party Transactions? in REST APIs
- Are there any restrictions to charge using only html, vanilla javascript and php with rest api? in REST APIs
- Disable shipping address in Pay with Credit or Debit card button integration in SDKs