Skip to main content

Checkout Sheet Kit for Swift

Checkout Sheet Kit is an open-source Swift Package library that allows you to integrate Shopify's checkout in your mobile app. To get started, see our sample projects, or follow the steps below to integrate it into your own project.


  • Integrate Checkout Sheet Kit to your project
  • Present the checkout through a checkout URL or cart permalink

  • Swift 5.7+
  • iOS SDK 13.0+

Anchor to Step 1: Install the Checkout Sheet Kit as a package dependencyStep 1: Install the Checkout Sheet Kit as a package dependency

Package.swift

dependencies: [
.package(url: "https://github.com/Shopify/checkout-sheet-kit-swift", from: "3")
]

  1. Open your Xcode project
  2. Navigate to File > Add Package Dependencies…
  3. Enter https://github.com/Shopify/checkout-sheet-kit-swift into the search box
  4. Click Add Package

For more details on managing Swift Package dependencies in Xcode, please see Apple's documentation.

iOS

pod "ShopifyCheckoutSheetKit", "~> 3"

For more information on CocoaPods, please see their getting started guide.


Anchor to Step 2: Import the libraryStep 2: Import the library

After adding Checkout Sheet Kit as a dependency, you can import the library in your code:

iOS

import ShopifyCheckoutSheetKit

To present a checkout to the customer, your app must specify a checkout URL. To get this URL, you can use Storefront GraphQL API to build a cart and load its checkout URL. Or, you can provide a cart permalink.

When using GraphQL to get a checkout URL, Shopify's Mobile Buy SDK for iOS can simplify the development workflow, as shown in the following code sample:

iOS

import Buy

let client = Graph.Client(
shopDomain: "yourshop.myshopify.com",
apiKey: "<storefront access token>"
)

let query = Storefront.buildQuery { $0
.cart(id: "myCartId") { $0
.checkoutUrl()
}
}

let task = client.queryGraphWith(query) { response, error in
let checkoutURL = response?.cart.checkoutUrl
}
task.resume()

checkoutUrl is a standard web checkout URL that can be opened in any browser.

To present the checkout in your mobile app, call present on ShopifyCheckoutSheetKit. Pass in the checkout URL, along with other runtime configuration settings, as shown in this code:

iOS

import UIKit
import ShopifyCheckoutSheetKit

class MyViewController: UIViewController {
func presentCheckout() {
let checkoutURL: URL = // obtained from buyer's cart or cart permalink
ShopifyCheckoutSheetKit.present(checkout: checkoutURL, from: self, delegate: self)
}
}

Was this page helpful?