https://github.com/tikhop/tpinappreceipt
Reading and Validating In App Purchase Receipt Locally.
https://github.com/tikhop/tpinappreceipt
asn1 catalyst cocoapods in-app-purchase in-app-receipt ios macos osx payment pkcs7 purchase receipt receipt-validation receipt-verification storekit swift swift5 verify
Last synced: 4 months ago
JSON representation
Reading and Validating In App Purchase Receipt Locally.
- Host: GitHub
- URL: https://github.com/tikhop/tpinappreceipt
- Owner: tikhop
- License: mit
- Created: 2016-09-30T02:40:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T18:33:21.000Z (over 1 year ago)
- Last Synced: 2025-04-01T10:06:27.532Z (about 1 year ago)
- Topics: asn1, catalyst, cocoapods, in-app-purchase, in-app-receipt, ios, macos, osx, payment, pkcs7, purchase, receipt, receipt-validation, receipt-verification, storekit, swift, swift5, verify
- Language: Swift
- Homepage:
- Size: 30 MB
- Stars: 661
- Watchers: 19
- Forks: 94
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# TPInAppReceipt
[](https://github.com/apple/swift-package-manager)
[]()
[](https://raw.githubusercontent.com/tikhop/TPInAppReceipt/master/LICENSE)
TPInAppReceipt is a lightweight, pure-Swift library for reading and validating Apple In App Purchase Receipt locally.
## Installation
### Requirements
- Swift 6.0+ / Xcode 16+
- macOS 10.15+ / iOS 13+ / tvOS 13+ / watchOS 6.2+ / visionOS 1+
### Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/tikhop/TPInAppReceipt.git", from: "4.0.1")
]
```
```swift
.target(
name: "YourTarget",
dependencies: ["TPInAppReceipt"]
)
```
## Usage
### Decoding and Reading
```swift
import TPInAppReceipt
// Local receipt
let receipt = try await AppReceipt.local
// From raw data
let receipt = try AppReceipt.receipt(from: data)
```
Access receipt fields, query purchases, check subscriptions and introductory offer eligibility. See [Working with Receipt](Sources/Docs.docc/Working%20with%20Receipt.md) for details.
### Validating
Default validation: certificate chain + signature + hash + metadata.
```swift
let result = await receipt.validate()
switch result {
case .valid:
break
case .invalid(let error):
print(error)
}
```
Supports custom validators via `@VerifierBuilder`. See [Validating Receipt](Sources/Docs.docc/Validating%20Receipt.md) for details.
### Blocking API
For contexts where async is not available. See [Blocking Mode](Sources/Docs.docc/Blocking%20Mode.md).
```swift
@_spi(Blocking) import TPInAppReceipt
let receipt = try AppReceipt.local_blocking
let result = receipt.validate_blocking()
```
## Migrating from v3
See [TPInAppReceipt 4.0 Migration Guide](Sources/Docs.docc/TPInAppReceipt%204.0%20Migration%20Guide.md).
## Essential Reading
* [Apple - About Receipt Validation](https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Introduction.html)
* [Apple - Receipt Validation Programming Guide](https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW1)
* [Apple - Validating Receipts Locally](https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html)
* [fluffy.es - Tutorial: Read and validate in-app purchase receipt locally using TPInAppReceipt](https://fluffy.es/in-app-purchase-receipt-local/)
* [Faisal Bin Ahmed - All the wrong ways to persist in-app purchase status in your macOS app](https://medium.com/@Faisalbin/all-the-wrong-ways-to-persist-in-app-purchase-status-in-your-macos-app-ce6eb9bcb0c3)
* [objc.io - Receipt Validation](https://www.objc.io/issues/17-security/receipt-validation/)
## License
MIT