Search code examples
javascriptpaypal-sandbox

Paypal SDK, how to add Order details?


I am using paypal SDK Javascript to make an order to my page. I can't see anything in their documentation about how adding the order description, how can I ?

Paypal order summary

1

 paypal.Buttons({
            style: {
                shape: 'pill',
                color: 'gold',
                layout: 'vertical',
                label: 'paypal',
                height: 50,
            },


            createOrder: function (data, actions) {

                $.ajax
                ({
                    url: '@Url.Action("GetPaymentPrice", "Payment")',
                    method: "get",
                    data: { id: @Model.Id },
                    contentType: "application/json;charset=utf-8",
                    dataType: 'json',
                    beforeSend: function () {
                        $("#loaderDiv").show();
                    },
                    success: function (success) {
                        pricePaypal = success.Result.Total;
                    },
                    async: false,
                    error: function () {

                    }
                });


                return actions.order.create({
                    purchase_units: [{ "amount": { "currency_code": "EUR", "value": pricePaypal} }]
                });
            },

I tried to check a lot of help in google, paypal documentation, but found nothing about it.


Solution

  • Add an items array and required amount breakdown. The example from the documentation:

    createOrder: (data, actions) => {
          return actions.order.create({
             "purchase_units": [{
                "amount": {
                  "currency_code": "USD",
                  "value": "100",
                  "breakdown": {
                    "item_total": {  /* Required when including the items array */
                      "currency_code": "USD",
                      "value": "100"
                    }
                  }
                },
                "items": [
                  {
                    "name": "First Product Name", /* Shows within upper-right dropdown during payment approval */
                    "description": "Optional descriptive text..", /* Item details will also be in the completed paypal.com transaction view */
                    "unit_amount": {
                      "currency_code": "USD",
                      "value": "50"
                    },
                    "quantity": "2"
                  },
                ]
              }]
          });
        },