-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from paynl/UnitTests
More Unit tests
- Loading branch information
Showing
13 changed files
with
302 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ | |
'initials' => 'T', | ||
'lastName' => 'Test', | ||
'gender' => 'M', | ||
'dob' => '14-05-1999', | ||
'birthDate' => '14-05-1999', | ||
'phoneNumber' => '0612345678', | ||
'emailAddress' => '[email protected]', | ||
), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
<?php | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: andy | ||
* Date: 20-4-2016 | ||
* Time: 14:06 | ||
*/ | ||
class TransactionTest extends PHPUnit_Framework_TestCase | ||
{ | ||
private $testApiResult; | ||
|
||
private function setDummyData($name) | ||
{ | ||
$this->testApiResult = file_get_contents(dirname(__FILE__) . '/dummyData/Transaction/' . $name . '.json'); | ||
$curl = new \Paynl\Curl\Dummy(); | ||
$curl->setResult($this->testApiResult); | ||
\Paynl\Config::setCurl($curl); | ||
} | ||
|
||
/** | ||
* Start a transaction with all options | ||
* | ||
* @return \Paynl\Result\Transaction\Start | ||
*/ | ||
private function startTransactionFull() | ||
{ | ||
$this->setDummyData('startOk'); | ||
$result = \Paynl\Transaction::start(array( | ||
// required | ||
'amount' => 10, | ||
'returnUrl' => '/return.php', | ||
|
||
// optional | ||
'exchangeUrl' => '/exchange.php', | ||
'paymentMethod' => 10, | ||
'currency' => 'EUR', | ||
'expireDate' => 'tomorrow', | ||
'bank' => 1, | ||
'description' => '123456', | ||
'testmode' => 1, | ||
'extra1' => 'ext1', | ||
'extra2' => 'ext2', | ||
'extra3' => 'ext3', | ||
'ipaddress' => '123.123.123.123', | ||
'invoiceDate' => 'now', | ||
'deliveryDate' => 'tomorrow', // in case of tickets for an event, use the event date here | ||
'products' => array( | ||
array( | ||
'id' => 1, | ||
'name' => 'een product', | ||
'price' => 5, | ||
'tax' => 0.87, | ||
'qty' => 1, | ||
), | ||
array( | ||
'id' => 2, | ||
'name' => 'ander product', | ||
'price' => 5, | ||
'tax' => 0.87, | ||
'qty' => 1, | ||
) | ||
), | ||
'language' => 'EN', | ||
'enduser' => array( | ||
'initials' => 'T', | ||
'lastName' => 'Test', | ||
'gender' => 'M', | ||
'birthDate' => '14-05-1999', | ||
'phoneNumber' => '0612345678', | ||
'emailAddress' => '[email protected]', | ||
), | ||
'address' => array( | ||
'streetName' => 'Test', | ||
'houseNumber' => '10', | ||
'zipCode' => '1234AB', | ||
'city' => 'Test', | ||
'country' => 'NL', | ||
), | ||
'invoiceAddress' => array( | ||
'initials' => 'IT', | ||
'lastName' => 'ITEST', | ||
'streetName' => 'Istreet', | ||
'houseNumber' => '70', | ||
'zipCode' => '5678CD', | ||
'city' => 'ITest', | ||
'country' => 'NL', | ||
), | ||
)); | ||
return $result; | ||
} | ||
|
||
public function testStartNoToken() | ||
{ | ||
$this->setExpectedException('\Paynl\Error\Required\ApiToken'); | ||
|
||
\Paynl\Config::setApiToken(''); | ||
\Paynl\Config::setServiceId('SL-1234-5678'); | ||
|
||
$this->startTransactionFull(); | ||
} | ||
|
||
public function testStartNoServiceId() | ||
{ | ||
$this->setExpectedException('\Paynl\Error\Required\ServiceId'); | ||
|
||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
\Paynl\Config::setServiceId(''); | ||
|
||
$this->startTransactionFull(); | ||
} | ||
|
||
public function testStartNoAmount() | ||
{ | ||
$this->setExpectedException('\Paynl\Error\Required'); | ||
$this->setDummyData('startOk'); | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
\Paynl\Config::setServiceId('SL-1234-5678'); | ||
|
||
\Paynl\Transaction::start(array( | ||
'returnUrl' => '/return.php', | ||
'ipaddress' => '127.0.0.1', | ||
)); | ||
} | ||
|
||
public function testStartNoReturn() | ||
{ | ||
$this->setExpectedException('\Paynl\Error\Required'); | ||
$this->setDummyData('startOk'); | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
\Paynl\Config::setServiceId('SL-1234-5678'); | ||
|
||
\Paynl\Transaction::start(array( | ||
'amount' => 10, | ||
'ipaddress' => '127.0.0.1', | ||
)); | ||
} | ||
|
||
public function testStartMinumumOk() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
\Paynl\Config::setServiceId('SL-1234-5678'); | ||
|
||
$this->setDummyData('startOk'); | ||
$result = \Paynl\Transaction::start(array( | ||
'amount' => 10, | ||
'returnUrl' => '/return.php', | ||
'ipaddress' => '127.0.0.1', | ||
)); | ||
|
||
$this->validateStartResult($result); | ||
} | ||
|
||
private function validateStartResult($result) | ||
{ | ||
$this->assertInstanceOf('\Paynl\Result\Transaction\Start', $result); | ||
|
||
/** | ||
* @var $result \Paynl\Result\Transaction\Start | ||
*/ | ||
|
||
$this->assertNotEmpty($result->getTransactionId(), 'Could not get the transactionId'); | ||
$this->assertNotEmpty($result->getPaymentReference(), 'Could not get the PaymentReference'); | ||
$this->assertNotEmpty($result->getRedirectUrl(), 'Could not get the redirectUrl'); | ||
} | ||
|
||
public function testStartFullOk() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
\Paynl\Config::setServiceId('SL-1234-5678'); | ||
|
||
$result = $this->startTransactionFull(); | ||
|
||
$this->validateStartResult($result); | ||
} | ||
|
||
public function testGetTransactionPaid() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
|
||
$this->setDummyData('Result/transactionPaid'); | ||
|
||
$transaction = Paynl\Transaction::get('645958819Xdd3ea1'); | ||
|
||
$this->assertInstanceOf('\Paynl\Result\Transaction\Transaction', $transaction); | ||
|
||
} | ||
|
||
public function testGetForReturn() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
|
||
$this->setDummyData('Result/transactionPaid'); | ||
|
||
$_GET['orderId'] = "645958819Xdd3ea1"; | ||
|
||
$transaction = Paynl\Transaction::getForReturn(); | ||
$this->assertInstanceOf('\Paynl\Result\Transaction\Transaction', $transaction); | ||
} | ||
|
||
public function testGetForExchange() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
|
||
$this->setDummyData('Result/transactionPaid'); | ||
|
||
$_GET['order_id'] = "645958819Xdd3ea1"; | ||
|
||
$transaction = Paynl\Transaction::getForExchange(); | ||
$this->assertInstanceOf('\Paynl\Result\Transaction\Transaction', $transaction); | ||
} | ||
|
||
public function testGetForExchangePost() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
|
||
$this->setDummyData('Result/transactionPaid'); | ||
|
||
unset($_GET['order_id']); | ||
|
||
$_POST['order_id'] = "645958819Xdd3ea1"; | ||
|
||
$transaction = Paynl\Transaction::getForExchange(); | ||
$this->assertInstanceOf('\Paynl\Result\Transaction\Transaction', $transaction); | ||
} | ||
|
||
public function testRefund() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
|
||
$this->setDummyData('Result/refund'); | ||
$refund = \Paynl\Transaction::refund('645958819Xdd3ea1', 5); | ||
|
||
$this->assertInstanceOf('Paynl\Result\Transaction\Refund', $refund); | ||
} | ||
|
||
public function testRefundError() | ||
{ | ||
\Paynl\Config::setApiToken('123456789012345678901234567890'); | ||
|
||
$this->setExpectedException('\Paynl\Error\Api'); | ||
|
||
$this->setDummyData('Result/refundError'); | ||
\Paynl\Transaction::refund('645958819Xdd3ea1', 5, 'Description'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* Created by PhpStorm. | ||
* User: andy | ||
* Date: 26-4-16 | ||
* Time: 19:30 | ||
*/ | ||
class ValidateTest extends PHPUnit_Framework_TestCase | ||
{ | ||
private $testApiResult; | ||
|
||
private function setDummyData($name){ | ||
$this->testApiResult = file_get_contents(dirname(__FILE__).'/dummyData/Validate/'.$name.'.json'); | ||
$curl = new \Paynl\Curl\Dummy(); | ||
$curl->setResult($this->testApiResult); | ||
\Paynl\Config::setCurl($curl); | ||
} | ||
|
||
public function testIsPayServerIpYes(){ | ||
$this->setDummyData('isPayServerIpYes'); | ||
$result = \Paynl\Validate::isPayServerIp('37.46.137.137'); | ||
|
||
$this->assertEquals(true, $result); | ||
} | ||
public function testIsPayServerIpNo(){ | ||
$this->setDummyData('isPayServerIpNo'); | ||
|
||
$result = \Paynl\Validate::isPayServerIp('192.168.20.1'); | ||
|
||
$this->assertEquals(false, $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"request":{"result":"1"},"refundId":"RF-1234-1234"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"request":{"result":"0","errorId":"1","errorMessage":"You do not have enough credit to refund this amount."},"refundId":""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"request":{"result":"1","errorId":"","errorMessage":""},"connection":{"trust":"10","country":"NL","city":"Zwolle","locationLat":"52.505798339844","locationLon":"6.0858001708984","browserData":"","ipAddress":"213.126.82.230","countryName":"Netherlands","blacklist":"0","host":"D57E52E6.static.ziggozakelijk.nl","orderIpAddress":"213.126.82.230","orderReturnURL":"http:\/\/c80fde59.ngrok.io\/pay_payment\/order\/return\/","merchantCode":"M-3421-2120","merchantName":"Classic Carparts"},"enduser":{"gender":"0","emailAddress":"[email protected]","initials":"A","lastName":"Pieters","phoneNumber":"0612345678","address":{"streetName":"Kopersteden","streetNumber":"10","zipCode":"7547 TK","city":"Enschede","countryCode":"NL"},"invoiceAddress":{"streetName":"Kopersteden","streetNumber":"10","zipCode":"7547 TK","city":"Enschede","countryCode":"NL","initials":"A","lastName":"Pieters","gender":""},"language":"nl","accessCode":"","dob":"","bankAccount":"","iban":"","bic":"","sendConfirmMail":"","confirmMailTemplate":""},"saleData":{"invoiceDate":"26-04-2016","deliveryDate":"27-04-2016","orderData":[{"productId":"608","description":"Tori Tank","price":"6000","quantity":"1","vatCode":"N"},{"productId":"0","description":"Verzendkosten","price":"500","quantity":"1","vatCode":"N"}]},"paymentDetails":{"amount":"6500","currenyAmount":"6500","paidAmount":"6500","paidCurrenyAmount":"6500","paidBase":"6500","paidCosts":"0","paidCostsVat":"0","paidCurrency":"EUR","paidAttemps":"1","paidDuration":"0","description":"145000011","processTime":"10","state":"100","stateName":"PAID","stateDescription":"Paid","exchange":"","storno":"0","paymentOptionId":"613","paymentOptionSubId":"0","secure":"0","secureStatus":"","identifierName":"A Pieters","identifierPublic":"","identifierHash":"","customerKey":"11f2365950119362500e06af693e380b","serviceId":"SL-6712-4510","serviceName":"Andy","serviceDescription":"Test voor andys webshops","created":"2016-04-26 15:34:03","modified":"2016-04-26 15:34:13","paymentMethodId":"4","paymentMethodName":"Transacties ","paymentMethodDescription":"Pay Per Transaction","paymentProfileName":"SandBox"},"statsDetails":{"tool":"","info":"","object":"","extra1":"145000011","extra2":"[email protected]","extra3":"","promotorId":"0","transferData":"","paymentSessionId":"645958819"},"stornoDetails":{"stornoId":"","stornoAmount":"","bankAccount":"","iban":"","bic":"","city":"","datetime":"","reason":"","emailAddress":""}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"request":{"result":"1","errorId":"","errorMessage":""},"endUser":{"blacklist":"0"},"transaction":{"transactionId":"643872862Xe19e4c","paymentURL":"https:\/\/betalen.rabobank.nl\/ideal-betaling\/landingpage?random=93ea6be3e748ed876158a6ebd5fa8ce1c3950a67f9551c990a5f6f7acd7432c3&trxid=0020001238088229","popupAllowed":"0","paymentReference":"6000 0006 4387 2862"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"result":"0"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"result":"1"} |