Skip to content

Commit

Permalink
Add support for Rapid versions
Browse files Browse the repository at this point in the history
  • Loading branch information
incarnate committed Apr 6, 2016
1 parent de542ce commit 5f895d8
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ php:
- 5.4
- 5.5
- 5.6
- 7
- 7.0

matrix:
fast_finish: true
include:
- php: hhvm
script: phpunit --testsuite integration

env:
- EWAY_API_VERSION=31
- EWAY_API_VERSION=40

cache:
directories:
- $HOME/.composer/cache
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes will be documented in this file

## 1.3.0

- Added support for setting a Rapid version

## 1.2.2

- Added support for a PSR-3 logger to log errors
Expand Down
19 changes: 19 additions & 0 deletions src/Rapid/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ class Client implements ClientContract
*/
private $endpoint;

/**
* The eWAY Rapid API version to be used.
*
*
* @var string
*/
private $version;

/**
* True if the Client has a valid API Key, Password and Endpoint Set.
*
Expand Down Expand Up @@ -144,6 +152,17 @@ public function setEndpoint($endpoint)
return $this;
}

/**
* @inheritdoc
*/
public function setVersion($version)
{
$this->version = $version;
$this->getHttpService()->setVersion($version);

return $this;
}

/**
* @inheritdoc
*/
Expand Down
12 changes: 11 additions & 1 deletion src/Rapid/Contract/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface Client
/**
* Rapid SDK Version.
*/
const VERSION = '1.2.3';
const VERSION = '1.3.0';

/**
* Sandbox mode.
Expand Down Expand Up @@ -135,6 +135,16 @@ public function setEndpoint($endpoint);
*/
public function setCredential($apiKey, $apiPassword);

/**
* Sets the version of Rapid API to use (e.g. 40)
* If not set, the account's default version is used.
*
* @param int $version
*
* @return $this
*/
public function setVersion($version);

/**
* Sets the PSR-3 compliant logger
*
Expand Down
10 changes: 10 additions & 0 deletions src/Rapid/Contract/HttpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,14 @@ public function setBaseUrl($baseUrl);
* @return string
*/
public function getBaseUrl();

/**
* @param int $version
*/
public function setVersion($version);

/**
* @return int
*/
public function getVersion();
}
2 changes: 2 additions & 0 deletions src/Rapid/Model/Response/CreateTransactionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @property string TransactionType The transaction type that this transaction was processed under.
* One of: Purchase, MOTO, Recurring
* @property Verification Verification
* @property string AmexECEncryptedData (v40+ only) A token used to configure AMEX Express Checkout
*/
class CreateTransactionResponse extends AbstractResponse
{
Expand All @@ -64,5 +65,6 @@ class CreateTransactionResponse extends AbstractResponse
'TransactionStatus',
'TransactionType',
'Verification',
'AmexECEncryptedData',
];
}
5 changes: 4 additions & 1 deletion src/Rapid/Model/Support/HasTransactionTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ trait HasTransactionTypeTrait
*/
public function setTransactionTypeAttribute($transactionType)
{
$this->validateEnum('Eway\Rapid\Enum\TransactionType', 'TransactionType', $transactionType);
// Handle version 40 and error response values
if (!is_int($transactionType) && $transactionType != 'Unknown') {
$this->validateEnum('Eway\Rapid\Enum\TransactionType', 'TransactionType', $transactionType);
}

return $this;
}
Expand Down
19 changes: 19 additions & 0 deletions src/Rapid/Model/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@
* @property string $InvoiceNumber
* @property string $InvoiceDescription
* @property string $TokenCustomerID
* @property string $TransactionDateTime (v40+ query response only) The date and time the transaction took
* place
* @property boolean $TransactionCaptured (v40+ query response only) True if funds were captured in the transaction.
* @property int $Source (v40+ query response only) Reserved for future use
* @property int $MaxRefund (v40+ query response only) The maximum amount that could be refunded
* from this transaction
* @property int $OriginalTransactionId (v40+ query response only) Contains the original transaction ID if
* the queried transaction is a refund
* @property string $FraudAction (v40+ query response only) The fraud action that occurred if any.
* One of NotChallenged, Allow, Review, PreAuth, Processed, Approved, Block
* @property string $CurrencyCode (v40+ query response only) The ISO 4217 numeric currency code
* (e.g. AUD = 036)
*/
class Transaction extends AbstractModel
{
Expand Down Expand Up @@ -123,6 +135,13 @@ class Transaction extends AbstractModel

'VerifyCustomerEmail',
'VerifyCustomerPhone',

// v40 fields
'TransactionDateTime',
'TransactionCaptured',
'Source',
'MaxRefund',
'OriginalTransactionId',
];

/**
Expand Down
31 changes: 31 additions & 0 deletions src/Rapid/Service/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class Http implements HttpServiceContract
*/
private $baseUrl;

/**
*
* @var int
*/
private $version;

/**
* Extra proxy "Connection Established" header text
*/
Expand Down Expand Up @@ -294,6 +300,27 @@ public function getBaseUrl()
return $this->baseUrl;
}

/**
*
* @param int $version
* @return Http
*/
public function setVersion($version)
{
$this->version = $version;

return $this;
}

/**
*
* @return int
*/
public function getVersion()
{
return $this->version;
}

/**
* @param $url
*
Expand Down Expand Up @@ -360,6 +387,10 @@ private function request($method, $uri, $data = [])
$options[CURLOPT_POSTFIELDS] = $jsonData;
}

if (isset($this->version) && is_numeric($this->version)) {
$headers[] = 'X-EWAY-APIVERSION: '.$this->version;
}

$options[CURLOPT_HTTPHEADER] = $headers;

curl_setopt_array($ch, $options);
Expand Down
13 changes: 13 additions & 0 deletions tests/AbstractClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,23 @@ protected function getApiPassword()
}
}

/**
* @return string
*/
protected function getVersion()
{
if (getenv('EWAY_API_VERSION')) {
return getenv('EWAY_API_VERSION');
} else {
return '';
}
}

protected function setup()
{
parent::setUp();
$this->client = Rapid::createClient($this->getApiKey(), $this->getApiPassword());
$this->client->setVersion($this->getVersion());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testInvokeInvalidMethod()

public function testInvokeInvalidData()
{
$response = $this->client->createTransaction(ApiMethod::DIRECT, ['bar' => 'baz']);
$response = $this->client->createTransaction(ApiMethod::DIRECT, ['TransactionType' => 'baz']);

$this->assertInstanceOf(CreateTransactionResponse::getClass(), $response);
$this->assertTrue(is_array($response->getErrors()));
Expand Down

0 comments on commit 5f895d8

Please sign in to comment.