1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PhpMob package. |
5
|
|
|
* |
6
|
|
|
* (c) Ishmael Doss <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace PhpMob\Omise\Api; |
13
|
|
|
|
14
|
|
|
use PhpMob\Omise\Api; |
15
|
|
|
use PhpMob\Omise\Domain\Card as Domain; |
16
|
|
|
use PhpMob\Omise\Domain\Customer; |
|
|
|
|
17
|
|
|
use PhpMob\Omise\Domain\Pagination; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Ishmael Doss <[email protected]> |
21
|
|
|
* |
22
|
|
|
* @see https://www.omise.co/cards-api |
23
|
|
|
*/ |
24
|
|
|
final class Card extends Api |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param string $customerId |
28
|
|
|
* @param string $cardId |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
private static function path($customerId, $cardId) |
33
|
|
|
{ |
34
|
|
|
return "/customers/$customerId/cards/$cardId"; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Customer $customer |
39
|
|
|
* @param array $parameters |
40
|
|
|
* |
41
|
|
|
* @return Pagination |
42
|
|
|
*/ |
43
|
|
|
public function all(Customer $customer, array $parameters = []) |
44
|
|
|
{ |
45
|
|
|
self::assertNotEmpty($customer->id, 'Customer Id cannot be empty.'); |
46
|
|
|
|
47
|
|
|
return $this->doRequest('GET', "/customers/$customer->id/cards", $parameters); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $customerId |
52
|
|
|
* @param string $id |
53
|
|
|
* |
54
|
|
|
* @return Domain |
55
|
|
|
*/ |
56
|
|
|
public function find($customerId, $id) |
57
|
|
|
{ |
58
|
|
|
self::assertNotEmpty($customerId && $id, 'Customer Id or Id cannot be empty.'); |
|
|
|
|
59
|
|
|
|
60
|
|
|
return $this->doRequest('GET', self::path($customerId, $id)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param Domain $card |
65
|
|
|
*/ |
66
|
|
|
public function refresh(Domain $card) |
67
|
|
|
{ |
68
|
|
|
$card->updateStore($this->find(@$card->customer->id, $card->id)->toArray()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param Domain $card |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function update(Domain $card) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
self::assertNotEmpty(@$card->customer->id && $card->id, 'CustomerId or Id cannot be empty.'); |
77
|
|
|
|
78
|
|
|
$card->updateStore( |
79
|
|
|
$this->doRequest('PATCH', self::path($card->customer->id, $card->id), $card->getUpdateData())->getData() |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param Domain $card |
85
|
|
|
*/ |
86
|
|
View Code Duplication |
public function destroy(Domain $card) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
self::assertNotEmpty(@$card->customer->id && $card->id, 'CustomerId or Id cannot be empty.'); |
89
|
|
|
|
90
|
|
|
$card->updateStore( |
91
|
|
|
$this->doRequest('DELETE', self::path($card->customer->id, $card->id), $card->getUpdateData())->toArray() |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: