diff --git a/samples/transaction/start.php b/samples/transaction/start.php index 426c0c9f..738b92ae 100644 --- a/samples/transaction/start.php +++ b/samples/transaction/start.php @@ -60,7 +60,7 @@ 'initials' => 'T', 'lastName' => 'Test', 'gender' => 'M', - 'dob' => '14-05-1999', + 'birthDate' => '14-05-1999', 'phoneNumber' => '0612345678', 'emailAddress' => 'test@test.nl', ), diff --git a/src/Curl/Dummy.php b/src/Curl/Dummy.php old mode 100644 new mode 100755 index 5d57b25a..be3d26f8 --- a/src/Curl/Dummy.php +++ b/src/Curl/Dummy.php @@ -6,18 +6,11 @@ class Dummy private $_result; public $error; - - /** - * Set the result, this will be returned when post - * - * @param $result - */ - public function __construct($result) - { + + public function setResult($result){ $this->_result = $result; } - //dummy function to prevent errors public function __call($name, $arguments) { diff --git a/src/Refund.php b/src/Refund.php index eedb041a..1825cbc3 100644 --- a/src/Refund.php +++ b/src/Refund.php @@ -34,7 +34,7 @@ class Refund * Start a new transaction * * @param array|null $options - * @return Result\Start + * @return Result\Add * @throws Error\Error */ public static function add($options = array()) @@ -89,6 +89,9 @@ public static function add($options = array()) $api->setCurrency($options['currency']); } if (isset($options['processDate'])) { + if(is_string($options['processDate'])){ + $options['processDate'] = new \DateTime($options['processDate']); + } $api->setProcessDate($options['processDate']); } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 21f4b8ce..e0a73cd9 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -44,7 +44,11 @@ public function testGetCurlDefault(){ $this->assertInstanceOf('\Curl\Curl', \Paynl\Config::getCurl()); } public function testGetCurlCustom(){ - \Paynl\Config::setCurl(new DateTime()); - $this->assertInstanceOf('\DateTime', \Paynl\Config::getCurl()); + \Paynl\Config::setCurl(new \Paynl\Curl\Dummy()); + $this->assertInstanceOf('\Paynl\Curl\Dummy', \Paynl\Config::getCurl()); + } + public function testGetCurlCustomString(){ + \Paynl\Config::setCurl('\Paynl\Curl\Dummy'); + $this->assertInstanceOf('\Paynl\Curl\Dummy', \Paynl\Config::getCurl()); } } diff --git a/tests/PaymentmethodsTest.php b/tests/PaymentmethodsTest.php index 3817bcb1..88e52824 100644 --- a/tests/PaymentmethodsTest.php +++ b/tests/PaymentmethodsTest.php @@ -13,7 +13,10 @@ class PaymentmethodsTest extends PHPUnit_Framework_TestCase private function setDummyData(){ $this->testApiResult = file_get_contents(dirname(__FILE__).'/dummyData/getService.json'); - \Paynl\Config::setCurl(new \Paynl\Curl\Dummy($this->testApiResult)); + + $curl = new \Paynl\Curl\Dummy(); + $curl->setResult($this->testApiResult); + \Paynl\Config::setCurl($curl); } public function testGetPaymentMethodsNoServiceId(){ diff --git a/tests/TransactionTest.php b/tests/TransactionTest.php new file mode 100755 index 00000000..a229c231 --- /dev/null +++ b/tests/TransactionTest.php @@ -0,0 +1,246 @@ +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' => 'test@test.nl', + ), + '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'); + } +} diff --git a/tests/ValidateTest.php b/tests/ValidateTest.php new file mode 100644 index 00000000..5066a785 --- /dev/null +++ b/tests/ValidateTest.php @@ -0,0 +1,33 @@ +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); + } +} \ No newline at end of file diff --git a/tests/dummyData/Transaction/Result/refund.json b/tests/dummyData/Transaction/Result/refund.json new file mode 100644 index 00000000..509b5ea9 --- /dev/null +++ b/tests/dummyData/Transaction/Result/refund.json @@ -0,0 +1 @@ +{"request":{"result":"1"},"refundId":"RF-1234-1234"} \ No newline at end of file diff --git a/tests/dummyData/Transaction/Result/refundError.json b/tests/dummyData/Transaction/Result/refundError.json new file mode 100644 index 00000000..a59da458 --- /dev/null +++ b/tests/dummyData/Transaction/Result/refundError.json @@ -0,0 +1 @@ +{"request":{"result":"0","errorId":"1","errorMessage":"You do not have enough credit to refund this amount."},"refundId":""} \ No newline at end of file diff --git a/tests/dummyData/Transaction/Result/transactionPaid.json b/tests/dummyData/Transaction/Result/transactionPaid.json new file mode 100644 index 00000000..72fd6380 --- /dev/null +++ b/tests/dummyData/Transaction/Result/transactionPaid.json @@ -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":"andy@pay.nl","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":"andy@pay.nl","extra3":"","promotorId":"0","transferData":"","paymentSessionId":"645958819"},"stornoDetails":{"stornoId":"","stornoAmount":"","bankAccount":"","iban":"","bic":"","city":"","datetime":"","reason":"","emailAddress":""}} \ No newline at end of file diff --git a/tests/dummyData/Transaction/startOk.json b/tests/dummyData/Transaction/startOk.json new file mode 100755 index 00000000..3288d9fa --- /dev/null +++ b/tests/dummyData/Transaction/startOk.json @@ -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"}} \ No newline at end of file diff --git a/tests/dummyData/Validate/isPayServerIpNo.json b/tests/dummyData/Validate/isPayServerIpNo.json new file mode 100644 index 00000000..1eca8ddd --- /dev/null +++ b/tests/dummyData/Validate/isPayServerIpNo.json @@ -0,0 +1 @@ +{"result":"0"} \ No newline at end of file diff --git a/tests/dummyData/Validate/isPayServerIpYes.json b/tests/dummyData/Validate/isPayServerIpYes.json new file mode 100644 index 00000000..94393caa --- /dev/null +++ b/tests/dummyData/Validate/isPayServerIpYes.json @@ -0,0 +1 @@ +{"result":"1"} \ No newline at end of file