Skip to content

Commit

Permalink
Merge pull request #24 from IDCI-Consulting/feat/gateway-return-response
Browse files Browse the repository at this point in the history
Update: add getReturnResponse on payment gateway
  • Loading branch information
BeBlood authored Nov 30, 2022
2 parents 52188e4 + b74ade3 commit 834aa3a
Show file tree
Hide file tree
Showing 29 changed files with 296 additions and 226 deletions.
10 changes: 9 additions & 1 deletion Gateway/AbstractPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ abstract public function buildHTMLView(
/**
* {@inheritdoc}
*/
abstract public function getResponse(
abstract public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse;

/**
* {@inheritdoc}
*/
abstract public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse;
Expand Down
36 changes: 35 additions & 1 deletion Gateway/AlmaPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,46 @@ public function buildHTMLView(
]);
}

/**
* {@inheritdoc}
*/
public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
$gatewayResponse = new GatewayResponse();

if (!$request->query->has('pid')) {
return $gatewayResponse;
}

try {
$payment = $this->getClient($paymentGatewayConfiguration)->payments->fetch($request->query->get('pid'));

$gatewayResponse
->setTransactionUuid($payment->orders[0]->merchant_reference)
->setAmount($payment->purchase_amount)
->setRaw(get_object_vars($payment))
;

if (!in_array($payment->state, [AlmaStatusCode::STATUS_IN_PROGRESS, AlmaStatusCode::STATUS_PAID])) {
return $gatewayResponse->setStatus(PaymentStatus::STATUS_FAILED);
}

return $gatewayResponse->setStatus(PaymentStatus::STATUS_APPROVED);
} catch (\Exception $e) {
$this->logger->error(sprintf('Error: %s. Context: %s', $e->getMessage(), json_encode($e->response->json)));
}

return $gatewayResponse;
}

/**
* {@inheritdoc}
*
* @throws \UnexpectedValueException If the request method is not POST
*/
public function getResponse(
public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
Expand Down
25 changes: 13 additions & 12 deletions Gateway/AtosSipsBinPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ public function __construct(
* Build notification response parameters.
*
* @method buildResponseParams
*
* @param Request $request
*
* @return array
*/
private function buildResponseParams(Request $request): array
{
$shellOptions = array(
$shellOptions = [
'pathfile' => $this->pathfile,
'message' => $request->request->get('DATA'),
);
];

$args = implode(' ', array_map(
function ($k, $v) { return sprintf('%s=%s', $k, $v); },
Expand Down Expand Up @@ -129,11 +125,6 @@ function ($k, $v) { return sprintf('%s=%s', $k, $v); },
* Build payment gateway options.
*
* @method buildOptions
*
* @param PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
* @param Transaction $transaction
*
* @return array
*/
private function buildOptions(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Expand Down Expand Up @@ -208,12 +199,22 @@ public function buildHTMLView(
]);
}

/**
* {@inheritdoc}
*/
public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
return new GatewayResponse();
}

/**
* {@inheritdoc}
*
* @throws \UnexpectedValueException If the request method is not POST
*/
public function getResponse(
public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
Expand Down
28 changes: 12 additions & 16 deletions Gateway/AtosSipsJsonPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function __construct(
* Get Atos Sips Json server url.
*
* @method getServerUrl
*
* @return string
*/
protected function getServerUrl(): string
{
Expand All @@ -46,11 +44,6 @@ protected function getServerUrl(): string
* Build payment gateway options.
*
* @method buildOptions
*
* @param PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
* @param Transaction $transaction
*
* @return array
*/
private function buildOptions(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Expand All @@ -75,11 +68,6 @@ private function buildOptions(
* Build payment gateway signature hash.
*
* @method buildSeal
*
* @param array $options
* @param string $secretKey
*
* @return string
*/
private function buildSeal(array $options, string $secretKey): string
{
Expand Down Expand Up @@ -120,9 +108,7 @@ public function initialize(
}

if ('00' != $returnParams['redirectionStatusCode']) {
throw new UnexpectedAtosSipsResponseCodeException(
AtosSipsStatusCode::getStatusMessage($returnParams['redirectionStatusCode'])
);
throw new UnexpectedAtosSipsResponseCodeException(AtosSipsStatusCode::getStatusMessage($returnParams['redirectionStatusCode']));
}

return $returnParams;
Expand All @@ -142,12 +128,22 @@ public function buildHTMLView(
]);
}

/**
* {@inheritdoc}
*/
public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
return new GatewayResponse();
}

/**
* {@inheritdoc}
*
* @throws \UnexpectedValueException If the request method is not POST
*/
public function getResponse(
public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
Expand Down
23 changes: 11 additions & 12 deletions Gateway/AtosSipsPostPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public function __construct(
* Get Atos Sips POST server url.
*
* @method getServerUrl
*
* @return string
*/
private function getServerUrl(): string
{
Expand All @@ -44,11 +42,6 @@ private function getServerUrl(): string
* Build payment gateway options.
*
* @method buildOptions
*
* @param PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
* @param Transaction $transaction
*
* @return array
*/
private function buildOptions(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Expand All @@ -71,10 +64,6 @@ private function buildOptions(
* Build payment gateway signature hash.
*
* @method buildSeal
*
* @param array $options
*
* @return string
*/
private function buildSeal(array $options): string
{
Expand Down Expand Up @@ -126,12 +115,22 @@ public function buildHTMLView(
]);
}

/**
* {@inheritdoc}
*/
public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
return new GatewayResponse();
}

/**
* {@inheritdoc}
*
* @throws \UnexpectedValueException If the request method is not POST
*/
public function getResponse(
public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
Expand Down
37 changes: 12 additions & 25 deletions Gateway/EurekaPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ public function __construct(
*
* @method buildOptions
*
* @param PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
* @param Transaction $transaction
*
* @return array
*
* @throws \UnexpectedValueException If required transaction metadata is not set
*/
private function buildOptions(
Expand All @@ -50,9 +45,7 @@ private function buildOptions(
): array {
foreach ($this->getRequiredTransactionMetadata() as $requiredTransactionMetadata) {
if (!$transaction->hasMetadata($requiredTransactionMetadata)) {
throw new \UnexpectedValueException(
sprintf('The transaction metadata "%s" must be set', $requiredTransactionMetadata)
);
throw new \UnexpectedValueException(sprintf('The transaction metadata "%s" must be set', $requiredTransactionMetadata));
}
}

Expand Down Expand Up @@ -83,11 +76,6 @@ private function buildOptions(
* Request payment gateway request token.
*
* @method requestScoringToken
*
* @param PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
* @param Transaction $transaction
*
* @return string
*/
private function requestScoringToken(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Expand Down Expand Up @@ -218,11 +206,6 @@ private function requestScoringToken(
* Build payment gateway HMAC signature according to its type (IN|OUT).
*
* @method buildHmac
*
* @param array $options
* @param string $hmacType
*
* @return string
*/
private function buildHmac(array $options, string $hmacType): string
{
Expand Down Expand Up @@ -278,12 +261,22 @@ public function buildHTMLView(
]);
}

/**
* {@inheritdoc}
*/
public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
return new GatewayResponse();
}

/**
* {@inheritdoc}
*
* @throws \UnexpectedValueException If the request method is not POST
*/
public function getResponse(
public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
Expand Down Expand Up @@ -353,10 +346,6 @@ public static function getParameterNames(): ?array
* Get the HMAC build parameters names according to its type (IN|OUT).
*
* @method getHmacBuildParameters
*
* @param string $hmacType
*
* @return array
*/
private function getHmacBuildParameters(string $hmacType): array
{
Expand Down Expand Up @@ -414,8 +403,6 @@ private function getHmacBuildParameters(string $hmacType): array
* Get required transaction metadata names.
*
* @method getRequiredTransactionMetadata
*
* @return array
*/
private function getRequiredTransactionMetadata(): array
{
Expand Down
19 changes: 11 additions & 8 deletions Gateway/MoneticoPaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class MoneticoPaymentGateway extends AbstractPaymentGateway
* Get Monetico server url.
*
* @method getServerUrl
*
* @return string
*/
private function getServerUrl(): string
{
Expand All @@ -25,11 +23,6 @@ private function getServerUrl(): string
* Build payment gateway options.
*
* @method buildOptions
*
* @param PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
* @param Transaction $transaction
*
* @return array
*/
private function buildOptions(
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration,
Expand Down Expand Up @@ -122,7 +115,17 @@ public function buildHTMLView(
/**
* {@inheritdoc}
*/
public function getResponse(
public function getReturnResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
return new GatewayResponse();
}

/**
* {@inheritdoc}
*/
public function getCallbackResponse(
Request $request,
PaymentGatewayConfigurationInterface $paymentGatewayConfiguration
): GatewayResponse {
Expand Down
Loading

0 comments on commit 834aa3a

Please sign in to comment.