Skip to content

Commit

Permalink
[11.x] Send invoice (#942)
Browse files Browse the repository at this point in the history
* Use sendInvoice() when collection method is 'send_invoice'

In some edge cases (like mine) we have clients that can't use a credit card, but we still want to have all the data in Stripe. So we create a subscription with collection_method = 'send_invoice' and the manually sent the invoices to be paid, once we received payment we just change the status manually in Stripe.

´´´
$model->invoice(['collection_method' => 'send_invoice']);
$subscription->invoice(['collection_method' => 'send_invoice']);
´´´

When you use this collection method you can't apply $stripeInvoice->pay() function, you need to use the $stripeInvoice->sendInvoice();

When using the $stripeInvoice->pay() on when a colletion_method is 'send_invoice' it throws PaymentFailure, it doesn't require a payment method.

The only two options in 'collection_methods' is charge_automatically (default) or 'send_invoice' there fore using a simple if else statement.

https://stripe.com/docs/api/invoices/create#create_invoice-collection_method

* Use constant

Co-authored-by: Erik Larsson <eriklarsson@me.com>
  • Loading branch information
driesvints and eckelarsson committed May 21, 2020
1 parent 3c8ee44 commit 92eb7d8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Concerns/ManagesInvoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public function invoice(array $options = [])
/** @var \Stripe\Invoice $invoice */
$stripeInvoice = StripeInvoice::create($parameters, $this->stripeOptions());

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

return new Invoice($this, $stripeInvoice);
} catch (StripeInvalidRequestException $exception) {
Expand Down

0 comments on commit 92eb7d8

Please sign in to comment.