Skip to content

Commit e1bfda5

Browse files
committed
fix production server ip problem
1 parent 3b342bc commit e1bfda5

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

config/upay.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
return [
44
"sandbox" => env("UPAY_SANDBOX", false),
5+
"server_ip" => env("UPAY_SERVER_IP", ""),
56
"merchant_id" => env("UPAY_MERCHANT_ID", ""),
67
"merchant_key" => env("UPAY_MERCHANT_KEY", ""),
78
"merchant_code" => env("UPAY_MERCHANT_CODE", ""),

src/Managers/BaseApi.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,31 @@
44

55
use Codeboxr\Upay\Exception\UpayException;
66
use Illuminate\Support\Facades\Http;
7+
use Illuminate\Http\Client\PendingRequest;
78

89
class BaseApi
910
{
11+
/**
12+
* @var string
13+
*/
1014
protected $token = "";
1115

16+
/**
17+
* @var string
18+
*/
1219
protected $baseUrl = "";
1320

1421
public function __construct()
1522
{
1623
$this->baseUrl = config('upay.sandbox') == true ? "https://uat-pg.upay.systems/" : "https://pg.upaysystem.com/";
1724
}
1825

26+
/**
27+
* Set headers
28+
*
29+
* @return string[]
30+
* @throws UpayException
31+
*/
1932
protected function headers()
2033
{
2134
return [
@@ -24,22 +37,41 @@ protected function headers()
2437
];
2538
}
2639

40+
/**
41+
* Token generate
42+
*
43+
* @return mixed|null
44+
* @throws UpayException
45+
*/
2746
protected function getToken()
2847
{
2948
if (empty($this->token)) {
30-
$response = Http::acceptJson()
31-
->post($this->baseUrl . "payment/merchant-auth/", [
32-
"merchant_id" => config("upay.merchant_id"),
33-
"merchant_key" => config("upay.merchant_key"),
34-
]);
49+
$response = $this->request()->post($this->baseUrl . "payment/merchant-auth/", [
50+
"merchant_id" => config("upay.merchant_id"),
51+
"merchant_key" => config("upay.merchant_key"),
52+
]);
3553

3654
$result = json_decode($response->body());
3755
if ($response->failed()) {
3856
throw new UpayException($result->message, $response->status());
3957
}
58+
4059
$this->token = optional($result->data)->token;
4160
}
4261

4362
return $this->token;
4463
}
64+
65+
/**
66+
* request
67+
*
68+
* @return PendingRequest
69+
*/
70+
protected function request()
71+
{
72+
return Http::acceptJson()
73+
->withOptions([
74+
'curl' => [CURLOPT_INTERFACE => config("upay.server_ip"), CURLOPT_IPRESOLVE => 1],
75+
]);
76+
}
4577
}

src/Managers/Payment.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
namespace Codeboxr\Upay\Managers;
44

5+
use Illuminate\Http\JsonResponse;
6+
use Illuminate\Routing\Redirector;
57
use Illuminate\Support\Facades\Http;
8+
use Illuminate\Http\RedirectResponse;
69
use Codeboxr\Upay\Exception\UpayException;
10+
use Illuminate\Contracts\Foundation\Application;
711

812
class Payment extends BaseApi
913
{
@@ -15,12 +19,12 @@ class Payment extends BaseApi
1519
* @param string $txnId
1620
* @param string $date
1721
*
18-
* @return \Illuminate\Http\JsonResponse
22+
* @return JsonResponse
1923
* @throws UpayException
2024
*/
2125
public function createPayment($amount, $invoiceId, $txnId, $date)
2226
{
23-
$upayResponse = Http::withHeaders($this->headers())
27+
$upayResponse = $this->request()
2428
->post($this->baseUrl . "payment/merchant-payment-init/", [
2529
"date" => $date,
2630
"txn_id" => $txnId,
@@ -61,7 +65,7 @@ public function createPayment($amount, $invoiceId, $txnId, $date)
6165
* @param string $txnId
6266
* @param string $date
6367
*
64-
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void
68+
* @return Application|RedirectResponse|Redirector|void
6569
* @throws UpayException
6670
*/
6771
public function executePayment($amount, $invoiceId, $txnId, $date)
@@ -75,13 +79,12 @@ public function executePayment($amount, $invoiceId, $txnId, $date)
7579
*
7680
* @param string $txnId
7781
*
78-
* @return \Illuminate\Http\JsonResponse
82+
* @return JsonResponse
7983
* @throws UpayException
8084
*/
8185
public function queryPayment(string $txnId)
8286
{
83-
$upayResponse = Http::withHeaders($this->headers())
84-
->get($this->baseUrl . "payment/single-payment-status/{$txnId}/");
87+
$upayResponse = $this->request()->get($this->baseUrl . "payment/single-payment-status/{$txnId}/");
8588

8689
$result = json_decode($upayResponse->body());
8790
if ($upayResponse->failed()) {
@@ -106,12 +109,12 @@ public function queryPayment(string $txnId)
106109
*
107110
* @param array $txnIds
108111
*
109-
* @return \Illuminate\Http\JsonResponse
112+
* @return JsonResponse
110113
* @throws UpayException
111114
*/
112115
public function getMultiStatus(array $txnIds)
113116
{
114-
$upayResponse = Http::withHeaders($this->headers())
117+
$upayResponse = $this->request()
115118
->post($this->baseUrl . "payment/bulk-payment-status/", [
116119
"txn_id_list" => $txnIds
117120
]);

0 commit comments

Comments
 (0)