<!--
{
  "availability" : [
    "iOS: 14.0.0 - 17.0.0",
    "iPadOS: 14.0.0 - 17.0.0",
    "macCatalyst: 14.0.0 - 17.0.0",
    "macOS: 11.0.0 - 14.0.0",
    "tvOS: 14.0.0 - 17.0.0",
    "watchOS: 7.0.0 - 10.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "StoreKitTest",
  "identifier" : "/documentation/StoreKitTest/SKTestSession/buyProduct(productIdentifier:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "StoreKit Test"
    ],
    "preciseIdentifier" : "c:objc(cs)SKTestSession(im)buyProductWithIdentifier:error:"
  },
  "title" : "buyProduct(productIdentifier:)"
}
-->

# buyProduct(productIdentifier:)

Simulates buying an in-app purchase or subscription outside the app.

```
func buyProduct(productIdentifier: String) throws
```

## Parameters

`productIdentifier`

Product identifier of the in-app purchase.

## Discussion

After calling this function, handle the new transaction in your payment queue.

---

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)