Skip to content

Commit 5338e7d

Browse files
committed
update paddle
1 parent 0e902e1 commit 5338e7d

45 files changed

Lines changed: 252 additions & 155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Http/Controllers/Billing/BillingController.php

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,68 @@ public function index(Request $request): Response
5858
]);
5959
}
6060

61+
public function subscribe(Request $request): Response
62+
{
63+
$request->validate([
64+
'plan' => ['required', 'string', 'in:monthly,yearly'],
65+
]);
66+
67+
$user = $request->user();
68+
69+
$plan = $request->input('plan');
70+
$priceId = $plan === 'yearly'
71+
? config('subscription.yearly_price_id')
72+
: config('subscription.monthly_price_id');
73+
74+
$checkout = $user->subscribe($priceId, 'default')
75+
->returnTo(route('billing.index'));
76+
77+
$subscription = $user->subscription('default');
78+
79+
$invoices = $user->transactions()
80+
->orderBy('billed_at', 'desc')
81+
->get()
82+
->map(fn ($invoice) => [
83+
'id' => $invoice->id,
84+
'number' => $invoice->invoice_number,
85+
'amount' => $invoice->total,
86+
'tax' => $invoice->tax,
87+
'currency' => $invoice->currency,
88+
'status' => $invoice->status,
89+
'billed_at' => $invoice->billed_at?->toIso8601String(),
90+
'url' => route('billing.download-invoice', $invoice),
91+
]);
92+
93+
return Inertia::render('billing/index', [
94+
'subscription' => $subscription ? [
95+
'id' => $subscription->paddle_id,
96+
'status' => $subscription->status,
97+
'type' => $subscription->type,
98+
'trial_ends_at' => $subscription->trial_ends_at?->toIso8601String(),
99+
'paused_at' => $subscription->paused_at?->toIso8601String(),
100+
'ends_at' => $subscription->ends_at?->toIso8601String(),
101+
'currentPeriodEndsAt' => $subscription->currentPeriodEndsAt()?->toIso8601String(),
102+
'price_id' => $subscription->items()->first()?->price_id,
103+
] : null,
104+
'invoices' => $invoices,
105+
'upcomingInvoice' => null,
106+
'customer' => [
107+
'paddle_id' => $user->paddle_id,
108+
'name' => $user->name,
109+
'email' => $user->email,
110+
],
111+
'plans' => [
112+
'monthly' => [
113+
'price_id' => config('subscription.monthly_price_id'),
114+
],
115+
'yearly' => [
116+
'price_id' => config('subscription.yearly_price_id'),
117+
],
118+
],
119+
'checkout' => $checkout->options(),
120+
]);
121+
}
122+
61123
public function updatePaymentMethod(Request $request): RedirectResponse
62124
{
63125
$session = $request->user()->updatePaymentMethod();
@@ -74,13 +136,12 @@ public function switchPlan(Request $request): RedirectResponse
74136

75137
$user = $request->user();
76138
$plan = $request->input('plan');
77-
78139
$priceId = $plan === 'yearly'
79140
? config('subscription.yearly_price_id')
80141
: config('subscription.monthly_price_id');
81142

82143
if (! $user->subscription('default')) {
83-
return redirect()->route('subscribe', ['plan' => $plan]);
144+
return redirect()->route('billing.subscribe');
84145
}
85146

86147
$user->subscription('default')->swap($priceId);

app/Http/Controllers/Billing/SubscriptionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function checkout(Request $request)
1515
: config('subscription.monthly_price_id');
1616

1717
$checkout = $request->user()->subscribe($priceId, 'default')
18-
->returnTo(route('dashboard'));
18+
->returnTo(route('billing.index'));
1919

2020
return Inertia::render('subscribe', [
2121
'checkout' => $checkout->options(),

public/build/assets/animations-Cih0tb3x.js renamed to public/build/assets/animations-DDgZVZxl.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/appearance-eHwqSIFN.js renamed to public/build/assets/appearance-CUbmIn0m.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/arrow-left-CTabWRHo.js renamed to public/build/assets/arrow-left-DqbKTqH0.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)