Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Handle multiple paybox accounts #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ phpunit.xml
.buildpath
.project
.settings
.idea
13 changes: 11 additions & 2 deletions Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
* Class DefaultController
Expand All @@ -19,11 +20,19 @@ class DefaultController extends Controller
* Instant Payment Notification action.
* Here, presentation is anecdotal, the requesting server only looks at the http status.
*
* @param string $account
*
* @return Response
*/
public function ipnAction()
public function ipnAction($account)
{
$payboxResponse = $this->container->get('lexik_paybox.response_handler');
$service = sprintf('lexik_paybox.response_handler.%s', $account);

if (!$this->container->has($service)) {
throw new NotFoundHttpException(sprintf('Service %s not found', $service));
}

$payboxResponse = $this->container->get($service);
$result = $payboxResponse->verifySignature();

return new Response($result ? 'OK' : 'KO');
Expand Down
25 changes: 18 additions & 7 deletions Controller/SampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Generator\UrlGenerator;

/**
Expand All @@ -20,11 +21,19 @@ class SampleController extends Controller
/**
* Index action creates the form for a payment call.
*
* @param string $account
*
* @return Response
*/
public function indexAction()
public function indexAction($account)
{
$paybox = $this->get('lexik_paybox.request_handler');
$service = sprintf('lexik_paybox.request_handler.%s', $account);

if (!$this->has($service)) {
throw new NotFoundHttpException(sprintf('Service %s not found', $service));
}

$paybox = $this->get($service);
$paybox->setParameters(array(
'PBX_CMD' => 'CMD'.time(),
'PBX_DEVISE' => '978',
Expand All @@ -33,11 +42,11 @@ public function indexAction()
'PBX_TOTAL' => '1000',
'PBX_TYPEPAIEMENT' => 'CARTE',
'PBX_TYPECARTE' => 'CB',
'PBX_EFFECTUE' => $this->generateUrl('lexik_paybox_sample_return', array('status' => 'success'), UrlGenerator::ABSOLUTE_URL),
'PBX_REFUSE' => $this->generateUrl('lexik_paybox_sample_return', array('status' => 'denied'), UrlGenerator::ABSOLUTE_URL),
'PBX_ANNULE' => $this->generateUrl('lexik_paybox_sample_return', array('status' => 'canceled'), UrlGenerator::ABSOLUTE_URL),
'PBX_EFFECTUE' => $this->generateUrl('lexik_paybox_sample_return', array('account' => $account, 'status' => 'success'), UrlGenerator::ABSOLUTE_URL),
'PBX_REFUSE' => $this->generateUrl('lexik_paybox_sample_return', array('account' => $account, 'status' => 'denied'), UrlGenerator::ABSOLUTE_URL),
'PBX_ANNULE' => $this->generateUrl('lexik_paybox_sample_return', array('account' => $account, 'status' => 'canceled'), UrlGenerator::ABSOLUTE_URL),
'PBX_RUF1' => 'POST',
'PBX_REPONDRE_A' => $this->generateUrl('lexik_paybox_ipn', array('time' => time()), UrlGenerator::ABSOLUTE_URL),
'PBX_REPONDRE_A' => $this->generateUrl('lexik_paybox_ipn', array('account' => $account, 'time' => time()), UrlGenerator::ABSOLUTE_URL),
));

return $this->render(
Expand All @@ -56,13 +65,15 @@ public function indexAction()
*
* @param Request $request
* @param string $status
* @param string $account
*
* @return Response
*/
public function returnAction(Request $request, $status)
public function returnAction(Request $request, $status, $account)
{
return $this->render('LexikPayboxBundle:Sample:return.html.twig', array(
'status' => $status,
'account' => $account,
'parameters' => $request->query,
));
}
Expand Down
202 changes: 109 additions & 93 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,123 +23,139 @@ public function getConfigTreeBuilder()
$rootNode
->addDefaultsIfNotSet()
->children()
->scalarNode('public_key')->defaultValue(null)->end()
->append($this->createAccountsNode())
->end()
;

->arrayNode('parameters')
->isRequired()
->children()
->scalarNode('production')->defaultValue(false)->end()
->arrayNode('currencies')
->defaultValue(array(
'036', // AUD
'124', // CAD
'756', // CHF
'826', // GBP
'840', // USD
'978', // EUR
))
->prototype('scalar')->end()
->end()
->scalarNode('site')->isRequired()->end()
->scalarNode('rank')->defaultValue(null)->end()
->scalarNode('rang')->defaultValue(null)->end()
->scalarNode('login')->defaultValue(null)->end()
->scalarNode('cle')->defaultValue(null)->end()
->arrayNode('hmac')
->isRequired()
->children()
->scalarNode('algorithm')->defaultValue('sha512')->end()
->scalarNode('key')->isRequired()->end()
->scalarNode('signature_name')->defaultValue('Sign')->end()
return $treeBuilder;
}

private function createAccountsNode()
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('accounts');

$node
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('public_key')->defaultValue(null)->end()

->arrayNode('parameters')
->isRequired()
->children()
->scalarNode('production')->defaultValue(false)->end()
->arrayNode('currencies')
->defaultValue(array(
'036', // AUD
'124', // CAD
'756', // CHF
'826', // GBP
'840', // USD
'978', // EUR
))
->prototype('scalar')->end()
->end()
->scalarNode('site')->isRequired()->end()
->scalarNode('rank')->defaultValue(null)->end()
->scalarNode('rang')->defaultValue(null)->end()
->scalarNode('login')->defaultValue(null)->end()
->scalarNode('cle')->defaultValue(null)->end()
->arrayNode('hmac')
->isRequired()
->children()
->scalarNode('algorithm')->defaultValue('sha512')->end()
->scalarNode('key')->isRequired()->end()
->scalarNode('signature_name')->defaultValue('Sign')->end()
->end()
->end()
->end()
->end()
->end()

->arrayNode('servers')
->addDefaultsIfNotSet()
->children()
->arrayNode('servers')
->addDefaultsIfNotSet()
->children()

->arrayNode('system')
->addDefaultsIfNotSet()
->children()
->arrayNode('primary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('tpeweb.paybox.com')->end()
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
->scalarNode('test_path')->defaultValue('/load.html')->end()
->arrayNode('system')
->addDefaultsIfNotSet()
->children()
->arrayNode('primary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('tpeweb.paybox.com')->end()
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
->scalarNode('test_path')->defaultValue('/load.html')->end()
->end()
->end()
->end()
->arrayNode('secondary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('tpeweb1.paybox.com')->end()
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
->scalarNode('test_path')->defaultValue('/load.html')->end()
->arrayNode('secondary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('tpeweb1.paybox.com')->end()
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
->scalarNode('test_path')->defaultValue('/load.html')->end()
->end()
->end()
->end()
->arrayNode('preprod')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('preprod-tpeweb.paybox.com')->end()
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
->scalarNode('test_path')->defaultValue('/load.html')->end()
->arrayNode('preprod')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('preprod-tpeweb.paybox.com')->end()
->scalarNode('system_path')->defaultValue('/cgi/MYchoix_pagepaiement.cgi')->end()
->scalarNode('cancellation_path')->defaultValue('/cgi-bin/ResAbon.cgi')->end()
->scalarNode('test_path')->defaultValue('/load.html')->end()
->end()
->end()
->end()
->end()
->end()

->arrayNode('direct_plus')
->addDefaultsIfNotSet()
->children()
->arrayNode('primary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('ppps.paybox.com')->end()
->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
->arrayNode('direct_plus')
->addDefaultsIfNotSet()
->children()
->arrayNode('primary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('ppps.paybox.com')->end()
->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
->end()
->end()
->end()
->arrayNode('secondary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('ppps1.paybox.com')->end()
->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
->arrayNode('secondary')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('ppps1.paybox.com')->end()
->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
->end()
->end()
->end()
->arrayNode('preprod')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('preprod-ppps.paybox.com')->end()
->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
->arrayNode('preprod')
->addDefaultsIfNotSet()
->children()
->scalarNode('protocol')->defaultValue('https')->end()
->scalarNode('host')->defaultValue('preprod-ppps.paybox.com')->end()
->scalarNode('api_path')->defaultValue('/PPPS.php')->end()
->end()
->end()
->end()
->end()
->end()

->end()
->end()
->end()

->scalarNode('transport')
->defaultValue('Lexik\Bundle\PayboxBundle\Transport\CurlTransport')
->validate()
->ifTrue(function($v) { return !class_exists($v); })
->thenInvalid('Invalid "transport" parameter.')
->scalarNode('transport')
->defaultValue('Lexik\Bundle\PayboxBundle\Transport\CurlTransport')
->validate()
->ifTrue(function($v) { return !class_exists($v); })
->thenInvalid('Invalid "transport" parameter.')
->end()
->end()
->end()

->end()
;

return $treeBuilder;
return $node;
}
}
Loading