From c37fa44a0441d8822d719a60628cf869b3f0d727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Wed, 17 Apr 2019 16:47:50 +0200 Subject: [PATCH 1/8] Add Dotpay CHk Parameter support --- Controller/CallbackController.php | 72 ++++--- DependencyInjection/Configuration.php | 16 +- .../ETSPaymentDotpayExtension.php | 4 + Plugin/DotpayDirectPlugin.php | 190 ++++++++++++++---- Resources/config/services.xml | 4 + Resources/doc/usage.rst | 12 +- 6 files changed, 233 insertions(+), 65 deletions(-) diff --git a/Controller/CallbackController.php b/Controller/CallbackController.php index 3d6fdbc..1af91c7 100644 --- a/Controller/CallbackController.php +++ b/Controller/CallbackController.php @@ -48,9 +48,11 @@ public function urlcAction(Request $request, PaymentInstruction $instruction) $client = $this->get('payment.dotpay.client.token'); $logger = $this->get('logger'); + $ppc = $this->get('payment.plugin_controller'); $transactionId = $request->request->get('t_id'); $transactionStatus = $request->request->get('t_status'); + $amount = (float) $request->get('amount'); // Check the PIN $control = md5(sprintf( @@ -70,64 +72,88 @@ 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 - $logger->info( - '[Dotpay - URLC] no pending transaction found for the payment instruction', - array( + if ($instruction->getAmount() < $instruction->getDepositedAmount()) { + $logger->error( + '[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->error( + '[Dotpay - URLC - {dotpayTransactionId}] no pending transaction found for the payment instruction, creating new one', + [ 'paymentInstructionId' => $instruction->getId(), 'dotpayTransactionId' => $transactionId, 'dotpayTransactionStatus' => $transactionStatus, - ) + ] ); - return new Response('FAIL', 500); + $payment = $ppc->createPayment($instruction->getId(), $amount); + $ppc->approveAndDeposit($payment->getId(), $amount); + $transaction = $payment->getPendingTransaction(); + + if (null === $transaction) { + $logger->err( + '[Dotpay - URLC - {dotpayTransactionId}] error while creating new transaction', + [ + 'paymentInstructionId' => $instruction->getId(), + 'dotpayTransactionId' => $transactionId, + 'dotpayTransactionStatus' => $transactionStatus, + ] + ); + + return new Response('FAIL CREATING NEW TRANSACTION', 500); + } } - $amountParts = explode(' ', $request->get('orginal_amount')); // Yes, the right parameter is 'orginal_amount' - $amount = (float) $amountParts[0]; // there is a typo error in the DotPay API - $transaction->getExtendedData()->set('t_status', $transactionStatus); $transaction->getExtendedData()->set('t_id', $transactionId); $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'); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ee69114..7e5da95 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() diff --git a/DependencyInjection/ETSPaymentDotpayExtension.php b/DependencyInjection/ETSPaymentDotpayExtension.php index 93f8825..59adc5c 100644 --- a/DependencyInjection/ETSPaymentDotpayExtension.php +++ b/DependencyInjection/ETSPaymentDotpayExtension.php @@ -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']); } } diff --git a/Plugin/DotpayDirectPlugin.php b/Plugin/DotpayDirectPlugin.php index c8ce9d2..8b17f85 100644 --- a/Plugin/DotpayDirectPlugin.php +++ b/Plugin/DotpayDirectPlugin.php @@ -51,45 +51,45 @@ class DotpayDirectPlugin extends AbstractPlugin const STATUS_REFUND = 4; const STATUS_COMPLAINT = 5; - public static $statuses = array( + public static $statuses = [ self::STATUS_CLOSED => 'Closed', self::STATUS_NEW => 'New', self::STATUS_DONE => 'Done', self::STATUS_REJECTED => 'Rejected', self::STATUS_REFUND => 'Refund', self::STATUS_COMPLAINT => 'Complaint', - ); + ]; - /** - * @var Router - */ + /** @var Router */ protected $router; - /** - * @var \ETS\Payment\DotpayBundle\Client\Token - */ + /** @var \ETS\Payment\DotpayBundle\Client\Token */ protected $token; - /** - * @var \ETS\Payment\DotpayBundle\Tools\StringNormalizer - */ + /** @var \ETS\Payment\DotpayBundle\Tools\StringNormalizer */ protected $stringTools; - /** - * @var string - */ + /** @var string */ protected $url; - /** - * @var string - */ + /** @var string */ protected $returnUrl; - /** - * @var integer - */ + /** @var integer */ protected $type; + /** @var bool */ + protected $chk; + + /** @var bool */ + protected $recipientChk; + + /** @var bool */ + protected $onlineTransfer; + + /** @var bool */ + protected $expirationTime; + /** * @param Router $router The router * @param Token $token The client token @@ -97,15 +97,33 @@ class DotpayDirectPlugin extends AbstractPlugin * @param string $url The urlc * @param int $type The type * @param string $returnUrl The return url + * @param bool $chk Using DotPay CHK parameter, by default false + * @param bool $recipientChk + * @param bool $onlineTransfer + * @param int $expirationTime */ - public function __construct(Router $router, Token $token, StringNormalizer $stringTools, $url, $type, $returnUrl) - { + public function __construct( + Router $router, + Token $token, + StringNormalizer $stringTools, + $url, + $type, + $returnUrl, + $chk = false, + $recipientChk = false, + $onlineTransfer = false, + $expirationTime = 0 + ) { $this->router = $router; $this->token = $token; $this->stringTools = $stringTools; $this->returnUrl = $returnUrl; $this->url = $url; $this->type = $type; + $this->chk = $chk; + $this->recipientChk = $recipientChk; + $this->onlineTransfer = $onlineTransfer; + $this->expirationTime = $expirationTime; } /** @@ -143,25 +161,36 @@ public function createDotpayRedirectActionException(FinancialTransactionInterfac $instruction = $transaction->getPayment()->getPaymentInstruction(); $extendedData = $transaction->getExtendedData(); - $urlc = $this->router->generate('ets_payment_dotpay_callback_urlc', array( - 'id' => $instruction->getId() - ), true); + $urlc = $this->router->generate( + 'ets_payment_dotpay_callback_urlc', + ['id' => $instruction->getId()], + true + ); - $datas = array( + $datas = [ 'id' => $this->token->getId(), - 'url' => $this->getReturnUrl($extendedData), + 'URL' => $this->getReturnUrl($extendedData), 'URLC' => $urlc, 'type' => $this->type, - + 'onlinetransfer' => $this->onlineTransfer ? 1 : 0, 'amount' => $transaction->getRequestedAmount(), 'currency' => $instruction->getCurrency(), 'description' => sprintf('Payment Instruction #%d', $instruction->getId()), - ); - - $additionalDatas = array( - 'street', 'phone', 'postcode', 'lastname', - 'firstname', 'email', 'country', 'city', 'grupykanalow', - ); + 'data_waznosci' => $this->expirationTime > 0 ? date('Y-m-d H:i:s', time() + $this->expirationTime * 60) : null, + 'data_zapadalnosci' => null, + ]; + + $additionalDatas = [ + 'street', 'phone', 'postcode', 'lastname', 'firstname', + 'email', 'country', 'city', 'grupykanalow', 'street_n1', 'street_n2', 'description', + ]; + + if ($this->recipientChk) { + $additionalDatas = array_merge($additionalDatas, [ + 'recipientAccountNumber', 'recipientCompany', 'recipientFirstName', 'recipientLastName', 'recipientAddressStreet', + 'recipientAddressBuilding', 'recipientAddressApartment', 'recipientAddressPostcode', 'recipientAddressCity', + ]); + } foreach ($additionalDatas as $value) { if ($extendedData->has($value)) { @@ -173,11 +202,104 @@ public function createDotpayRedirectActionException(FinancialTransactionInterfac $datas['lang'] = substr($extendedData->get('lang'), 0, 2); } + if ($this->recipientChk) { + $datas['recipientChk'] = $this->generateRecipientChk($datas, $this->token->getPin()); + } + + if ($this->chk) { + $datas['chk'] = $this->generateChk($datas, $this->token->getPin()); + } + $actionRequest->setAction(new VisitUrl($this->url . '?' . http_build_query($datas))); return $actionRequest; } + /** + * This method generates chk parameter user to sign request to dotpay + * + * @param array $datas + * @param string $pin + * + * @return string + */ + protected function generateChk(array $datas, $pin) + { + $key = $datas['id']; + $key .= number_format($datas['amount'], 2, '.', ''); + $key .= $datas['currency']; + $key .= rawurlencode($datas['description']); + + if (isset($datas['control'])) { + $key .= $datas['control']; + } + + $key .= $pin; + + if (isset($datas['channel'])) { + $key .= $datas['channel']; + + if (isset($datas['chlock'])) { + $key .= $datas['chlock']; + } + } + + if (isset($datas['data_waznosci'])) { + if (isset($datas['data_zapadalnosci'])) { + $key .= $datas['data_zapadalnosci']; + } + + $key .= $datas['data_waznosci']; + } + + if (isset($datas['recipientChk'])) { + $key .= $datas['recipientChk']; + } + + return md5($key); + } + + /** + * This method generates recipientChk parameter user to sign request with recipient data to dotpay + * + * @param array $datas + * @param string $pin + * + * @return string + */ + protected function generateRecipientChk(array $datas, $pin) + { + $key = $datas['id']; + $key .= number_format($datas['amount'], 2, '.', ''); + $key .= $datas['currency']; + + if (isset($datas['control'])) { + $key .= $datas['control']; + } + + $recipientFields = [ + 'recipientAccountNumber', + 'recipientCompany', + 'recipientFirstName', + 'recipientLastName', + 'recipientAddressStreet', + 'recipientAddressBuilding', + 'recipientAddressApartment', + 'recipientAddressPostcode', + 'recipientAddressCity', + ]; + + foreach ($recipientFields as $f) { + if (isset($datas[$f])) { + $key .= $datas[$f]; + } + } + + $key .= $pin; + + return hash( 'sha256', $key); + } + /** * This method executes an approve transaction. * diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 7f2b282..d1945d2 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -26,6 +26,10 @@ %payment.dotpay.direct.url% %payment.dotpay.direct.type% %payment.dotpay.direct.return_url% + %payment.dotpay.direct.chk% + %payment.dotpay.direct.recipientChk% + %payment.dotpay.direct.onlineTransfer% + %payment.dotpay.direct.expirationTime% diff --git a/Resources/doc/usage.rst b/Resources/doc/usage.rst index 0a228c7..b7ea8d4 100644 --- a/Resources/doc/usage.rst +++ b/Resources/doc/usage.rst @@ -15,12 +15,12 @@ You can configure some custom fields : { ... - $form = $this->getFormFactory()->create('jms_choose_payment_method', null, array( + $form = $this->getFormFactory()->create('jms_choose_payment_method', null, [ 'amount' => $order->getAmount(), 'currency' => 'EUR', 'default_method' => 'dotpay_direct', // Optional - 'predefined_data' => array( - 'dotpay_direct' => array( + 'predefined_data' => [ + 'dotpay_direct' => [ 'street' => 'Customer\'s address street line', // Optional 'phone' => 'Customer phone number', // Optional 'postcode' => 'Customer address postal code', // Optional @@ -33,9 +33,9 @@ You can configure some custom fields : 'return_url' => $this->router->generate('payment_complete', array( 'orderNumber' => $order->getOrderNumber(), ), true), - ), - ), - )); + ], + ], + ]); ... } From 1cc4a80f11beea7172cb97ea57c929a2df464891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Wed, 17 Apr 2019 18:09:11 +0200 Subject: [PATCH 2/8] Add test --- Tests/Plugin/DotpayDirectPluginTest.php | 382 ++++++++++++++++++++++++ 1 file changed, 382 insertions(+) diff --git a/Tests/Plugin/DotpayDirectPluginTest.php b/Tests/Plugin/DotpayDirectPluginTest.php index ea0d5f7..7f4ea84 100644 --- a/Tests/Plugin/DotpayDirectPluginTest.php +++ b/Tests/Plugin/DotpayDirectPluginTest.php @@ -32,6 +32,9 @@ */ class DotpayDirectPluginTest extends TestCase { + /** @var DotpayDirectPlugin */ + private $dotpayDirectPlugin; + public function setUp() { $this->router = $this->prophesize('Symfony\Component\Routing\Router'); @@ -268,4 +271,383 @@ public function testDepositExceptionBadStatus() $this->dotpayDirectPlugin->deposit($financialTransaction->reveal(), false); } + + /** + * @dataProvider provideDataForGenerateChk + */ + public function testGenerateChk(array $datas, $pin, $expected) + { + $chk = $this->invokeMethod($this->dotpayDirectPlugin, 'generateChk', [$datas, $pin]); + + $this->assertEquals($expected, $chk); + } + + public function provideDataForGenerateChk() + { + return [ + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + 'control' => 'my_fake_control', + 'channel' => 'my_fake_chanel', + 'chlock' => 'my_fake_chlock', + 'data_waznosci' => 'my_fake_data_waznosci', + 'data_zapadalnosci' => 'my_fake_data_zapadalnosci', + 'recipientChk' => 'my_fake_recipientChk', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_controlmy_fake_pinmy_fake_chanelmy_fake_chlockmy_fake_data_zapadalnoscimy_fake_data_waznoscimy_fake_recipientChk'), + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + 'control' => 'my_fake_control', + 'channel' => 'my_fake_chanel', + 'chlock' => 'my_fake_chlock', + 'data_waznosci' => 'my_fake_data_waznosci', + 'data_zapadalnosci' => 'my_fake_data_zapadalnosci', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_controlmy_fake_pinmy_fake_chanelmy_fake_chlockmy_fake_data_zapadalnoscimy_fake_data_waznosci'), + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + 'control' => 'my_fake_control', + 'channel' => 'my_fake_chanel', + 'chlock' => 'my_fake_chlock', + 'data_zapadalnosci' => 'my_fake_data_zapadalnosci', + 'recipientChk' => 'my_fake_recipientChk', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_controlmy_fake_pinmy_fake_chanelmy_fake_chlockmy_fake_recipientChk'), + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + 'control' => 'my_fake_control', + 'channel' => 'my_fake_chanel', + 'chlock' => 'my_fake_chlock', + 'data_waznosci' => 'my_fake_data_waznosci', + 'recipientChk' => 'my_fake_recipientChk', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_controlmy_fake_pinmy_fake_chanelmy_fake_chlockmy_fake_data_waznoscimy_fake_recipientChk'), + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + 'control' => 'my_fake_control', + 'chlock' => 'my_fake_chlock', + 'data_waznosci' => 'my_fake_data_waznosci', + 'data_zapadalnosci' => 'my_fake_data_zapadalnosci', + 'recipientChk' => 'my_fake_recipientChk', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_controlmy_fake_pinmy_fake_data_zapadalnoscimy_fake_data_waznoscimy_fake_recipientChk'), + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + 'control' => 'my_fake_control', + 'channel' => 'my_fake_chanel', + 'data_waznosci' => 'my_fake_data_waznosci', + 'data_zapadalnosci' => 'my_fake_data_zapadalnosci', + 'recipientChk' => 'my_fake_recipientChk', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_controlmy_fake_pinmy_fake_chanelmy_fake_data_zapadalnoscimy_fake_data_waznoscimy_fake_recipientChk'), + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + 'channel' => 'my_fake_chanel', + 'chlock' => 'my_fake_chlock', + 'data_waznosci' => 'my_fake_data_waznosci', + 'data_zapadalnosci' => 'my_fake_data_zapadalnosci', + 'recipientChk' => 'my_fake_recipientChk', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_pinmy_fake_chanelmy_fake_chlockmy_fake_data_zapadalnoscimy_fake_data_waznoscimy_fake_recipientChk'), + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.11111, + 'currency' => 'EUR', + 'description' => 'my_fake_description', + ], + 'my_fake_pin', + md5('my_fake_id11.11EURmy_fake_descriptionmy_fake_pin'), + ], + ]; + } + + /** + * @param array $datas + * @param $pin + * @param $expected + * + * @dataProvider provideDataForGenerateRecipientChk + */ + public function testGenerateRecipientChk(array $datas, $pin, $expected) + { + $recipientChk = $this->invokeMethod($this->dotpayDirectPlugin, 'generateRecipientChk', [$datas, $pin]); + + $this->assertEquals($expected, $recipientChk); + } + + public function provideDataForGenerateRecipientChk() + { + return [ + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientAccountNumbermy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'control' => 'my_fake_control', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_controlmy_fake_pin') + ], + [ + [ + 'id' => 'my_fake_id', + 'amount' => 11.1111, + 'currency' => 'EUR', + 'recipientAccountNumber' => 'my_fake_recipientAccountNumber', + 'recipientCompany' => 'my_fake_recipientCompany', + 'recipientFirstName' => 'my_fake_recipientFirstName', + 'recipientLastName' => 'my_fake_recipientLastName', + 'recipientAddressStreet' => 'my_fake_recipientAddressStreet', + 'recipientAddressBuilding' => 'my_fake_recipientAddressBuilding', + 'recipientAddressApartment' => 'my_fake_recipientAddressApartment', + 'recipientAddressPostcode' => 'my_fake_recipientAddressPostcode', + 'recipientAddressCity' => 'my_fake_recipientAddressCity', + ], + 'my_fake_pin', + hash('sha256', 'my_fake_id11.11EURmy_fake_recipientAccountNumbermy_fake_recipientCompanymy_fake_recipientFirstNamemy_fake_recipientLastNamemy_fake_recipientAddressStreetmy_fake_recipientAddressBuildingmy_fake_recipientAddressApartmentmy_fake_recipientAddressPostcodemy_fake_recipientAddressCitymy_fake_pin') + ], + ]; + } + + /** + * Call protected/private method of a class. + * + * @param object &$object Instantiated object that we will run method on. + * @param string $methodName Method name to call + * @param array $parameters Array of parameters to pass into method. + * + * @return mixed Method return. + */ + private function invokeMethod(&$object, $methodName, array $parameters = array()) + { + $reflection = new \ReflectionClass(get_class($object)); + $method = $reflection->getMethod($methodName); + $method->setAccessible(true); + + return $method->invokeArgs($object, $parameters); + } } From f4f0466d3032bbe1306c6e7d92b57f2d62112025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Thu, 18 Apr 2019 11:41:38 +0200 Subject: [PATCH 3/8] Fix typo --- Plugin/DotpayDirectPlugin.php | 72 ++++++++++++------------- Tests/Plugin/DotpayDirectPluginTest.php | 14 +++-- 2 files changed, 45 insertions(+), 41 deletions(-) diff --git a/Plugin/DotpayDirectPlugin.php b/Plugin/DotpayDirectPlugin.php index 8b17f85..90409a9 100644 --- a/Plugin/DotpayDirectPlugin.php +++ b/Plugin/DotpayDirectPlugin.php @@ -167,7 +167,7 @@ public function createDotpayRedirectActionException(FinancialTransactionInterfac true ); - $datas = [ + $data = [ 'id' => $this->token->getId(), 'URL' => $this->getReturnUrl($extendedData), 'URLC' => $urlc, @@ -180,37 +180,37 @@ public function createDotpayRedirectActionException(FinancialTransactionInterfac 'data_zapadalnosci' => null, ]; - $additionalDatas = [ + $additionalData = [ 'street', 'phone', 'postcode', 'lastname', 'firstname', 'email', 'country', 'city', 'grupykanalow', 'street_n1', 'street_n2', 'description', ]; if ($this->recipientChk) { - $additionalDatas = array_merge($additionalDatas, [ + $additionalData = array_merge($additionalData, [ 'recipientAccountNumber', 'recipientCompany', 'recipientFirstName', 'recipientLastName', 'recipientAddressStreet', 'recipientAddressBuilding', 'recipientAddressApartment', 'recipientAddressPostcode', 'recipientAddressCity', ]); } - foreach ($additionalDatas as $value) { + foreach ($additionalData as $value) { if ($extendedData->has($value)) { - $datas[$value] = $this->stringTools->normalize($extendedData->get($value)); + $data[$value] = $this->stringTools->normalize($extendedData->get($value)); } } if ($extendedData->has('lang')) { - $datas['lang'] = substr($extendedData->get('lang'), 0, 2); + $data['lang'] = substr($extendedData->get('lang'), 0, 2); } if ($this->recipientChk) { - $datas['recipientChk'] = $this->generateRecipientChk($datas, $this->token->getPin()); + $data['recipientChk'] = $this->generateRecipientChk($data, $this->token->getPin()); } if ($this->chk) { - $datas['chk'] = $this->generateChk($datas, $this->token->getPin()); + $data['chk'] = $this->generateChk($data, $this->token->getPin()); } - $actionRequest->setAction(new VisitUrl($this->url . '?' . http_build_query($datas))); + $actionRequest->setAction(new VisitUrl($this->url . '?' . http_build_query($data))); return $actionRequest; } @@ -218,42 +218,42 @@ public function createDotpayRedirectActionException(FinancialTransactionInterfac /** * This method generates chk parameter user to sign request to dotpay * - * @param array $datas + * @param array $data * @param string $pin * * @return string */ - protected function generateChk(array $datas, $pin) + protected function generateChk(array $data, $pin) { - $key = $datas['id']; - $key .= number_format($datas['amount'], 2, '.', ''); - $key .= $datas['currency']; - $key .= rawurlencode($datas['description']); + $key = $data['id']; + $key .= number_format($data['amount'], 2, '.', ''); + $key .= $data['currency']; + $key .= rawurlencode($data['description']); - if (isset($datas['control'])) { - $key .= $datas['control']; + if (isset($data['control'])) { + $key .= $data['control']; } $key .= $pin; - if (isset($datas['channel'])) { - $key .= $datas['channel']; + if (isset($data['channel'])) { + $key .= $data['channel']; - if (isset($datas['chlock'])) { - $key .= $datas['chlock']; + if (isset($data['chlock'])) { + $key .= $data['chlock']; } } - if (isset($datas['data_waznosci'])) { - if (isset($datas['data_zapadalnosci'])) { - $key .= $datas['data_zapadalnosci']; + if (isset($data['data_waznosci'])) { + if (isset($data['data_zapadalnosci'])) { + $key .= $data['data_zapadalnosci']; } - $key .= $datas['data_waznosci']; + $key .= $data['data_waznosci']; } - if (isset($datas['recipientChk'])) { - $key .= $datas['recipientChk']; + if (isset($data['recipientChk'])) { + $key .= $data['recipientChk']; } return md5($key); @@ -262,19 +262,19 @@ protected function generateChk(array $datas, $pin) /** * This method generates recipientChk parameter user to sign request with recipient data to dotpay * - * @param array $datas + * @param array $data * @param string $pin * * @return string */ - protected function generateRecipientChk(array $datas, $pin) + protected function generateRecipientChk(array $data, $pin) { - $key = $datas['id']; - $key .= number_format($datas['amount'], 2, '.', ''); - $key .= $datas['currency']; + $key = $data['id']; + $key .= number_format($data['amount'], 2, '.', ''); + $key .= $data['currency']; - if (isset($datas['control'])) { - $key .= $datas['control']; + if (isset($data['control'])) { + $key .= $data['control']; } $recipientFields = [ @@ -290,8 +290,8 @@ protected function generateRecipientChk(array $datas, $pin) ]; foreach ($recipientFields as $f) { - if (isset($datas[$f])) { - $key .= $datas[$f]; + if (isset($data[$f])) { + $key .= $data[$f]; } } diff --git a/Tests/Plugin/DotpayDirectPluginTest.php b/Tests/Plugin/DotpayDirectPluginTest.php index 7f4ea84..d2702a8 100644 --- a/Tests/Plugin/DotpayDirectPluginTest.php +++ b/Tests/Plugin/DotpayDirectPluginTest.php @@ -273,11 +273,15 @@ public function testDepositExceptionBadStatus() } /** + * @param array $data + * @param $pin + * @param $expected + * * @dataProvider provideDataForGenerateChk */ - public function testGenerateChk(array $datas, $pin, $expected) + public function testGenerateChk(array $data, $pin, $expected) { - $chk = $this->invokeMethod($this->dotpayDirectPlugin, 'generateChk', [$datas, $pin]); + $chk = $this->invokeMethod($this->dotpayDirectPlugin, 'generateChk', [$data, $pin]); $this->assertEquals($expected, $chk); } @@ -405,15 +409,15 @@ public function provideDataForGenerateChk() } /** - * @param array $datas + * @param array $data * @param $pin * @param $expected * * @dataProvider provideDataForGenerateRecipientChk */ - public function testGenerateRecipientChk(array $datas, $pin, $expected) + public function testGenerateRecipientChk(array $data, $pin, $expected) { - $recipientChk = $this->invokeMethod($this->dotpayDirectPlugin, 'generateRecipientChk', [$datas, $pin]); + $recipientChk = $this->invokeMethod($this->dotpayDirectPlugin, 'generateRecipientChk', [$data, $pin]); $this->assertEquals($expected, $recipientChk); } From b24e02f2f543ee4a6cb4faf46666d27656e50c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Thu, 18 Apr 2019 11:42:02 +0200 Subject: [PATCH 4/8] Fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dfd746a..5b1f5e5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ETSPaymentDotpayBundle [![Build Status](https://travis-ci.org/ETSGlobal/ETSPayme This is an extension to the CorePaymentBundle providing access to Dotpay. -Instalation: +Installation: [Resources/doc/install](https://github.com/ETSGlobal/ETSPaymentDotpayBundle/blob/master/Resources/doc/install.rst) Usage: From 23e5fedb7968de386557e042ba9b7ab1bff15f06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Thu, 18 Apr 2019 11:43:57 +0200 Subject: [PATCH 5/8] Removed create new transaction, rollback change get amount and add log --- Controller/CallbackController.php | 33 +++++++++++++------------------ 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/Controller/CallbackController.php b/Controller/CallbackController.php index 1af91c7..981a34b 100644 --- a/Controller/CallbackController.php +++ b/Controller/CallbackController.php @@ -50,9 +50,16 @@ public function urlcAction(Request $request, PaymentInstruction $instruction) $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'); - $amount = (float) $request->get('amount'); // Check the PIN $control = md5(sprintf( @@ -84,6 +91,8 @@ public function urlcAction(Request $request, PaymentInstruction $instruction) } if (null === $transaction = $instruction->getPendingTransaction()) { + // this could happen if the transaction is already validated via http redirection + if ($instruction->getAmount() < $instruction->getDepositedAmount()) { $logger->error( '[Dotpay - URLC - {dotpayTransactionId}] unable to create new transaction, all of amount has been deposited', @@ -98,32 +107,18 @@ public function urlcAction(Request $request, PaymentInstruction $instruction) } $logger->error( - '[Dotpay - URLC - {dotpayTransactionId}] no pending transaction found for the payment instruction, creating new one', + '[Dotpay - URLC - {dotpayTransactionId}] no pending transaction found for the payment instruction', [ 'paymentInstructionId' => $instruction->getId(), 'dotpayTransactionId' => $transactionId, 'dotpayTransactionStatus' => $transactionStatus, ] ); - - $payment = $ppc->createPayment($instruction->getId(), $amount); - $ppc->approveAndDeposit($payment->getId(), $amount); - $transaction = $payment->getPendingTransaction(); - - if (null === $transaction) { - $logger->err( - '[Dotpay - URLC - {dotpayTransactionId}] error while creating new transaction', - [ - 'paymentInstructionId' => $instruction->getId(), - 'dotpayTransactionId' => $transactionId, - 'dotpayTransactionStatus' => $transactionStatus, - ] - ); - - return new Response('FAIL CREATING NEW TRANSACTION', 500); - } } + $amountParts = explode(' ', $request->get('orginal_amount')); // Yes, the right parameter is 'orginal_amount' + $amount = (float) $amountParts[0]; // there is a typo error in the DotPay API + $transaction->getExtendedData()->set('t_status', $transactionStatus); $transaction->getExtendedData()->set('t_id', $transactionId); $transaction->getExtendedData()->set('amount', $amount); From 9bee883f9edba0a725d3e210884f31537a2c21f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Thu, 18 Apr 2019 11:47:14 +0200 Subject: [PATCH 6/8] Add return and indent --- Controller/CallbackController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Controller/CallbackController.php b/Controller/CallbackController.php index 981a34b..c38229e 100644 --- a/Controller/CallbackController.php +++ b/Controller/CallbackController.php @@ -114,10 +114,12 @@ public function urlcAction(Request $request, PaymentInstruction $instruction) 'dotpayTransactionStatus' => $transactionStatus, ] ); + + return new Response('FAIL', 500); } $amountParts = explode(' ', $request->get('orginal_amount')); // Yes, the right parameter is 'orginal_amount' - $amount = (float) $amountParts[0]; // there is a typo error in the DotPay API + $amount = (float) $amountParts[0]; // there is a typo error in the DotPay API $transaction->getExtendedData()->set('t_status', $transactionStatus); $transaction->getExtendedData()->set('t_id', $transactionId); From d1ac9a98243146640c29ef05cba58999920ce39a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Thu, 18 Apr 2019 11:57:09 +0200 Subject: [PATCH 7/8] Fix link docs --- Resources/doc/install.rst | 2 ++ Resources/doc/usage.rst | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Resources/doc/install.rst b/Resources/doc/install.rst index 755c388..02e5a05 100644 --- a/Resources/doc/install.rst +++ b/Resources/doc/install.rst @@ -36,3 +36,5 @@ Routing //YAML routing.yml ets_payment_dotpay_bundle: resource: "@ETSPaymentDotpayBundle/Resources/config/routing.yml" + +.. _JMSPaymentCoreBundle: https://github.com/schmittjoh/JMSPaymentCoreBundle/blob/master/Resources/doc/index.rst diff --git a/Resources/doc/usage.rst b/Resources/doc/usage.rst index b7ea8d4..3e3e842 100644 --- a/Resources/doc/usage.rst +++ b/Resources/doc/usage.rst @@ -49,4 +49,4 @@ an easy way to communicate with the Dotpay API, then you can use the plugin dire $plugin = $container->get('payment.plugin.dotpay'); -.. _JMSPaymentCoreBundle: https://github.com/schmittjoh/JMSPaymentCoreBundle/blob/master/Resources/doc/index.rst + From 8f4d48d183f98cd0866a276c7dee83aa17fd03b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Gr=C3=A9vin?= Date: Thu, 18 Apr 2019 14:25:17 +0200 Subject: [PATCH 8/8] Change log error to info, fix typo --- Controller/CallbackController.php | 4 ++-- Plugin/DotpayDirectPlugin.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Controller/CallbackController.php b/Controller/CallbackController.php index c38229e..fcd8d92 100644 --- a/Controller/CallbackController.php +++ b/Controller/CallbackController.php @@ -94,7 +94,7 @@ public function urlcAction(Request $request, PaymentInstruction $instruction) // this could happen if the transaction is already validated via http redirection if ($instruction->getAmount() < $instruction->getDepositedAmount()) { - $logger->error( + $logger->info( '[Dotpay - URLC - {dotpayTransactionId}] unable to create new transaction, all of amount has been deposited', [ 'paymentInstructionId' => $instruction->getId(), @@ -106,7 +106,7 @@ public function urlcAction(Request $request, PaymentInstruction $instruction) return new Response('FAIL, TRANSACTION IS COMPLETED', 500); } - $logger->error( + $logger->info( '[Dotpay - URLC - {dotpayTransactionId}] no pending transaction found for the payment instruction', [ 'paymentInstructionId' => $instruction->getId(), diff --git a/Plugin/DotpayDirectPlugin.php b/Plugin/DotpayDirectPlugin.php index 90409a9..54a9f24 100644 --- a/Plugin/DotpayDirectPlugin.php +++ b/Plugin/DotpayDirectPlugin.php @@ -173,10 +173,10 @@ public function createDotpayRedirectActionException(FinancialTransactionInterfac 'URLC' => $urlc, 'type' => $this->type, 'onlinetransfer' => $this->onlineTransfer ? 1 : 0, - 'amount' => $transaction->getRequestedAmount(), - 'currency' => $instruction->getCurrency(), - 'description' => sprintf('Payment Instruction #%d', $instruction->getId()), - 'data_waznosci' => $this->expirationTime > 0 ? date('Y-m-d H:i:s', time() + $this->expirationTime * 60) : null, + 'amount' => $transaction->getRequestedAmount(), + 'currency' => $instruction->getCurrency(), + 'description' => sprintf('Payment Instruction #%d', $instruction->getId()), + 'data_waznosci' => $this->expirationTime > 0 ? date('Y-m-d H:i:s', time() + $this->expirationTime * 60) : null, 'data_zapadalnosci' => null, ]; @@ -297,7 +297,7 @@ protected function generateRecipientChk(array $data, $pin) $key .= $pin; - return hash( 'sha256', $key); + return hash('sha256', $key); } /**