<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/EnvironmentValues/purchase",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftUI",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI17EnvironmentValuesV010_StoreKit_aB0E8purchaseAD14PurchaseActionVvp"
  },
  "title" : "purchase"
}
-->

# purchase

An action that starts an in-app purchase.

```
@MainActor @preconcurrency var purchase: PurchaseAction { get }
```

## Discussion

Read this environment value to get an `PurchaseAction`
instance for a given [`Environment`](/documentation/SwiftUI/Environment). Call the
instance to start an in-app purchase. You call the instance directly because it
defines a `PurchaseAction/callAsFunction(_:options:)` method that Swift
calls when you call the instance.

For example, you can start an in-app purchase when the user taps a button:

```
struct PurchaseExample: View {
    @Environment(\.purchase) private var purchase
    let product: Product
    let purchaseOptions: [Product.PurchaseOption]

    var body: some View {
        Button {
            Task {
                let purchaseResult = try? await purchase(product, options: purchaseOptions)
                // Process purchase result.
            }
        } label: {
            Text(product.displayName)
        }
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)