Search code examples
javascriptpaypalpaypal-sandboxpaypal-rest-sdk

Paypal Smart Buttons digital goods


I'm using the Paypal Smart Buttons for reciving money to integrate in my digital platform. I'm not selling a phisical goods, but a Service/Digital Good.

I have followed the tutorial from the Paypal website and by looking the Paypal web documentation i have created this order :

order = actions.order.create({
    application_context: {
        locale : "ITA",
        shipping_preference:"NO_SHIPPING"
    },
    purchase_units: [{
        description:"BLA BLA",

        items:[
            {
                name: "BLA BLA",
                category:"DIGITAL_GOODS",
                quantity:"1",
                unit_amount :{
                    currency_code:"EUR",
                    value : "5.00"
                }
            }
        ],

        amount: {
            currency_code: "EUR",
            value: 5.00
        }
    }]
});

When i try it, i recive this error ( By Google Chrome Dev Tool Console )

POST https://www.sandbox.paypal.com/v2/checkout/orders 422 (Unprocessable Entity)

I have tryed to remove the item parameter, by doing that i do not have any problem by paying, but i'm not sure that is right for my case, that i'm selling a Service/Digital Good.

Which is the right way to do it?


Solution

  • You should click to read the body of the 422 response in Dev Tools; it contains a message with full information about the problem.

    You are missing an amount breakdown with an item_total, which is required when passing line items.

    See the documentation about this required parameter: https://developer.paypal.com/docs/api/orders/v2/#definition-item

        amount: {
            currency_code: "USD",
            value: '5.00',
            breakdown: {
                item_total: {
                    currency_code: "USD",
                    value: '5.00',
                }
            }
        }