简体   繁体   中英

How can I pass order details to a PayPal smart button checkout

I'm building an ecommerce website with django and looking for a way to pass order details to the merchant account. I have tried this

 createOrder: function(data, actions) {
        return actions.order.create({
            purchase_units: [{
                amount: {
                    value: '30.11',
                },
                description: 'this is a description',
            }]
        });
    },

this method worked but i can only pass strings. I have tried to pass lists but it didn't work

        createOrder: function(data, actions) {
        return actions.order.create({
            purchase_units: [{
                amount: {
                    value: '30.11',
                },
                description: [{
                    order: "dress5",
                    price: "30"
                }]
            }]
        });
    },

any recommendations on what i should do?

Since you are using django, you should probably be creating and capturing the order on your backend with a REST API call--likely using the Checkout-Python-SDK in your case. You'll need to create two new routes, one for 'Create an Order' and one for 'Capture Order', documented here .

Then pair your two routes with the following HTML/JS approval front-end: https://developer.paypal.com/demo/checkout/#/pattern/server

(Either way, the object passed to an actions.order.create() is also a v2/checkout/orders request object , so all the same syntax applies.)


As for how to actually pass the details: if you specify an items array, the amount must have a breakdown object with an item_total that matches the sum, and its own sum must match the total amount value.

Here's a JSON example of a working purchase_units array from another question:

{
    "purchase_units":[{
        "amount":{
            "value":259.96,
            "currency_code":"USD",
            "breakdown":{
                "item_total":{
                    "currency_code":"USD",
                    "value":259.96
                }
            }
        },
        "items":[
            {
                "unit_amount":{
                    "currency_code":"USD",
                    "value":"49.99"
                },
                "quantity":"1",
                "name":"GB Stacked"
            },
            {
                "unit_amount":{
                    "currency_code":"USD",
                    "value":"79.99"
                },
                "quantity":"1",
                "name":"Stacked Jeans"
            },
            {
                "unit_amount":{
                    "currency_code":"USD",
                    "value":"49.99"
                },
                "quantity":"1",
                "name":"GB Stacked"
            },
            {
                "unit_amount":{
                    "currency_code":"USD",
                    "value":"79.99"
                },
                "quantity":"1",
                "name":"Stacked Jeans"
            }
        ]
    }]
}

This gives:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM