Go to file
Moritz Lang 979127f0a6
Run CI with latest versions of Xcode & Swift (#4)
2020-12-13 13:34:41 +01:00
.github/workflows Run CI with latest versions of Xcode & Swift (#4) 2020-12-13 13:34:41 +01:00
Sources/AppStoreReceiptValidation Re-format Swift code (#3) 2020-12-13 13:15:19 +01:00
Tests Changed AppStoreClient to behave more like a simple Facade (#1) 2020-07-21 08:47:47 +02:00
scripts Changed AppStoreClient to behave more like a simple Facade (#1) 2020-07-21 08:47:47 +02:00
.gitignore Re-format Swift code (#3) 2020-12-13 13:15:19 +01:00
LICENSE Initial commit 2019-11-28 10:37:05 +01:00
Package.swift Changed AppStoreClient to behave more like a simple Facade (#1) 2020-07-21 08:47:47 +02:00
README.md Update usage instructions 📖 2020-12-13 12:19:19 +01:00

README.md

AppStoreReceiptValidation

Swift 5.1 github-actions codecov

This package implements the validating receipts with the app store api.

Features:

  • Great swift server citizen: Uses AsyncHTTPClient and Swift-NIO under the hood.
  • Automatic retry, if sandbox receipt was send to production.
  • Response object is pure swift struct using enums.
  • 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:

  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.

  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:


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()