Skip to content

Commit eb44e06

Browse files
Fixed issue with returning after payment
1 parent c34d74a commit eb44e06

File tree

7 files changed

+34
-39
lines changed

7 files changed

+34
-39
lines changed

Http/Controllers/Payment.php

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,53 +33,35 @@ public function show(Document $invoice, PaymentRequest $request, $cards = [])
3333
$return_url = $this->getReturnUrl($invoice);
3434
$confirm_url = $this->getConfirmUrl($invoice);
3535

36-
$html = view('paypal-standard::show', compact('setting', 'invoice', 'invoice_url', 'return_url', 'confirm_url'))->render();
37-
3836
return response()->json([
3937
'code' => $setting['code'],
4038
'name' => $setting['name'],
4139
'description' => trans('paypal-standard::general.description'),
4240
'redirect' => false,
43-
'html' => $html,
41+
'html' => view('paypal-standard::show', compact('setting', 'invoice', 'invoice_url', 'return_url', 'confirm_url'))->render(),
4442
]);
4543
}
4644

4745
public function return(Document $invoice, Request $request)
4846
{
49-
$success = true;
47+
if ($request['payment_status'] === 'Completed') {
48+
$this->setReference($invoice, $request->id);
5049

51-
switch ($request['payment_status']) {
52-
case 'Completed':
53-
$message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);
54-
break;
55-
case 'Canceled_Reversal':
56-
case 'Denied':
57-
case 'Expired':
58-
case 'Failed':
59-
case 'Pending':
60-
case 'Processed':
61-
case 'Refunded':
62-
case 'Reversed':
63-
case 'Voided':
64-
$message = trans('messages.error.added', ['type' => trans_choice('general.payments', 1)]);
65-
$success = false;
66-
break;
50+
$this->finish($invoice, $request);
51+
52+
return redirect($this->getFinishUrl($invoice));
6753
}
6854

69-
if ($success) {
70-
flash($message)->success();
55+
if (in_array($request['payment_status'], ['Pending', 'Canceled_Reversal', 'Denied', 'Expired', 'Failed', 'Processed', 'Refunded', 'Reversed', 'Voided'])) {
56+
$message = $request['payment_status'] === 'Pending' ? trans('paypal-standard::general.payment.pending') : trans('paypal-standard::general.payment.not_added');
7157

72-
$url = $this->getFinishUrl($invoice);
73-
} else {
7458
flash($message)->warning();
7559

76-
$url = $this->getInvoiceUrl($invoice);
60+
return redirect($this->getInvoiceUrl($invoice));
7761
}
78-
79-
return redirect($url);
8062
}
8163

82-
public function complete(Document $invoice, Request $request)
64+
public function confirm(Document $invoice, Request $request)
8365
{
8466
$setting = $this->setting;
8567

@@ -91,7 +73,7 @@ public function complete(Document $invoice, Request $request)
9173
return;
9274
}
9375

94-
$url = ($setting['mode'] == 'live') ? 'https://ipnpb.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/cgi-bin/webscr';
76+
$url = ($setting['mode'] == 'live') ? 'https://ipnpb.paypal.com/cgi-bin/webscr' : 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
9577

9678
$client = new Client(['verify' => false]);
9779

@@ -104,7 +86,7 @@ public function complete(Document $invoice, Request $request)
10486
$response = $client->post($url, $paypal_request);
10587

10688
if ($response->getStatusCode() != 200) {
107-
$paypal_log->info('PAYPAL_STANDARD :: CURL failed ', $response->getBody()->getContents());
89+
$paypal_log->info('PAYPAL_STANDARD :: CURL failed ' . $response->getBody()->getContents());
10890
} else {
10991
$response = $response->getBody()->getContents();
11092
}

Providers/Main.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function loadRoutes()
5959
}
6060

6161
$routes = [
62-
'guest.php',
6362
'portal.php',
6463
'signed.php',
6564
];

Resources/lang/en-GB/general.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
'order' => 'Order',
1515
],
1616

17+
'payment' => [
18+
'pending' => 'Payment is pending',
19+
'not_added' => 'Payment not added!',
20+
],
21+
1722
'test_mode' => 'Warning: The payment gateway is in \'Sandbox Mode\'. Your account will not be charged.',
1823
//'description' => 'Pay with PAYPAL',
1924

Resources/views/show.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
<input type="hidden" name="currency_code" value="{{ $invoice->currency_code}}" />
3131
<input type="hidden" name="first_name" value="{{ $invoice->first_name }}" />
3232
<input type="hidden" name="last_name" value="{{ $invoice->last_name }}" />
33-
<input type="hidden" name="address1" value="{{ $invoice->customer_address }}" />
33+
<input type="hidden" name="address1" value="{{ $invoice->contact_address }}" />
3434
<input type="hidden" name="address_override" value="0" />
35-
<input type="hidden" name="email" value="{{ $invoice->customer_email }}" />
36-
<input type="hidden" name="invoice" value="{{ $invoice->id . '-' . $invoice->customer_name }}" />
35+
<input type="hidden" name="email" value="{{ $invoice->contact_email }}" />
36+
<input type="hidden" name="invoice" value="{{ $invoice->id . '-' . $invoice->contact_name }}" />
3737
<input type="hidden" name="lc" value="{{ $setting['language'] }}" />
3838
<input type="hidden" name="rm" value="2" />
3939
<input type="hidden" name="no_note" value="1" />
@@ -50,4 +50,4 @@
5050
</form>
5151
</div>
5252
</div>
53-
</div>
53+
</div>

Routes/guest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Http\Middleware\VerifyCsrfToken;
34
use Illuminate\Support\Facades\Route;
45

56
/**
@@ -9,6 +10,8 @@
910
*/
1011

1112
Route::portal('paypal-standard', function () {
12-
Route::get('invoices/{invoice}/complete', 'Payment@return')->name('invoices.return');
13-
Route::post('invoices/{invoice}/complete', 'Payment@complete')->name('invoices.confirm');
13+
Route::get('invoices/{invoice}', 'Payment@show')->name('invoices.show');
14+
Route::post('invoices/{invoice}/confirm', 'Payment@confirm')->withoutMiddleware(VerifyCsrfToken::class)->name('invoices.confirm');
15+
Route::post('invoices/{invoice}/return', 'Payment@return')->withoutMiddleware(VerifyCsrfToken::class)->name('invoices.return');
16+
Route::get('invoices/{invoice}/cancel', 'Payment@cancel')->name('invoices.cancel');
1417
}, ['middleware' => 'guest']);

Routes/portal.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Http\Middleware\VerifyCsrfToken;
34
use Illuminate\Support\Facades\Route;
45

56
/**
@@ -10,4 +11,7 @@
1011

1112
Route::portal('paypal-standard', function () {
1213
Route::get('invoices/{invoice}', 'Payment@show')->name('invoices.show');
14+
Route::post('invoices/{invoice}/confirm', 'Payment@confirm')->withoutMiddleware(VerifyCsrfToken::class)->name('invoices.confirm');
15+
Route::post('invoices/{invoice}/return', 'Payment@return')->withoutMiddleware(VerifyCsrfToken::class)->name('invoices.return');
16+
Route::get('invoices/{invoice}/cancel', 'Payment@cancel')->name('invoices.cancel');
1317
});

Routes/signed.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Http\Middleware\VerifyCsrfToken;
34
use Illuminate\Support\Facades\Route;
45

56
/**
@@ -10,6 +11,7 @@
1011

1112
Route::signed('paypal-standard', function () {
1213
Route::get('invoices/{invoice}', 'Payment@show')->name('invoices.show');
13-
Route::get('invoices/{invoice}/complete', 'Payment@return')->name('invoices.return');
14-
Route::post('invoices/{invoice}/complete', 'Payment@complete')->name('invoices.confirm');
14+
Route::post('invoices/{invoice}/confirm', 'Payment@confirm')->withoutMiddleware(VerifyCsrfToken::class)->name('invoices.confirm');
15+
Route::post('invoices/{invoice}/return', 'Payment@return')->withoutMiddleware(VerifyCsrfToken::class)->name('invoices.return');
16+
Route::get('invoices/{invoice}/cancel', 'Payment@cancel')->name('invoices.cancel');
1517
});

0 commit comments

Comments
 (0)