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

[14.x] Log more info about invalid pm exception #1582

Merged
merged 1 commit into from
Oct 16, 2023
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
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