flutter-stripe / flutter_stripe

Flutter SDK for Stripe.
https://pub.dev/packages/flutter_stripe
960 stars 528 forks source link

Not getting SEPA Debit Direct in PaymentSheet while Subscription: None of the requested payment methods ([sepa_debit]) match the supported payment types ([card, bancontact, sofort, ideal, sepa_debit, eps, giropay, p24, klarna, paypal, afterpay_clearpay]) #897

Closed ShwetaChauhan18 closed 2 years ago

ShwetaChauhan18 commented 2 years ago

Describe the bug When I try to create one time payment and using client secret if I open PaymentSheet I am able to get all payment method which is enable. e.g. Card, SEPA Debit Direct.

Now, when I try to do same thing for Subscription then not getting SEPA Direct Debit payment method.

To Reproduce Steps to reproduce the behavior:

  1. Create Setup Intent for Subscription
  2. Get Client Secret
  3. Using that client secret open Payment Sheet
  4. SEPA Debit Direct payment method should available in payment sheet
  5. But only getting Card and Gpay payment method.

Expected behavior All payment method which is enable should show in PaymentSheet for Subscription.

Smartphone / tablet

Some code

{
  "id": "seti_1Lc0n9GVrxoPH8K03CeVt4ei",
  "object": "setup_intent",
  "application": null,
  "cancellation_reason": null,
  "client_secret": "seti_1Lc0n9GVrxoPH8K03CeVt4ei_secret_MKg9rKCWv1FOJAEDZbmWOHTFapLJJtc",
  "created": 1661751947,
  "customer": "cus_MKg79MrzKRUqhZ",
  "description": null,
  "flow_directions": null,
  "last_setup_error": null,
  "latest_attempt": null,
  "livemode": false,
  "mandate": null,
  "metadata": {},
  "next_action": null,
  "on_behalf_of": null,
  "payment_method": null,
  "payment_method_options": {},
  "payment_method_types": [
    "sepa_debit"
  ],
  "single_use_mandate": null,
  "status": "requires_payment_method",
  "usage": "off_session"
}
jonasbark commented 2 years ago

Hi @ShwetaChauhan18 can you try adding

allowsDelayedPaymentMethods: true,

to your initPaymentSheet method?

ShwetaChauhan18 commented 2 years ago

I already did.

Here is my code,

await Stripe.instance.initPaymentSheet(
        paymentSheetParameters: SetupPaymentSheetParameters(
          // Enable custom flow
          /*customFlow: true,*/
          // Main params
          merchantDisplayName: 'Flutter Stripe Store Demo',
          /*paymentIntentClientSecret:
          'pi_3LcR53GVrxoPH8K00Fk4j5F4_secret_WlGh0mFKYe2wlsImrzzZo3qfU',*/
          setupIntentClientSecret: 'seti_1Lc0n9GVrxoPH8K03CeVt4ei_secret_MKg9rKCWv1FOJAEDZbmWOHTFapLJJtc',
          /*data['paymentIntent'],*/
          // Customer keys
          /*customerEphemeralKeySecret: data['ephemeralKey'],*/
          /*customerId: 'cus_MDbypsfwxoTP6q',*/
          // Extra options
          applePay: PaymentSheetApplePay(
            merchantCountryCode: 'DE',
            paymentSummaryItems: [
              ApplePayCartSummaryItem.immediate(
                  label:
                  'ABC',
                  amount: "0.0",
              ),
            ],
          ),
          googlePay: PaymentSheetGooglePay(merchantCountryCode: 'DE'),
          style: ThemeMode.dark,
          allowsDelayedPaymentMethods: true,
        ),
      );
mobile-simformsolutions commented 2 years ago

Anyone can answer?? I think it's with this flutter implementation because, in stripe dashboard, I am getting SEPA DD option in Checkout page.

ShwetaChauhan18 commented 2 years ago

Here is our server side code:

async createSubscription(payload: CreateSubscriptionDto): Promise<{
    data: Stripe.Response<Stripe.Subscription> | null;
    error: Stripe.Errors | null;
  }> {
    try {
      const {
        customerId,
        priceId,
        coupon = null,
        trial_end = null,
        metadata,
        default_payment_method = null,
      } = payload;
      let payment_behaviour = payload.payment_behaviour;
      const PAYMENT_BEHAVIOUR = Object.values(paymentBehaviour);
      if (
        !payment_behaviour ||
        !PAYMENT_BEHAVIOUR.includes(payment_behaviour)
      ) {
        payment_behaviour = paymentBehaviour.DEFAULT_INCOMPLETE;
      }
      let paymentMethodType: Stripe.Emptyable<
        Stripe.SubscriptionCreateParams.PaymentSettings.PaymentMethodType[]
      > = ['card'];
      const priceInfo: Stripe.Response<Stripe.Price> =
        await this.stripeClient.prices.retrieve(priceId);
      if (priceInfo?.currency === 'eur') {
        paymentMethodType = ['card', 'sepa_debit'];
      }
      const createSubscription: Stripe.SubscriptionCreateParams = {
        customer: customerId,
        items: [{ price: priceId }],
        coupon,
        payment_behavior: payment_behaviour,
        expand: ['latest_invoice.payment_intent', 'pending_setup_intent'],
        metadata,
        payment_settings: {
          payment_method_types: paymentMethodType,
        },
      };
      if (trial_end) {
        createSubscription.trial_end = trial_end;
        createSubscription.payment_behavior = paymentBehaviour.ALLOW_INCOMPLETE;
      }
      if (default_payment_method) {
        createSubscription.default_payment_method = default_payment_method;
      }
      const subscriptionInfo: Stripe.Response<Stripe.Subscription> =
        await this.stripeClient.subscriptions.create(createSubscription);
      if (!subscriptionInfo) {
        return { data: null, error: null };
      }
      return { data: subscriptionInfo, error: null };
    } catch (error) {
      return { data: null, error: error };
    }
  }

Using this below is ClientSecret which I got and using that ClientSecret I open payment sheet.

{subscriptionId: sub_1Ld6I1GVrxoPH8K0AH6Alnuc, customerId: cus_MJcqkLF2BE29I1, payment_intent: {clientSecret: pi_3Ld6I2GVrxoPH8K02ceAEvai_secret_TFTa0uL1BJMk8G8ReTxlyhHti}, pending_setup_intent: {clientSecret: null}, prices: {price: 1000, currency: eur}, subscriptionStatus: incomplete}}

You can see in attached image, SEPA DD is not showing as payment option.

sepa
jonasbark commented 2 years ago

does it show up when you only enable sepa_debit as paymentMethodType? I tried it in our development (sync) branch and it showed up correctly.

ShwetaChauhan18 commented 2 years ago

Let me check with your development branch again.

ShwetaChauhan18 commented 2 years ago

Here is development(sync) branch output.

image

Here is initPaymentSheet code. (I tried with customFlow: true option also)

 await Stripe.instance.initPaymentSheet(
        paymentSheetParameters: SetupPaymentSheetParameters(
          // Enable custom flow
          /*customFlow: true,*/
          // Main params
          allowsDelayedPaymentMethods: true,
          merchantDisplayName: 'Flutter Stripe Store Demo',
          paymentIntentClientSecret: 'pi_3Ld6I2GVrxoPH8K02ceAEvai_secret_TFTa0uL1BJMk8G8ReTxlyhHti',
          // Customer keys
          /*customerEphemeralKeySecret: data['ephemeralKey'],*/
          customerId: 'cus_MJcqkLF2BE29I1',
          // Extra options
          applePay: PaymentSheetApplePay(
            merchantCountryCode: 'DE',
          ),
          googlePay: PaymentSheetGooglePay(merchantCountryCode: 'DE'),
          style: ThemeMode.dark,
        ),
      );
ShwetaChauhan18 commented 2 years ago

@jonasbark: Any solution or anything which I missed from my side?? Can you please guide us?

jonasbark commented 2 years ago

with the latest Flutter Stripe 5.0.0 release, I was able to successfully show sepa_debit payment types in the payment sheet, using allowsDelayedPaymentMethods: true and enabling sepa_debit in the backend as a singular supported payment type.

ShwetaChauhan18 commented 2 years ago

@jonasbark : What do you mean by "enabling sepa_debit in the backend as a singular supported payment type"

Can you please confirm, will it work in subscription or not?? Because I am still not getting in your demo.

ShwetaChauhan18 commented 2 years ago

@jonasbark : Can you please try using this paymentIntentClientSecret and customerID.

    allowsDelayedPaymentMethods: true,
    merchantDisplayName: 'Flutter Stripe Store Demo',
    paymentIntentClientSecret: 'pi_3LeZNeGVrxoPH8K024F9PNkt_secret_TkcnsoHgrmgntO3Cmieyk1BCc',
    customerId: 'cus_MJcqkLF2BE29I1',

See here, you can see SEPA DD is available and when I click on this link it will ask detail for SEPA DD: https://invoice.stripe.com/i/acct_1GkcatGVrxoPH8K0/test_YWNjdF8xR2tjYXRHVnJ4b1BIOEswLF9NTksxOVJIdndKWnpiam5Fa0RYenY0QTAzZnhqcUlYLDUyOTEwMDY402005u8UlzDK?s=db

image

In Mobile payment sheet, It will show error like this:

MicrosoftTeams-image (4)

So, my concern is, will it work in PaymentSheet for subscription??? Just need confirmation.