Skip to content

Commit

Permalink
Update: use callback url to retrieve sofinco cacf transaction id
Browse files Browse the repository at this point in the history
  • Loading branch information
BeBlood committed Sep 30, 2021
1 parent 1be11bf commit a11c2e8
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions Gateway/SofincoCACFPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function buildOptions(
'providerContext' => [
'businessProviderId' => $paymentGatewayConfiguration->get('business_provider_id'),
'returnUrl' => $paymentGatewayConfiguration->get('return_url'),
'exchangeUrl' => $paymentGatewayConfiguration->get('callback_url'),
'exchangeUrl' => $this->buildExchangeUrl($paymentGatewayConfiguration->get('callback_url'), $transaction->getId()),
],
'customerContext' => [
'externalCustomerId' => $transaction->getCustomerId(),
Expand Down Expand Up @@ -149,8 +149,22 @@ public function getResponse(
throw new \UnexpectedValueException(sprintf('Sofinco - JSON Error: %s', json_last_error_msg()));
}

if (!$request->query->has('transactionId')) {
throw new \UnexpectedValueException('The query parameter transactionId was not found.');
}

if (strtoupper($request->query->get('transactionId')) !== $requestData['ORDER_ID']) {
throw new \UnexpectedValueException(
sprintf(
'The transaction/order id mismatch in the data (query: %s, body: %s).',
$request->query->get('transactionId'),
$requestData['ORDER_ID']
)
);
}

$gatewayResponse = (new GatewayResponse())
->setTransactionUuid($requestData['ORDER_ID'])
->setTransactionUuid($request->query->get('transactionId'))
->setAmount($requestData['AMOUNT'])
->setDate(new \DateTime())
->setStatus(PaymentStatus::STATUS_FAILED)
Expand Down Expand Up @@ -189,4 +203,22 @@ public static function getParameterNames(): ?array
]
);
}

/**
* Build exchange url with transactionId query parameter.
*
* @param string $url
*
* @return string
*/
private function buildExchangeUrl(string $url, string $transactionId): string
{
$query = parse_url($url, PHP_URL_QUERY);

if ($query) {
return sprintf('%s&transactionId=%s', $url, $transactionId);
}

return sprintf('%s?transactionId=%s', $url, $transactionId);
}
}

0 comments on commit a11c2e8

Please sign in to comment.