Skip to content

Commit 96f4e3c

Browse files
Remove deprecated method; Extend testing; Add deep link method for short links
1 parent 55336c6 commit 96f4e3c

5 files changed

Lines changed: 82 additions & 32 deletions

File tree

src/MerchantApi/ShortLinks.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ public function delete($short_link_id)
7070
*/
7171
public function getLink($short_link_id, $extraData = [])
7272
{
73-
return parent::createLink(SettleApiClient::LINK_TEMPLATE_SHORT_LINK, compact('short_link_id'), $extraData);
73+
return $this->createLink(SettleApiClient::LINK_TEMPLATE_SHORT_LINK, compact('short_link_id'), $extraData);
74+
}
75+
76+
/**
77+
* @param string $short_link_id
78+
* @param array $extraData
79+
* @return string
80+
*/
81+
public function getDeepLink($short_link_id, $extraData = [])
82+
{
83+
return $this->createDeepLink($this->getLink($short_link_id, $extraData));
7484
}
7585
}

src/SettleApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final protected function call(string $method, string $path, array $data = [], $s
3636
/**
3737
* @return bool
3838
*/
39-
final protected function isSandbox()
39+
final public function isSandbox()
4040
{
4141
return $this->api_client->getIsSandbox();
4242
}

src/SettleApiClient.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace SettleApi;
44

5+
use DanielZ\ShapeValidator\ShapeException;
56
use DanielZ\ShapeValidator\ShapeValidator;
67
use DateTime;
78
use DateTimeZone;
@@ -120,8 +121,12 @@ public function setValidateShapes($validateShapes)
120121
public function call(string $method, string $path, array $data = [], $shape = [])
121122
{
122123
if ($this->validateShapes && !empty($shape)) {
123-
$validator = new ShapeValidator($shape);
124-
$validator->validate($data);
124+
try {
125+
$validator = new ShapeValidator($shape);
126+
$validator->validate($data);
127+
} catch (ShapeException $e) {
128+
throw new SettleApiException($e->getMessage(), $e->getCode(), $e, $e->getValidationErrors());
129+
}
125130
}
126131

127132
$curl_options = [
@@ -297,18 +302,6 @@ public function isValidCallback($callbackUrl, $body, $headers, $method = 'POST')
297302
return ($expected_content_digest == $content_digest) && $valid_signature;
298303
}
299304

300-
/**
301-
* @param string $template
302-
* @param array $data
303-
* @param array $extraData
304-
* @return string
305-
* @deprecated
306-
*/
307-
public function createLink($template, array $data = [], array $extraData = [])
308-
{
309-
return $this->getLink($template, $data, $extraData);
310-
}
311-
312305
/**
313306
* @param string $template
314307
* @param array $data

tests/ApiTest.php

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
);
1414
$merchant_api = new MerchantApi($api_client);
1515

16+
//test('Invalid endpoint', function() {
17+
// global $api_client;
18+
// try {
19+
// $api_client->call('GET', '/invalid', ['some' => 'data']);
20+
// expect(true)->toBeFalse(); // make sure we don't hit this line
21+
// } catch (SettleApiException $e) {
22+
// expect($e->getCode())->toBe(404);
23+
// expect($e->getMessage())->toBe("The resource could not be found.");
24+
// }
25+
//});
26+
1627
test('API: Api Keys', function() {
1728
global $merchant_api;
1829

@@ -159,6 +170,16 @@
159170
expect($outcome['status'])->toBe('fail');
160171
});
161172

173+
test('Permission Requests', function() {
174+
global $merchant_api;
175+
176+
$request = $merchant_api->permission_requests->get('e5t4uwmmxz2rygtvwcse382xt3ddv4zd');
177+
expect($request['customer'])->toBe('token:5647354929610752');
178+
179+
$request = $merchant_api->permission_requests->outcome('e5t4uwmmxz2rygtvwcse382xt3ddv4zd');
180+
expect($request['status'])->toBe('ok');
181+
});
182+
162183
test('API [not working]: Settlements', function() {
163184
global $merchant_api;
164185

@@ -206,23 +227,33 @@
206227

207228
test('API: Links', function() {
208229
global $api_client, $merchant_api;
230+
$deepLinkBase = 'https://settledemo.page.link?apn=eu.settle.app.sandbox&ibi=eu.settle.app.sandbox&isi=1453180781&ius=eu.settle.app.firebaselink&link=https%3A%2F%2Fsettle-demo%3A%2F%2Fqr%2F';
209231
$api_client->setIsSandbox(true);
232+
$requests_api = $merchant_api->payment_requests;
233+
$short_links_api = $merchant_api->short_links;
210234

211235
// Global
212-
expect($api_client->createLink('missing'))->toBe(SettleApiClient::SETTLE_LINK);
213-
expect($api_client->createLink(SettleApiClient::LINK_TEMPLATE_PAYMENT))->toBe(SettleApiClient::PAYMENT_LINK);
214-
expect($api_client->createLink(SettleApiClient::LINK_TEMPLATE_SHORT_LINK))->toBe(SettleApiClient::SHORT_LINK_LINK);
215-
216-
// Payment Requests
217-
$api = $merchant_api->payment_requests;
218-
expect($api->getLink('pcqghkrpztq1'))->toBe('http://settle.eu/p/pcqghkrpztq1/');
219-
expect($api->getLink('pcqghkrpztq1', ['a' => 'b', 'c' => 1]))->toBe('http://settle.eu/p/pcqghkrpztq1/a=b&c=1');
220-
221-
// Deep links
222-
$deepLink = 'https://settledemo.page.link?apn=eu.settle.app.sandbox&ibi=eu.settle.app.sandbox&isi=1453180781&ius=eu.settle.app.firebaselink&link=https%3A%2F%2Fsettle-demo%3A%2F%2Fqr%2Fhttp%3A%2F%2Fsettle.eu%2Fp%2Fpypz44mcswz3%2F';
223-
expect($api->getDeepLink('pypz44mcswz3'))->toBe($deepLink);
224-
expect($api_client->getDeepLink('http://settle.eu/p/pypz44mcswz3/'))->toBe($deepLink);
225-
236+
expect($api_client->getLink('missing'))->toBe(SettleApiClient::SETTLE_LINK);
237+
expect($api_client->getLink(SettleApiClient::LINK_TEMPLATE_PAYMENT))->toBe(SettleApiClient::PAYMENT_LINK);
238+
expect($api_client->getLink(SettleApiClient::LINK_TEMPLATE_SHORT_LINK))->toBe(SettleApiClient::SHORT_LINK_LINK);
239+
240+
// Payment Request Link
241+
$payment_request_link = 'http://settle.eu/p/pcqghkrpztq1/';
242+
expect($requests_api->getLink('pcqghkrpztq1'))->toBe($payment_request_link);
243+
244+
$extra_data = ['a' => 'b', 'c' => 1];
245+
expect($requests_api->getLink('pcqghkrpztq1', $extra_data))
246+
->toBe($payment_request_link . http_build_query($extra_data));
247+
248+
// Payment Request Deep link
249+
$deepLink = $deepLinkBase . urlencode($payment_request_link);
250+
expect($requests_api->getDeepLink('pcqghkrpztq1'))->toBe($deepLink);
251+
expect($api_client->getDeepLink($payment_request_link))->toBe($deepLink);
252+
253+
// Short Links
254+
$short_link = 'http://settle.eu/s/N4JEV/';
255+
expect($short_links_api->getLink('N4JEV'))->toBe($short_link);
256+
expect($short_links_api->getDeepLink('N4JEV'))->toBe($deepLinkBase . urlencode($short_link));
226257
});
227258

228259
test('API: Utility', function() {

tests/MainTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
expect(method_exists($merchant_api->api_keys, 'list'))->toBeTrue();
2020
});
2121

22+
test('Sandbox flag', function() {
23+
$api_client = new SettleApiClient('', '', '', '', true);
24+
$merchant_api = new MerchantApi($api_client);
25+
expect($merchant_api->isSandbox())->toBeTrue();
26+
27+
$api_client->setIsSandbox(false);
28+
expect($merchant_api->isSandbox())->toBeFalse();
29+
});
30+
2231
test('Callback data', function () {
2332
$api = new SettleApiClient('', '', '', '', true);
2433
try {
@@ -29,10 +38,17 @@
2938
}
3039
});
3140

32-
33-
test('Shape valiation', function () {
41+
test('Shape validation', function () {
3442
$api = new SettleApiClient('', '', '', '', true);
3543
expect($api->getValidateShapes())->toBeTrue();
3644
$api->setValidateShapes(false);
3745
expect($api->getValidateShapes())->toBeFalse();
46+
47+
$merchant_api = new MerchantApi(new SettleApiClient('', '', '', '', true));
48+
try {
49+
$merchant_api->payment_requests->create(['invalid_field' => '']);
50+
expect(true)->toBeFalse(); // make sure we don't hit this line
51+
} catch (SettleApiException $e) {
52+
expect(count($e->getValidationErrors()))->toBe(2);
53+
}
3854
});

0 commit comments

Comments
 (0)