Shipping Options

Enable shipping changes during checkout

SDKLast updated: September 6th 2023, @ 12:43:42 pm


You can enable your buyers to update their shipping options during checkout. After adding the OnShippingChange callback to your integration, your buyers can:

  • Enter a new shipping address.
  • Select a local pickup option.
  • Select different shipping services.
  • Buy Online, Pick up In Store (BOPIS).

If a buyer updates their shipping options during checkout, the order must also update the OnShippingChange callback.

Note: In this documentation, we refer to both shipping and pickup as shipping option. The shipping option is represented by the object ShippingMethod.

Create an Order with shipping options

You can add shipping options to either a client-side or server-side integration.

Client-side integration

To provide shipping options to the buyer, add shipping options to the shipping object provided in the OrderRequest object and pass it inside the createOrder callback.

Make sure to have exactly one shipping option with selected: true as a default option. To support Buy Online, Pick up In Store (BOPIS) add only the .pickup shipping type ShippingMethod to the shipping options and set selected: true.

  1. Swift
  2. Obj-C
1createOrder: { action in
2 let order = OrderRequest(
3 intent: .authorize,
4 purchaseUnits: [
5 PurchaseUnit(
6 amount: PurchaseUnit.Amount(currencyCode: .usd, value: "5.00"),
7 shipping: PurchaseUnit.Shipping(
8 options: [
9 ShippingMethod(
10 id: "SHIP_123",
11 label: "2-day Shipping",
12 selected: true,
13 type: .shipping,
14 amount: UnitAmount(currencyCode: .usd, value: "2.00")),
15 ShippingMethod(
16 id: "PICKUP_123",
17 label: "Pickup in store",
18 selected: false,
19 type: .pickup,
20 amount: UnitAmount(currencyCode: .usd, value: "0.00"))
21 ],
22 ),
23 ),
24 ],
25 applicationContext: OrderApplicationContext(userAction: .payNow)
26 )
27 action.create(order: order)
28}

For more information on how to implement the createOrder callback, refer to the initialize SDK instructions.

Server-side integration

If you use a server-side integration, refer to the documentation for Server-side integration and use one of our APIs (NVP/SOAP, REST v1, or REST v2) to create an order with shipping options.

Implement the onShippingChange callback

Implement the onShippingChange callback to approve or reject a change a buyer makes to their shipping address or shipping option.

Add the onShippingChange callback

Depending on your integration, you need to add the onShippingChange callback to either the PaymentButtonContainer or CheckoutConfig.init() or Checkout.start().

Standard integration

Add the onShippingChange callback to PaymentButtonContainer.

  1. Swift
  2. Obj-C
1let paymentButton = PaymentButtonContainer()
2paymentButton.setup(
3 ...
4 onShippingChange: { change, action in
5 ...
6 }
7)

Advanced integration

If your integration programatically starts the SDK, you can add the onShippingChange callback to CheckoutConfig.init().

  1. Swift
  2. Obj-C
1let config = CheckoutConfig(
2 ...
3 onShippingChange: { change, action in
4 ...
5 }
6 ...
7)

Or you can add the onShippingChange callback when starting the checkout paysheet. Note: If you've already set the callback in CheckoutConfig.init(), setting it again here will overwrite the previous value. It is recommended that you only set it using one of these two ways.

  1. Swift
  2. Obj-C
1Checkout.start(
2 ...
3 onShippingChange: { change, action in
4 ...
5 }
6 ...
7)

Approve address or shipping option changes

You can approve the update a buyer makes to their address or shipping option.

  1. Swift
  2. Obj-C
1onShippingChange: { change, action in
2 action.approve()
3},
4onApprove: {},
5onCancel: {},
6onError: {}

Reject address or shipping option changes

You can reject an update to an address or shipping option that is not supported. This displays an error to the buyer that requires them to change their shipping option or address in order to proceed.

  1. Swift
  2. Obj-C
1onShippingChange: { change, action in
2 switch change.type {
3 case .shippingAddress:
4 if !yourSupportedListOfZipCode.contains(change.selectedShippingAddress.postalCode) {
5 action.reject()
6 }
7 default:
8 break
9 }
10}