Skip to content

Commit 1f84f20

Browse files
authored
Merge pull request #297 from enupal/bugfix/stripe-elements-subscription
Bugfix/stripe elements subscription
2 parents 287681e + 2068917 commit 1f84f20

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/jobs/SyncOneTimePayments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function execute($queue): void
125125
$newOrder->quantity = 1;
126126
$newOrder->isSubscription = false;
127127
$newOrder->dateOrdered = DateTimeHelper::toDateTime($charge['created'])->format('Y-m-d H:i:s');
128-
$newOrder->dateCreated = $newOrder->dateOrdered;
128+
$newOrder->dateCreated = DateTimeHelper::toDateTime($charge['created']);
129129
$newOrder->orderStatusId = $this->defaultStatusId;
130130
$newOrder->stripeTransactionId = $charge['id'];
131131
$newOrder->email = $email;

src/jobs/SyncSubscriptionPayments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function execute($queue): void
132132
$newOrder->totalPrice = StripePlugin::$app->orders->convertFromCents($invoice['amount_paid'], $newOrder->currency);
133133
$newOrder->quantity = $subscription['quantity'];
134134
$newOrder->dateOrdered = DateTimeHelper::toDateTime($invoice['created'])->format('Y-m-d H:i:s');
135-
$newOrder->dateCreated = $newOrder->dateOrdered;
135+
$newOrder->dateCreated = DateTimeHelper::toDateTime($invoice['created']);
136136
$newOrder->orderStatusId = $this->defaultStatusId;
137137
$newOrder->stripeTransactionId = $subscriptionId;
138138
$newOrder->email = $email;

src/services/Orders.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Stripe\InvoiceItem;
3434
use Stripe\Refund;
3535
use Stripe\Source;
36+
use Stripe\Subscription;
3637
use yii\base\Component;
3738
use enupal\stripe\records\Order as OrderRecord;
3839
use enupal\stripe\records\Customer as CustomerRecord;
@@ -1160,6 +1161,7 @@ private function addPlanToCustomer($customer, $planId, $data, $order)
11601161

11611162
// Add the plan to the customer
11621163
$subscriptionSettings = [
1164+
"customer" => $customer->id,
11631165
"plan" => $planId,
11641166
"trial_from_plan" => true,
11651167
'metadata' => $this->getStripeMetadata($data)
@@ -1183,8 +1185,7 @@ private function addPlanToCustomer($customer, $planId, $data, $order)
11831185
}
11841186

11851187
$subscriptionSettings['metadata'] = $this->getStripeMetadata($data);
1186-
1187-
$subscription = $customer->subscriptions->create($subscriptionSettings);
1188+
$subscription = Subscription::create($subscriptionSettings);
11881189

11891190
return $subscription;
11901191
}
@@ -1243,6 +1244,7 @@ private function addRecurringPayment($customer, $data, $paymentForm, $order)
12431244

12441245
// Add the plan to the customer
12451246
$subscriptionSettings = [
1247+
"customer" => $customer->id,
12461248
"plan" => $plan['id']
12471249
];
12481250

@@ -1258,7 +1260,7 @@ private function addRecurringPayment($customer, $data, $paymentForm, $order)
12581260

12591261
$subscriptionSettings['metadata'] = $this->getStripeMetadata($data);
12601262

1261-
$subscription = $customer->subscriptions->create($subscriptionSettings);
1263+
$subscription = Subscription::create($subscriptionSettings);
12621264

12631265
return $subscription;
12641266
}
@@ -1303,6 +1305,7 @@ private function addCustomPlan($customer, $data, $paymentForm)
13031305

13041306
// Add the plan to the customer
13051307
$subscriptionSettings = [
1308+
"customer" => $customer->id,
13061309
"plan" => $plan['id'],
13071310
"trial_from_plan" => true
13081311
];
@@ -1313,8 +1316,7 @@ private function addCustomPlan($customer, $data, $paymentForm)
13131316
}
13141317

13151318
$subscriptionSettings['metadata'] = $this->getStripeMetadata($data);
1316-
1317-
$subscription = $customer->subscriptions->create($subscriptionSettings);
1319+
$subscription = Subscription::create($subscriptionSettings);
13181320

13191321
return $subscription;
13201322
}

0 commit comments

Comments
 (0)