Skip to content

Commit 04a1987

Browse files
committed
Add bulk list methods
1 parent 2d94c36 commit 04a1987

File tree

9 files changed

+136
-17
lines changed

9 files changed

+136
-17
lines changed

changelog.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6+
7+
## Paylike client (PHP)
8+
9+
## 1.0.1 - 2018-09-04
10+
### Added
11+
- This CHANGELOG file
12+
- Transactions and Merchants bulk list methods and test

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "paylike/php-api",
33
"description": "PHP SDK to communicate with the Paylike HTTP api",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"license": "MIT",
66
"authors": [
77
{

phpunit-d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export XDEBUG_CONFIG="idekey=phpstorm-xdebug";
2+
vendor/bin/phpunit $@
3+

phpunit.xml.dist

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="vendor/autoload.php"
13+
>
14+
<testsuites>
15+
<testsuite name="Capbasic php sdk Test Suite">
16+
<directory>./test/Capbasic/</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<filter>
21+
<whitelist>
22+
<directory suffix=".php">./lib/Capbasic/</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

src/Resource/Apps.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ public function fetch()
3737

3838
return $api_response->json['identity'];
3939
}
40+
4041
}

src/Resource/Merchants.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,22 @@ public function update($merchant_id, $args)
5454

5555
$this->paylike->client->request('PUT', $url, $args);
5656
}
57+
58+
/**
59+
* https://github.com/paylike/api-docs#fetch-all-merchants
60+
* @param int $app_id
61+
* @param int $limit
62+
* @param null $before
63+
* @return array
64+
*/
65+
public function get($app_id, $limit = 10, $before = null)
66+
{
67+
$url = 'identities/' . $app_id . '/merchants?limit=' . $limit;
68+
if ($before) {
69+
$url .= '&before=' . $before;
70+
}
71+
$api_response = $this->paylike->client->request('GET', $url);
72+
$merchants = $api_response->json;
73+
return $merchants;
74+
}
5775
}

src/Resource/Transactions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,21 @@ public function refund($transaction_id, $args)
9292

9393
return $api_response->json['transaction'];
9494
}
95+
96+
/**
97+
* @link https://github.com/paylike/api-docs#fetch-all-transactions
98+
*
99+
* @param $merchant_id
100+
* @param int $limit
101+
* @param null $before
102+
*/
103+
public function get($merchant_id, $limit = 10, $before = null){
104+
$url = 'merchants/' . $merchant_id . '/transactions?limit=' . $limit;
105+
if ($before) {
106+
$url .= '&before=' . $before;
107+
}
108+
$api_response = $this->paylike->client->request('GET', $url);
109+
$merchants = $api_response->json;
110+
return $merchants;
111+
}
95112
}

tests/MerchantsTest.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public function setUp()
2121
public function testCreate()
2222
{
2323
$merchant_id = $this->merchants->create(array(
24-
'company' => array(
24+
'company' => array(
2525
'country' => 'DK'
2626
),
27-
'currency' => 'DKK',
28-
'email' => 'john@example.com',
29-
'website' => 'https://example.com',
27+
'currency' => 'DKK',
28+
'email' => 'john@example.com',
29+
'website' => 'https://example.com',
3030
'descriptor' => 'Test Merchant Name',
31-
'test' => true,
31+
'test' => true,
3232
));
3333

3434
$this->assertNotEmpty($merchant_id, 'primary key');
@@ -44,6 +44,26 @@ public function testFetch()
4444
$this->assertEquals($merchant['id'], $merchant_id, 'primary key');
4545
}
4646

47+
public function testGetAll()
48+
{
49+
$app_id = $this->app_id;
50+
$merchants = array();
51+
$limit = 10;
52+
$before = null;
53+
54+
do {
55+
$api_merchants = $this->merchants->get($app_id, $limit, $before);
56+
if (count($api_merchants) < $limit) {
57+
$before = null;
58+
} else {
59+
$before = $api_merchants[$limit - 1]['id'];
60+
}
61+
$merchants = array_merge($merchants,$api_merchants);
62+
} while ($before);
63+
64+
$this->assertGreaterThan(0, count($merchants), 'number of merchants');
65+
}
66+
4767
public function testUpdate()
4868
{
4969
$merchant_id = $this->merchant_id;

tests/TransactionsTest.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public function setUp()
2121

2222
public function testCreate()
2323
{
24-
$merchant_id = $this->merchant_id;
24+
$merchant_id = $this->merchant_id;
2525
$transaction_id = $this->transaction_id;
2626

2727
$new_transaction_id = $this->transactions->create($merchant_id, array(
2828
'transactionId' => $transaction_id,
29-
'currency' => 'EUR',
30-
'amount' => 200,
31-
'custom' => array(
29+
'currency' => 'EUR',
30+
'amount' => 200,
31+
'custom' => array(
3232
'source' => 'php client test'
3333
)
3434
));
@@ -58,7 +58,7 @@ public function testCapture()
5858

5959
$transaction = $this->transactions->capture($new_transaction_id, array(
6060
'currency' => 'EUR',
61-
'amount' => 100
61+
'amount' => 100
6262
));
6363

6464
$this->assertEquals($transaction['capturedAmount'], 100,
@@ -79,7 +79,7 @@ public function testCaptureBiggerAmount()
7979
$new_transaction_id = $this->createNewTransactionForTest();
8080
$this->transactions->capture($new_transaction_id, array(
8181
'currency' => 'EUR',
82-
'amount' => 400
82+
'amount' => 400
8383
));
8484
}
8585

@@ -89,7 +89,7 @@ public function testRefund()
8989

9090
$this->transactions->capture($new_transaction_id, array(
9191
'currency' => 'EUR',
92-
'amount' => 200
92+
'amount' => 200
9393
));
9494

9595
$transaction = $this->transactions->refund($new_transaction_id, array(
@@ -134,18 +134,41 @@ public function testVoid()
134134
*/
135135
private function createNewTransactionForTest()
136136
{
137-
$merchant_id = $this->merchant_id;
137+
$merchant_id = $this->merchant_id;
138138
$transaction_id = $this->transaction_id;
139139

140140
$new_transaction_id = $this->transactions->create($merchant_id, array(
141141
'transactionId' => $transaction_id,
142-
'currency' => 'EUR',
143-
'amount' => 300,
144-
'custom' => array(
142+
'currency' => 'EUR',
143+
'amount' => 300,
144+
'custom' => array(
145145
'source' => 'php client test'
146146
)
147147
));
148148

149149
return $new_transaction_id;
150150
}
151+
152+
/**
153+
*
154+
*/
155+
public function testGetAllTransactions()
156+
{
157+
$merchant_id = $this->merchant_id;
158+
$transactions = array();
159+
$limit = 10;
160+
$before = null;
161+
162+
do {
163+
$api_transactions = $this->transactions->get($merchant_id, $limit, $before);
164+
if (count($api_transactions) < $limit) {
165+
$before = null;
166+
} else {
167+
$before = $api_transactions[$limit - 1]['id'];
168+
}
169+
$transactions = array_merge($transactions, $api_transactions);
170+
} while ($before);
171+
172+
$this->assertGreaterThan(0, count($transactions), 'number of transactions');
173+
}
151174
}

0 commit comments

Comments
 (0)