# Making Purchases

Purchase any StoreKit product easily, with or without a paywall.

Making purchases of a consumable, non-consumable or subscription product in Superwall takes only one line. You can use this whether or not you are using Superwall's paywalls:

```swift
let result = await Superwall.shared.purchase(product)
```

This method takes a `StoreProduct` and returns a `PurchaseResult` so you can take action on the result. Here's an example from our demo app, [Caffeine Pal](https://github.com/superwall/CaffeinePal/blob/using-superwall-sdk/Caffeine%20Pal/Store%20and%20Models/CaffeineStore.swift#L121):

> **Warning**

`Superwall.shared.purchase(product)` is for StoreKit-backed products. For Custom Store Products on a paywall, handle the purchase in your [`PurchaseController`](/docs/ios/sdk-reference/PurchaseController) using `product.productIdentifier`. See [Custom Store Products](/docs/ios/guides/custom-store-products).



```swift
func purchase(_ product: StoreProduct) async throws {
    let result = await Superwall.shared.purchase(product)
    
    switch result {
    case .cancelled:
        throw CaffeinePalStoreFrontError.cancelled
    case .purchased:
        // In `handleSuperwallEvent` delegate method, we'll check if an espresso recipe was
        // Purchased and if it was, we'll add it to the purchased drinks set.
        print("Purchased product \(product.productIdentifier)")
    case .pending:
        throw CaffeinePalStoreFrontError.pending
    case .failed(let error):
        throw error
    }
}
```

> **Note**

For the SDK reference, check out this [page](/docs/ios/guides/advanced/direct-purchasing).



The flow looks like this:

1. Fetch your products.
2. Call `purchase` on any of them.
3. Respond to the result.

Here's an example:

Fetch products [#fetch-products]

A `StoreProduct` can be fetched using its corresponding identifier from App Store Connect or a [StoreKit Configuration File](/docs/ios/guides/testing-purchases). Custom Store Products are loaded from paywalls and are not fetched with `products(for:)`. For example, `subscription.caffeinePalPro.monthly` here:

<img src="__img0" />

That product could be fetched like so:

```swift
let caffeineSub = await Superwall.shared.products(for: Set(["subscription.caffeinePalPro.monthly"]))
```

Call purchase [#call-purchase]

Now, simply call `purchase`:

```swift
let result = await Superwall.shared.purchase(caffeineSub)
```

Respond to result [#respond-to-result]

Finally, respond to the result:

```swift
switch result {
case .cancelled:
    // user cancelled the purchase flow
case .purchased:
    // Purchase completed
case .pending:
    // Purchase in flight
case .failed(let error):
    // Couldn't purchase, check out the error
}
```

There are a number of additional ways to respond to a purchase outside of this `result`, depending on how the product was purchased (for example, within a paywall). For examples, see this [doc](/docs/ios/guides/advanced/viewing-purchased-products).