Skip to content

Commit

Permalink
fix sandbox payment
Browse files Browse the repository at this point in the history
  • Loading branch information
dipudey committed Sep 1, 2022
1 parent 61105ff commit 6a71bf3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/Managers/BaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ protected function headers()
protected function getToken()
{
if (empty($this->token)) {
$response = $this->request()->post($this->baseUrl . "payment/merchant-auth/", [
"merchant_id" => config("upay.merchant_id"),
"merchant_key" => config("upay.merchant_key"),
]);
$response = $this->request()
->post($this->baseUrl . "payment/merchant-auth/", [
"merchant_id" => config("upay.merchant_id"),
"merchant_key" => config("upay.merchant_key"),
]);

$result = json_decode($response->body());
if ($response->failed()) {
Expand All @@ -69,9 +70,12 @@ protected function getToken()
*/
protected function request()
{
return Http::acceptJson()
->withOptions([
$request = Http::acceptJson();
if (config('upay.sandbox') != true) {
$request->withOptions([
'curl' => [CURLOPT_INTERFACE => config("upay.server_ip"), CURLOPT_IPRESOLVE => 1],
]);
}
return $request;
}
}
6 changes: 5 additions & 1 deletion src/Managers/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Payment extends BaseApi
public function createPayment($amount, $invoiceId, $txnId, $date)
{
$upayResponse = $this->request()
->withHeaders($this->headers())
->post($this->baseUrl . "payment/merchant-payment-init/", [
"date" => $date,
"txn_id" => $txnId,
Expand Down Expand Up @@ -84,7 +85,9 @@ public function executePayment($amount, $invoiceId, $txnId, $date)
*/
public function queryPayment(string $txnId)
{
$upayResponse = $this->request()->get($this->baseUrl . "payment/single-payment-status/{$txnId}/");
$upayResponse = $this->request()
->withHeaders($this->headers())
->get($this->baseUrl . "payment/single-payment-status/{$txnId}/");

$result = json_decode($upayResponse->body());
if ($upayResponse->failed()) {
Expand Down Expand Up @@ -115,6 +118,7 @@ public function queryPayment(string $txnId)
public function getMultiStatus(array $txnIds)
{
$upayResponse = $this->request()
->withHeaders($this->headers())
->post($this->baseUrl . "payment/bulk-payment-status/", [
"txn_id_list" => $txnIds
]);
Expand Down

0 comments on commit 6a71bf3

Please sign in to comment.