Skip to content

Commit

Permalink
Merge pull request #297 from enupal/bugfix/stripe-elements-subscription
Browse files Browse the repository at this point in the history
Bugfix/stripe elements subscription
  • Loading branch information
andrelopez authored Jun 26, 2022
2 parents 287681e + 2068917 commit 1f84f20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/jobs/SyncOneTimePayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/SyncSubscriptionPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions src/services/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -1243,6 +1244,7 @@ private function addRecurringPayment($customer, $data, $paymentForm, $order)

// Add the plan to the customer
$subscriptionSettings = [
"customer" => $customer->id,
"plan" => $plan['id']
];

Expand All @@ -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;
}
Expand Down Expand Up @@ -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
];
Expand All @@ -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;
}
Expand Down

0 comments on commit 1f84f20

Please sign in to comment.