Skip to content

Commit

Permalink
Added test for refund/info
Browse files Browse the repository at this point in the history
  • Loading branch information
andypieters committed Oct 18, 2018
1 parent 2e10079 commit bf8b879
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 14 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
nbproject/*
samples/config.php
.idea/*
vendor/
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "paynl/sdk",
"require": {
"php-curl-class/php-curl-class": "^8.3"
"php-curl-class/php-curl-class": "^8.3",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
10 changes: 10 additions & 0 deletions samples/refund/get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
require_once '../../vendor/autoload.php';
require_once '../config.php';

try {
$refund = \Paynl\Refund::get('RF-1234-5678-1234');
echo json_encode($refund->getData(), JSON_PRETTY_PRINT);
} catch (\Paynl\Error\Error $e) {
echo $e->getMessage();
}
4 changes: 3 additions & 1 deletion src/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace Paynl;

use Paynl\Error\Error;
use Paynl\Result\Refund as Result;

use Paynl\Api\Refund as Api;
Expand All @@ -35,7 +36,7 @@ class Refund
*
* @param array $options
* @return Result\Add
* @throws Error\Error
* @throws Error
*/
public static function add(array $options = array())
{
Expand Down Expand Up @@ -101,6 +102,7 @@ public static function add(array $options = array())
* @param string $refundId
*
* @return Result\Refund
* @throws Error
*/
public static function get($refundId)
{
Expand Down
11 changes: 10 additions & 1 deletion src/Result/Refund/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

namespace Paynl\Result\Refund;

use Paynl\Error\Error;
use Paynl\Result\Result;

/**
Expand All @@ -35,4 +34,14 @@ public function getId()
{
return $this->data['refundId'];
}

public function isRefunded()
{
return $this->data['refund']['statusName'] == 'Verwerkt';
}

public function getRefund()
{
return $this->data['refund'];
}
}
10 changes: 0 additions & 10 deletions src/Result/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,11 @@ public function __construct($data)
$this->data = $data;
}

public function isRefunded()
{
return $this->data['refund']['statusName'] == 'Verwerkt';
}

public function getRequest()
{
return $this->data['request'];
}

public function getRefund()
{
return $this->data['refund'];
}

/**
* Get the complete result as an array
* @return array
Expand Down
16 changes: 16 additions & 0 deletions tests/RefundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ private function setDummyData($name)
\Paynl\Config::setCurl($curl);
}

/**
* @return \Paynl\Result\Refund\Add
*/
private function refundAddFull()
{
return \Paynl\Refund::add(array(
Expand Down Expand Up @@ -64,4 +67,17 @@ public function testRefundAdd()
$this->assertInstanceOf('\Paynl\Result\Refund\Add', $result);
$this->assertStringStartsWith('RF-', $result->getRefundId());
}

public function testRefundGet(){
$this->setDummyData('info');

\Paynl\Config::setApiToken('123456789012345678901234567890');

$result = \Paynl\Refund::get('RF-1234-1234-1234');

$this->assertInstanceOf('\Paynl\Result\Refund\Refund', $result);
$this->assertTrue($result->isRefunded());
$this->assertInternalType('array', $result->getRefund());
$this->assertStringStartsWith('RF-', $result->getId());
}
}
19 changes: 19 additions & 0 deletions tests/dummyData/Refund/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"request": {
"result": "1",
"errorId": "",
"errorMessage": ""
},
"refund": {
"paymentSessionId": "915930241",
"amount": "2",
"description": "EX-1234-4567-0000",
"bankaccountHolder": "F. Lastname",
"bankaccountNumber": "NL12RABO0123456789",
"bankaccountBic": "RABONL2U",
"statusCode": "316",
"statusName": "Verwerkt",
"processedDate": "2018-01-22"
},
"refundId": "RF-1234-4567-1234"
}

0 comments on commit bf8b879

Please sign in to comment.