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.0] Payment Methods #696

Merged
merged 1 commit into from
Jul 11, 2019
Merged

[10.0] Payment Methods #696

merged 1 commit into from
Jul 11, 2019

Conversation

driesvints
Copy link
Member

@driesvints driesvints commented Jul 8, 2019

These changes replace the old Sources and Token based APIs from Stripe with the new and recommended Payment Methods API. This new API will handle all card based interaction and in the future also new payment methods like IDEAL, Bancontact, etc.

Basically all card-based methods and its related class were replayed by payment method methods (wording djeez) and a new PaymentMethod class. New tests for these methods were added.

There's one legacy backwards compatibility that's maintained and that's for the defaultPaymentMethod method. This will return an instance of a Stripe\Card or Stripe\BankAccount source if no default payment method was found. This way, older apps migrating to the new Cashier release, can still use these objects to interact with their apps.

The subscription creation process now also requires a payment method instead of a Stripe token.

Developers will need to update their Stripe JS integration to make use of the new payment method apis.

Closes #649

These changes replace the old Sources and Token based APIs from Stripe with the new and recommended Payment Methods API. This new API will handle all card based interaction and in the future also new payment methods like IDEAL, Bancontact, etc.

Basically all card-based methods and its related class were replayed by payment method methods (wording djeez) and a new PaymentMethod class. New tests for these methods were added.

There's one legacy backwards compatibility that's maintained and that's for the defaultPaymentMethod method. This will return an instance of a Stripe\Card or Stripe\BankAccount source if no default payment method was found. This way, older apps migrating to the new Cashier release, can still use these objects to interact with their apps.

The subscription creation process now also requires a payment method instead of a Stripe token.
@taylorotwell taylorotwell merged commit 52b7dd5 into master Jul 11, 2019
@driesvints driesvints deleted the payment-methods branch July 11, 2019 15:31
@pierrocknroll
Copy link

pierrocknroll commented Sep 10, 2019

Hello @driesvints, my app is an API and I have to return the card informations, I used defaultCard().
Since defaultPaymentMethod can return a Stripe\Card or a PaymentMethod, do I have to do check like this or is there an other solution ?

$paymentMethod = $user->defaultPaymentMethod();
if (get_class($paymentMethod) === PaymentMethod::class && $paymentMethod->type === 'card' && isset($paymentMethod->card)) {
    $card = $paymentMethod->card;
} else {
    $card = $paymentMethod;
}
return [
    'brand'     => $card->brand,
    'country'   => $card->country,
    'exp_month' => $card->exp_month,
    'exp_year'  => $card->exp_year,
    'last4'     => $card->last4
];

Thanks a lot

@driesvints
Copy link
Member Author

@pierrocknroll unfortunately Stripe hasn't migrated the default source to the default payment methods yet so you'd indeed have to check for instanceof when retrieving it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants