1 | <?php |
||
8 | class Payment extends MoipResource |
||
9 | { |
||
10 | /** |
||
11 | * @const string |
||
12 | */ |
||
13 | const PATH = 'payments'; |
||
14 | |||
15 | /** |
||
16 | * @const string |
||
17 | */ |
||
18 | const MULTI_PAYMENTS_PATH = 'multipayments'; |
||
19 | |||
20 | /** |
||
21 | * Payment means. |
||
22 | * |
||
23 | * @const string |
||
24 | */ |
||
25 | const METHOD_CREDIT_CARD = 'CREDIT_CARD'; |
||
26 | |||
27 | /** |
||
28 | * Payment means. |
||
29 | * |
||
30 | * @const string |
||
31 | */ |
||
32 | const METHOD_BOLETO = 'BOLETO'; |
||
33 | |||
34 | /** |
||
35 | * Payment means. |
||
36 | * |
||
37 | * @const string |
||
38 | */ |
||
39 | const METHOD_ONLINE_DEBIT = 'ONLINE_DEBIT'; |
||
40 | |||
41 | /** |
||
42 | * Payment means. |
||
43 | * |
||
44 | * @const string |
||
45 | */ |
||
46 | const METHOD_WALLET = 'WALLET'; |
||
47 | |||
48 | /** |
||
49 | * Payment means. |
||
50 | * |
||
51 | * @const string |
||
52 | */ |
||
53 | const METHOD_ONLINE_BANK_DEBIT = 'ONLINE_BANK_DEBIT'; |
||
54 | |||
55 | /** |
||
56 | * @var \Moip\Resource\Orders |
||
57 | */ |
||
58 | private $order; |
||
59 | |||
60 | /** |
||
61 | * @var \Moip\Resource\Multiorders |
||
62 | */ |
||
63 | private $multiorder; |
||
64 | |||
65 | /** |
||
66 | * Initializes new instances. |
||
67 | */ |
||
68 | protected function initialize() |
||
69 | { |
||
70 | $this->data = new stdClass(); |
||
71 | $this->data->installmentCount = 1; |
||
72 | $this->data->fundingInstrument = new stdClass(); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Create a new payment in api MoIP. |
||
77 | * |
||
78 | * @return $this |
||
79 | */ |
||
80 | public function execute() |
||
81 | { |
||
82 | if ($this->order !== null) { |
||
83 | $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Orders::PATH, $this->order->getId(), self::PATH); |
||
84 | } else { |
||
85 | $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Multiorders::PATH, $this->multiorder->getId(), |
||
86 | self::MULTI_PAYMENTS_PATH); |
||
87 | } |
||
88 | $response = $this->httpRequest($path, Requests::POST, $this); |
||
89 | |||
90 | return $this->populate($response); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Get an payment in MoIP. |
||
95 | * |
||
96 | * @param string $id_moip Id MoIP payment |
||
97 | * |
||
98 | * @return stdClass |
||
99 | */ |
||
100 | public function get($id_moip) |
||
104 | |||
105 | /** |
||
106 | * Get id MoIP payment. |
||
107 | * |
||
108 | * |
||
109 | * @return \Moip\Resource\Payment |
||
110 | */ |
||
111 | public function getId() |
||
115 | |||
116 | /** |
||
117 | * Mount payment structure. |
||
118 | * |
||
119 | * @param \stdClass $response |
||
120 | * |
||
121 | * @return Payment |
||
122 | */ |
||
123 | protected function populate(stdClass $response) |
||
143 | |||
144 | /** |
||
145 | * Refunds. |
||
146 | * |
||
147 | * @return Refund |
||
148 | */ |
||
149 | public function refunds() |
||
156 | |||
157 | /** |
||
158 | * get creation time. |
||
159 | * |
||
160 | * @return \DateTime |
||
161 | */ |
||
162 | public function getCreatedAt() |
||
166 | |||
167 | /** |
||
168 | * Returns when the last update occurred. |
||
169 | * |
||
170 | * @return \DateTime |
||
171 | */ |
||
172 | public function getUpdatedAt() |
||
176 | |||
177 | /** |
||
178 | * Returns the funding instrument. |
||
179 | * |
||
180 | * @return stdClass |
||
181 | */ |
||
182 | public function getFundingInstrument() |
||
187 | |||
188 | /** |
||
189 | * Set means of payment. |
||
190 | * |
||
191 | * @param \stdClass $fundingInstrument |
||
192 | * |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function setFundingInstrument(stdClass $fundingInstrument) |
||
201 | |||
202 | /** |
||
203 | * Set billet. |
||
204 | * |
||
205 | * @param \DateTime|string $expirationDate Expiration date of a billet. |
||
206 | * @param string $logoUri Logo of billet. |
||
207 | * @param array $instructionLines Instructions billet. |
||
208 | * |
||
209 | * @return $this |
||
210 | */ |
||
211 | public function setBoleto($expirationDate, $logoUri, array $instructionLines = []) |
||
232 | |||
233 | /** |
||
234 | * Set credit card holder. |
||
235 | * |
||
236 | * @param \Moip\Resource\Customer $holder |
||
237 | */ |
||
238 | private function setCreditCardHolder(Customer $holder) |
||
255 | |||
256 | /** |
||
257 | * Set credit cardHash. |
||
258 | * |
||
259 | * @param string $hash Credit card hash encripted using Moip.js |
||
260 | * @param \Moip\Resource\Customer $holder |
||
261 | * |
||
262 | * @return $this |
||
263 | */ |
||
264 | public function setCreditCardHash($hash, Customer $holder) |
||
273 | |||
274 | /** |
||
275 | * Set credit card |
||
276 | * Credit card used in a payment. |
||
277 | * The card when returned within a parent resource is presented in its minimum representation. |
||
278 | * |
||
279 | * @param int $expirationMonth Card expiration month |
||
280 | * @param int $expirationYear Year of card expiration. |
||
281 | * @param string $number Card number. |
||
282 | * @param int $cvc Card Security Code. |
||
283 | * @param \Moip\Resource\Customer $holder |
||
284 | * |
||
285 | * @return $this |
||
286 | */ |
||
287 | public function setCreditCard($expirationMonth, $expirationYear, $number, $cvc, Customer $holder) |
||
299 | |||
300 | /** |
||
301 | * Set installment count. |
||
302 | * |
||
303 | * @param int $installmentCount |
||
304 | * |
||
305 | * @return $this |
||
306 | */ |
||
307 | public function setInstallmentCount($installmentCount) |
||
313 | |||
314 | /** |
||
315 | * Set payment means made available by banks. |
||
316 | * |
||
317 | * @param string $bankNumber Bank number. Possible values: 001, 237, 341, 041. |
||
318 | * @param \DateTime|string $expirationDate Date of expiration debit. |
||
319 | * @param string $returnUri Return Uri. |
||
320 | * |
||
321 | * @return $this |
||
322 | */ |
||
323 | public function setOnlineBankDebit($bankNumber, $expirationDate, $returnUri) |
||
336 | |||
337 | /** |
||
338 | * Set delay capture. |
||
339 | * |
||
340 | * @return $this |
||
341 | */ |
||
342 | public function setDelayCapture() |
||
348 | |||
349 | /** |
||
350 | * Set Multiorders. |
||
351 | * |
||
352 | * @param \Moip\Resource\Multiorders $multiorder |
||
353 | * |
||
354 | * @return $this |
||
355 | */ |
||
356 | public function setMultiorder(Multiorders $multiorder) |
||
362 | |||
363 | /** |
||
364 | * Set order. |
||
365 | * |
||
366 | * @param \Moip\Resource\Orders $order |
||
367 | * |
||
368 | * @return $this |
||
369 | */ |
||
370 | public function setOrder(Orders $order) |
||
376 | } |
||
377 |