flutter_stripe_payment icon indicating copy to clipboard operation
flutter_stripe_payment copied to clipboard

Crash on iOS createPaymentMethod using native pay token

Open siemarell opened this issue 4 years ago • 10 comments

Hi. App crashes when createPaymentMethod is invoked using native pay token:

  final token = await StripePayment.paymentRequestWithNativePay(
              androidPayOptions: AndroidPayPaymentRequest(
                total_price: "1.20",
                currency_code: "EUR",
              ),
              applePayOptions: ApplePayPaymentOptions(
                countryCode: 'DE',
                currencyCode: 'EUR',
                items: [
                  ApplePayItem(
                    label: 'Test',
                    amount: '13',
                  )
                ],
              ),
            );
final req = PaymentMethodRequest(token: token);

final PaymentMethod paymentMethod = await StripePayment.createPaymentMethod(req);

Error trace from xcode:

2020-02-26 18:47:51.251608+0300 Runner[58294:3702114] flutter: Instance of 'PaymentService'
2020-02-26 18:47:58.023108+0300 Runner[58294:3701827] *** Assertion failure in -[StripeModule createPaymentMethod:resolver:rejecter:], /Users/siem/.pub-cache/hosted/pub.dartlang.org/stripe_payment-1.0.6/ios/Classes/TPSStripeManager.m:345
2020-02-26 18:47:58.062680+0300 Runner[58294:3701827] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: parsed'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff23c70ff8 +[NSException raise:format:arguments:] + 88
	3   Foundation                          0x00007fff256e9b51 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
	4   stripe_payment                      0x00000001100067c8 -[StripeModule createPaymentMethod:resolver:rejecter:] + 456
	5   stripe_payment                      0x0000000110002fc1 -[StripePaymentPlugin handleMethodCall:result:] + 1569
	6   Flutter                             0x000000010cb46db5 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 104
	7   Flutter                             0x000000010cadaba0 _ZNK7flutter21PlatformMessageRouter21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 166
	8   Flutter                             0x000000010cade64e _ZN7flutter15PlatformViewIOS21HandlePlatformMessageEN3fml6RefPtrINS_15PlatformMessageEEE + 38
	9   Flutter                             0x000000010cb40969 _ZNSt3__110__function6__funcIZN7flutter5Shell29OnEngineHandlePlatformMessageEN3fml6RefPtrINS2_15PlatformMessageEEEE4$_32NS_9allocatorIS8_EEFvvEEclEv + 57
	10  Flutter                             0x000000010caedb73 _ZN3fml15MessageLoopImpl10FlushTasksENS_9FlushTypeE + 117
	11  Flutter                             0x000000010caf28b8 _ZN3fml17MessageLoopDarwin11OnTimerFireEP16__CFRunLoopTimerPS0_ + 26
	12  CoreFoundation                      0x00007fff23bd4b94 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
	13  CoreFoundation                      0x00007fff23bd4882 __CFRunLoopDoTimer + 1026
	14  CoreFoundation                      0x00007fff23bd3eda __CFRunLoopDoTimers + 266
	15  CoreFoundation                      0x00007fff23bcec4e __CFRunLoopRun + 2238
	16  CoreFoundation                      0x00007fff23bce066 CFRunLoopRunSpecific + 438
	17  GraphicsServices                    0x00007fff384c0bb0 GSEventRunModal + 65
	18  UIKitCore                           0x00007fff48092d4d UIApplicationMain + 1621
	19  Runner                              0x000000010a5a89cb main + 75
	20  libdyld.dylib                       0x00007fff5227ec25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

This assert fails in TPSStripeManager. Seems like extractCreatePaymentMethodParamsFromDictionary returns nil for dictionary filled with token data.

Unfortunately, I have 0 experience in Objective-C and cannot fix it by myself. Please help.

siemarell avatar Feb 27 '20 08:02 siemarell

I met the same issue. I couldn't get iOS stack trace, but on flutter side, I got following logs

  Future<void> _makePaymentRequestByNativePayment(int amount) async {
    try {
      print('creating token');
      final token = await StripePayment.paymentRequestWithNativePay(
        androidPayOptions: AndroidPayPaymentRequest(
          total_price: amount.toString(),
          currency_code: 'JPY',
        ),
        applePayOptions: ApplePayPaymentOptions(
          countryCode: 'JP',
          currencyCode: 'JPY',
          items: [
            ApplePayItem(
              label: 'payment',
              amount: amount.toString(),
              type: 'final',
            )
          ],
        ),
      );

      print('token: ${token.toJson()}');
      print('creating payment method');
      final paymentMethodRequest = PaymentMethodRequest(token: token);
      print('json: ${paymentMethodRequest.toJson()}');
      final paymentMethod = await StripePayment.createPaymentMethod(
        paymentMethodRequest,
      );

      print('set state');
      setState(() {
        _paymentMethod = paymentMethod;
        _isNativePayment = true;
      });

      print('run make payment');
      await _makePayment(amount, paymentMethod.id);
    } catch (e, stackTrace) {
      print(stackTrace);
      setError(e);
    }
  }
2020-03-02 17:04:48.401512+0900 Runner[24966:10469477] flutter: deviceSupportNativePay: true
2020-03-02 17:04:48.402244+0900 Runner[24966:10469477] flutter: canMakeNativePayment: true
2020-03-02 17:04:49.409552+0900 Runner[24966:10469477] flutter: creating token
2020-03-02 17:04:57.377922+0900 Runner[24966:10469129] ℹ️ You're using your Stripe testmode key. Make sure to use your livemode key when submitting to the App Store!
2020-03-02 17:04:57.790331+0900 Runner[24966:10469477] flutter: token: {created: 1583136297.0, livemode: false, tokenId: tok_1GI9GnEPIquAphfurwVU51FA, card: {addressLine1: null, addressLine2: null, brand: Visa, cardId: card_1GI9GnEPIquAphfuS4KlAk8s, country: US, expMonth: 12, expYear: 2020, funding: credit, last4: 4242}}
2020-03-02 17:04:57.790592+0900 Runner[24966:10469477] flutter: creating payment method
2020-03-02 17:04:57.791722+0900 Runner[24966:10469477] flutter: json: {token: {created: 1583136297.0, livemode: false, tokenId: tok_1GI9GnEPIquAphfurwVU51FA, card: {addressLine1: null, addressLine2: null, brand: Visa, cardId: card_1GI9GnEPIquAphfuS4KlAk8s, country: US, expMonth: 12, expYear: 2020, funding: credit, last4: 4242}}}
2020-03-02 17:04:58.065713+0900 Runner[24966:10469477] flutter: #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
<asynchronous suspension>
#2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#3      StripePayment.createPaymentMethod (package:stripe_payment/src/stripe_payment.dart:144:42)
#4      _PaymentDetail._makePaymentRequestByNativePayment (package:customer/screens/checkin/payment_screen.dart:211:49)
<asynchronous suspension>
#5      _PaymentDetail.build.<anonymous closure> (package:customer/screens/checkin/payment_screen.dart:256:19)
#6      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:705:14)
#7      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:788:36)
#8      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
#9      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
#10     BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
#11     BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
#12     PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:470:9)
#13     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
#14     PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
#15     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
#16     PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
#17     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
#18     GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
#19     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
#20     GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
#21     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
#22     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
#23     _rootRunUnary (dart:async/zone.dart:1138:13)
#24     _CustomZone.runUnary (dart:async/zone.dart:1031:19)
#25     _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
#26     _invoke1 (dart:ui/hooks.dart:274:10)
#27     _dispatchPointerDataPacket (dart:ui/hooks.dart:183:5)
2020-03-02 17:04:58.066758+0900 Runner[24966:10469477] flutter: PlatformException(api, Missing required param: type., null)

On stripe dashboard, there is a 400 log on /v1/payment_methods.

request body: none

response body:

{
  "error": {
    "code": "parameter_missing",
    "doc_url": "https://stripe.com/docs/error-codes/parameter-missing",
    "message": "Missing required param: type.",
    "param": "type",
    "type": "invalid_request_error"
  }
}

wawoon avatar Mar 02 '20 08:03 wawoon

I have just made an article in medium and everything works fine. Have a look there https://medium.com/flutter-community/build-a-marketplace-in-your-flutter-app-and-accept-payments-using-stripe-and-firebase-72f3f7228625

macmatrix avatar Mar 03 '20 09:03 macmatrix

@siemarell @wawoon how did you solve it?

@macmatrix it didn't work with your guide

RicardoRB avatar Jun 06 '20 11:06 RicardoRB

@siemarell @wawoon how did you solve it?

@macmatrix it didn't work with your guide

What is the error you have got?

macmatrix avatar Jun 06 '20 13:06 macmatrix

@siemarell @wawoon how did you solve it? @macmatrix it didn't work with your guide

What is the error you have got?

It is solved, I just added a "label" into "ApplePayItem". Now I'm getting an error saying that the user canceled the payment.

RicardoRB avatar Jun 06 '20 14:06 RicardoRB

@siemarell @wawoon how did you solve it?

@macmatrix it didn't work with your guide

I've used stripe REST API directly for that

siemarell avatar Jun 08 '20 06:06 siemarell

Thanks not it is working, it was just a problem with the label and add apple pay in xcode

RicardoRB avatar Jun 08 '20 07:06 RicardoRB

I'm also having an issue with creating payment methods on ios. I'm getting a different error though:

PlatformException (PlatformException(api, Missing required param: type., null, null))

Code:

 _token = await StripePayment.paymentRequestWithNativePay(
        androidPayOptions: AndroidPayPaymentRequest(
            currencyCode: "USD",
            totalPrice: _total,
            billingAddressRequired: true),
        applePayOptions: ApplePayPaymentOptions(
          countryCode: "US",
          currencyCode: "USD",
          items: [
            ApplePayItem(
              label: 'Cortado Mobile Order',
              amount: _total,
            )
          ],
          requiredBillingAddressFields: [RequiredBillingAddressFields.all],
        ));
    final req = PaymentMethodRequest(token: _token);
    _paymentMethod = await StripePayment.createPaymentMethod(req);

sam-parks avatar Aug 24 '20 14:08 sam-parks

@all Has anyone solve the apple pay here? If so, would you mind post the source code? I have difficulties to create payment method it crashes the app right away with error: "Failed to send request: {"jsonrpc": "2.0", "id": "185", "method": "getStack"}"

haifzhan avatar Apr 04 '21 00:04 haifzhan

I have solved the issue and have paste my answer in SO, you can find it here https://stackoverflow.com/questions/66899675/flutter-stripe-payment-native-pay-not-chargedapple-pay-and-google-pay/66945461#66945461 , hope it helps

haifzhan avatar Apr 04 '21 20:04 haifzhan