I’m trying to generate an invoice through stripe but the API requires a Client ID which I have no idea how to retrieve.
I’m using Session checkout:
method called by ajax
$checkout_session = CheckoutSession::create([ 'payment_method_types' => ['card'], 'line_items' => [[ 'price_data' => [ 'currency' => 'usd', 'unit_amount' => 2000, 'product_data' => [ 'name' => 'Stubborn Attachments', 'images' => ["https://i.imgur.com/EHyR2nP.png"], ], ], 'quantity' => 1, ]], 'customer_email' => $email, 'mode' => 'payment', 'success_url' => $domain. '/success/{CHECKOUT_SESSION_ID}', 'cancel_url' => $domain. '/cancel/{CHECKOUT_SESSION_ID}', ]);
I receive
[ "id" => "cs_test_xxxxxxxxxxxxxxxx" "object" => "checkout.session" "allow_promotion_codes" => null "amount_subtotal" => 2000 "amount_total" => 2000 "billing_address_collection" => null "cancel_url" => "http://localhost/cancel/{CHECKOUT_SESSION_ID}" "client_reference_id" => null "currency" => "usd" "customer" => null "customer_details" => null "customer_email" => "xxxxxxxxxxx@gmail.com" "livemode" => false "locale" => null "metadata" => [] "mode" => "payment" "payment_intent" => "pi_xxxxxxxxxxxxx" "payment_method_options" => [] "payment_method_types" => array:1 [ 0 => "card" ] "payment_status" => "unpaid" "setup_intent" => null "shipping" => null "shipping_address_collection" => null "submit_type" => null "subscription" => null "success_url" => "http://localhost/success/{CHECKOUT_SESSION_ID}" "total_details" => array:3 [ "amount_discount" => 0 "amount_shipping" => 0 "amount_tax" => 0 ] ]
Create invoice requires a customer id which I don’t have and have no idea where to get since session checkout creates a customer without giving me an id.
Advertisement
Answer
A Checkout Session in payment
mode will generate a Payment Intent, not an Invoice. If you want to work solely with Invoices, you Checkout Session is not the right solution. If you don’t care about Invoices and just want to be able to charge a customer for a one-off payment then you can continue using Checkout.
If you do want to work solely with Invoices, you need to do the following:
- Create a Customer
- Pass in the Customer ID when you create as many Invoice Items as you need
- Pass in the Customer ID when you create an Invoice – this will automatically pull in any pending Invoice Items tied to the customer.
This is all summarized in this guide: https://stripe.com/docs/invoicing/integration