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

Added dotpay CHK parameter support and Symfony version requirments. #3

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
4 changes: 4 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public function getConfigTreeBuilder()
->end()
->end()
->scalarNode('return_url')->defaultNull()->end()
->scalarNode('chk')
->defaultValue(false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this node is a boolean you should validate using booleanNode instead of scalarNode

->end()
->end()

->end()
->end()
->end();
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/ETSPaymentDotpayExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ 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']);
}
}
35 changes: 34 additions & 1 deletion Plugin/DotpayDirectPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ class DotpayDirectPlugin extends AbstractPlugin
*/
protected $type;

/**
* @var boolean
*/
protected $chk;


/**
* @param Router $router The router
* @param Token $token The client token
Expand All @@ -97,14 +103,15 @@ class DotpayDirectPlugin extends AbstractPlugin
* @param integer $type The type
* @param string $returnUrl The return url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the parameter to the param list

*/
public function __construct(Router $router, Token $token, String $stringTools, $url, $type, $returnUrl)
public function __construct(Router $router, Token $token, String $stringTools, $url, $type, $returnUrl, $chk = false)
{
$this->router = $router;
$this->token = $token;
$this->stringTools = $stringTools;
$this->returnUrl = $returnUrl;
$this->url = $url;
$this->type = $type;
$this->chk = $chk ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useless, you already validated by the configuration that this value is a boolean.

}

/**
Expand Down Expand Up @@ -171,11 +178,37 @@ public function createDotpayRedirectActionException(FinancialTransactionInterfac
if ($extendedData->has('lang')) {
$datas['lang'] = substr($extendedData->get('lang'), 0, 2);
}

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
*/
protected function generateChk(array $datas, $pin)
{
$key = $datas['id'].
number_format($datas['amount'], 2, '.', '').
$datas['currency'].
rawurlencode($datas['description']).
(isset($datas['control']) ? $datas['control'] : '').
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be more readable in this function please.

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'];
    }

    if (isset($datas['channel'])) {
        $key .= $datas['channel'];

        if (isset($datas['chlock'])) {
            $key .= $datas['chlock'];
        }
    }

    return md5($key);
}

$pin;

if (isset($datas['channel'])) {
$key .= $datas['channel'].
(isset($datas['chlock']) ? $datas['chlock'] : '');
}
return md5($key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a blank line before the return statement

}

/**
* This method executes an approve transaction.
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<argument>%payment.dotpay.direct.url%</argument>
<argument>%payment.dotpay.direct.type%</argument>
<argument>%payment.dotpay.direct.return_url%</argument>
<argument>%payment.dotpay.direct.chk%</argument>
<tag name="payment.plugin" />
</service>

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": ">=5.3.2",
"symfony/framework-bundle": ">=2.0,<2.2-dev",
"symfony/framework-bundle": ">=2.0,<2.4",
"jms/payment-core-bundle": "dev-master"
},
"require-dev": {
Expand All @@ -23,4 +23,4 @@
"psr-0": { "ETS\\Payment\\DotpayBundle": "" }
},
"target-dir": "ETS/Payment/DotpayBundle"
}
}