Skip to content

Commit

Permalink
Merge pull request #801 from laravel/retrieve-payment-method
Browse files Browse the repository at this point in the history
[10.x] Add findPaymentMethod method
  • Loading branch information
taylorotwell authored Oct 18, 2019
2 parents 8b42e7e + 1d2c7a7 commit 2be5859
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ public function findInvoice($id)
$stripeInvoice = StripeInvoice::retrieve(
$id, $this->stripeOptions()
);

return new Invoice($this, $stripeInvoice);
} catch (Exception $exception) {
//
}

return new Invoice($this, $stripeInvoice);
}

/**
Expand Down Expand Up @@ -604,6 +604,23 @@ public function deletePaymentMethods()
$this->updateDefaultPaymentMethodFromStripe();
}

/**
* Find a PaymentMethod by ID.
*
* @param string $paymentMethod
* @return \Laravel\Cashier\PaymentMethod
*/
public function findPaymentMethod($paymentMethod)
{
try {
$stripePaymentMethod = $this->resolveStripePaymentMethod($paymentMethod);
} catch (Exception $exception) {
//
}

return new PaymentMethod($this, $stripePaymentMethod);
}

/**
* Resolve a PaymentMethod ID to a Stripe PaymentMethod object.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\Carbon;
use Dompdf\Dompdf;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\View;
use Stripe\Invoice as StripeInvoice;
Expand Down Expand Up @@ -42,6 +43,10 @@ class Invoice
*/
public function __construct($owner, StripeInvoice $invoice)
{
if ($owner->stripe_id !== $invoice->customer) {
throw new Exception("The invoice `{$invoice->id}` does not belong to this customer `$owner->stripe_id`.");
}

$this->owner = $owner;
$this->invoice = $invoice;
}
Expand Down
2 changes: 1 addition & 1 deletion src/InvoiceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class InvoiceItem
* Create a new invoice item instance.
*
* @param \Illuminate\Database\Eloquent\Model $owner
* @param \Stripe\StripeObject $item
* @param \Stripe\InvoiceLineItem $item
* @return void
*/
public function __construct($owner, $item)
Expand Down
5 changes: 5 additions & 0 deletions src/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Cashier;

use Exception;
use Stripe\PaymentMethod as StripePaymentMethod;

class PaymentMethod
Expand Down Expand Up @@ -29,6 +30,10 @@ class PaymentMethod
*/
public function __construct($owner, StripePaymentMethod $paymentMethod)
{
if ($owner->stripe_id !== $paymentMethod->customer) {
throw new Exception("The invoice `{$paymentMethod->id}` does not belong to this customer `$owner->stripe_id`.");
}

$this->owner = $owner;
$this->paymentMethod = $paymentMethod;
}
Expand Down

0 comments on commit 2be5859

Please sign in to comment.