#Gerald - Redfluencer

1 messages · Page 1 of 1 (latest)

unreal sorrelBOT
rich kestrel
humble basin
#

Hi Jack give me a moment

#

req_IevfTVR81kUEGV

rich kestrel
#

I don't think this is the correct request ID, the response is 200 and there's no error

humble basin
#

let me try it again

#

Hi jack, still the same. The intent pops up for a quick second before it closes and throws the same error

#

would it be alright if I could do a video call to show you?

rich kestrel
#

I can only support you through chat.

#

Or can you share with me the relevant code? both backend and frontend.

humble basin
#

sure

#

backend

    apiVersion: "2022-08-01",
  });

  const token = await stripe.tokens.create(
    { customer: "cus_Mg2WOw41gS1ggp" },
    { stripeAccount: "acct_1LwfZwCGwb4Rcxpz" }
  );

  const customer = await stripe.customers.create(
    { source: token.id },
    { stripeAccount: "acct_1LwfZwCGwb4Rcxpz" }
  );

  console.log(customer);

  const ephemeralKey = await stripe.ephemeralKeys.create(
    { customer: "cus_Mg2WOw41gS1ggp" },
    { apiVersion: "2022-08-01" }
  );

  const paymentIntent = await stripe.paymentIntents.create(
    {
      amount: 999,
      currency: "sgd",
      payment_method_types: ["card"],
      customer: customer.id,
      payment_method: customer.default_source,
    },
    {
      stripeAccount: "acct_1LwfZwCGwb4Rcxpz",
    }
  );
  console.log(paymentIntent);
  res.json({
    paymentIntent: paymentIntent.client_secret,
    ephemeralKey: ephemeralKey.secret,
    customer: "cus_Mg2WOw41gS1ggp",
  });```
#

frontend

    // temp body
    const params = {
      userId: userInfo.uid,
      stripeId: userData.stripeId,
      amount: parseFloat(payToMerchantAmount),
      shopId: merchantData.shopUUID,
      merchantId: merchantData.merchantUUID,
      promoCode,
    };
    const { token } = await auth().currentUser.getIdTokenResult();
    const response = await fetch(`${API_URL}/stripe/checkout`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Accept: "application/json",
        Authorization: `Bearer ${token}`,
      },
      body: JSON.stringify({ params }),
    });
    const { paymentIntent, ephemeralKey, customer, dateCreated } =
      await response.json();

    return {
      paymentIntent,
      ephemeralKey,
      customer,
      dateCreated,
    };
  };
#
    const proceed = paymentControls();

    if (!proceed) {
      return;
    }

    setLoading(true);

    const { paymentIntent, ephemeralKey, customer, dateCreated } =
      await fetchPaymentSheetParams();
    const { error } = await initPaymentSheet({
      customerId: customer,
      customerEphemeralKeySecret: ephemeralKey,
      paymentIntentClientSecret: paymentIntent,
      merchantDisplayName: "testing",
      postalCodeField: false,
      defaultBillingDetails: {
        address: {
          country: "SG",
        },
      },
      appearance: {
        shapes: {
          borderRadius: 12,
          borderWidth: 0.5,
        },
        colors: {
          primary: "#FF2741",
          background: "#ffffff",
          componentBackground: "#f3f8fa",
          componentBorder: "#f3f8fa",
          componentDivider: "#000000",
          primaryText: "#000000",
          secondaryText: "#000000",
          componentText: "#000000",
          placeholderText: "#73757b",
        },
      },
    });
    if (!error) {
      await openPaymentSheet(paymentIntent, dateCreated);
    }
  };```
#

I will call initializePaymentSheet when a button is being pressed

rich kestrel
#

OK. I think I know the problem.

#

You need to specify the stripeAccountId when initializing the react-native SDK.

#
      publishableKey="{{PLATFORM_PUBLISHABLE_KEY}}"
      stripeAccountId="{{CONNECTED_STRIPE_ACCOUNT_ID}}"
    >
      // Your app code here
    </StripeProvider>```
humble basin
#

oh I see now it works. So does that I have to dynamically change the stripe account ID everytime I pay to a different merchant?

rich kestrel
#

And you also need to specify the stripeAccount when creating the ephemeral key

humble basin
rich kestrel
#

You should specify the stripe account ID for the merchant that you wish to operate on behalf of.

humble basin
rich kestrel
#
stripe.ephemeralKeys.create({
    customer: 'cux_XXX',
    apiVersion: '2022-08-01'
  },{
    stripeAccount: 'CONNECTED_ACCOUNT_ID'
  })
#

It should be something like this

humble basin
#

got it thanks