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 on iOS. #1782

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

Conversation

alex-gutev
Copy link

Summary

This pull request fixes a bug where the captureMethod parameter of the intent configuration, for deferred payments, is ignored on iOS. In the Swift code the captureMethod parameter is being retrieved from the intentConfiguration dictionary however the parameter is actually passed in the modeParams dictionary.

guard let modeParams = intentConfiguration["mode"] as? NSDictionary else {
resolve(Errors.createError(ErrorType.Failed, "One of `paymentIntentClientSecret`, `setupIntentClientSecret`, or `intentConfiguration.mode` is required"))
return
}
if (intentConfiguration.object(forKey: "confirmHandler") == nil) {
resolve(Errors.createError(ErrorType.Failed, "You must provide `intentConfiguration.confirmHandler` if you are not passing an intent client secret"))
return
}
let captureMethodString = intentConfiguration["captureMethod"] as? String

This issue does not occur on Android where the captureMethod parameter is being retrieved correctly from the modeParams map.

PaymentSheet.IntentConfiguration.Mode.Payment(
amount = modeParams.getInt("amount").toLong(),
currency = currencyCode,
setupFutureUse = mapToSetupFutureUse(modeParams.getString("setupFutureUsage")),
captureMethod = mapToCaptureMethod(modeParams.getString("captureMethod")),
)

Motivation

The issue appears when collecting payment details before creating a payment intent with a manual capture method. Since the capture method given to the payment sheet's intent configuration is ignored on iOS, there is a mismatch between the actual capture method of the payment intent (manual) and that of the payment sheet's intent configuration (automatic). This results in an error message being shown when the pay button is tapped. On Android the payment proceeds as expected.

To reproduce the bug:

Modify the example from https://docs.stripe.com/payments/accept-a-payment-deferred to specify a manual capture method in the intent configuration:

import { useStripe, PaymentSheet } from '@stripe/stripe-react-native';
import {View, Button} from 'react-native';

export default function CheckoutScreen() {
  const { initPaymentSheet, presentPaymentSheet } = useStripe();

  const initializePaymentSheet = async () => {
    const { error } = await initPaymentSheet({
      merchantDisplayName: "Example, Inc.",
      intentConfiguration: {
        mode: {
          amount: 1099,
          currencyCode: 'USD',
          captureMethod: PaymentSheet.CaptureMethod.Manual
        },
        confirmHandler: confirmHandler
      }
    });
    if (error) {
      // handle error
    }
  };

  useEffect(() => {
    initializePaymentSheet();
  }, []);

  const confirmHandler = async (paymentMethod, shouldSavePaymentMethod, intentCreationCallback) => {
    // explained later
  }

  const didTapCheckoutButton = async () => {
    // implement later
  }
  return (
    <View>
      <Button
        title="Checkout"
        onPress={didTapCheckoutButton}
      />
    </View>
  );
}

The backend should also be changed to create a payment intent with a manual capture method.

Testing

I have not directly tested these changes but I discovered the issue in the flutter_stripe library, which is based on stripe-react-native. A quick review of the code indicates that this library has the same issue.

Documentation

  • This PR does not result in any developer-facing changes.

Copy link

cla-assistant bot commented Nov 30, 2024

CLA assistant check
All committers have signed the CLA.

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