예제 #1
0
 /**
  * @cover Phaybox\Client::__construct()
  * @cover Phaybox\Client::getId()
  * @cover Phaybox\Client::getRang()
  * @cover Phaybox\Client::getSite()
  */
 public function testConstructorBuildsClient()
 {
     // client id and rang should be assigned
     $this->assertEquals('abc', $this->client->getId());
     $this->assertEquals('ghi', $this->client->getRang());
     // client site should be assigned
     $this->assertEquals('https://example.com', $this->client->getSite());
     // algorithm option should be equals to 'sha512'
     $this->assertEquals('sha512', $this->client->options['algorithm']);
 }
예제 #2
0
 /**
  * Create an array with the required form fields
  *
  * @param array $opts Additional optional fields to include in the generated array
  *
  * @return array
  */
 public function getFormattedParams()
 {
     // copy params var
     $params = $this->params;
     // create base array
     $fields = array('PBX_SITE' => $this->client->getSite(), 'PBX_RANG' => $this->client->getRang(), 'PBX_IDENTIFIANT' => $this->client->getId(), 'PBX_TOTAL' => $params['PBX_TOTAL'], 'PBX_DEVISE' => $params['PBX_DEVISE'], 'PBX_CMD' => $params['PBX_CMD'], 'PBX_PORTEUR' => $params['PBX_PORTEUR'], 'PBX_RETOUR' => $this->client->options['callback'], 'PBX_HASH' => strtoupper($this->client->options['algorithm']), 'PBX_TIME' => date(DATE_W3C));
     // Unset setted params
     unset($params['PBX_TOTAL'], $params['PBX_DEVISE'], $params['PBX_CMD'], $params['PBX_PORTEUR']);
     // Merge remaining params
     $fields = array_merge($fields, $params);
     // generate signature from base array
     $fields['PBX_HMAC'] = strtoupper($this->generateSignature(http_build_query($fields)));
     return $fields;
 }
예제 #3
0
 /**
  * @covers Phaybox\Transaction::generateSignature()
  * @covers Phaybox\Transaction::getFormattedParams()
  */
 public function testFormattedParams()
 {
     $formattedParams = $this->transaction->getFormattedParams();
     // PBX_ID, PBX_RANG, PBX_SITE, PBX_HASH, PBX_RETOUR should match client encapsuled data
     $this->assertEquals($this->client->getId(), $formattedParams['PBX_IDENTIFIANT']);
     $this->assertEquals($this->client->getRang(), $formattedParams['PBX_RANG']);
     $this->assertEquals($this->client->getSite(), $formattedParams['PBX_SITE']);
     $this->assertEquals(strtoupper($this->client->options['algorithm']), $formattedParams['PBX_HASH']);
     $this->assertEquals($this->client->options['callback'], $formattedParams['PBX_RETOUR']);
     // PBX_TOTAL, PBX_DEVISE, PBX_CMD, PBX_PORTEUR should match transaction params
     $this->assertEquals($this->transaction->getParam('PBX_TOTAL'), $formattedParams['PBX_TOTAL']);
     $this->assertEquals($this->transaction->getParam('PBX_DEVISE'), $formattedParams['PBX_DEVISE']);
     $this->assertEquals($this->transaction->getParam('PBX_CMD'), $formattedParams['PBX_CMD']);
     $this->assertEquals($this->transaction->getParam('PBX_PORTEUR'), $formattedParams['PBX_PORTEUR']);
     // PBX_TIME should be formatted as specified in ISO 8601
     $this->assertISO8601($formattedParams['PBX_TIME']);
     // PBX_HMAC shouldn't be an empty string
     $this->assertNotEquals('', $formattedParams['PBX_HMAC']);
 }
예제 #4
0
파일: app.php 프로젝트: keeguon/phaybox
<?php

// Autoload
// --------
$loader = (require_once __DIR__ . "/../vendor/autoload.php");
// Use libs
// --------
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);