1
|
|
|
<?php |
2
|
|
|
namespace CultureKings\Afterpay\Factory; |
3
|
|
|
|
4
|
|
|
use CultureKings\Afterpay\Model\InStore\Authorization; |
5
|
|
|
use CultureKings\Afterpay\Service; |
6
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
7
|
|
|
use GuzzleHttp\Client; |
8
|
|
|
use GuzzleHttp\ClientInterface; |
9
|
|
|
use JMS\Serializer\SerializerInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class InStoreApi |
13
|
|
|
* @package CultureKings\Afterpay\Factory |
14
|
|
|
*/ |
15
|
|
|
class InStoreApi extends Api |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param Authorization $authorization |
19
|
|
|
* @param ClientInterface|null $client |
20
|
|
|
* @param SerializerInterface|null $serializer |
21
|
|
|
* |
22
|
|
|
* @return Service\InStore\Device |
23
|
|
|
*/ |
24
|
|
|
public static function device( |
25
|
|
|
Authorization $authorization, |
26
|
|
|
ClientInterface $client = null, |
27
|
|
|
SerializerInterface $serializer = null |
28
|
|
|
) { |
29
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
30
|
|
|
|
31
|
|
|
$afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]); |
32
|
|
|
$afterpaySerializer = $serializer ?: SerializerFactory::getSerializer(); |
33
|
|
|
|
34
|
|
|
return new Service\InStore\Device($authorization, $afterpayClient, $afterpaySerializer); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Authorization $authorization |
39
|
|
|
* @param Client|null $client |
40
|
|
|
* @param SerializerInterface|null $serializer |
41
|
|
|
* |
42
|
|
|
* @return Service\InStore\PreApproval |
43
|
|
|
*/ |
44
|
|
|
public static function preapproval( |
45
|
|
|
Authorization $authorization, |
46
|
|
|
Client $client = null, |
47
|
|
|
SerializerInterface $serializer = null |
48
|
|
|
) { |
49
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
50
|
|
|
|
51
|
|
|
$afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]); |
52
|
|
|
$afterpaySerializer = $serializer ?: SerializerFactory::getSerializer(); |
53
|
|
|
|
54
|
|
|
return new Service\InStore\PreApproval($authorization, $afterpayClient, $afterpaySerializer); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param Authorization $authorization |
59
|
|
|
* @param Client|null $client |
60
|
|
|
* @param SerializerInterface|null $serializer |
61
|
|
|
* |
62
|
|
|
* @return Service\InStore\Order |
63
|
|
|
*/ |
64
|
|
|
public static function order( |
65
|
|
|
Authorization $authorization, |
66
|
|
|
Client $client = null, |
67
|
|
|
SerializerInterface $serializer = null |
68
|
|
|
) { |
69
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
70
|
|
|
|
71
|
|
|
$afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]); |
72
|
|
|
$afterpaySerializer = $serializer ?: SerializerFactory::getSerializer(); |
73
|
|
|
|
74
|
|
|
return new Service\InStore\Order($authorization, $afterpayClient, $afterpaySerializer); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Authorization $authorization |
79
|
|
|
* @param Client|null $client |
80
|
|
|
* @param SerializerInterface|null $serializer |
81
|
|
|
* |
82
|
|
|
* @return Service\InStore\Refund |
83
|
|
|
*/ |
84
|
|
|
public static function refund( |
85
|
|
|
Authorization $authorization, |
86
|
|
|
Client $client = null, |
87
|
|
|
SerializerInterface $serializer = null |
88
|
|
|
) { |
89
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
90
|
|
|
|
91
|
|
|
$afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]); |
92
|
|
|
$afterpaySerializer = $serializer ?: SerializerFactory::getSerializer(); |
93
|
|
|
|
94
|
|
|
return new Service\InStore\Refund($authorization, $afterpayClient, $afterpaySerializer); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param Authorization $authorization |
99
|
|
|
* @param Client|null $client |
100
|
|
|
* @param SerializerInterface|null $serializer |
101
|
|
|
* |
102
|
|
|
* @return Service\InStore\Customer |
103
|
|
|
*/ |
104
|
|
|
public static function customer( |
105
|
|
|
Authorization $authorization, |
106
|
|
|
Client $client = null, |
107
|
|
|
SerializerInterface $serializer = null |
108
|
|
|
) { |
109
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
110
|
|
|
|
111
|
|
|
$afterpayClient = $client ?: new Client([ 'base_uri' => $authorization->getEndpoint() ]); |
112
|
|
|
$afterpaySerializer = $serializer ?: SerializerFactory::getSerializer(); |
113
|
|
|
|
114
|
|
|
return new Service\InStore\Customer($authorization, $afterpayClient, $afterpaySerializer); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $endpoint |
119
|
|
|
* @param ClientInterface|null $client |
120
|
|
|
* |
121
|
|
|
* @return Service\InStore\Ping |
122
|
|
|
*/ |
123
|
|
|
public static function ping( |
124
|
|
|
$endpoint, |
125
|
|
|
ClientInterface $client = null |
126
|
|
|
) { |
127
|
|
|
AnnotationRegistry::registerLoader('class_exists'); |
128
|
|
|
|
129
|
|
|
$afterpayClient = $client ?: new Client([ 'base_uri' => $endpoint ]); |
130
|
|
|
|
131
|
|
|
return new Service\InStore\Ping($afterpayClient); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.