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

Commit

Permalink
Merge branch 'hotfix/0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Söderlund committed May 16, 2016
2 parents 8b16a4c + 937c381 commit 4330f38
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 7 deletions.
58 changes: 58 additions & 0 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class Client extends Object
*/
const API_ENDPOINT = 'https://payment.paytrail.com';

/**
* The base URL for getting the dynamic logo.
*
* @var string LOGO_BASE_URL
*/
const LOGO_BASE_URL = 'https://img.paytrail.com/index.svm';

/**
* The Paytrail API version.
*
Expand Down Expand Up @@ -64,6 +71,27 @@ class Client extends Object
*/
private $_client;

/**
* Type of the logo, vertical or horizontal.
*
* @var string $logoType
*/
protected $logoType;

/**
* How many columns to use in the logo.
*
* @var int $logoCols
*/
protected $logoCols;

/**
* Whether to show the payment text on logo or not.
*
* @var int $logoText
*/
protected $logoText;

/**
* @var array
*/
Expand Down Expand Up @@ -235,4 +263,34 @@ public function setApiVersion($apiVersion)
}
$this->apiVersion = $apiVersion;
}

/**
* Get the URL to the dynamic Paytrail logo.
*
* @return string
*/
public function getLogoUrl()
{
$params = [
'id' => $this->_apiKey,
'type' => $this->logoType,
'cols' => (int)$this->logoCols,
'text' => (int)$this->logoText,
'auth' => $this->calculateLogoAuth(),
];

return self::LOGO_BASE_URL . '?' . http_build_query($params);
}

/**
* Calculates the auth code for use with the logo request.
*
* @return string
*/
private function calculateLogoAuth()
{
$checksum = md5($this->_apiKey . $this->_apiSecret);

return substr($checksum, 0, 16);
}
}
42 changes: 35 additions & 7 deletions tests/unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testProcessPayment()
$client = $this->makeClient();
$client->connect();
$payment = $this->makePayment();
$result = $client->processPayment($payment);
$result = $client->processPayment($payment);
$this->assertEquals(1, $result->getOrderNumber());
}

Expand All @@ -58,10 +58,10 @@ public function testValidateSuccessChecksum()
$client = $this->makeClient();
$client->connect();

$orderNumber = 1;
$timestamp = 1459256594;
$paid = '840a0b45ee';
$method = 1;
$orderNumber = 1;
$timestamp = 1459256594;
$paid = '840a0b45ee';
$method = 1;
$returnAuthCode = '33BC65BC7C48B66B3BD765A07E910BCE';

$this->assertTrue($client->validateChecksum($returnAuthCode, $orderNumber, $timestamp, $paid, $method));
Expand All @@ -75,13 +75,41 @@ public function testValidateFailureChecksum()
$client = $this->makeClient();
$client->connect();

$orderNumber = 1;
$timestamp = 1459256669;
$orderNumber = 1;
$timestamp = 1459256669;
$returnAuthCode = '076F5C44FF72EBCE892E9B32FD761597';

$this->assertTrue($client->validateChecksum($returnAuthCode, $orderNumber, $timestamp));
}

/**
* Test creating a horizontal logo.
*/
public function testHorizontalLogoUrl()
{
$client = $this->makeClient();

$client->configure(['logoText' => 1, 'logoCols' => 15, 'logoType' => 'horizontal']);
$url = $client->getLogoUrl();

$this->assertEquals(Client::LOGO_BASE_URL . '?id=13466&type=horizontal&cols=15&text=1&auth=f6483cce23771e8f',
$url);
}

/**
* Test creating a vertical logo.
*/
public function testVerticalLogoUrl()
{
$client = $this->makeClient();

$client->configure(['logoText' => 0, 'logoCols' => 2, 'logoType' => 'vertical']);
$url = $client->getLogoUrl();

$this->assertEquals(Client::LOGO_BASE_URL . '?id=13466&type=vertical&cols=2&text=0&auth=f6483cce23771e8f',
$url);
}

/**
* Test setting of API version.
*
Expand Down

0 comments on commit 4330f38

Please sign in to comment.