#verox_api

1 messages ¡ Page 1 of 1 (latest)

fluid quartzBOT
#

👋 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/1234465290973347880

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

loud scaffold
#

Invoice Creation:

$invoice = Cashier::stripe()->invoices->create([
                'customer' => $request->user()->stripe_id,
                'auto_advance' => false,
                'collection_method' => 'charge_automatically',
                'currency' => $currency,
                'description' => 'Server - ' . $validated['name'],
                'payment_settings' => [
                    'payment_method_types' => config('cashier.charge.' . $currency)
                ],
                // Make sure the payment method gets saved if the invoice is paid
            ]);

Listener:

if (str_starts_with($type, 'payment_intent.') && ($data['status'] ?? 'failed') === 'succeeded' && $data['payment_method']) {
            $user = User::where('stripe_id', $data['customer'])->first();
            $paymentMethod = Cashier::stripe()->paymentMethods->retrieve($data['payment_method']);
            \Log::info($paymentMethod);

            $paymentMethod->attach(['customer' => $user->stripe_id]);

            // Attach payment method to user and update default payment method
            // $user->addPaymentMethod($data['payment_method']);
            $user->updateDefaultPaymentMethod($data['payment_method']);
        }

The error occurs on $paymentMethod->attach(['customer' => $user->stripe_id]);.

rustic juniperBOT
broken dome
#

I'm trying to attach a payment method used in an invoice to an user
No you can't achieve that. You need to collect the payment method first and then used with an invoice if you want.

#

Unless the customer choosed to save their payment method when paying the invoice

loud scaffold
#

So, I have to use a setup intent?

broken dome
#

Yes

loud scaffold
#

Alright, thank you.