Yevgeniy Afanasyev
Yevgeniy Afanasyev

Reputation: 41430

PayPal Checkout - Set up the transaction shipping address and shipping amount

PayPal Checkout

Set up the transaction

allow to set parameters like mount.value: '0.01 and other things like so

<script>
  paypal.Buttons({
    createOrder: function(data, actions) {
      // Set up the transaction
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '0.01'
          }
        }]
      });
    }
  }).render('#paypal-button-container');
</script>

But I need to set up the shipping address and shipping amount. How can I do it?

PS I found Orders API Integration Guide for Express Checkout. It has all the options

like details.shipping = 0.00 ...

and shipping_address, but it does not work with PayPal Checkout example. Is it because I'm testing in the sendbox?

Upvotes: 3

Views: 1765

Answers (2)

Yevgeniy Afanasyev
Yevgeniy Afanasyev

Reputation: 41430

basically, the whole idea of placing these details into <script> was a mistake. It should all go from server to server and html should only reflect the reference code.

for PHP users, look into

use PayPalCheckoutSdk\Core\PayPalHttpClient;
use PayPalCheckoutSdk\Core\PayPalEnvironment;
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;

Upvotes: 1

Priyesh Doshi
Priyesh Doshi

Reputation: 380

Below is the full list of parameters you can set over:

    {
       "intent": "AUTHORIZE",
       "application_context": {
    "return_url": "https://example.com",
    "cancel_url": "https://example.com",
    "brand_name": "EXAMPLE INC",
    "locale": "en-US",
    "landing_page": "BILLING",
    "shipping_preference": "SET_PROVIDED_ADDRESS",
    "user_action": "CONTINUE"
  },
  "purchase_units": [
    {
      "reference_id": "PUHF",
      "description": "Sporting Goods",
      "custom_id": "CUST-HighFashions",
      "soft_descriptor": "HighFashions",
      "amount": {
        "currency_code": "USD",
        "value": "230.00",
        "breakdown": {
          "item_total": {
            "currency_code": "USD",
            "value": "180.00"
          },
          "shipping": {
            "currency_code": "USD",
            "value": "30.00"
          },
          "handling": {
            "currency_code": "USD",
            "value": "10.00"
          },
          "tax_total": {
            "currency_code": "USD",
            "value": "20.00"
          },
          "shipping_discount": {
            "currency_code": "USD",
            "value": "10"
          }
        }
      },
      "items": [
        {
          "name": "T-Shirt",
          "description": "Green XL",
          "sku": "sku01",
          "unit_amount": {
            "currency_code": "USD",
            "value": "90.00"
          },
          "tax": {
            "currency_code": "USD",
            "value": "10.00"
          },
          "quantity": "1",
          "category": "PHYSICAL_GOODS"
        },
        {
          "name": "Shoes",
          "description": "Running, Size 10.5",
          "sku": "sku02",
          "unit_amount": {
            "currency_code": "USD",
            "value": "45.00"
          },
          "tax": {
            "currency_code": "USD",
            "value": "5.00"
          },
          "quantity": "2",
          "category": "PHYSICAL_GOODS"
        }
      ],
      "shipping": {
        "method": "United States Postal Service",
        "address": {
          "name": {
            "give_name":"John",
            "surname":"Doe"
          },
          "address_line_1": "123 Townsend St",
          "address_line_2": "Floor 6",
          "admin_area_2": "San Francisco",
          "admin_area_1": "CA",
          "postal_code": "94107",
          "country_code": "US"
        }
      }
    }
  ]
}

Upvotes: 5

Related Questions