Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specific line items in paypal checkout

I'm trying to set up PayPal to take payments on my website, and I would like to specify line items for the payments (Using the new SDK, not the javascript version)

I have tried going through the API documentation listed here: https://developer.paypal.com/docs/api/orders/v2/. However, it says I either have invalid syntax or I am missing a field.

<head>
<script>
paypal.Buttons({
    createOrder: function(data, actions) {
    return actions.order.create({
        purchase_units: [{
        amount: {
            currency_code: 'USD',
            value: '0.01',
            amount_breakdown: {

            }

          },
            items: {
                item: {
                    name: 'Cake',
                    quantity:'1',
                    unit_amount:{
                        currency_code:'USD',
                        value:'0.01'
                    }
                }
            }



    }],
        application_context: {
            shipping_preference: 'NO_SHIPPING',
        }

      });
    },
    onApprove: function(data, actions) {
    return actions.order.capture().then(function(details) {
            alert('Transaction completed by ' + details.payer.name.given_name);
            // Call your server to save the transaction
            return fetch('/paypal-transaction-complete', {
          method: 'post',
          body: JSON.stringify({
            orderID: data.orderID
          })
        });
      });
}
  }).render('#paypal-button-container');
</script>
</head>

<body>
<div id="paypal-button-container"></div>
</body>
like image 375
caleb Avatar asked Feb 11 '19 23:02

caleb


People also ask

How do I customize PayPal checkout?

Click your profile name in the top right corner of your account and then click Account Settings. From the left menu, click My selling tools. In the Selling online section, click the Update link next to Website preferences to see the Website Payment Preferences page.

Can I customize PayPal button?

PayPal button The default value is gold , but you can also set it to: black , blue , silver , or white . Overrides the shape of the button. The default value is softEdges , but you can also set it to hardEdges or rounded . Adds a label next to the button logo.

How do I add terms and conditions to PayPal?

Click into the “Terms and conditions” box. Type your disclaimer, which might include how many days a person has to return an item, what condition returned items must be in, warranty information and safety precautions.

What is the difference between PayPal Standard and Express checkout?

PayPal Express is very similar to PayPal Standard with one major difference: the checkout flow. PayPal Express avoids the IPN issues that arise with PayPal Standard. Customers will be directed to PayPal from your site, but they don't complete checkout at PayPal.


1 Answers

This is correct code for me for purchase_units. Got it from here:

https://github.com/paypal/paypal-checkout-components/issues/1016

purchase_units: [{
                amount: {
                    value: '7',
                    currency_code: 'USD',
                    breakdown: {
                        item_total: {value: '7', currency_code: 'USD'}
                    }
                },
                invoice_id: 'muesli_invoice_id',
                items: [{
                    name: 'Hafer',
                    unit_amount: {value: '3', currency_code: 'USD'},
                    quantity: '1',
                    sku: 'haf001'
                }, {
                    name: 'Discount',
                    unit_amount: {value: '4', currency_code: 'USD'},
                    quantity: '1',
                    sku: 'dsc002'
                }]
            }]
like image 65
G.F. Avatar answered Sep 28 '22 05:09

G.F.