Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement to the Cashier invoice #1397

Closed
ekrist1 opened this issue Jul 14, 2022 · 2 comments · Fixed by #1409
Closed

Improvement to the Cashier invoice #1397

ekrist1 opened this issue Jul 14, 2022 · 2 comments · Fixed by #1409

Comments

@ekrist1
Copy link

ekrist1 commented Jul 14, 2022

The Stripe Invoice is not only for invoicing outside of the regular billing cycle as commented in the ManageInvoices.php file. It´s also for invoicing one-time payment and subscriptions: https://stripe.com/en-gb-no/invoicing

It would be nice to be able to create the invoice and email the invoice as two seperate steps. This will also allow to finalize the invoice before emailing the invoice, aligned with the Stripe documentation: https://stripe.com/docs/invoicing/integration

Maybe the Cashier documentation should be updated with the option for emailing invoices, with a exclamation mark:
Requests made in test-mode result in no emails being sent, despite sending an invoice.sent event.

Current implentation to send a email invoice:

$createinvoice = auth()->user()->invoicePrice('price_xxyyzz', 1, [], [
'collection_method' => 'send_invoice',
'days_until_due' => 3,
'auto_advance' => true,
'description' => 'Product description',
]);

Src/Concerns/ManageInvoices.php:

/**
* Invoice the customer outside of the regular billing cycle.
*
* @param array $options
* @return \Laravel\Cashier\Invoice|bool
*
* @throws \Laravel\Cashier\Exceptions\IncompletePayment
*/
public function invoice(array $options = [])
{
$this->assertCustomerExists();

$parameters = array_merge([
'automatic_tax' => $this->automaticTaxPayload(),
'customer' => $this->stripe_id,
], $options);

try {
/** @var \Stripe\Invoice $invoice */
$stripeInvoice = $this->stripe()->invoices->create($parameters);

if ($stripeInvoice->collection_method === StripeInvoice::COLLECTION_METHOD_CHARGE_AUTOMATICALLY) {
$stripeInvoice = $stripeInvoice->pay();
} else {
$stripeInvoice = $stripeInvoice->sendInvoice();
}

return new Invoice($this, $stripeInvoice);
} catch (StripeInvalidRequestException $exception) {
return false;
} catch (StripeCardException $exception) {
$payment = new Payment(
$this->stripe()->paymentIntents->retrieve(
$stripeInvoice->refresh()->payment_intent,
['expand' => ['invoice.subscription']]
)
);

$payment->validate();
}
}
@driesvints
Copy link
Member

Yeah I feel we could offer some better API's here. I'll currently mark this as a feature request but right now have no plans on working this ourselves. Feel free to PR.

@driesvints
Copy link
Member

I sent in a PR for this with some new API's: #1409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants