1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ipag\Sdk\Endpoint; |
4
|
|
|
|
5
|
|
|
use Ipag\Sdk\Core\Endpoint; |
6
|
|
|
use Ipag\Sdk\Http\Response; |
7
|
|
|
use Ipag\Sdk\Model\Subscription; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* SubscriptionEndpoint class |
11
|
|
|
* |
12
|
|
|
* Classe responsável pelo controle dos endpoints do recurso Subscription. |
13
|
|
|
*/ |
14
|
|
|
class SubscriptionEndpoint extends Endpoint |
15
|
|
|
{ |
16
|
|
|
protected string $location = '/service/resources/subscriptions'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Endpoint para criar um recurso `Subscription` |
20
|
|
|
* |
21
|
|
|
* @param Subscription $subscription |
22
|
|
|
* @return Response |
23
|
|
|
*/ |
24
|
|
|
public function create(Subscription $subscription): Response |
25
|
|
|
{ |
26
|
|
|
return $this->_POST($subscription->jsonSerialize()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Endpoint para atualizar um recurso `Subscription` |
31
|
|
|
* |
32
|
|
|
* @param Subscription $subscription |
33
|
|
|
* @param integer $id |
34
|
|
|
* @return Response |
35
|
|
|
* |
36
|
|
|
* @codeCoverageIgnore |
37
|
|
|
*/ |
38
|
|
|
public function update(Subscription $subscription, int $id): Response |
39
|
|
|
{ |
40
|
|
|
return $this->_PUT($subscription, ['id' => $id]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Endpoint para obter um recurso `Subscription` |
45
|
|
|
* |
46
|
|
|
* @param integer $id |
47
|
|
|
* @return Response |
48
|
|
|
* |
49
|
|
|
* @codeCoverageIgnore |
50
|
|
|
*/ |
51
|
|
|
public function get(int $id): Response |
52
|
|
|
{ |
53
|
|
|
return $this->_GET(['id' => $id]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Endpoint para listar recursos `Subscription` |
58
|
|
|
* |
59
|
|
|
* @param array|null $filters |
60
|
|
|
* @return Response |
61
|
|
|
* |
62
|
|
|
* @codeCoverageIgnore |
63
|
|
|
*/ |
64
|
|
|
public function list(?array $filters = []): Response |
65
|
|
|
{ |
66
|
|
|
return $this->_GET($filters ?? []); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Endpoint para Desvincular Token de um recurso `Subscription` |
71
|
|
|
* |
72
|
|
|
* @param integer $id |
73
|
|
|
* @return Response |
74
|
|
|
* |
75
|
|
|
* @codeCoverageIgnore |
76
|
|
|
*/ |
77
|
|
|
public function unlinkToken(int $id): Response |
78
|
|
|
{ |
79
|
|
|
$this->location = "/service/subscriptions/{$id}/card_token"; |
80
|
|
|
return $this->_DELETE(['id' => $id]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Disparo de ações de parcelas de um recurso `Subscription` |
85
|
|
|
* |
86
|
|
|
* @param integer $subscription_id |
87
|
|
|
* @param integer $invoice_number |
88
|
|
|
* @param string $action |
89
|
|
|
* @return Response |
90
|
|
|
* |
91
|
|
|
* @codeCoverageIgnore |
92
|
|
|
*/ |
93
|
|
|
private function _actionsInstallmentPayment(int $subscription_id, int $invoice_number, string $action) |
94
|
|
|
{ |
95
|
|
|
$this->location = '/service/resources/invoice_installments'; |
96
|
|
|
|
97
|
|
|
return $this->_POST( |
98
|
|
|
['subscription_id' => $subscription_id, 'invoice_number' => $invoice_number, 'action' => $action], |
99
|
|
|
['subscription_id' => $subscription_id, 'invoice_number' => $invoice_number, 'action' => $action] |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Endpoint para quitar uma parcela de um recurso `Subscription` |
105
|
|
|
* |
106
|
|
|
* @param integer $subscription_id |
107
|
|
|
* @param integer $invoice_number |
108
|
|
|
* @return Response |
109
|
|
|
* |
110
|
|
|
* @codeCoverageIgnore |
111
|
|
|
*/ |
112
|
|
|
public function payOffInstallment(int $subscription_id, int $invoice_number): Response |
113
|
|
|
{ |
114
|
|
|
return $this->_actionsInstallmentPayment($subscription_id, $invoice_number, 'pay'); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Endpoint para agendar pagamento de uma parcela de um recurso `Subscription` |
119
|
|
|
* |
120
|
|
|
* @param integer $subscription_id |
121
|
|
|
* @param integer $invoice_number |
122
|
|
|
* @return Response |
123
|
|
|
* |
124
|
|
|
* @codeCoverageIgnore |
125
|
|
|
*/ |
126
|
|
|
public function scheduleInstallmentPayment(int $subscription_id, int $invoice_number): Response |
127
|
|
|
{ |
128
|
|
|
return $this->_actionsInstallmentPayment($subscription_id, $invoice_number, 'schedule'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
} |