#just4skiillz-paymentsheet

1 messages ยท Page 1 of 1 (latest)

blissful sparrowBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

abstract ember
#

to be as clear as possible, the first time a customer buys he makes a setupIntent with a card payment method attach to it, the next time hes coming back, how to privide the saved card option in the payment sheed?

#

sheet*

#

im in react native*

icy kraken
#

If you're using the Payment Sheet, the saved payment methods will be automatically populted in the sheet as long as you pass in the Customer ID and Customer Ephemeral Key secret when you initialize the Paymetn Sheet

abstract ember
#

can I show you my code because its not rendering...

#

my front end:

const initialisePaymentSheet = async () => {
const { setupIntent, ephemeralKey, customer } =
await fetchPaymentSheetParams();
console.log("intent:", setupIntent);
setIntent(setupIntent);
setCustomerId(customer);

const { error } = await initPaymentSheet({
  customerId: customer,
  customerEphemeralKeySecret: ephemeralKey,
  setupIntentClientSecret: setupIntent,
  merchantDisplayName: "Example Inc.",
  applePay: {
    merchantCountryCode: "CA",
  },
  googlePay: {
    merchantCountryCode: "CA",
    testEnv: true,
    currencyCode: "cad",
  },
  allowsDelayedPaymentMethods: true,
  returnURL: "stripe-example://stripe-redirect",
});
if (error) {
  Alert.alert(`Error code: ${error.code}`, error.message);
} else {
  setReady(true);
}

};
const address = {
city: user.city,
country: user.country,
line1: user.address,
postal_code: user.postalCode,
state: user.province,
};

const fetchPaymentSheetParams = async () => {
const response = await fetch(
http://${IP_Address}:4000/payment-sheet-setup-intent,
{
method: "POST",
body: JSON.stringify({
name: user.firstName + " " + user.lastName,
email: user.email,
address: address,
}),
headers: {
"Content-Type": "application/json",
},
}
);
const { setupIntent, ephemeralKey, customer } = await response.json();
return {
setupIntent,
ephemeralKey,
customer,
};
/////////////////////

////////////////

};

icy kraken
#

Sharing the code doesn't really help in this scenario - the code looks generally right, but a numer of other things could be going wrong

#

Like if the customer ID or ephemeral Key aren't valid that would be a problem

abstract ember
#

ok i have a question but on the loading of the modal im creating a new setupIntent maybe its that the problem?

#

like Ive put a used effect that do this:
(backend):
app.post("/payment-sheet-setup-intent", async (req, res) => {
const {
name = name,
email = email,
address = {
city: address.city,
country: address.country,
line1: address.line1,
postal_code: address.postal_code,
state: address.state,
},
metadata = { orderId: "65678" },

payment_method_types = [],

} = req.body;

const customer = await stripe.customers.create({
name,
email,
address,
metadata,
});

const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customer.id },
{ apiVersion: "2020-08-27" }
);
const setupIntent = await stripe.setupIntents.create({
...{
customer: customer.id,
payment_method_types,
},
});

return res.json({
setupIntent: setupIntent.client_secret,
ephemeralKey: ephemeralKey.secret,
customer: customer.id,
});
});

#

maybe I need to load the existing setupIntent of an existing customeId instead of always creating a new?

icy kraken
#

Yeah that's likely related - if you want to be offering your customer the ability to use a payment method they've already saved, you can't be creating a whole new customer ID. YOu need to use the one that's already been created and has payment methods associated with it

abstract ember
#

so do I fetch that custommer? and if he found one do I still create a new setupIntent or i need to fetch his setup intent?

icy kraken
#

just4skiillz-paymentsheet

#

That'll depend entirely on how your integration works - you need to associate the customer with something that allows you to know which customer to retrieve in the future (like if you have this concept of "logging-in" you can have your user log in and then retrieve the correct customer from there)

#

and if you're having them pay you wouldn't need a new etup intent at all, you'd use a paymetn intent instead

abstract ember
#

I just want to give them the choice of using a saved payment method or creating a new one

#

is there a way to retrieve a cusomer id with an email? because in my app they are logging with there email

blissful sparrowBOT
abstract ember
#

(Im french canadian my english is bad)

icy kraken
abstract ember
#

ok thank you ill try that

abstract ember
#

ok so ive updated my request to fetch if there is an existing customer,
app.post("/payment-sheet-setup-intent", async (req, res) => {
const {
name = name,
email = email,
address = {
city: address.city,
country: address.country,
line1: address.line1,
postal_code: address.postal_code,
state: address.state,
},
metadata = { orderId: "65678" },
payment_method_types = [],
} = req.body;

let customer;

try {
// Check if the customer already exists
const existingCustomer = await stripe.customers.list({
email: email,
limit: 1,
});

if (existingCustomer && existingCustomer.data.length > 0) {
  // Customer already exists
  console.log("existing:", existingCustomer);
  customer = existingCustomer.data[0];
} else {
  // Customer doesn't exist, create a new one
  customer = await stripe.customers.create({
    name,
    email,
    address,
    metadata,
  });
  console.log("new", customer);
}

const ephemeralKey = await stripe.ephemeralKeys.create(
  { customer: customer.id },
  { apiVersion: "2020-08-27" }
);

const setupIntent = await stripe.setupIntents.create({
  customer: customer.id,
  payment_method_types,
});

return res.json({
  setupIntent: setupIntent.client_secret,
  ephemeralKey: ephemeralKey.secret,
  customer: customer.id,
});

} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
}
});

#

i log if im getting an existing of a new customer and im getting existing:
existing: {
object: 'list',
data: [
{
id: 'cus_P8myN87HIOqX7Q',
object: 'customer',
address: [Object],
balance: 0,
created: 1701908697,
currency: null,
default_source: null,
delinquent: false,
description: null,
discount: null,
email: 'Screamwiso@hotmail.com',
invoice_prefix: '06D0413A',
invoice_settings: [Object],
livemode: false,
metadata: {},
name: 'Potato Jono',
next_invoice_sequence: 1,
phone: null,
preferred_locales: [],
shipping: null,
tax_exempt: 'none',
test_clock: null
}
],
has_more: true,
url: '/v1/customers'

#

but im still not getting the pmt attached...

bitter kiln
#

๐Ÿ‘‹ Taking over this thread, catching up now

abstract ember
#

ok thanks

bitter kiln
#

What is the issue here? Are you looking for the option to have customer saving his/her payment method entered or displaying the saved payment methods?

abstract ember
#

displaying the saved payment method while giving the option of entering a new pmt method

#

i succeed in the past of showing the 424242424242242 card but for a reason its not showing anymore

#

you know like in the payment sheet shown above, we are suppose to see above the "add pmt method", the saved card option

#

so i dont know whats wrond that I m not seeing it anymore

#

LOL i found the problem

#

The reason is so stupid lol

#

i need to explain

#

before i was not checking if the customer was existing before creating.....

#

so in my custommer i have 5 same eamil customer

#

4 without pmt method and one good

#

when I was retrieving by email with a limit of 1, i was always getting the one without pmt method

#

anyway sorry for your time

bitter kiln
#

Awesome! I was about to let you know that I don't see any payment method attached onto the customer cus_P8myN87HIOqX7Q. Great to hear everything is working well now ๐Ÿ˜„

abstract ember
#

yeah lol have a great night!