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

Fix issue with CaptureMethod.Manual on iOS. #2002

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alex-gutev
Copy link

This pull request fixes a bug in the stripe_ios package where the intent configuration capture method is ignored, when using deferred payments.

Steps to reproduce the bug

  1. Add captureMethod: CaptureMethod.Manual to the IntentMode in the deferred payments example from https://docs.page/flutter-stripe/flutter_stripe/sheet_deferred

    Future<void> initPaymentSheet() async {
        try {
          // 1. create payment intent on the server
          final data = await _createTestPaymentSheet();
    
          // 2. initialize the payment sheet
         await Stripe.instance.initPaymentSheet(
            paymentSheetParameters: SetupPaymentSheetParameters(
              // Enable custom flow
              customFlow: false,
              // Main params
              merchantDisplayName: 'Flutter Stripe Store Demo',
              intentConfiguration: IntentConfiguration(
                  mode: IntentMode(
                    currencyCode: 'USD',
                    amount: 1500,
                    captureMethod: CaptureMethod.Manual
                  ),
                  confirmHandler: (method, saveFuture) {
                    // This is the method where you call the server to create a paymentintent for the payment method id supplied in the callback.
                    _createIntentAndConfirmToUser(method.id);
                  }),         
              // Customer keys
              customerEphemeralKeySecret: data['ephemeralKey'],
              customerId: data['customer'],
              // Extra options
              testEnv: true,
              applePay: true,
              googlePay: true,
              style: ThemeMode.dark,
              merchantCountryCode: 'DE',
            ),
          );
          setState(() {
            _ready = true;
          });
        } catch (e) {
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(content: Text('Error: $e')),
          );
          rethrow;
        }
    }
  2. Update the backend to create a payment intent with the capture method set to manual.

  3. Run the example on iOS.

Expected result:

The payment intent is confirmed when the user taps the pay button in the payment sheet.

Actual result:

The following error is printed in the payment sheet:

"An error occurred in PaymentSheet. Your PaymentIntent captureMethod (manual) does not match the PaymentIntent.IntentConfiguration amount (automatic)"

The captureMethod parameter is ignored by the stripe_ios package and the automatic capture method is always used regardless of the value given for captureMethod.

@jonasbark
Copy link
Member

This looks correct to me. However, you'd need to do this pull request to https://github.com/stripe/stripe-react-native because this change would be overwritten (and lost) once we synchronize their sources with ours

@alex-gutev
Copy link
Author

I see they have the exact same bug.

@alex-gutev
Copy link
Author

I've opened a pull request on the react-native library. stripe/stripe-react-native#1782

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

Successfully merging this pull request may close these issues.

2 participants