Skip to content

Commit

Permalink
Log more info about invalid pm exception (#1582)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Oct 16, 2023
1 parent 44ae9dd commit f437600
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InvalidPaymentMethod extends Exception
public static function invalidOwner(StripePaymentMethod $paymentMethod, $owner)
{
return new static(
"The payment method `{$paymentMethod->id}` does not belong to this customer `$owner->stripe_id`."
"The payment method `{$paymentMethod->id}`'s customer `{$paymentMethod->customer}` does not belong to this customer `$owner->stripe_id`."
);
}
}
5 changes: 5 additions & 0 deletions src/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
use Laravel\Cashier\Exceptions\InvalidPaymentMethod;
use LogicException;
use Stripe\PaymentMethod as StripePaymentMethod;

class PaymentMethod implements Arrayable, Jsonable, JsonSerializable
Expand Down Expand Up @@ -35,6 +36,10 @@ class PaymentMethod implements Arrayable, Jsonable, JsonSerializable
*/
public function __construct($owner, StripePaymentMethod $paymentMethod)
{
if (is_null($paymentMethod->customer)) {
throw new LogicException('The payment method is not attached to a customer.');
}

if ($owner->stripe_id !== $paymentMethod->customer) {
throw InvalidPaymentMethod::invalidOwner($paymentMethod, $owner);
}
Expand Down

0 comments on commit f437600

Please sign in to comment.