1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kamerk22\AmazonGiftCode; |
4
|
|
|
|
5
|
|
|
use kamerk22\AmazonGiftCode\AWS\AWS; |
6
|
|
|
use kamerk22\AmazonGiftCode\Config\Config; |
7
|
|
|
use kamerk22\AmazonGiftCode\Config\ConfigInterface; |
8
|
|
|
use kamerk22\AmazonGiftCode\Exceptions\AmazonErrors; |
9
|
|
|
|
10
|
|
|
class AmazonGiftCode |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
private $_config; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* AmazonGiftCode constructor. |
17
|
|
|
* |
18
|
|
|
* @param null $key |
|
|
|
|
19
|
|
|
* @param null $secret |
|
|
|
|
20
|
|
|
* @param null $partner |
|
|
|
|
21
|
|
|
* @param null $endpoint |
|
|
|
|
22
|
|
|
* @param null $currency |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
public function __construct($key = null, $secret = null, $partner = null, $endpoint = null, $currency = null) |
25
|
|
|
{ |
26
|
|
|
$this->_config = new Config($key, $secret, $partner, $endpoint, $currency); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return ConfigInterface |
31
|
|
|
*/ |
32
|
|
|
public function getConfig(): ConfigInterface |
33
|
|
|
{ |
34
|
|
|
return $this->_config; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Float $value |
39
|
|
|
* @param string $creationRequestId |
40
|
|
|
* @return Response\CreateResponse |
41
|
|
|
* |
42
|
|
|
* @throws AmazonErrors |
43
|
|
|
*/ |
44
|
|
|
public function buyGiftCard(Float $value, string $creationRequestId = null): Response\CreateResponse |
45
|
|
|
{ |
46
|
|
|
return (new AWS($this->_config))->getCode($value, $creationRequestId); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $creationRequestId |
52
|
|
|
* @param string $gcId |
53
|
|
|
* @return Response\CancelResponse |
54
|
|
|
*/ |
55
|
|
|
public function cancelGiftCard(string $creationRequestId, string $gcId): Response\CancelResponse |
56
|
|
|
{ |
57
|
|
|
return (new AWS($this->_config))->cancelCode($creationRequestId, $gcId); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return Response\CreateBalanceResponse |
62
|
|
|
* |
63
|
|
|
* @throws AmazonErrors |
64
|
|
|
*/ |
65
|
|
|
public function getAvailableFunds(): Response\CreateBalanceResponse |
66
|
|
|
{ |
67
|
|
|
return (new AWS($this->_config))->getBalance(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* AmazonGiftCode make own client. |
72
|
|
|
* |
73
|
|
|
* @param null $key |
|
|
|
|
74
|
|
|
* @param null $secret |
|
|
|
|
75
|
|
|
* @param null $partner |
|
|
|
|
76
|
|
|
* @param null $endpoint |
|
|
|
|
77
|
|
|
* @param null $currency |
|
|
|
|
78
|
|
|
* @return AmazonGiftCode |
79
|
|
|
*/ |
80
|
|
|
public static function make($key = null, $secret = null, $partner = null, $endpoint = null, $currency = null): AmazonGiftCode |
81
|
|
|
{ |
82
|
|
|
return new static($key, $secret, $partner, $endpoint, $currency); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|