capacitor-community / stripe

Stripe Mobile SDK wrapper for Capacitor
MIT License
185 stars 74 forks source link

Return to merchant button not working #96

Closed raghuchaharsqm closed 2 years ago

raghuchaharsqm commented 2 years ago

I am trying to integrate payment flow using stripe and capacitor on frontend and stripe with NodeJs on backend, Following steps provided in this repo but stucked on return to merchant button after createPaymentFlow method.

Backend(NodeJs):

const createPaymentIntent = async (args) => {
  const { currency, amount, customerId } = args;
  const result = await stripe.paymentIntents.create({
    amount,
    currency: CURRENCY,
    customer: customerId
  });
  return result;
};

const createEphermalKey = async (args) => {
  const { customerId } = args || {};
  const ephemeralKey = await stripe.ephemeralKeys.create({ customer: customerId }, { apiVersion: "2020-08-27" });
  return ephemeralKey;
};

const createCustomer = async (args) => {
  const { email, metadata, name, paymentMethod } = args || {};
  const result = await stripe.customers.create({
    email,
    metadata,
    name

    // payment_method: paymentMethod
  });
  return result;
};

Fontend(Ionic-react/capacitor) -

const initiatePayment = async () => {
    var stripObj: any = await API.graphql(
      graphqlOperation(createStripeIntent, { reservationId: "121212121", paymentMethod: "card" })
    );
    try {
      const {
        clientSecret: paymentIntent,
        ephemeralKey,
        customerId: customer
      } = stripObj && stripObj.data && stripObj.data.createStripeIntent;
      let option: CreatePaymentSheetOption = {
        customerId: customer,
        paymentIntentClientSecret: paymentIntent,
        customerEphemeralKeySecret: ephemeralKey,
        style: "alwaysDark"
      };
      const result1 = await Stripe.createPaymentSheet(option);
      console.log("result1 >>> ", result1);

      const result = await Stripe.presentPaymentSheet();
      console.log("result >>> ", result);
    } catch (error) {
      console.error("4 : ", error);
    }
  };

When I am initiating payment, I am getting add your payment information page. After adding card, I am getting a button return to merchant in stripe web view, but that button is not working, neither the payment is successful. Is there any step missing in docs which I had to consider, please help me out in this.

rdlabo commented 2 years ago

@raghuchaharsqm Please try demo app. : https://github.com/capacitor-community/stripe/tree/master/demo/angular Also check the console for any errors.

raghuchaharsqm commented 2 years ago

@raghuchaharsqm Please try demo app. : https://github.com/capacitor-community/stripe/tree/master/demo/angular Also check the console for any errors.

I got the error, actually there were few things missing in docs i.e we have to save address, description and name while creating customer while paying in outside currency from India (eg. USD) which is not mentioned in docs and is explicitly mentioned on this doc https://stripe.com/docs/india-accept-international-payments. I guess stripe needs to update the docs for this specific case. Later I tried payments in INR which worked perfectly. Also, return to merchant button would start work after deep linking as mentioned in docs but the payment was successful after using INR or saving address, description and name for other currencies.

rdlabo commented 2 years ago

@raghuchaharsqm Thanks for good issues and resolve method. This plugin is wrapper for using stripe, so can't cover in this case in readme. But if anyone get same trouble, may support by this issues! And if you have a time, please conntact stripe for recommend update to document of stripe. Thanks.

rdlabo commented 2 years ago

It looks to resolved issue, so I will close this issue.

rdlabo commented 2 years ago

@raghuchaharsqm Did you adapt this plugin for production? If yes, please tell us what app. Please help us to develop this plugin in 2022. https://github.com/capacitor-community/stripe/issues/145 Thanks.