From 324d86b44996dc3b78a511a7cb40e7f3cdb12f84 Mon Sep 17 00:00:00 2001 From: winterpk Date: Fri, 28 Feb 2020 10:53:15 -0700 Subject: [PATCH 1/4] Fixed the hard 100 limit when retreiving subscription plans --- src/base/SubscriptionGateway.php | 34 ++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/base/SubscriptionGateway.php b/src/base/SubscriptionGateway.php index ad943a7..89089c6 100644 --- a/src/base/SubscriptionGateway.php +++ b/src/base/SubscriptionGateway.php @@ -285,11 +285,12 @@ public function getSubscriptionPlans(): array $plans = StripePlan::all([ 'limit' => 100, ]); + $output = []; $planProductMap = []; $planList = []; - + $offset = 100; if (\count($plans->data)) { foreach ($plans->data as $plan) { /** @var StripePlan $plan */ @@ -297,6 +298,20 @@ public function getSubscriptionPlans(): array $planProductMap[$plan['id']] = $plan['product']; $planList[] = $plan; } + while ($plans->has_more) { + + $plans = StripePlan::all([ + 'limit' => 100, + 'offset' => $offset + ]); + $offset = $offset + 100; + foreach ($plans->data as $plan) { + /** @var StripePlan $plan */ + $plan = $plan->jsonSerialize(); + $planProductMap[$plan['id']] = $plan['product']; + $planList[] = $plan; + } + } /** @var Collection $products */ $products = StripeProduct::all([ @@ -305,13 +320,28 @@ public function getSubscriptionPlans(): array ]); $productList = []; - + $offset = 100; if (\count($products->data)) { foreach ($products->data as $product) { /** @var StripeProduct $product */ $product = $product->jsonSerialize(); $productList[$product['id']] = $product; } + + while ($products->has_more) { + + $products = StripeProduct::all([ + 'limit' => 100, + 'ids' => array_values($planProductMap), + 'offset' => $offset + ]); + $offset = $offset + 100; + foreach ($products->data as $product) { + /** @var StripeProduct $product */ + $product = $product->jsonSerialize(); + $productList[$product['id']] = $product; + } + } } foreach ($planList as $plan) { From b08f5abdb342586255926894efb7f97dd3d8eea7 Mon Sep 17 00:00:00 2001 From: winterpk Date: Fri, 28 Feb 2020 11:35:51 -0700 Subject: [PATCH 2/4] Fixed an error --- src/base/SubscriptionGateway.php | 56 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/base/SubscriptionGateway.php b/src/base/SubscriptionGateway.php index d3664f4..89089c6 100644 --- a/src/base/SubscriptionGateway.php +++ b/src/base/SubscriptionGateway.php @@ -492,33 +492,6 @@ public function previewSwitchCost(Subscription $subscription, BasePlan $plan): f return $currency ? $invoice->total / (10 ** $currency->minorUnit) : $invoice->total; } - /** - * @inheritdoc - */ - public function handleWebhook(array $data) - { - switch ($data['type']) { - case 'plan.deleted': - case 'plan.updated': - $this->handlePlanEvent($data); - break; - case 'invoice.payment_succeeded': - $this->handleInvoiceSucceededEvent($data); - break; - case 'invoice.created': - $this->handleInvoiceCreated($data); - break; - case 'customer.subscription.deleted': - $this->handleSubscriptionExpired($data); - break; - case 'customer.subscription.updated': - $this->handleSubscriptionUpdated($data); - break; - } - - parent::handleWebhook($data); - } - // Protected methods // ========================================================================= @@ -772,4 +745,33 @@ protected function saveSubscriptionInvoice(array $stripeInvoice, Subscription $s return $invoice; } + + /** + * @inheritdoc + */ + protected function handleWebhook(array $data) + { + switch ($data['type']) { + case 'plan.deleted': + case 'plan.updated': + $this->handlePlanEvent($data); + break; + case 'invoice.payment_succeeded': + $this->handleInvoiceSucceededEvent($data); + break; + case 'invoice.created': + $this->handleInvoiceCreated($data); + break; + case 'customer.subscription.deleted': + $this->handleSubscriptionExpired($data); + break; + case 'customer.subscription.updated': + $this->handleSubscriptionUpdated($data); + break; + } + + parent::handleWebhook($data); + } + + } From d40a2faa4915741d1d98154bf3c68f2e69003db0 Mon Sep 17 00:00:00 2001 From: winterpk Date: Fri, 28 Feb 2020 11:40:06 -0700 Subject: [PATCH 3/4] Cleanup --- src/base/SubscriptionGateway.php | 58 +++++++++++++++----------------- 1 file changed, 28 insertions(+), 30 deletions(-) diff --git a/src/base/SubscriptionGateway.php b/src/base/SubscriptionGateway.php index 89089c6..b16cd56 100644 --- a/src/base/SubscriptionGateway.php +++ b/src/base/SubscriptionGateway.php @@ -492,6 +492,33 @@ public function previewSwitchCost(Subscription $subscription, BasePlan $plan): f return $currency ? $invoice->total / (10 ** $currency->minorUnit) : $invoice->total; } + /** + * @inheritdoc + */ + public function handleWebhook(array $data) + { + switch ($data['type']) { + case 'plan.deleted': + case 'plan.updated': + $this->handlePlanEvent($data); + break; + case 'invoice.payment_succeeded': + $this->handleInvoiceSucceededEvent($data); + break; + case 'invoice.created': + $this->handleInvoiceCreated($data); + break; + case 'customer.subscription.deleted': + $this->handleSubscriptionExpired($data); + break; + case 'customer.subscription.updated': + $this->handleSubscriptionUpdated($data); + break; + } + + parent::handleWebhook($data); + } + // Protected methods // ========================================================================= @@ -745,33 +772,4 @@ protected function saveSubscriptionInvoice(array $stripeInvoice, Subscription $s return $invoice; } - - /** - * @inheritdoc - */ - protected function handleWebhook(array $data) - { - switch ($data['type']) { - case 'plan.deleted': - case 'plan.updated': - $this->handlePlanEvent($data); - break; - case 'invoice.payment_succeeded': - $this->handleInvoiceSucceededEvent($data); - break; - case 'invoice.created': - $this->handleInvoiceCreated($data); - break; - case 'customer.subscription.deleted': - $this->handleSubscriptionExpired($data); - break; - case 'customer.subscription.updated': - $this->handleSubscriptionUpdated($data); - break; - } - - parent::handleWebhook($data); - } - - -} +} \ No newline at end of file From 21873706b0c932f39163ec0a435573d7f4c64647 Mon Sep 17 00:00:00 2001 From: Winter King Date: Thu, 9 Apr 2020 14:56:56 -0600 Subject: [PATCH 4/4] Updated composer.json Version bump --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c5cfbb6..2195a4a 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "craftcms/commerce-stripe", "description": "Stripe integration for Craft Commerce 2 & 3", - "version": "2.2.3", + "version": "2.3.0", "type": "craft-plugin", "keywords": [ "stripe",