https://github.com/slashmo/swift-app-store-receipt-validation
Small wrapper around AsyncHTTPClient to verify App Store Receipts.
https://github.com/slashmo/swift-app-store-receipt-validation
appstoreconnect asynchttpclient receipt swift swift-nio swift-server
Last synced: 5 months ago
JSON representation
Small wrapper around AsyncHTTPClient to verify App Store Receipts.
- Host: GitHub
- URL: https://github.com/slashmo/swift-app-store-receipt-validation
- Owner: slashmo
- License: apache-2.0
- Created: 2019-11-28T09:37:04.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2020-12-13T12:36:54.000Z (almost 5 years ago)
- Last Synced: 2025-05-13T02:13:02.725Z (5 months ago)
- Topics: appstoreconnect, asynchttpclient, receipt, swift, swift-nio, swift-server
- Language: Swift
- Homepage:
- Size: 25.4 KB
- Stars: 11
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AppStoreReceiptValidation
[](https://swift.org/download/)
[](https://github.com/fabianfett/swift-aws-lambda/actions)
[](https://codecov.io/gh/fabianfett/swift-app-store-receipt-validation)This package implements the [validating receipts with the app store](https://developer.apple.com/library/archive/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW1) api.
## Features:
- [x] Great swift server citizen: Uses [`AsyncHTTPClient`](https://github.com/swift-server/async-http-client) and [`Swift-NIO`](https://github.com/apple/swift-nio) under the hood.
- [x] Automatic retry, if sandbox receipt was send to production.
- [x] Response object is pure swift struct using enums.
- [x] API Erros are translated into corresponding swift errors.## Usage
Add `swift-app-store-receipt-validation`, `async-http-client` and `swift-nio` as dependencies to
your project. For this open your `Package.swift` and add this to your dependencies:```swift
dependencies: [
.package(url: "https://github.com/swift-server/async-http-client", .upToNextMajor(from: "1.1.0")),
.package(url: "https://github.com/apple/swift-nio", .upToNextMajor(from: "2.14.0")),
.package(url: "https://github.com/slashmo/swift-app-store-receipt-validation", .upToNextMajor(from: "0.1.0")),
]
```
Then, add `AsyncHTTPClient`, `SwiftNIO` and `AppStoreReceiptValidation` as target dependencies.```swift
targets: [
.target(name: "Hello", dependencies: [
.product(name: "NIO", package: "swift-nio"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "AppStoreReceiptValidation", package: "swift-app-store-receipt-validation"),
]
]
```To verify an AppStore Receipt in your code you need to create an `HTTPClient` first:
```swift
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
defer { try? httpClient.syncShutdown() }let appStoreClient = AppStore.Client(httpClient: httpClient, secret: "abc123")
let base64EncodedReceipt: String = ...
let receipt = try appStoreClient.validateReceipt(base64EncodedReceipt).wait()
```