Skip to content

Commit

Permalink
Update: Sofinco CACF payment gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
BeBlood committed Sep 27, 2021
1 parent aa80251 commit 1be11bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
5 changes: 3 additions & 2 deletions Controller/PaymentGatewayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public function callbackAction(Request $request, EventDispatcherInterface $dispa
try {
$this->logger->info(
sprintf(
'[gateway configuration alias: %s, data: %s, ip: %s]',
'[gateway configuration alias: %s, data: %s, ip: %s, content: %s]',
$configuration_alias,
json_encode($data),
json_encode($request->getClientIps())
json_encode($request->getClientIps()),
$request->getContent()
)
);
} catch (\Exception $e) {}
Expand Down
22 changes: 14 additions & 8 deletions Gateway/SofincoCACFPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,32 @@ public function buildHTMLView(
/**
* {@inheritdoc}
*
* @throws \UnexpectedValueException If the request method is not GET
* @throws \UnexpectedValueException If the request method is not POST
*/
public function getResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
if (!$request->isMethod(Request::METHOD_GET)) {
throw new \UnexpectedValueException('Sofinco : Payment Gateway error (Request method should be GET)');
if (!$request->isMethod(Request::METHOD_POST)) {
throw new \UnexpectedValueException('Sofinco : Payment Gateway error (Request method should be POST)');
}

$requestData = json_decode($request->getContent(), true);

if (json_last_error()) {
throw new \UnexpectedValueException(sprintf('Sofinco - JSON Error: %s', json_last_error_msg()));
}

$gatewayResponse = (new GatewayResponse())
->setTransactionUuid($request->request->get('ORDER_ID'))
->setAmount($request->request->get('AMOUNT'))
->setTransactionUuid($requestData['ORDER_ID'])
->setAmount($requestData['AMOUNT'])
->setDate(new \DateTime())
->setStatus(PaymentStatus::STATUS_FAILED)
->setRaw($request->request->all())
->setRaw($requestData)
;

if (in_array(
$request->request->get('CONTRACT_STATUS'),
$requestData['CONTRACT_STATUS'],
[
SofincoCACFPaymentGatewayClient::DOCUMENT_STATUS_REFUSED,
SofincoCACFPaymentGatewayClient::DOCUMENT_STATUS_CANCELED,
Expand All @@ -163,7 +169,7 @@ public function getResponse(
return $gatewayResponse->setMessage('Transaction unauthorized');
}

if (SofincoCACFPaymentGatewayClient::DOCUMENT_STATUS_FUNDED === $request->request->get('CONTRACT_STATUS')) {
if (SofincoCACFPaymentGatewayClient::DOCUMENT_STATUS_FUNDED === $requestData['CONTRACT_STATUS']) {
return $gatewayResponse->setStatus(PaymentStatus::STATUS_APPROVED);
}

Expand Down

0 comments on commit 1be11bf

Please sign in to comment.