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

# refundTransaction(identifier:)

Simulates a refund for an in-app purchase that completes outside of the app.

```
func refundTransaction(identifier: Int) throws
```

## Parameters

`identifier`

The transaction [`identifier`](/documentation/StoreKitTest/SKTestTransaction/identifier) of an in-app purchase to get a refund.

## Discussion

In the testing environment, the system always approves refund requests, and processes them immediately. You can choose the reason for the refund by using <doc://com.apple.documentation/documentation/StoreKit/Transaction/beginRefundRequest(in:)-9k0pj> in your app and selecting a reason. (Your app may also use <doc://com.apple.documentation/documentation/StoreKit/Transaction/beginRefundRequest(for:in:)-65tph>, <doc://com.apple.documentation/documentation/StoreKit/Transaction/beginRefundRequest(in:)-63bvd>, or <doc://com.apple.documentation/documentation/StoreKit/Transaction/beginRefundRequest(in:)-63bvd>.  If your app uses SwiftUI, it may use <doc://com.apple.documentation/documentation/SwiftUI/View/refundRequestSheet(for:isPresented:onDismiss:)>.) Otherwise, the refund reason defaults to <doc://com.apple.documentation/documentation/StoreKit/Transaction/RevocationReason-swift.struct/other>.

After calling this function, handle the new transaction in <doc://com.apple.documentation/documentation/StoreKit/Transaction/updates> or in your payment queue. Look for the <doc://com.apple.documentation/documentation/StoreKit/Transaction/revocationDate> and <doc://com.apple.documentation/documentation/StoreKit/Transaction/revocationReason-swift.property> properties, which indicate the refund.

---

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)