cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript SDK and discount/coupons/promos

Options
Go to solution
DKTim
New Community Member
Posted on

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Solved

Javascript SDK and discount/coupons/promos

Options
Go to solution
DKTim
New Community Member

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.

 



View solution in original post

1 REPLY 1
Solved

Javascript SDK and discount/coupons/promos

Options
Go to solution
DKTim
New Community Member

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.

 



View solution in original post

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.