Apple’s In-App Purchase service allows developers to sell virtual goods and services within their apps. This can be an easy way for independent game studios to monetize their work without having to worry about hosting servers or managing complicated online payments infrastructure. However, it is important that the receipts generated by these purchases are not tampered with in any way. To help verify receipt validity, this library was created using pure Swift code so it should run well on all iOS devices regardless of architecture or performance capability.,

The “in-app purchase receipt validation php” is a lightweight, pure-Swift library for reading and validating Apple In App Purchase Receipt locally.

A-lightweight-pure-Swift-library-for-reading-and-validating-Apple-In

1631681261_416_Access-Xcode-Server-API-with-native-Swift-objects

TPInAppReceipt is a small, Swift-only library for reading and verifying Apple In App Purchase Receipts locally.

Features

  • Read all of the Receipt Attributes in-app.
  • Validate the receipt from an in-app purchase (Signature, Bundle Version and Identifier, Hash)
  • Determine whether you are eligible for an introductory offer.
  • Use it in conjunction with StoreKitTest.
  • In Objective-C projects, it’s a good idea to use it.

Installation

Note: TPInAppReceipt in Objective-C Projects – Please follow this tutorial if you wish to utilize TPInAppReceipt in an Objective-C project.

CocoaPods

To use CocoaPods to incorporate TPInAppReceipt into your app, add the following to your Podfile:

use frameworks! platform:ios, ‘9.0’ target ‘YOUR TARGET’ end pod ‘TPInAppReceipt’

Run the following command after that:

Import the framework using import TPInAppReceipt in any swift project where you want to utilize TPInAppReceipt.

Swift Package Manager is a program that allows you to manage your

Add the following as a dependency to your Package to integrate using Apple’s Swift package management. swift:

.upToNextMajor(from: “3.0.0”),.package(url: “https://github.com/tikhop/TPInAppReceipt.git”),.package(url: “https://github.com/tikhop/TPInAppReceipt.git”),.package(url: “https://github.com/tikhop/TPInAppRece

Then, as a dependent of the Target in which you want to utilize TPInAppReceipt, provide “TPInAppReceipt.”

Run the following command as a last step:

Requirements

  • OSX 10.11+ / iOS 10.0+
  • Swift 5.3 and up

Usage

Using a Receipt as a Tool

The InAppReceipt object holds information about a receipt and the purchases it contains. Create an InAppReceipt object to verify an In-App Purchase Receipt.

Receipt Initialization

You may either supply raw receipt data or establish a local receipt to generate an InAppReceipt object.

do / Initialize receipt let receipt = try InAppReceipt.localReceipt() / Returns local receipt / let receipt = try InAppReceipt.localReceipt() / Returns local receipt try InAppReceipt.receipt(from: receiptData) / let receipt = try InAppReceipt.receipt(from: receiptData) print(error) print(error) print(error) print(error) print(error) print(error) print

Receipt Validation

For verifying In-App Purchase Receipt, TPInAppReceipt offers a number of convenient methods:

/ Is it possible to verify the hash? receipt.verify receipt.verifyBundleIdentifier() / Try to verify the bundle identifier? / Can you attempt to verify the bundle version? receipt.verify BundleVersion()/ Attempt to verify signature? receipt.verify / Signature() Try receipt.verify() to validate everything at once. IARError should be caught. validation Failed(reason:.hashValidation) / Catch IARError and do something. validation a failure (reason: .bundleIdentifierVerification) / Do something to capture the IARError. validation Failed(reason:.signatureValidation) / Do something catchy / Do something interesting

NOTE: Apple advises that you validate your receipts as soon as your app is released. You may perform this check regularly while your application is running for further protection. NOTE: If the receipt validation fails on iOS, try refreshing it first.

Determining Introductory Offer Eligibility

If your App has introductory pricing for auto-renewable subscriptions, you must pay the proper amount, whether it’s the intro or the normal price. The InAppReceipt class is used to determine whether or not an app is eligible for an introductory pricing. Provide a Set of product IDs that belong to the same subscription group at the most basic level:

/ Determine if the user is eligible for any of the goods in the same subscription group. var isEligible = receipt.isEligibleForIntroductoryOffer; (for: [“com.test.product.bronze”, “com.test.product.silver”, “com.test.product.gold”])

Note: You must first create and verify the receipt before checking for eligibility to see whether a user is qualified for an introductory offer.

Receipt for Reading

/ let receipt = try! initialize receipt let receipt = try! InAppReceipt.local Receipt() / Base64 Receipt() Receipt() Receipt Encoded Let base64 be the receipt. receipt.base64 Receipt = Receipt.base64 / Check to see whether there are any purchases on the receipt. let’s have a Receipts = purchases. has Purchases / For all auto-renewing ‘InAppPurchase’s, use the following syntax: [InAppPurchase] is the receipt for an in-app purchase. autoRenewable Purchases / all ACTIVE auto-renewing ‘InAppPurchases,’ leave active Purchases: receipt.active = [InAppPurchase] AutoRenewableSubscriptionPurchases

Methods that are beneficial

/ Get the original TransactionIdentifier for receipt.originalTransactionIdentifier for Product Name (ofProductIdentifier: subscriptionName) / Get Purchases for Product Name and Specific Date for Active Auto Renewable Subscriptions. activeAutoRenewableSubscriptionPurchases(ofProductIdentifier: subscriptionName, forDate: Date()), activeAutoRenewableSubscriptionPurchases(ofProductIdentifier: subscriptionName, forDate: Date()) / Get a list of all purchases for the product receipt.purchases (ofProductIdentifier: subscriptionName)

Receipt Refreshing/Requesting

Use this technique to verify the receipt you’re dealing with is current as required.

if let err = error print(err) else initializeReceipt() InAppReceipt.refresh (error) in if let err = error print(err) else initializeReceipt()

Reading Requirements

License

The MIT license applies to TPInAppReceipt. For additional information, see LICENSE.

GitHub

https://github.com/tikhop/TPInAppReceipt

The “android in-app purchase receipt validation” is a lightweight, pure-Swift library for reading and validating Apple In App Purchase Receipt locally. It can be used to validate that the data has not been tampered with.

Related Tags

  • validate receipt in-app purchase
  • ios validate receipt locally
  • receipt local verification failed
  • apple in-app purchase server
  • how to verify in-app purchases

About Author