jnbt / candy_check

Check and verify in-app receipts
MIT License
125 stars 70 forks source link

IOS expired subscription verification return VerificationFailure #32

Open catacs opened 5 years ago

catacs commented 5 years ago

When a user cancel a subscription and from server side I check the subscription later, I get VerificationFailure with code 21006 and message:

This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part of the response.

The message is self explanatory, the subscription data should be parsed from the response. The result must contains a Receipt when call verify method and ReceiptCollection for verify_subscription method.

Changes must be done in the valid? method from class CandyCheck::AppStore::Verification and CandyCheck::AppStore::SubscriptionVerification in the same overridden method, valid?. It should allow to parse the response for code 21006 and not only for STATUS_OK = 0

Posible solution for CandyCheck::AppStore::Verification:

module CandyCheck
  module AppStore
    # Verifies a receipt block against a verification server.
    # The call return either an {Receipt} or a {VerificationFailure}
    class Verification
      STATUS_EXPIRED = 21006

      private

      def valid?
        @response && (@response['status'] == STATUS_OK || @response['status'] == STATUS_EXPIRED) && @response['receipt']
      end
    end
  end
end