Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dotpay CHk Parameter support #15

Merged
merged 8 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions Controller/CallbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public function urlcAction(Request $request, PaymentInstruction $instruction)

$client = $this->get('payment.dotpay.client.token');
$logger = $this->get('logger');
$ppc = $this->get('payment.plugin_controller');

$logger->info(
'[Dotpay - URLC - {dotpayTransactionId}] Callback received: {request}',
[
'paymentInstructionId' => $instruction->getId(),
'request' => $request->request->all(),
]
);

$transactionId = $request->request->get('t_id');
$transactionStatus = $request->request->get('t_status');
Expand All @@ -70,26 +79,40 @@ public function urlcAction(Request $request, PaymentInstruction $instruction)

if ($control !== $request->request->get('md5')) {
$logger->error(
'[Dotpay - URLC] pin verification failed',
array(
'[Dotpay - URLC - {dotpayTransactionId}] pin verification failed',
[
'paymentInstructionId' => $instruction->getId(),
'dotpayTransactionId' => $transactionId,
'dotpayTransactionStatus' => $transactionStatus,
)
]
);

return new Response('FAIL', 500);
return new Response('FAIL SIGNATURE', 500);
}

if (null === $transaction = $instruction->getPendingTransaction()) {
// this could happen if the transaction is already validated via http redirection

if ($instruction->getAmount() < $instruction->getDepositedAmount()) {
$logger->info(
'[Dotpay - URLC - {dotpayTransactionId}] unable to create new transaction, all of amount has been deposited',
[
'paymentInstructionId' => $instruction->getId(),
'dotpayTransactionId' => $transactionId,
'dotpayTransactionStatus' => $transactionStatus,
]
);

return new Response('FAIL, TRANSACTION IS COMPLETED', 500);
}

$logger->info(
'[Dotpay - URLC] no pending transaction found for the payment instruction',
array(
'[Dotpay - URLC - {dotpayTransactionId}] no pending transaction found for the payment instruction',
[
'paymentInstructionId' => $instruction->getId(),
'dotpayTransactionId' => $transactionId,
'dotpayTransactionStatus' => $transactionStatus,
)
]
);

return new Response('FAIL', 500);
Expand All @@ -103,31 +126,31 @@ public function urlcAction(Request $request, PaymentInstruction $instruction)
$transaction->getExtendedData()->set('amount', $amount);

try {
$this->get('payment.plugin_controller')->approveAndDeposit($transaction->getPayment()->getId(), $amount);
$ppc->approveAndDeposit($transaction->getPayment()->getId(), $amount);
} catch (\Exception $exception) {
$logger->error(
'[Dotpay - URLC] error {exceptionClass} {exceptionMessage}',
array(
'[Dotpay - URLC - {dotpayTransactionId}] error {exceptionClass} {exceptionMessage}',
[
'paymentInstructionId' => $instruction->getId(),
'dotpayTransactionId' => $transactionId,
'dotpayTransactionStatus' => $transactionStatus,
'exceptionClass' => get_class($exception),
'exceptionMessage' => $e->getMessage()
)
'exceptionMessage' => $exception->getMessage(),
]
);

return new Response('FAIL', 500);
return new Response('FAIL APPROVE AND DEPOSIT', 500);
}

$this->getDoctrine()->getManager()->flush();

$logger->info(
'[Dotpay - URLC] Payment instruction {paymentInstructionId} successfully updated',
array(
'[Dotpay - URLC - {dotpayTransactionId}] Payment instruction {paymentInstructionId} successfully updated',
[
'paymentInstructionId' => $instruction->getId(),
'dotpayTransactionId' => $transactionId,
'dotpayTransactionStatus' => $transactionStatus
)
'dotpayTransactionStatus' => $transactionStatus,
]
);

return new Response('OK');
Expand Down
16 changes: 14 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,30 @@ public function getConfigTreeBuilder()
->defaultValue('https://ssl.dotpay.pl/')
->cannotBeEmpty()
->validate()
->ifNotInArray(array('https://ssl.dotpay.pl/', 'https://ssl.dotpay.eu/'))
->ifNotInArray(['https://ssl.dotpay.pl/', 'https://ssl.dotpay.eu/'])
->thenInvalid('Invalid dotpay url "%s"')
->end()
->end()
->scalarNode('type')
->defaultValue(2)
->validate()
->ifNotInArray(array(0, 1, 2, 3))
->ifNotInArray([0, 1, 2, 3])
->thenInvalid('Invalid type "%s"')
->end()
->end()
->scalarNode('return_url')->defaultNull()->end()
->booleanNode('chk')
->defaultFalse()
->end()
->booleanNode('recipientChk')
->defaultFalse()
->end()
->booleanNode('onlineTransfer')
->defaultFalse()
->end()
->integerNode('expirationTime')
->defaultValue(0)
->end()
->end()
->end()
->end()
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/ETSPaymentDotpayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,9 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('payment.dotpay.direct.url', $config['direct']['url']);
$container->setParameter('payment.dotpay.direct.type', $config['direct']['type']);
$container->setParameter('payment.dotpay.direct.return_url', $config['direct']['return_url']);
$container->setParameter('payment.dotpay.direct.chk', $config['direct']['chk']);
$container->setParameter('payment.dotpay.direct.recipientChk', $config['direct']['recipientChk']);
$container->setParameter('payment.dotpay.direct.onlineTransfer', $config['direct']['onlineTransfer']);
$container->setParameter('payment.dotpay.direct.expirationTime', $config['direct']['expirationTime']);
}
}
Loading