Skip to content

Commit c0d526b

Browse files
authored
refactor url resirect (#3)
1 parent 4fad8d4 commit c0d526b

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ use Omnipay\Omnipay;
2121

2222
$gateway = Omnipay::create('OfflineDummy');
2323

24-
$gateway->initialize([
25-
'url_notify' => 'http://example.com/payment/notify',
26-
'url_return' => 'http://example.com/payment/return',
27-
]);
28-
2924
$request = $gateway->purchase([
3025
'amount' => '12.00',
3126
'description' => 'Test purchase',
3227
'transactionId' => 1,
28+
'url_notify' => 'http://example.com/payment/notify',
29+
'url_return' => 'http://example.com/payment/return',
3330
])->send();
3431

3532
$response->redirect();

resources/views/payment.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<form method="POST" action="/payment/process">
3535
<input type="hidden" name="transition_id" value="{{ $transactionId }}" />
3636
<input type="hidden" name="amount" value="{{ $amount }}" />
37+
<input type="hidden" name="url_notify" value="{{ $url_notify }}" />
38+
<input type="hidden" name="url_return" value="{{ $url_return }}" />
3739
<input type="submit" name="status" value="{{ $label_success }}" />
3840
<input type="submit" name="status" value="{{ $label_denied }}" />
3941
</form>

src/App/Http/Controllers/PaymentController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function __invoke(Request $request)
2020
'transactionId' => $request->input('transaction_id'),
2121
'description' => $request->input('description'),
2222
'amount' => $request->input('amount'),
23+
'url_notify' => $request->input('url_notify'),
24+
'url_return' => $request->input('url_return'),
2325
'label_success' => App::STATUS_SUCCESS,
2426
'label_denied' => App::STATUS_DENIED,
2527
]);

src/App/Http/Controllers/PaymentProcessController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public function __invoke(Request $request)
1616
$response = $gateway->completePurchase($request->all())->send();
1717

1818
Http::acceptJson()->post(
19-
$gateway->getUrlNotify(),
19+
$request->input('url_notify'),
2020
$response->getData()
2121
);
2222

23-
return response()->redirectTo($gateway->getUrlReturn());
23+
return response()->redirectTo($request->input('url_return'));
2424
}
2525
}

src/Message/PurchaseRequest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ public function getData()
3535
$this->validate(
3636
'amount',
3737
'description',
38-
'transactionId'
38+
'transactionId',
39+
'url_notify',
40+
'url_return',
3941
);
4042

4143
return [
4244
'transaction_id' => $this->getTransactionId(),
4345
'amount' => $this->getAmount(),
4446
'description' => $this->getDescription(),
47+
'url_notify' => $this->getUrlNotify(),
48+
'url_return' => $this->getUrlReturn(),
4549
];
4650
}
4751

tests/AppTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function testPurchase()
2626
'amount' => '12.00',
2727
'description' => 'Test purchase',
2828
'transactionId' => 1,
29+
'notify_url' => 'http://localhost:8080/gateway/notify',
30+
'url_return' => 'http://localhost:8080/gateway/return',
2931
]
3032
)->send();
3133

@@ -45,13 +47,14 @@ public function testCompletePurchase()
4547
'transaction_id' => 1,
4648
'amount' => 12.00,
4749
'description' => 'Test purchase',
48-
'notify_url' => 'http://localhost:8080/gateway/notify',
50+
'url_notify' => 'http://localhost:8080/gateway/notify',
51+
'url_return' => 'http://localhost:8080/gateway/return',
4952
'status' => App::STATUS_SUCCESS,
5053
])->assertStatus(302)
51-
->assertRedirect($this->gateway->getUrlReturn());
54+
->assertRedirect('http://localhost:8080/gateway/return');
5255

5356
Http::assertSent(function ($request) {
54-
return $request->url() === $this->gateway->getUrlNotify();
57+
return $request->url() === 'http://localhost:8080/gateway/notify';
5558
});
5659
}
5760
}

0 commit comments

Comments
 (0)