Skip to content

Commit 6a71bf3

Browse files
committed
fix sandbox payment
1 parent 61105ff commit 6a71bf3

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Managers/BaseApi.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ protected function headers()
4646
protected function getToken()
4747
{
4848
if (empty($this->token)) {
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-
]);
49+
$response = $this->request()
50+
->post($this->baseUrl . "payment/merchant-auth/", [
51+
"merchant_id" => config("upay.merchant_id"),
52+
"merchant_key" => config("upay.merchant_key"),
53+
]);
5354

5455
$result = json_decode($response->body());
5556
if ($response->failed()) {
@@ -69,9 +70,12 @@ protected function getToken()
6970
*/
7071
protected function request()
7172
{
72-
return Http::acceptJson()
73-
->withOptions([
73+
$request = Http::acceptJson();
74+
if (config('upay.sandbox') != true) {
75+
$request->withOptions([
7476
'curl' => [CURLOPT_INTERFACE => config("upay.server_ip"), CURLOPT_IPRESOLVE => 1],
7577
]);
78+
}
79+
return $request;
7680
}
7781
}

src/Managers/Payment.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Payment extends BaseApi
2525
public function createPayment($amount, $invoiceId, $txnId, $date)
2626
{
2727
$upayResponse = $this->request()
28+
->withHeaders($this->headers())
2829
->post($this->baseUrl . "payment/merchant-payment-init/", [
2930
"date" => $date,
3031
"txn_id" => $txnId,
@@ -84,7 +85,9 @@ public function executePayment($amount, $invoiceId, $txnId, $date)
8485
*/
8586
public function queryPayment(string $txnId)
8687
{
87-
$upayResponse = $this->request()->get($this->baseUrl . "payment/single-payment-status/{$txnId}/");
88+
$upayResponse = $this->request()
89+
->withHeaders($this->headers())
90+
->get($this->baseUrl . "payment/single-payment-status/{$txnId}/");
8891

8992
$result = json_decode($upayResponse->body());
9093
if ($upayResponse->failed()) {
@@ -115,6 +118,7 @@ public function queryPayment(string $txnId)
115118
public function getMultiStatus(array $txnIds)
116119
{
117120
$upayResponse = $this->request()
121+
->withHeaders($this->headers())
118122
->post($this->baseUrl . "payment/bulk-payment-status/", [
119123
"txn_id_list" => $txnIds
120124
]);

0 commit comments

Comments
 (0)