Skip to content

Commit a778a93

Browse files
committed
Update: add logger in EurekaPaymentGatewayClient
1 parent 0fd4195 commit a778a93

File tree

1 file changed

+59
-40
lines changed

1 file changed

+59
-40
lines changed

Gateway/Client/EurekaPaymentGatewayClient.php

Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace IDCI\Bundle\PaymentBundle\Gateway\Client;
44

55
use GuzzleHttp\Client;
6+
use GuzzleHttp\Exception\RequestException;
67
use Payum\ISO4217\ISO4217;
8+
use Psr\Log\LoggerInterface;
79
use Symfony\Component\Cache\Adapter\AdapterInterface;
810
use Symfony\Component\DomCrawler\Crawler;
911
use Symfony\Component\OptionsResolver\Options;
@@ -110,9 +112,10 @@ class EurekaPaymentGatewayClient
110112
*/
111113
private $serverHostName;
112114

113-
public function __construct(Environment $templating, string $serverHostName)
115+
public function __construct(Environment $templating, LoggerInterface $logger, string $serverHostName)
114116
{
115117
$this->templating = $templating;
118+
$this->logger = $logger;
116119
$this->client = new Client(['defaults' => ['verify' => false, 'timeout' => 5]]);
117120
$this->cache = null;
118121
$this->serverHostName = $serverHostName;
@@ -167,17 +170,21 @@ private function getSTSTokenHash(string $username)
167170

168171
public function getSTSTokenResponse(string $username, string $password)
169172
{
170-
return $this->client->request('POST', $this->getSTSConnectionUrl(), [
171-
'body' => $this->templating->render('@IDCIPayment/Gateway/eureka/sts_token.xml.twig', [
172-
'username' => $username,
173-
'password' => $password,
174-
'merchant_url' => $this->getMerchantUrl(),
175-
]),
176-
'headers' => [
177-
'Content-Type' => 'text/xml',
178-
'SOAPAction' => 'http://www.cdiscount.com/SoapTokenServiceContract/Issue',
179-
],
180-
]);
173+
try {
174+
return $this->client->request('POST', $this->getSTSConnectionUrl(), [
175+
'body' => $this->templating->render('@IDCIPayment/Gateway/eureka/sts_token.xml.twig', [
176+
'username' => $username,
177+
'password' => $password,
178+
'merchant_url' => $this->getMerchantUrl(),
179+
]),
180+
'headers' => [
181+
'Content-Type' => 'text/xml',
182+
'SOAPAction' => 'http://www.cdiscount.com/SoapTokenServiceContract/Issue',
183+
],
184+
]);
185+
} catch (RequestException $e) {
186+
$this->logger->error((string) $e->getResponse()->getBody());
187+
}
181188
}
182189

183190
public function getSTSToken(string $username, string $password)
@@ -207,20 +214,24 @@ public function getScoringTokenResponse(string $type, array $options)
207214
);
208215
}
209216

210-
return $this->client->request(
211-
'POST',
212-
self::SCORE_V3 === $type ? $this->getScoreV3Url() : $this->getScoreCclUrl(),
213-
[
214-
'body' => $this->templating->render(
215-
'@IDCIPayment/Gateway/eureka/score.xml.twig',
216-
$this->resolveScoreOptions($options)
217-
),
218-
'headers' => [
219-
'Content-Type' => 'text/xml',
220-
'SOAPAction' => 'http://www.cb4x.fr/ICb4xFrontService/Score',
221-
],
222-
]
223-
);
217+
try {
218+
return $this->client->request(
219+
'POST',
220+
self::SCORE_V3 === $type ? $this->getScoreV3Url() : $this->getScoreCclUrl(),
221+
[
222+
'body' => $this->templating->render(
223+
'@IDCIPayment/Gateway/eureka/score.xml.twig',
224+
$this->resolveScoreOptions($options)
225+
),
226+
'headers' => [
227+
'Content-Type' => 'text/xml',
228+
'SOAPAction' => 'http://www.cb4x.fr/ICb4xFrontService/Score',
229+
],
230+
]
231+
);
232+
} catch (RequestException $e) {
233+
$this->logger->error((string) $e->getResponse()->getBody());
234+
}
224235
}
225236

226237
public function getScoringToken(string $type, array $options)
@@ -240,24 +251,32 @@ public function getScoringToken(string $type, array $options)
240251

241252
public function payOrderRank(array $options)
242253
{
243-
return $this->client->request('POST', $this->getMerchantUrl(), [
244-
'body' => $this->templating->render('@IDCIPayment/Gateway/eureka/pay_order_rank.xml.twig', $this->resolvePayOrderRankOptions($options)),
245-
'headers' => [
246-
'Content-Type' => 'text/xml',
247-
'SoapAction' => 'PayOrderRank',
248-
],
249-
]);
254+
try {
255+
return $this->client->request('POST', $this->getMerchantUrl(), [
256+
'body' => $this->templating->render('@IDCIPayment/Gateway/eureka/pay_order_rank.xml.twig', $this->resolvePayOrderRankOptions($options)),
257+
'headers' => [
258+
'Content-Type' => 'text/xml',
259+
'SoapAction' => 'PayOrderRank',
260+
],
261+
]);
262+
} catch (RequestException $e) {
263+
$this->logger->error((string) $e->getResponse()->getBody());
264+
}
250265
}
251266

252267
public function updateOrder(array $options)
253268
{
254-
return $this->client->request('POST', $this->getMerchantUrl(), [
255-
'body' => $this->templating->render('@IDCIPayment/Gateway/eureka/update_order.xml.twig', $this->resolveUpdateOrderOptions($options)),
256-
'headers' => [
257-
'Content-Type' => 'text/xml',
258-
'SoapAction' => 'UpdateOrder',
259-
],
260-
]);
269+
try {
270+
return $this->client->request('POST', $this->getMerchantUrl(), [
271+
'body' => $this->templating->render('@IDCIPayment/Gateway/eureka/update_order.xml.twig', $this->resolveUpdateOrderOptions($options)),
272+
'headers' => [
273+
'Content-Type' => 'text/xml',
274+
'SoapAction' => 'UpdateOrder',
275+
],
276+
]);
277+
} catch (RequestException $e) {
278+
$this->logger->error((string) $e->getResponse()->getBody());
279+
}
261280
}
262281

263282
private function resolveScoreOptions(array $scoreOptions): array

0 commit comments

Comments
 (0)