Overview
dyfstorereceiptverifier_swift is a Swift library that allows developers to easily verify purchase receipts from Apple App Store and Google Play Store. It provides a simple and convenient way to authenticate and validate purchase receipts in iOS applications. It supports both consumable and non-consumable purchases.
Installation
To install dyfstorereceiptverifier_swift, you can use Cocoapods. Make sure you have Cocoapods installed on your system before proceeding with the following steps:
1. Open your terminal and navigate to your project directory.
2. Create a Podfile by running the command: `pod init`.
3. Open the Podfile with a text editor and add the following line: `pod ‘dyfstorereceiptverifier_swift’`.
4. Save the file and run the command: `pod install`.
5. Once the installation is complete, open the newly created `.xcworkspace` file (instead of `.xcodeproj`) and start using dyfstorereceiptverifier_swift in your project.
Usage Example
Here’s an example of how to use dyfstorereceiptverifier_swift to verify a purchase receipt in your iOS application:
“`
import dyfstorereceiptverifier
func verifyPurchaseReceipt(receiptData: Data) {
let verifier = StoreReceiptVerifier()
verifier.verifyPurchase(receiptData: receiptData) { result in
switch result {
case .success(let purchaseReceipt):
// Receipt is valid, process the purchase receipt
handleValidReceipt(purchaseReceipt)
case .failure(let error):
// Receipt is invalid or verification failed, handle the error
handleError(error)
}
}
}
func handleValidReceipt(_ purchaseReceipt: PurchaseReceipt) {
// Process the purchase receipt
}
func handleError(_ error: Error) {
// Handle error
}
“`
Make sure you have the latest version of the purchase receipt data before calling the `verifyPurchase` method. You can obtain this data using the `appStoreReceiptURL` property from the `Bundle.main` object.
Available Methods
verifyPurchase(receiptData: Data, completion: @escaping (Result
This method is used to verify the purchase receipt provided as `receiptData`. It performs the necessary steps to verify the receipt and calls the completion handler with a `Result` object. If the receipt is valid, the `Result` carries a `PurchaseReceipt` object containing the verified receipt. If the receipt is invalid or the verification fails, the `Result` carries a `ReceiptVerificationError` object with details about the error.
That’s it! You now have the necessary information about dyfstorereceiptverifier_swift and how to use it in your iOS application. Feel free to explore the library and its additional methods for more advanced receipt verification functionality.