Skip to content

Commit

Permalink
Modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkIncognito85 committed Jan 4, 2023
1 parent 3c2d8e7 commit 627a475
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/Stripe/StripeSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
use App\Shop\Entity\SubscriptionDetails;
use App\Shop\Entity\Transaction;
use App\Shop\Entity\TransactionItem;
use App\Shop\Payment\SubscribeInterface;
use App\Shop\Services\SubscriptionService;
use App\Stripe\Api\Entity\StripeUser;
use App\Stripe\Api\Stripe;
use Carbon\Carbon;
use ClientX\Database\NoRecordException;
use ClientX\Renderer\RendererInterface;

class StripeSubscriber implements SubscribeInterface
class StripeSubscriber implements \App\Shop\Payment\SubscribeInterface
{

private Stripe $stripe;
Expand Down Expand Up @@ -54,23 +53,21 @@ public function getLink(User $user, Transaction $transaction, array $links)
})->first();
$months = Recurring::from(json_decode($product->getData(), true)['_recurring'])->getMonths();

$items = collect($transaction->getItems())->map(function (TransactionItem $item) use ($transaction, $months, $discounts) {
return [
[
'price_data' =>
[
'currency' => $transaction->getCurrency(),
'recurring' => [
'interval_count' => $months,
'interval' => 'month'
],
'unit_amount' => number_format($item->priceWithTax() + $discounts, 2) * 100,
'product_data' => ["name" => $item->getName()]
$items = [[
[
'price_data' =>
[
'currency' => $transaction->getCurrency(),
'recurring' => [
'interval_count' => $months,
'interval' => 'month'
],
'quantity' => $item->getQuantity(),
]
];
})->toArray();
'unit_amount' => number_format($product->getPrice(Recurring::from(json_decode($product->getData(), true)['_recurring'])->getName()) + $discounts, 2) * 100,
'product_data' => ["name" => $product->getName()]
],
'quantity' => 1,
]
]];

$user = $this->createStripeUser($user);
$session = $this->stripe->createPaymentSession($user, $items, $links, $transaction, 'subscription');
Expand Down Expand Up @@ -165,9 +162,10 @@ public function estimatedIncomeSubscription(int $months = 0): IncomeSubscription
$details = $this->stripe->getSubscription($subscription->token);
if ($details->status == 'active' && Carbon::createFromTimestamp($details->current_period_end)->format('m') == $currentMonth){
$income->addAmount($details->items->data[0]->plan->amount_decimal / 100);
$income->addNextRenewal($subscription->token,Carbon::createFromTimestamp(Carbon::createFromTimestamp($details->current_period_end))->toDate());
$income->addInterval($subscription->token,$details->items->data[0]->plan->interval_count);
}

$income->addNextRenewal($subscription->token,Carbon::createFromTimestamp($details->current_period_end)->toDate());
$income->addInterval($subscription->token,$details->items->data[0]->plan->interval_count);
}
return $income;
}
Expand Down

0 comments on commit 627a475

Please sign in to comment.