Skip to content

Commit 7892b07

Browse files
committed
add argument
1 parent 9732195 commit 7892b07

File tree

11 files changed

+250
-60
lines changed

11 files changed

+250
-60
lines changed

resources/views/index.blade.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Descom Payment Demo</title>
8+
</head>
9+
<body>
10+
<div class="container">
11+
<header>
12+
<h1>Método de pago de pruebas</h1>
13+
<p>
14+
Este método de pago ha sido desarrollado por Descom para testear los procesos de compra.
15+
</p>
16+
</header>
17+
18+
<div class="resume">
19+
<h2>Resume Pedido #{{ $transactionId }}</h2>
20+
<p>
21+
{{ $description }}
22+
</p>
23+
<span>
24+
{{ $amount }}
25+
</span>
26+
</div>
27+
28+
<div class="form">
29+
<h2>Seleccione el resultado de la transacción:</h2>
30+
31+
<div>
32+
<form action="POST" action="/process">
33+
<input type="hidden" name="transitionId" value="{{ $transactionId }}" />
34+
<input type="hidden" name="amount" value="{{ $amount }}" />
35+
<input type="hidden" name="notifyUrl" value="{{ $notifyUrl }}" />
36+
<input type="submit" name="status" value="{{ $label_success }" />
37+
<input type="submit" name="status" value="{{ $label_denied }}" />
38+
</form>
39+
</div>
40+
</div>
41+
</div>
42+
</body>
43+
</html>

src/App/App.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
class App
66
{
7+
const STATUS_SUCCESS = 'ACEPTAR PAGO';
8+
const STATUS_DENIED = 'RECHAZAR PAGO';
9+
710
public static function url(string $path): string
811
{
912
return url($path);

src/App/AppServiceProvider.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace Omnipay\RedirectDummy\App;
44

55
use Descom\Skeleton\Console\Install;
6+
use Illuminate\Support\Facades\Route;
67
use Illuminate\Support\ServiceProvider;
8+
use Omnipay\RedirectDummy\App\Http\Controllers\PaymentController;
9+
use Omnipay\RedirectDummy\App\Http\Controllers\PaymentProcessController;
710

811
class AppServiceProvider extends ServiceProvider
912
{
@@ -14,6 +17,16 @@ public function register()
1417

1518
public function boot()
1619
{
17-
//
20+
$this->registerRouters();
21+
22+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'redirectdummy');
23+
}
24+
25+
private function registerRouters(): void
26+
{
27+
Route::middleware('web')->group(function () {
28+
Route::post('/payment', PaymentController::class);
29+
Route::post('/payment/process', PaymentProcessController::class);
30+
});
1831
}
1932
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Omnipay\RedirectDummy\App\Http\Controllers;
4+
5+
use GuzzleHttp\Client;
6+
use Illuminate\Routing\Controller;
7+
use Omnipay\RedirectDummy\App\App;
8+
9+
class PaymentController extends Controller
10+
{
11+
public function __invoke(Request $request)
12+
{
13+
$request->validate([
14+
'transactionId' => 'required',
15+
'description' => 'required',
16+
'amount' => 'required|numeric',
17+
'notifyUrl' => 'required|url',
18+
]);
19+
20+
return view('redirectdummy::payment', [
21+
'transactionId' => $request->input('transitionId'),
22+
'description' => $request->input('description'),
23+
'amount' => $request->input('amount'),
24+
'notifyUrl' => $request->input('notifyUrl'),
25+
'label_success' => App::STATUS_SUCCESS,
26+
'label_denied' => App::STATUS_DENIED,
27+
]);
28+
}
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Omnipay\RedirectDummy\App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Routing\Controller;
7+
use Omnipay\Omnipay;
8+
9+
class PaymentProcessController extends Controller
10+
{
11+
public function __invoke(Request $request)
12+
{
13+
$gateway = Omnipay::create('RedirectDummy');
14+
15+
$response = $gateway->completePurchase($request->all())->send();
16+
17+
return response()->json(['message' => $response->getMessage()]);
18+
}
19+
}

src/Gateway.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,24 @@ public function getName()
1212
return 'RedirectDummy';
1313
}
1414

15-
public function purchase(array $parameters = array())
15+
public function getDefaultParameters()
16+
{
17+
return [
18+
'token' => '',
19+
];
20+
}
21+
22+
public function getToken()
23+
{
24+
return $this->getParameter('token');
25+
}
26+
27+
public function setToken($value)
28+
{
29+
return $this->setParameter('token', $value);
30+
}
31+
32+
public function purchase(array $parameters = [])
1633
{
1734
return $this->createRequest(PurchaseRequest::class, $parameters);
1835
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Omnipay\RedirectDummy\Message;
4+
5+
use Omnipay\Common\Message\AbstractRequest;
6+
use Omnipay\RedirectDummy\App\App;
7+
8+
/**
9+
* PayFast Purchase Request
10+
*/
11+
class CompletedPurchaseRequest extends AbstractRequest
12+
{
13+
public function getData()
14+
{
15+
return [
16+
'transaction_id' => $this->getTransactionId(),
17+
'amount' => $this->getAmount(),
18+
'success' => App::STATUS_SUCCESS === $this->getStatus(),
19+
];
20+
}
21+
22+
public function sendData($data)
23+
{
24+
return $this->response = new CompletedPurchaseResponse($this, $data);
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Omnipay\RedirectDummy\Message;
4+
5+
use Omnipay\Common\Message\AbstractResponse;
6+
use Omnipay\Common\Message\RequestInterface;
7+
use Omnipay\Common\Message\RedirectResponseInterface;
8+
9+
class CompletedPurchaseResponse extends AbstractResponse implements RedirectResponseInterface
10+
{
11+
public function isSuccessful()
12+
{
13+
return (bool)$this->getStatus();;
14+
}
15+
16+
}

tests/GatewayTest.php

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,17 @@
11
<?php
22

3-
namespace Omnipay\RedirectDummy;
3+
namespace Omnipay\RedirectDummy\Tests;
44

5-
use Omnipay\Common\Http\Client;
65
use Omnipay\RedirectDummy\Gateway;
7-
use Omnipay\RedirectDummy\Message\PurchaseRequest;
8-
use Omnipay\RedirectDummy\Message\PurchaseResponse;
9-
use Omnipay\RedirectDummy\Tests\TestCase;
106
use Omnipay\Tests\GatewayTestCase;
11-
use Symfony\Component\HttpFoundation\Request;
127

13-
class GatewayTest extends TestCase
8+
class GatewayTest extends GatewayTestCase
149
{
15-
private Gateway $gateway;
16-
17-
private function getHttpClient()
18-
{
19-
return new Client();
20-
}
21-
22-
private function getHttpRequest()
23-
{
24-
return Request::createFromGlobals();
25-
}
26-
2710
public function setUp(): void
2811
{
2912
parent::setUp();
3013

3114
$this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest());
32-
$this->gateway->initialize([
33-
'url_gateway' => 'http://localhost',
34-
]);
35-
}
36-
37-
public function testPurchase()
38-
{
39-
$request = $this->gateway->purchase([
40-
'amount' => '12.00',
41-
'description' => 'Test purchase',
42-
'transactionId' => 1,
43-
'notifyUrl' => 'http://localhost:8080/gateway/notify',
44-
]);
45-
46-
$this->assertInstanceOf(PurchaseRequest::class, $request);
47-
$this->assertSame('12.00', $request->getAmount());
48-
49-
$response = $request->sendData($request->getData());
50-
51-
$this->assertInstanceOf(PurchaseResponse::class, $response);
52-
$this->assertTrue($response->isRedirect());
53-
$this->assertEquals('http://localhost/payment', $response->getRedirectUrl());
54-
$this->assertEquals('http://localhost:8080/gateway/notify', $response->getData()['notify_url']);
15+
$this->gateway->initialize();
5516
}
5617
}

tests/OmnipayTest.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)