diff --git a/CHANGELOG.md b/CHANGELOG.md index bae4fe7..1c78dd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Stripe Payments Changelog +## 5.0.4 - 2022.06.26 +### Fixed +- Fixed issue on subscription when using stripe elements ([#295]) +- Fixed issue when sync one-time and recurring orders ([#296]) + +[#295]: https://github.com/enupal/stripe/issues/295 +[#296]: https://github.com/enupal/stripe/issues/296 + ## 5.0.3 - 2022.06.14 ### Added - Added support for [Affirm](https://stripe.com/en-gb/payments/affirm) payment method diff --git a/composer.json b/composer.json index 33af059..65ccc42 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "enupal/stripe", "description": "Allows customers sign up for recurring and one-time payments with Stripe, perfect for orders, donations, subscriptions, and events. Create simple payment forms in seconds easily without coding. For Craft CMS 3.x", "type": "craft-plugin", - "version": "5.0.3", + "version": "5.0.4", "keywords": [ "craft", "cms", diff --git a/src/jobs/SyncOneTimePayments.php b/src/jobs/SyncOneTimePayments.php index 7e838ab..7fec130 100644 --- a/src/jobs/SyncOneTimePayments.php +++ b/src/jobs/SyncOneTimePayments.php @@ -125,7 +125,7 @@ public function execute($queue): void $newOrder->quantity = 1; $newOrder->isSubscription = false; $newOrder->dateOrdered = DateTimeHelper::toDateTime($charge['created'])->format('Y-m-d H:i:s'); - $newOrder->dateCreated = $newOrder->dateOrdered; + $newOrder->dateCreated = DateTimeHelper::toDateTime($charge['created']); $newOrder->orderStatusId = $this->defaultStatusId; $newOrder->stripeTransactionId = $charge['id']; $newOrder->email = $email; diff --git a/src/jobs/SyncSubscriptionPayments.php b/src/jobs/SyncSubscriptionPayments.php index 6bcb499..352ac22 100644 --- a/src/jobs/SyncSubscriptionPayments.php +++ b/src/jobs/SyncSubscriptionPayments.php @@ -132,7 +132,7 @@ public function execute($queue): void $newOrder->totalPrice = StripePlugin::$app->orders->convertFromCents($invoice['amount_paid'], $newOrder->currency); $newOrder->quantity = $subscription['quantity']; $newOrder->dateOrdered = DateTimeHelper::toDateTime($invoice['created'])->format('Y-m-d H:i:s'); - $newOrder->dateCreated = $newOrder->dateOrdered; + $newOrder->dateCreated = DateTimeHelper::toDateTime($invoice['created']); $newOrder->orderStatusId = $this->defaultStatusId; $newOrder->stripeTransactionId = $subscriptionId; $newOrder->email = $email; diff --git a/src/services/Orders.php b/src/services/Orders.php index 74904d9..4e67187 100644 --- a/src/services/Orders.php +++ b/src/services/Orders.php @@ -33,6 +33,7 @@ use Stripe\InvoiceItem; use Stripe\Refund; use Stripe\Source; +use Stripe\Subscription; use yii\base\Component; use enupal\stripe\records\Order as OrderRecord; use enupal\stripe\records\Customer as CustomerRecord; @@ -1160,6 +1161,7 @@ private function addPlanToCustomer($customer, $planId, $data, $order) // Add the plan to the customer $subscriptionSettings = [ + "customer" => $customer->id, "plan" => $planId, "trial_from_plan" => true, 'metadata' => $this->getStripeMetadata($data) @@ -1183,8 +1185,7 @@ private function addPlanToCustomer($customer, $planId, $data, $order) } $subscriptionSettings['metadata'] = $this->getStripeMetadata($data); - - $subscription = $customer->subscriptions->create($subscriptionSettings); + $subscription = Subscription::create($subscriptionSettings); return $subscription; } @@ -1243,6 +1244,7 @@ private function addRecurringPayment($customer, $data, $paymentForm, $order) // Add the plan to the customer $subscriptionSettings = [ + "customer" => $customer->id, "plan" => $plan['id'] ]; @@ -1258,7 +1260,7 @@ private function addRecurringPayment($customer, $data, $paymentForm, $order) $subscriptionSettings['metadata'] = $this->getStripeMetadata($data); - $subscription = $customer->subscriptions->create($subscriptionSettings); + $subscription = Subscription::create($subscriptionSettings); return $subscription; } @@ -1303,6 +1305,7 @@ private function addCustomPlan($customer, $data, $paymentForm) // Add the plan to the customer $subscriptionSettings = [ + "customer" => $customer->id, "plan" => $plan['id'], "trial_from_plan" => true ]; @@ -1313,8 +1316,7 @@ private function addCustomPlan($customer, $data, $paymentForm) } $subscriptionSettings['metadata'] = $this->getStripeMetadata($data); - - $subscription = $customer->subscriptions->create($subscriptionSettings); + $subscription = Subscription::create($subscriptionSettings); return $subscription; }