#harry_api

1 messages ¡ Page 1 of 1 (latest)

dire blazeBOT
#

👋 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.

viscid bison
#

What data exactly do you need from the API? Just their PMs?

runic surge
#

no I am actually storing ids of customers from stripe

viscid bison
#

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?

runic surge
#

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?

viscid bison
#

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

runic surge
#

I am not saving any payment method data actually. I can send you the piece of code, for more clarity

viscid bison
#

Sure

dire blazeBOT
runic surge
#

$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;
viscid bison
#

Sure, so how can I help? Still not really clear how/where we can help exactly

runic surge
#

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

soft schooner
#

Basically, you want to get all PaymentMethods of all customers in a single call?

runic surge
#

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

soft schooner