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] Update Stripe SDK to v7 #784

Merged
merged 4 commits into from
Sep 26, 2019
Merged

Conversation

sebdesign
Copy link
Contributor

The changes from v6 to v7 seem trivial to me, so I think this can be merged into Casher v10.

Update Stripe SDK to v7

  • Replace Charge::refund() to Refund::create()
  • Replace Customer::invoices() to Invoice::all()
  • Replace renamed exception classes

Fix removing default payment method

After upgrading to the v7 of the Stripe SDK, the $customer->invoice_settings->default_payment_method is null.

In that case, we don't need to update the Stripe customer, so we will just update the database.

The previous functionality has been kept as is.

Lazy-load the invoice line items

According to #562, the invoice response contains only 10 line items, so we were manually fetching 1000 items.

But Stripe's pagination limit is 100 items, so that doesn't ensure that all the line items will be fetched.

Instead, we can use the Stripe\Collection::autoPagingIterator() which automatically fetches all the paginated results with a generator.

I was tempted to use a lazy collection here, but since this method will be called by the Invoice::invoiceItems() and Invoice::subscriptions() methods, we don't want to hit the API twice just to filter the results.

- Replace `Charge::refund()` to `Refund::create()`
- Replace `Customer::invoices()` to `Invoice::all()`
- Replace renamed exception classes
After upgrading to the v7 of the Stripe SDK, the `$customer->invoice_settings->default_payment_method` is null.

In that case, we don't need to update the Stripe customer, so we will just update the database.

The previous functionality has been kept as is.
According to laravel#562, the invoice response contains only 10 line items, so we were manually fetching 1000 items.

But Stripe's pagination limit is 100 items, so that doesn't ensure that all the line items will be fetched.

Instead, we can use the `Stripe\Collection::autoPagingIterator()` which automatically fetches all the paginated results with a generator.

I was tempted to use a lazy collection here, but since this method will be called by the `Invoice::invoiceItems()` and `Invoice::subscriptions()` methods, we don't want to hit the API twice just to filter the results.
@driesvints
Copy link
Member

@taylorotwell I'll take a thorough look at this when I'm back next week.

@driesvints driesvints changed the title Update Stripe SDK to v7 [10.x] Update Stripe SDK to v7 Sep 24, 2019
@driesvints
Copy link
Member

@sebdesign First of all: thanks for sending this in!

I changed some things for the payment methods though. In the changes you made, the default card details could also be unset in the case when the customer was still using a default from the old legacy sources api. That would cause their default payment method to be unset. I've refactored this a little bit.

What turns out that got changed is that Stripe will now also remove the default payment method when you detach a card. That wasn't the case before. The implementation is now more simpler this way.

@taylorotwell taylorotwell merged commit 3dc4636 into laravel:10.0 Sep 26, 2019
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