Search code examples
iosflutterin-app-purchasein-app-subscription

Flutter in-app-purchase fails to restore purchase


I submitted an issue to the Flutter repo, but this is very weird. It seems rather like an Apple issue.

Basically, the restore purchase fails with an error. It could be a Sandbox environment stuff, but we can't ship without confirming this in the Sandbox environment.

This code is supposed to send a previously purchased product to my purchase stream,

              try {
                await _inAppPurchase.restorePurchases();
              } catch (e) {
                if (e is SKError) {
                  debugPrint(
                      "SKError code: '${e.code}', userInfo: '${e.userInfo}'");
                }
              }

But instead, it will emit error in the debug console, and there is no purchased item coming into my purchase stream.

flutter: SKError code: '-1202', userInfo: '{NSLocalizedDescription: このサーバの証明書は無効です。“mzstorekit-sb.itunes.apple.com”に偽装したサーバに接続している可能性があり、機密情報が漏えいするおそれがあります。, NSUnderlyingError: {domain: kCFErrorDomainCFNetwork, userInfo: {_kCFStreamPropertySSLClientCertificateState: 0, _kCFNetworkCFStreamSSLErrorOriginalValue: -9807, kCFStreamPropertySSLPeerTrust_desc: <SecTrustRef: 0x7c8a61cd0>, _kCFStreamErrorDomainKey: 3, _kCFStreamErrorCodeKey: -9807, kCFStreamPropertySSLPeerCertificates: [<cert(0x7c9810800) s: mzstorekit.itunes.apple.com i: Apple Public EV Server RSA CA 2 - G1>, <cert(0x7c984c800) s: Apple Public EV Server RSA CA 2 - G1 i: DigiCert High Assurance EV Root CA>, <cert(0x7c9846200) s: DigiCert High Assurance EV Root CA i: DigiCert High Assurance EV Root CA>]}, code: -1202}}'

The Japanese part basically says

'The certificate for this server is invalid. There is a possibility that you are connecting to a server impersonating "mzstorekit-sb.itunes.apple.com," and confidential information may be leaked.'

Did anybody encounter this error? How did you manage to work around?


Solution

  • Well, this turned out to be a simple Apple server issue and is now resolved.

    https://developer.apple.com/forums/thread/736720

    The lesson is, to always check system status. I thought of removing the question, but leaving this for the lesson 😓