#harry_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1318204902350131220
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
What data exactly do you need from the API? Just their PMs?
no I am actually storing ids of customers from stripe
Yes I understand you have a list of cus_xxx IDs, but what data do you need from the API that you're making requests for?
So If in the customers list i have duplicates by email, I only need the ones with payment method, can I check if the customer has payment method on file? without calling list payment methods?
No, there's no reference to available methods on the Customer object. You'd just use this endpoint, or store the most recent pm_xxx in your DB
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I am not saving any payment method data actually. I can send you the piece of code, for more clarity
Sure
$customers = [];
$starting_after = null;
do {
// list api https://docs.stripe.com/api/customers/list
$response = $stripeService->listAllCustomers($starting_after);
$responseData = $response['data'];
foreach ($responseData as $customer) {
if (!empty($customer->email)) {
// If multiple customers exist with same email, prefer one with payment method
if (isset($customers[$customer->email])) {
// https://docs.stripe.com/api/payment_methods/list
$hasPaymentMethod = !empty($stripeService->getCustomerPaymentMethods($customer->id)->data);
if ($hasPaymentMethod) {
$customers[$customer->email] = [
'gateway' => 'stripe',
'gateway_id' => $customer->id,
'has_payment' => true
];
}
} else {
$hasPaymentMethod = !empty($stripeService->getCustomerPaymentMethods($customer->id)->data);
$customers[$customer->email] = [
'gateway' => 'stripe',
'gateway_id' => $customer->id,
'has_payment' => $hasPaymentMethod
];
}
}
}
// Get the last customer ID for pagination
$lastCustomer = collect($responseData)->last();
$starting_after = $lastCustomer ? $lastCustomer->id : null;
} while ($response['has_more']);
return $customers;
Sure, so how can I help? Still not really clear how/where we can help exactly
So do you see the api calls in a loop? I need to avoid those. So basically try to achieve that from $response from listAllCustomers
Basically, you want to get all PaymentMethods of all customers in a single call?
I am only calling that api to check if customer has payment method on file or not. So if I can only get that from response in listAllCustomers that will do
You can only check if the Customer has the default_payment_method for Billing in that way: https://docs.stripe.com/api/customers/object#customer_object-invoice_settings-default_payment_method
The Customer object doesn't have the PaymentMethods property, so you can't expand it unfortunately. You need to make a separate call to get the list of attached PaymentMethods for each Customer.