Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider move back *refreshReceipt* #272

Closed
3 of 9 tasks
pddkhanh opened this issue Sep 20, 2017 · 19 comments
Closed
3 of 9 tasks

Please consider move back *refreshReceipt* #272

pddkhanh opened this issue Sep 20, 2017 · 19 comments

Comments

@pddkhanh
Copy link

pddkhanh commented Sep 20, 2017

Platform

  • iOS
  • macOS
  • tvOS

In app purchase type

  • Consumable
  • Non-consumable
  • Auto-Renewable Subscription
  • Non-Renewing Subscription

Environment

  • Sandbox
  • Production

Version

ℹ 4.0.0

Related issues

ℹ N/A.

Report

Issue summary

ℹ I'm migrating from version 3 to 4 and found the API removed the method refreshReceipt. My app handles the verification flow on server. So in the client, I need to retrieve the receiptData and post to my server. So I called refreshReceipt before upload it to server to make sure it is the latest but now it's not available anymore. I know I can workaround by just upload the localReceipt, but I'm not sure it is latest or not. Please advise.

What did you expect to happen

ℹ Migrate from version 3 to 4

What happened instead

ℹ Need refreshReceipt method.

@vovkaprigarin
Copy link

Oh... we was already ask about this in the 223 issue. But author don't want move back refreshReceipt method. It's so sad :(

@bizz84
Copy link
Owner

bizz84 commented Oct 10, 2017

Apologies for the late reply.

If you want to do receipt validation on your server, verifyReceipt is your friend and you can use it like this:

// Implement MyCustomReceiptValidator to send the encrypted receipt data to your server
let validator = MyCustomReceiptValidator(service: .production)
SwiftyStoreKit.verifyReceipt(using: validator, password: "your-shared-secret", forceRefresh: false) { result in
    switch result {
    case .success(let receipt):
        print("Verify receipt Success: \(receipt)")
    case .error(let error):
        print("Verify receipt Failed: \(error)")
	}
}

If you want to send the plain text receipt data to your server instead, but keep the default AppleReceiptValidator for decryption, you can do this:

let appleValidator = AppleReceiptValidator(service: .production)
SwiftyStoreKit.verifyReceipt(using: appleValidator, password: "your-shared-secret", forceRefresh: false) { result in
    switch result {
    case .success(let receipt):
        // send plain text receipt to server
    case .error(let error):
        print("Verify receipt Failed: \(error)")
	}
}

In both cases, refreshReceipt is not strictly needed. You can use forceRefresh: true if desired.

Makes sense?

@pddkhanh
Copy link
Author

pddkhanh commented Oct 10, 2017 via email

@vovkaprigarin
Copy link

I agree with itleo31.

@pddkhanh
Copy link
Author

@bizz84 : We just need to load the receipt data and upload to server. Server will do all logic like verify receipt and update models and other stuffs. On client, this process is not verify receipt. So we just need "loadReceipt" only.

@bizz84
Copy link
Owner

bizz84 commented Oct 11, 2017

@itleo31 I think I understand now, apologies or the confusion.

So basically you want access to the localReceiptData, or refresh the receipt if this is missing or outdated.

Ok, I will implement this. My idea is to add a new method:

func fetchReceipt(forceRefresh: Bool, completion: (receipt: String) -> Void))
  • If forceRefresh = false, it just returns the local receipt, or refreshes the receipt if missing
  • If forceRefresh = true, always refreshes the receipt regardless

This way, you can then send the encrypted receipt to your server for processing.

Would this work for you?

@pddkhanh
Copy link
Author

Ya that will be great. Thank you very much.

@bizz84
Copy link
Owner

bizz84 commented Oct 11, 2017

Cool. Will do this now, should be available today.

@bizz84
Copy link
Owner

bizz84 commented Oct 11, 2017

@itleo31 This is now implemented in #278 in case you want to give it a quick test.

Will be doing a bit more cleanup and publish a new version soon.

@bizz84
Copy link
Owner

bizz84 commented Oct 11, 2017

@itleo31 do you think it makes more sense to return the receipt as Data or as a base64EncodedString?

Currently all receipt verification methods use String.

@shuhrat10
Copy link

@bizz84 I would return as Data. That way it will match to localReceiptData.

@vovkaprigarin
Copy link

vovkaprigarin commented Oct 12, 2017

@bizz84 why you didn't do this 4 month ago?? (issue 223)

P.S. thx.
P.P.S. I think need return Data and need function for encoding ofc.

@bizz84
Copy link
Owner

bizz84 commented Oct 12, 2017

@shuhrat10 RE string vs data, done in #284.

@vovkaprigarin Apologies, I did not understand the problem clearly back then.

@pddkhanh
Copy link
Author

@bizz84 : Same with @shuhrat10 , I think return Data is good. Can I close this issue?

@bizz84
Copy link
Owner

bizz84 commented Oct 12, 2017

@itleo31 the fix is currently on develop.

I'm waiting for CI to finish on a separate PR, merge, and publish a new pod version.

Feel free to close it.

@shuhrat10
Copy link

@bizz84 can you release new pod with this changes?

@bizz84
Copy link
Owner

bizz84 commented Oct 12, 2017

@shuhrat10 I've been trying to but I'm having problems with it. See #285. Any ideas?

For the time being, you can point your pod to master.

@bizz84
Copy link
Owner

bizz84 commented Oct 16, 2017

Version 0.11.0 has been published with this fix.

@androidcn
Copy link

Please consider move back refreshReceipt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants