Skip to content

Commit 1b45541

Browse files
committed
Adding functionality so that way the invoice downloads work again
1 parent 5501065 commit 1b45541

File tree

6 files changed

+60
-69
lines changed

6 files changed

+60
-69
lines changed

config/wave.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
'paddle' => [
2424
'vendor' => env('PADDLE_VENDOR_ID', ''),
25-
'auth_code' => env('PADDLE_VENDOR_AUTH_CODE', ''),
25+
'auth_code' => env('PADDLE_API_KEY', ''),
26+
'api_key' => env('PADDLE_API_KEY', ''),
27+
'client_side_token' => env('PADDLE_CLIENT_SIDE_TOKEN', ''),
2628
'env' => env('PADDLE_ENV', 'sandbox'),
2729
'public_key' => env('PADDLE_PUBLIC_KEY', ''),
2830
]

resources/views/themes/tailwind/settings/partials/invoices.blade.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
@subscriber
44
@php
55
$subscription = new \Wave\Http\Controllers\SubscriptionController;
6-
$invoices = $subscription->invoices( auth()->user() );
6+
$transactions = $subscription->transactions( auth()->user() );
77
@endphp
88

99

1010

11-
@if(isset($invoices->success) && $invoices->success == true)
11+
@if(count($transactions) > 0)
1212

1313
<table class="min-w-full overflow-hidden divide-y divide-gray-200 rounded-lg">
1414
<thead>
@@ -25,17 +25,17 @@
2525
</tr>
2626
</thead>
2727
<tbody>
28-
@foreach($invoices->response as $invoice)
28+
@foreach($transactions as $transaction)
2929
<tr class="@if($loop->index%2 == 0){{ 'bg-gray-50' }}@else{{ 'bg-gray-100' }}@endif">
3030
<td class="px-6 py-4 text-sm font-medium leading-5 text-gray-900 whitespace-no-wrap">
31-
{{ Carbon\Carbon::parse($invoice->payout_date)->toFormattedDateString() }}
31+
{{ Carbon\Carbon::parse($transaction->created_at)->toFormattedDateString() }}
3232
</td>
3333
<td class="px-6 py-4 text-sm font-medium leading-5 text-right text-gray-900 whitespace-no-wrap">
34-
${{ $invoice->amount }}
34+
{{ $transaction->details->totals->subtotal }}
3535
</td>
3636
<td class="px-6 py-4 text-sm font-medium leading-5 text-right whitespace-no-wrap">
37-
<a href="{{ $invoice->receipt_url }}" target="_blank" class="mr-2 text-indigo-600 hover:underline focus:outline-none">
38-
Download
37+
<a href="/settings/invoices/{{ $transaction->id }}" target="_blank" class="mr-2 text-indigo-600 hover:underline focus:outline-none">
38+
Generate Invoice
3939
</a>
4040
</td>
4141

@@ -45,7 +45,7 @@
4545
</table>
4646

4747
@else
48-
<p>Sorry, there seems to be an issue retrieving your invoices or you may not have any invoices yet.</p>
48+
<p>You currently do not have any invoices associated with your account</p>
4949
@endif
5050

5151
@notsubscriber

wave/resources/views/checkout.blade.php

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
<script src="https://cdn.paddle.com/paddle/v2/paddle.js"></script>
22
<script>
33
4-
window.vendor_id = parseInt('{{ config("wave.paddle.vendor") }}');
5-
6-
7-
Paddle.Initialize({
8-
9-
token: 'test_fa19977d2cd05ecf60d462606b8', // replace with a client-side token
10-
checkout: {
11-
settings: {
12-
displayMode: "overlay",
13-
frameStyle: "width: 100%; min-width: 312px; background-color: transparent; border: none;",
14-
locale: "en",
15-
allowLogout: false
16-
}
17-
},
18-
eventCallback: function(data) {
19-
if (data.name == "checkout.completed") {
20-
checkoutComplete(data.data);
21-
}
4+
window.client_side_token = '{{ config("wave.paddle.client_side_token") }}';
5+
6+
Paddle.Initialize({
7+
token: client_side_token,
8+
checkout: {
9+
settings: {
10+
displayMode: "overlay",
11+
frameStyle: "width: 100%; min-width: 312px; background-color: transparent; border: none;",
12+
locale: "en",
13+
allowLogout: false
2214
}
23-
});
15+
},
16+
eventCallback: function(data) {
17+
if (data.name == "checkout.completed") {
18+
checkoutComplete(data.data);
19+
}
20+
}
21+
});
2422
2523
if("{{ config('wave.paddle.env') }}" == 'sandbox') {
2624
Paddle.Environment.set('sandbox');
@@ -43,20 +41,25 @@
4341
cancelBtns[i].addEventListener('click', waveCancel, false);
4442
}
4543
46-
4744
function waveCheckout(plan_id) {
48-
if(vendor_id){
45+
if(client_side_token){
4946
let product = [{
5047
priceId: plan_id,
5148
quantity: 1
5249
}];
50+
custom = {};
51+
@if(!auth()->guest())
52+
customer = {
53+
email: '{{ auth()->user()->email }}'
54+
};
55+
@endif
5356
Paddle.Checkout.open({
5457
items: product,
55-
email: '@if(!auth()->guest()){{ auth()->user()->email }}@endif',
58+
customer: customer,
5659
successCallback: "checkoutComplete",
5760
});
5861
} else {
59-
alert('Paddle Vendor ID is not set, please see the docs and learn how to setup billing.');
62+
alert('Paddle API keys and tokens must be set');
6063
}
6164
}
6265
@@ -76,14 +79,10 @@ function waveCancel(){
7679
});
7780
}
7881
79-
80-
/********** Start Billing Checkout Functionality ***********/
81-
82-
/***** Payment Success Functionality */
83-
8482
window.checkoutComplete = function(data) {
8583
var checkoutId = data.transaction_id;
86-
addCheckoutOverlay();
84+
85+
addCheckoutOverlay();
8786
Paddle.Checkout.close();
8887
8988
axios.post('/checkout', { _token: csrf, checkout_id: checkoutId })
@@ -99,7 +98,6 @@ function waveCancel(){
9998
window.location = '/checkout/welcome' + queryParams;
10099
}
101100
});
102-
103101
}
104102
105103
window.addCheckoutOverlay = function(){
@@ -144,8 +142,4 @@ function waveCancel(){
144142
});
145143
}
146144
147-
/***** End Payment Success Functionality */
148-
149-
/********** End Billing Checkout Functionality ***********/
150-
151145
</script>

wave/routes/web.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
Route::put('settings/api/{id?}', '\Wave\Http\Controllers\SettingsController@apiPut')->name('wave.settings.api.put');
4848
Route::delete('settings/api/{id?}', '\Wave\Http\Controllers\SettingsController@apiDelete')->name('wave.settings.api.delete');
4949

50-
Route::get('settings/invoices/{invoice}', '\Wave\Http\Controllers\SettingsController@invoice')->name('wave.invoice');
50+
Route::get('settings/invoices/{invoice}', '\Wave\Http\Controllers\SubscriptionController@invoice')->name('wave.invoice');
5151

5252
Route::get('notifications', '\Wave\Http\Controllers\NotificationController@index')->name('wave.notifications');
5353
Route::get('announcements', '\Wave\Http\Controllers\AnnouncementController@index')->name('wave.announcements');

wave/src/Http/Controllers/SettingsController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,4 @@ private function saveAvatar($avatar, $filename){
137137
Storage::disk(config('voyager.storage.disk'))->put($path, file_get_contents($avatar));
138138
return $path;
139139
}
140-
141-
public function invoice(Request $request, $invoiceId) {
142-
return $request->user()->downloadInvoice($invoiceId, [
143-
'vendor' => setting('site.title', 'Wave'),
144-
'product' => ucfirst(auth()->user()->role->name) . ' Subscription Plan',
145-
]);
146-
}
147140
}

wave/src/Http/Controllers/SubscriptionController.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ class SubscriptionController extends Controller
1919
private $paddle_url;
2020

2121
private $vendor_id;
22-
private $vendor_auth_code;
22+
private $api_key;
2323

2424
public function __construct(){
25-
$this->vendor_auth_code = config('wave.paddle.auth_code');
25+
$this->api_key = config('wave.paddle.auth_code');
2626
$this->vendor_id = config('wave.paddle.vendor');
2727

2828
$this->paddle_url = (config('wave.paddle.env') == 'sandbox') ? 'https://sandbox-api.paddle.com' : 'https://api.paddle.com';
@@ -49,7 +49,7 @@ private function cancelSubscription(){
4949
return back()->with(['message' => 'Invalid subscription ID.', 'message_type' => 'danger']);
5050
}
5151

52-
$response = Http::withToken($this->vendor_auth_code)
52+
$response = Http::withToken($this->api_key)
5353
->post($this->paddle_url . '/subscriptions/' . $subscription_id . '/cancel', [
5454
'effective_from' => 'immediately'
5555
]);
@@ -94,7 +94,7 @@ public function checkout(Request $request){
9494
$guest = (auth()->guest()) ? 1 : 0;
9595

9696
for ($i = 0; $i < $retryCount; $i++) {
97-
$response = Http::withToken($this->vendor_auth_code)->get($this->paddle_url . '/transactions/' . $request->checkout_id);
97+
$response = Http::withToken($this->api_key)->get($this->paddle_url . '/transactions/' . $request->checkout_id);
9898

9999
if ($response->successful()) {
100100
$resBody = json_decode($response->body());
@@ -111,11 +111,11 @@ public function checkout(Request $request){
111111
// Proceed with processing the transaction
112112
$plans = Plan::all();
113113
if($transaction->origin === "web" && $plans->contains('plan_id', $transaction->items[0]->price->id)){
114-
$subscriptionUser = Http::withToken($this->vendor_auth_code)->get($this->paddle_url . '/subscriptions/' . $transaction->subscription_id);
114+
$subscriptionUser = Http::withToken($this->api_key)->get($this->paddle_url . '/subscriptions/' . $transaction->subscription_id);
115115
$subscriptionData = json_decode($subscriptionUser->body());
116116
$subscription = $subscriptionData->data;
117117

118-
$customerResponse = Http::withToken($this->vendor_auth_code)->get($this->paddle_url . '/customers/' . $subscription->customer_id);
118+
$customerResponse = Http::withToken($this->api_key)->get($this->paddle_url . '/customers/' . $subscription->customer_id);
119119
$customerData = json_decode($customerResponse->body());
120120
$customerEmail = $customerData->data->email;
121121
$customerName = $customerData->data->name;
@@ -174,23 +174,25 @@ public function checkout(Request $request){
174174
]);
175175
}
176176

177-
public function invoices(User $user){
177+
public function transactions(User $user){
178178

179179
$invoices = [];
180+
$response = Http::withToken($this->api_key)->get($this->paddle_url . '/transactions', [
181+
'subscription_id' => $user->subscription->subscription_id
182+
]);
180183

181-
if(isset($user->subscription->subscription_id)){
182-
$response = Http::post($this->paddle_url . '/2.0/subscription/payments', [
183-
'vendor_id' => $this->vendor_id,
184-
'vendor_auth_code' => $this->vendor_auth_code,
185-
'subscription_id' => $user->subscription->subscription_id,
186-
'is_paid' => 1
187-
]);
188184

189-
$invoices = json_decode($response->body());
190-
}
185+
$transactions = json_decode($response->body());
186+
return $transactions->data;
187+
188+
}
191189

192-
return $invoices;
190+
public function invoice(Request $request, $transactionId) {
193191

192+
$response = Http::withToken($this->api_key)->get($this->paddle_url . '/transactions/' . $transactionId . '/invoice');
193+
$invoice = json_decode($response->body());
194+
// redirect user to the invoice download URL
195+
return redirect($invoice->data->url);
194196
}
195197

196198
public function switchPlans(Request $request)
@@ -199,7 +201,7 @@ public function switchPlans(Request $request)
199201

200202
if (isset($plan->id)) {
201203
// Update the user plan with Paddle
202-
$response = Http::withToken($this->vendor_auth_code)->patch(
204+
$response = Http::withToken($this->api_key)->patch(
203205
$this->paddle_url . '/subscriptions/' . (string)$request->user()->latestSubscription->subscription_id,
204206
[
205207
'items' => [

0 commit comments

Comments
 (0)