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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace PhpMob\Omise\Api; |
15
|
|
|
|
16
|
|
|
use PhpMob\Omise\Api; |
17
|
|
|
use PhpMob\Omise\Domain\Card as Domain; |
18
|
|
|
use PhpMob\Omise\Domain\Customer; |
|
|
|
|
19
|
|
|
use PhpMob\Omise\Domain\Pagination; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Ishmael Doss <[email protected]> |
23
|
|
|
* |
24
|
|
|
* @see https://www.omise.co/cards-api |
25
|
|
|
*/ |
26
|
|
|
final class Card extends Api |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @param string $customerId |
30
|
|
|
* @param string $cardId |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
private static function path($customerId, $cardId) |
35
|
|
|
{ |
36
|
|
|
return "/customers/$customerId/cards/$cardId"; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param Customer $customer |
41
|
|
|
* @param array $parameters |
42
|
|
|
* |
43
|
|
|
* @return Pagination |
44
|
|
|
*/ |
45
|
|
|
public function all(Customer $customer, array $parameters = []) |
46
|
|
|
{ |
47
|
|
|
self::assertNotEmpty($customer->id, 'Customer Id cannot be empty.'); |
48
|
|
|
|
49
|
|
|
return $this->doRequest('GET', "/customers/$customer->id/cards", $parameters); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $customerId |
54
|
|
|
* @param string $id |
55
|
|
|
* |
56
|
|
|
* @return Domain |
57
|
|
|
*/ |
58
|
|
|
public function find($customerId, $id) |
59
|
|
|
{ |
60
|
|
|
self::assertNotEmpty($customerId && $id, 'Customer Id or Id cannot be empty.'); |
61
|
|
|
|
62
|
|
|
return $this->doRequest('GET', self::path($customerId, $id)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param Domain $card |
67
|
|
|
*/ |
68
|
|
|
public function refresh(Domain $card) |
69
|
|
|
{ |
70
|
|
|
$card->updateStore($this->find((string) ($card->customer), $card->id)->toArray()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param Domain $card |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function update(Domain $card) |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
self::assertNotEmpty((string) ($card->customer) && $card->id, 'CustomerId or Id cannot be empty.'); |
79
|
|
|
|
80
|
|
|
$card->updateStore( |
81
|
|
|
$this->doRequest('PATCH', self::path((string) ($card->customer), $card->id), $card->getUpdateData())->getData() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param Domain $card |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function destroy(Domain $card) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
self::assertNotEmpty((string) ($card->customer) && $card->id, 'CustomerId or Id cannot be empty.'); |
91
|
|
|
|
92
|
|
|
$card->updateStore( |
93
|
|
|
$this->doRequest('DELETE', self::path((string) ($card->customer), $card->id), $card->getUpdateData())->toArray() |
94
|
|
|
); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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: