use Symfony\Component\HttpFoundation\Request, Symfony\Component\HttpFoundation\Response, Symfony\Component\Yaml\Yaml; // Load views // ---------- require_once __DIR__ . '/views/PaymentView.php'; // Configure Paybox client // ----------------------- $payboxConfig = array_merge(array('client_id' => '', 'client_secret' => '', 'client_rang' => '', 'client_site' => '', 'client_options' => array()), Yaml::parse(__DIR__ . '/config/phaybox.yml')); $payboxClient = new Phaybox\Client($payboxConfig['client_id'], $payboxConfig['client_secret'], $payboxConfig['client_rang'], $payboxConfig['client_site'], $payboxConfig['client_options']); // Configure Silex app // ------------------- $app = new Silex\Application(); // Routes // ------ $app->get('/payment', function (Request $request) use($app, $payboxClient) { // Create Paybox transaction $payboxTransaction = $payboxClient->getTransaction(array('PBX_TOTAL' => '1000', 'PBX_DEVISE' => 978, 'PBX_CMD' => 'My order', 'PBX_PORTEUR' => '*****@*****.**', 'PBX_EFFECTUE' => 'http://phaybox.local/payment/callback', 'PBX_REFUSE' => 'http://phaybox.local/payment/callback', 'PBX_ANNULE' => 'http://phaybox.local/payment/callback')); // Get form fields $formFields = $payboxTransaction->getFormattedParams(); // Get template and instantiate view $paymentTemplate = file_get_contents(__DIR__ . '/templates/payment.mustache'); $paymentView = new PaymentView(); $paymentView->vars = $formFields; // Return response object w/ the rendered view return new Response($paymentView->render($paymentTemplate), 200); }); $app->get('/payment/callback', function (Request $request) use($app) { $payboxError = null; // Handle error $errorCode = $request->query->get('Err'); if ($errorCode !== '00000') { $payboxError = new Phaybox\Error($errorCode);
/** * Set up fixtures */ protected function setUp() { $this->client = new \Phaybox\Client('abc', 'def', 'ghi', 'https://example.com'); $this->transaction = $this->client->getTransaction(array('PBX_TOTAL' => 1000, 'PBX_DEVISE' => 978, 'PBX_CMD' => 'TEST+Paybox', 'PBX_PORTEUR' => '*****@*****.**')); }