Paypal Shopping cart custom create order objects and user details

两盒软妹~` 提交于 2020-01-25 01:07:22

问题


I have a shopping cart that holds an array or my objects. I have all my custom user details serialized with a form and jQuery. I would like to insert the user data I got from my user details form (maybe I use payer or payer_info? Object. Also, I would like to insert my items to the PayPal

CreateOrder:        actions.order.create({

I am guessing I do it like this?

"item_list": {
"items": [
{
"name": "hat",
"description": "Brown color hat",
"quantity": "5",
"price": "3",
"tax": "0.01",
"sku": "1",
"currency": "USD"
},
{
"name": "handbag",
"description": "Black color hand bag",
"quantity": "1",

OR maybe in

 "data": { 

and I can have my own custom objects for the PayPal order class. Could anyone give me an example or more input on how I will do this? In the developer.paypal.com/docs I have been reading pretty much all the different project SDKs for JavaScript / PHP I would like to use my JavasSript to insert the information

This is what I have

    $fname = $_POST['txtFirstname'];
    $lname = $_POST['txtLastname'];
    $email = $_POST['txtEmail'];
var totalPrice = <?php echo $newTotal; ?>

paypal.Buttons({
    createOrder: function(data, actions) {
        // setup transaction
        return actions.order.create({
            payer: {
                name:
            },
            purchase_units: [{
               amount: {
                   value: totalPrice
               } 
            }]
        });
    },

回答1:


It could be done like this:

actions.order.create({
                //prefer: 'return=representation',
                application_context: {
                    //Accept URL
                    //return_url: successOrderUrl,
                    //Cancel URL
                    //cancel_url: cancelOrderUrl,
                    brand_name: "Company Name",
                    user_action: "PAY_NOW"
                },
                purchase_units: [{
                    amount: {
                        currency_code: 'EUR',
                        value: net_total,
                        breakdown: {
                            item_total: {
                                currency_code: 'EUR',
                                value : sub_total
                            },
                            tax_total: {
                                currency_code: 'EUR',
                                value: vat_amt
                            }
                        }
                    }
                }],
                payer: {
                    name: {
                        given_name: given_name,
                        surname: surname
                    },
                    email_address: email_address
                }
            });


来源:https://stackoverflow.com/questions/54820720/paypal-shopping-cart-custom-create-order-objects-and-user-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!