Search code examples
iosflutterxcodeapplepay

Flutter app ApplePayButton widget retunes the error: failed to present payment controller


To test the ApplePayButton widget, I tried creating a new sample Flutter project using flutter create . And in the Hello world screen, I added one thing only which is ApplePayButton widget from pay dependency because my original project was returning a weird error which is platformexception(paymenterror, failed to present payment controller, null, null) from the onError property, but I ended up getting the same error in the new hello world project so there is hardly any context. Here is the widget I used and the configuration:

            ApplePayButton(
              onPaymentResult: (result) => greenToast(result.toString()),
              paymentItems: [
                PaymentItem(
                  amount: "111.01",
                  label: "test",
                ),
              ],
              onError: (error) => redToast(error.toString()),
              paymentConfiguration: PaymentConfiguration.fromJsonString('''
                {
                "provider": "apple_pay",
                "data": {
                  "merchantIdentifier": "merchant.xxx.xxx",
                  "displayName": "app_name",
                  "merchantCapabilities": ["3DS", "debit", "credit"],
                  "supportedNetworks": ["amex", "visa", "mada", "masterCard"],
                  "countryCode": "SA",
                  "currencyCode": "SAR"
                  }
                }
                '''),
            ),

Some notes about my setup and things I tried:

  • My original app's primary language is Arabic
  • I tried restarting the MacOS and XCode for possible cache issues
  • In the MacOS, I compile the Runner using the command: flutter ios --release --no-tree-shake-icons
  • Then updated Flutter to fix the issue of shaking icons and compiled the app using flutter ios --release
  • the app name was containing arabic characters along with the character '|', but I fixed that and made all the naming in only English, specially in the new Flutter sample project
  • the Apple Pay button is working fine on the iOS simulator on MacOS
  • I tried 2 different physical iPhones but got the same error
  • The iPhones I tested have been used to buy through Apple Pay before
  • Merchant ID is setup with an active Apple Pay Payment Processing Certificate
  • The Class PlatformException from Flutter didn't return any more information as far as I know except: platformexception(paymenterror, failed to present payment controller, null, null)

Solution

  • I didn't notice that I needed to check the checkbox here:

    enter image description here