Skip to content

Commit 307d6c7

Browse files
committed
Update zarinpal request from http curl to laravel HTTP Client
1 parent a343411 commit 307d6c7

File tree

2 files changed

+17
-56
lines changed

2 files changed

+17
-56
lines changed

src/Adapter/Zarinpal.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
namespace PhpMonsters\Larapay\Adapter;
55

6-
use SoapClient;
7-
use SoapFault;
8-
use PhpMonsters\Larapay\Adapter\Zarinpal\Helper;
6+
use Illuminate\Support\Facades\Http;
97
use PhpMonsters\Larapay\Adapter\Zarinpal\Exception;
108
use PhpMonsters\Log\Facades\XLog;
119

@@ -61,9 +59,13 @@ protected function requestToken(): string
6159
try {
6260
XLog::debug('PaymentRequest call', $sendParams);
6361

64-
$response = Helper::post2https($sendParams, $this->getPaymentRequestEndpPoint());
65-
$result = json_decode($response);
66-
XLog::info('reservation result', $result);
62+
$response = Http::withHeaders([
63+
'Content-Type' => 'application/json',
64+
])->post($this->getPaymentRequestEndpPoint(), $sendParams);
65+
66+
$response->throw();
67+
68+
$result = $response->object();
6769

6870
if (empty($result->errors)) {
6971
if ($result->data->code == 100) {
@@ -138,9 +140,15 @@ protected function verifyTransaction(): bool
138140
XLog::debug('PaymentVerification call', $sendParams);
139141

140142
try {
141-
$response = Helper::post2https($sendParams, $this->getPaymentVerifyEndpPoint());
142-
$result = json_decode($response);
143-
XLog::info('PaymentVerification response', $this->obj2array($result));
143+
$response = Http::withHeaders([
144+
'Content-Type' => 'application/json',
145+
])->post($this->getPaymentVerifyEndpPoint(), $sendParams);
146+
147+
$response->throw();
148+
149+
$result = $response->object();
150+
151+
XLog::info('PaymentVerification response', $response->json());
144152

145153
if ($result->data->code === 100) {
146154
$this->getTransaction()->setVerified();

src/Adapter/Zarinpal/Helper.php

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

0 commit comments

Comments
 (0)