#inquisitive_code

1 messages ¡ Page 1 of 1 (latest)

heavy meadowBOT
#

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

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

fading quail
round path
#

wont' it automatically charge the customer?

$invoice = $this->stripe->invoices->create([
 'customer' => $stripeCustomer->id,
 'collection_method' => 'charge_automatically',
 'metadata' => $metaData,
 'pending_invoice_items_behavior' => 'exclude'
]);

//add subscription invoice item
$this->stripe->invoiceItems->create([
  'customer'    => $stripeCustomer->id,
  'price'       => config('services.stripe.per_user_base_price_id'),  // env
  'quantity'    => $perUserBillingDTO->baseCharge->quantity,
  'description' => 'Per User Subscription Base Price',
  'invoice'     => $invoice->id
]);

//add extra invoice item
if(!empty($perUserBillingDTO->extraCharge->quantity)){
   $this->stripe->invoiceItems->create([
        'customer'    => $stripeCustomer->id,
        'price'       => config('services.stripe.per_user_price_id'), // env
        'quantity'    => $perUserBillingDTO->extraCharge->quantity,
        'description' => 'Extra Per User Subscription Fee',
        'invoice'     => $invoice->id
   ]);
}

//finalize invoice
$this->stripe->invoices->finalizeInvoice($invoice->id);

so you mean at the end I should attach the payment intent like this?

$stripe->invoices->finalizeInvoice(
  '{{INVOICE_ID}}',
  ['expand' => ['payment_intent']]
);
fading quail
#

The guide I linked has a full API integration guide

#

But no, invoices created via API won't auto charge a customer

round path
#

so what should I be doing instead?

fading quail
round path
#

I still do not get it, that it looks like the code is passing the invoice to the payment page and user themselves is making the payment. Right?

Isn't there any other way to create a invoice on start of the month based on the usage of the customer on last month and let stripe collect the payment automatically?

fading quail
#

I still do not get it, that it looks like the code is passing the invoice to the payment page and user themselves is making the payment. Right?
Well, if you need to collec tpayment information from them yes. That will facilitate collecting that. Otherwise, if there's already an payment method set on the invoice/intent you can just call confirmPayment and pass the existing pm_xxx ID

grizzled timberBOT
round path
#

yes they already do have the payment method

#

One way I do see is using $invoice->pay(). But instead of running the job I was looking for stripe trying themselves to collect payment

bold bear
#

Stripe will do it, after the invoice is finalized we will eventually pick it up and attempt to charge it(I think it takes an hour). Or you can force payment earlier using the approaches discussed.

round path
#

can I simulate to verify if it will charge the customer or not?

#

if so, how can I verify it. Also, this invoice is the one creating using the above shared code though.

bold bear
round path