-
Notifications
You must be signed in to change notification settings - Fork 8
Receipt verification
DYFStore
doesn't perform receipt verification by default, but provides reference implementations. You can implement your own custom verification or use the reference verifier provided by the library.
The reference verifier is outlined below.
You create and return a receipt verifier(DYFStoreReceiptVerifier
) by using lazy loading.
lazy var receiptVerifier: DYFStoreReceiptVerifier = {
let verifier = DYFStoreReceiptVerifier()
verifier.delegate = self
return verifier
}()
The receipt verifier delegates receipt verification, enabling you to provide your own implementation using the DYFStoreReceiptVerifierDelegate
protocol:
public func verifyReceiptDidFinish(_ verifier: DYFStoreReceiptVerifier, didReceiveData data: [String : Any]) {}
public func verifyReceipt(_ verifier: DYFStoreReceiptVerifier, didFailWithError error: NSError) {}
You can start verifying the in-app purchase receipt.
// Fetches the data of the bundle’s App Store receipt.
let data = receiptData
or
let data = try? Data(contentsOf: DYFStore.receiptURL())
self.receiptVerifier.verifyReceipt(data)
// Only used for receipts that contain auto-renewable subscriptions.
//self.receiptVerifier.verifyReceipt(data, sharedSecret: "A43512564ACBEF687924646CAFEFBDCAEDF4155125657")
If security is a concern you might want to avoid using an open source verification logic, and provide your own custom verifier instead.
It is better to use your own server to obtain the parameters uploaded from the client to verify the receipt from the app store server (C -> Uploaded Parameters -> S -> App Store S -> S -> Receive And Parse Data -> C, C: client, S: server).