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

[10.x] Add findPaymentMethod method #801

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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