Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 32d70e7

Browse files
committed
feat(Payment): changed 'capture' method to allow multipayments
changed 'capture' method to allow multipayments
1 parent ae1e26a commit 32d70e7

File tree

8 files changed

+60
-200
lines changed

8 files changed

+60
-200
lines changed

src/Resource/Payment.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -604,29 +604,31 @@ public function setEscrow($description)
604604
*/
605605
public function capture()
606606
{
607-
if (is_null($this->order)) {
608-
throw new \Exception('Sorry, multipayment capture is not available on this version');
607+
if (!$this->isMultipayment($this->getId())) {
608+
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'capture');
609+
} else {
610+
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $this->getId(), 'capture');
609611
}
610-
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'capture');
611612

612613
$response = $this->httpRequest($path, Requests::POST, $this);
613614

614615
return $this->populate($response);
615616
}
616617

617618
/**
618-
* Avoid a pre-authorized amount on a credit card payment.
619+
* Cancel a pre-authorized amount on a credit card payment.
619620
*
620621
* @throws \Exception
621622
*
622623
* @return Payment
623624
*/
624-
public function avoid()
625+
public function cancel()
625626
{
626-
if (is_null($this->order)) {
627-
throw new \Exception('Sorry, multipayment capture is not available on this version');
627+
if (!$this->isMultipayment($this->getId())) {
628+
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'void');
629+
} else {
630+
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $this->getId(), 'void');
628631
}
629-
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'void');
630632

631633
$response = $this->httpRequest($path, Requests::POST, $this);
632634

tests/Resource/PaymentTest.php

+35-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function testMultipaymentCreditCardPCI()
6868
{
6969
$this->mockHttpSession($this->body_multiorder);
7070
$order = $this->createMultiorder()->create();
71-
$this->mockHttpSession($this->body_cc_pay_pci);
72-
$cc = '5555666677778884';
71+
$this->mockHttpSession($this->body_cc_multipay);
72+
$cc = '4012001037141112';
7373
$payment = $order->multipayments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer())->execute();
7474

7575
$first6 = $payment->getPayments()[0]->fundingInstrument->creditCard->first6;
@@ -85,8 +85,40 @@ public function testMultipaymentBillet()
8585
{
8686
$this->mockHttpSession($this->body_multiorder);
8787
$order = $this->createMultiorder()->create();
88-
$this->mockHttpSession($this->body_billet_pay);
88+
$this->mockHttpSession($this->body_billet_multipay);
8989
$payment = $order->multipayments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->execute();
9090
$this->assertNotEmpty($payment->getFundingInstrument()->boleto);
9191
}
92+
93+
public function testCapturePreAuthorizedPayment()
94+
{
95+
$this->mockHttpSession($this->body_order);
96+
$order = $this->createOrder()->create();
97+
$this->mockHttpSession($this->body_cc_delay_capture);
98+
$payment = $order->payments()
99+
->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer(), false)
100+
->setDelayCapture(true)
101+
->execute();
102+
103+
$this->mockHttpSession($this->body_capture_pay);
104+
$captured_payment = $payment->capture();
105+
106+
$this->assertEquals('AUTHORIZED', $captured_payment->getStatus());
107+
}
108+
109+
public function testCapturePreAuthorizedMultiPayment()
110+
{
111+
$this->mockHttpSession($this->body_multiorder);
112+
$order = $this->createMultiorder()->create();
113+
$this->mockHttpSession($this->body_cc_multipay);
114+
$payment = $order->multipayments()
115+
->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer())
116+
->setDelayCapture(true)
117+
->execute();
118+
119+
$this->mockHttpSession($this->body_capture_multipay);
120+
$captured_payment = $payment->capture();
121+
122+
$this->assertEquals('AUTHORIZED', $captured_payment->getStatus());
123+
}
92124
}

tests/TestCase.php

+10
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public function __construct()
136136

137137
$this->body_billet_pay = $this->readJsonFile('jsons/payment/create_billet');
138138

139+
$this->body_billet_multipay = $this->readJsonFile('jsons/multipayment/create_billet');
140+
141+
$this->body_cc_multipay = $this->readJsonFile('jsons/multipayment/create_cc');
142+
139143
$this->body_refund_full_bankaccount = $this->readJsonFile('jsons/refund/full_bankaccount');
140144

141145
$this->body_refund_partial_bankaccount = $this->readJsonFile('jsons/refund/partial_bankaccount');
@@ -157,6 +161,12 @@ public function __construct()
157161
$this->body_notification_list = $this->readJsonFile('jsons/notification/list');
158162

159163
$this->body_multiorder = $this->readJsonFile('jsons/multiorder/create');
164+
165+
$this->body_cc_delay_capture = $this->readJsonFile('jsons/payment/create_cc_delay_capture');
166+
167+
$this->body_capture_pay = $this->readJsonFile('jsons/payment/capture');
168+
169+
$this->body_capture_multipay = $this->readJsonFile('jsons/multipayment/capture');
160170
}
161171

162172
/**

tests/jsons/multipayment/capture.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"MPY-NKZBOXU4B44U","status":"AUTHORIZED","amount":{"total":8000,"gross":8000,"currency":"BRL"},"installmentCount":1,"payments":[{"id":"PAY-LBUR73TATCIC","status":"AUTHORIZED","delayCapture":true,"amount":{"total":4000,"gross":4000,"fees":289,"refunds":0,"liquid":3711,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"creditCard":{"id":"CRC-UARTCOXFHAQI","brand":"VISA","first6":"401200","last4":"1112","store":true,"holder":{"birthdate":"1988-12-30","birthDate":"1988-12-30","taxDocument":{"type":"CPF","number":"22222222222"},"fullname":"Jose Portador da Silva"}},"method":"CREDIT_CARD"},"fees":[{"type":"TRANSACTION","amount":289}],"escrows":[{"id":"ECW-ITVY5KCWP3BF","status":"HOLD_PENDING","description":"Teste","amount":4000,"createdAt":"2017-10-02T10:12:24.000-03","updatedAt":"2017-10-02T10:12:24.000-03","_links":{"self":{"href":"https://sandbox.moip.com.br/v2/escrows/ECW-ITVY5KCWP3BF"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-VQ9OAU9CVLRT","title":"ORD-VQ9OAU9CVLRT"},"payment":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-LBUR73TATCIC","title":"PAY-LBUR73TATCIC"}}}],"events":[{"type":"PAYMENT.AUTHORIZED","createdAt":"2017-10-02T10:13:21.427-03"},{"type":"PAYMENT.IN_ANALYSIS","createdAt":"2017-10-02T10:12:25.000-03"},{"type":"PAYMENT.PRE_AUTHORIZED","createdAt":"2017-10-02T10:12:25.000-03"},{"type":"PAYMENT.CREATED","createdAt":"2017-10-02T10:12:24.000-03"},{"type":"PAYMENT.WAITING","createdAt":"2017-10-02T10:12:24.000-03"}],"receivers":[{"moipAccount":{"id":"MPA-E3D8493A06AE","login":"test@moip.com.br","fullname":"Moip Test"},"type":"PRIMARY","amount":{"total":3500,"refunds":0}},{"moipAccount":{"id":"MPA-8D5DCB4EF8B8","login":"test2@moip.com.br","fullname":"Moip Test2"},"type":"SECONDARY","amount":{"total":500,"fees":0,"refunds":0},"feePayor":false}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-LBUR73TATCIC"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-VQ9OAU9CVLRT","title":"ORD-VQ9OAU9CVLRT"}},"createdAt":"2017-10-02T10:12:24.000-03","updatedAt":"2017-10-02T10:13:21.426-03"},{"id":"PAY-6ICL332BUEXT","status":"AUTHORIZED","delayCapture":true,"amount":{"total":4000,"gross":4000,"fees":289,"refunds":0,"liquid":3711,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"creditCard":{"id":"CRC-UARTCOXFHAQI","brand":"VISA","first6":"401200","last4":"1112","store":true,"holder":{"birthdate":"1988-12-30","birthDate":"1988-12-30","taxDocument":{"type":"CPF","number":"22222222222"},"fullname":"Jose Portador da Silva"}},"method":"CREDIT_CARD"},"fees":[{"type":"TRANSACTION","amount":289}],"escrows":[{"id":"ECW-OX2Z8PFN6EG5","status":"HOLD_PENDING","description":"Teste","amount":4000,"createdAt":"2017-10-02T10:12:24.000-03","updatedAt":"2017-10-02T10:12:24.000-03","_links":{"self":{"href":"https://sandbox.moip.com.br/v2/escrows/ECW-OX2Z8PFN6EG5"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-CMBFPT9AIVPC","title":"ORD-CMBFPT9AIVPC"},"payment":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-6ICL332BUEXT","title":"PAY-6ICL332BUEXT"}}}],"events":[{"type":"PAYMENT.AUTHORIZED","createdAt":"2017-10-02T10:13:21.428-03"},{"type":"PAYMENT.IN_ANALYSIS","createdAt":"2017-10-02T10:12:25.000-03"},{"type":"PAYMENT.PRE_AUTHORIZED","createdAt":"2017-10-02T10:12:25.000-03"},{"type":"PAYMENT.CREATED","createdAt":"2017-10-02T10:12:24.000-03"},{"type":"PAYMENT.WAITING","createdAt":"2017-10-02T10:12:24.000-03"}],"receivers":[{"moipAccount":{"id":"MPA-8D5DBB4EF8B8","login":"caio.gaspar@moip.com.br","fullname":"Caio Gaspar"},"type":"PRIMARY","amount":{"total":4000,"refunds":0}}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-6ICL332BUEXT"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-CMBFPT9AIVPC","title":"ORD-CMBFPT9AIVPC"}},"createdAt":"2017-10-02T10:12:24.000-03","updatedAt":"2017-10-02T10:13:21.427-03"}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/multipayments/MPY-NKZBOXU4B44U"},"multiorder":{"href":"https://sandbox.moip.com.br/v2/multiorders/MOR-GZ5OKB7R36GO"}}}
+1-189
Original file line numberDiff line numberDiff line change
@@ -1,189 +1 @@
1-
{
2-
"id": "MPY-V5CEK24WDD27",
3-
"status": "WAITING",
4-
"amount": {
5-
"total": 8000,
6-
"gross": 8000,
7-
"currency": "BRL"
8-
},
9-
"installmentCount": 1,
10-
"fundingInstrument": {
11-
"boleto": {
12-
"expirationDate": "2017-09-30",
13-
"lineCode": "23793.39126 60000.130140 77001.747904 6 72980000008000",
14-
"logoUri": "http://",
15-
"instructionLines": {
16-
"first": "Primeira linha se instrução",
17-
"second": "Segunda linha se instrução",
18-
"third": "Terceira linha se instrução"
19-
}
20-
},
21-
"method": "BOLETO"
22-
},
23-
"payments": [
24-
{
25-
"id": "PAY-ATNIHH3XI4KJ",
26-
"status": "WAITING",
27-
"delayCapture": false,
28-
"amount": {
29-
"total": 4000,
30-
"gross": 4000,
31-
"fees": 0,
32-
"refunds": 0,
33-
"liquid": 4000,
34-
"currency": "BRL"
35-
},
36-
"installmentCount": 1,
37-
"fundingInstrument": {
38-
"boleto": {
39-
"expirationDate": "2017-09-30",
40-
"lineCode": "23793.39126 60000.130140 77001.747904 6 72980000008000",
41-
"logoUri": "http://",
42-
"instructionLines": {
43-
"first": "Primeira linha se instrução",
44-
"second": "Segunda linha se instrução",
45-
"third": "Terceira linha se instrução"
46-
}
47-
},
48-
"method": "BOLETO"
49-
},
50-
"fees": [
51-
{
52-
"type": "TRANSACTION",
53-
"amount": 0
54-
}
55-
],
56-
"events": [
57-
{
58-
"type": "PAYMENT.CREATED",
59-
"createdAt": "2017-09-29T10:33:46.000-03"
60-
},
61-
{
62-
"type": "PAYMENT.WAITING",
63-
"createdAt": "2017-09-29T10:33:46.000-03"
64-
}
65-
],
66-
"receivers": [
67-
{
68-
"moipAccount": {
69-
"id": "MPA-E3C8493A06AE",
70-
"login": "marcos150895@gmail.com",
71-
"fullname": "Marcos Santana Santos"
72-
},
73-
"type": "PRIMARY",
74-
"amount": {
75-
"total": 3500,
76-
"refunds": 0
77-
}
78-
},
79-
{
80-
"moipAccount": {
81-
"id": "MPA-8D5DBB4EF8B8",
82-
"login": "caio.gaspar@moip.com.br",
83-
"fullname": "Caio Gaspar"
84-
},
85-
"type": "SECONDARY",
86-
"amount": {
87-
"total": 500,
88-
"fees": 0,
89-
"refunds": 0
90-
},
91-
"feePayor": false
92-
}
93-
],
94-
"_links": {
95-
"self": {
96-
"href": "https://sandbox.moip.com.br/v2/payments/PAY-ATNIHH3XI4KJ"
97-
},
98-
"order": {
99-
"href": "https://sandbox.moip.com.br/v2/orders/ORD-U15QTT5DPYSZ",
100-
"title": "ORD-U15QTT5DPYSZ"
101-
}
102-
},
103-
"createdAt": "2017-09-29T10:33:46.000-03",
104-
"updatedAt": "2017-09-29T10:33:46.000-03"
105-
},
106-
{
107-
"id": "PAY-4YIMXKU1SNHW",
108-
"status": "WAITING",
109-
"delayCapture": false,
110-
"amount": {
111-
"total": 4000,
112-
"gross": 4000,
113-
"fees": 0,
114-
"refunds": 0,
115-
"liquid": 4000,
116-
"currency": "BRL"
117-
},
118-
"installmentCount": 1,
119-
"fundingInstrument": {
120-
"boleto": {
121-
"expirationDate": "2017-09-30",
122-
"lineCode": "23793.39126 60000.130140 77001.747904 6 72980000008000",
123-
"logoUri": "http://",
124-
"instructionLines": {
125-
"first": "Primeira linha se instrução",
126-
"second": "Segunda linha se instrução",
127-
"third": "Terceira linha se instrução"
128-
}
129-
},
130-
"method": "BOLETO"
131-
},
132-
"fees": [
133-
{
134-
"type": "TRANSACTION",
135-
"amount": 0
136-
}
137-
],
138-
"events": [
139-
{
140-
"type": "PAYMENT.CREATED",
141-
"createdAt": "2017-09-29T10:33:46.000-03"
142-
},
143-
{
144-
"type": "PAYMENT.WAITING",
145-
"createdAt": "2017-09-29T10:33:46.000-03"
146-
}
147-
],
148-
"receivers": [
149-
{
150-
"moipAccount": {
151-
"id": "MPA-8D5DBB4EF8B8",
152-
"login": "caio.gaspar@moip.com.br",
153-
"fullname": "Caio Gaspar"
154-
},
155-
"type": "PRIMARY",
156-
"amount": {
157-
"total": 4000,
158-
"refunds": 0
159-
}
160-
}
161-
],
162-
"_links": {
163-
"self": {
164-
"href": "https://sandbox.moip.com.br/v2/payments/PAY-4YIMXKU1SNHW"
165-
},
166-
"order": {
167-
"href": "https://sandbox.moip.com.br/v2/orders/ORD-Q3R12CHPQPGO",
168-
"title": "ORD-Q3R12CHPQPGO"
169-
}
170-
},
171-
"createdAt": "2017-09-29T10:33:46.000-03",
172-
"updatedAt": "2017-09-29T10:33:46.000-03"
173-
}
174-
],
175-
"_links": {
176-
"self": {
177-
"href": "https://sandbox.moip.com.br/v2/multipayments/MPY-V5CEK24WDD27"
178-
},
179-
"multiorder": {
180-
"href": "https://sandbox.moip.com.br/v2/multiorders/MOR-R0T7IYR36W3T"
181-
},
182-
"checkout": {
183-
"payBoleto": {
184-
"printHref": "https://checkout-sandbox.moip.com.br/boleto/MPY-V5CEK24WDD27/print",
185-
"redirectHref": "https://checkout-sandbox.moip.com.br/boleto/MPY-V5CEK24WDD27"
186-
}
187-
}
188-
}
189-
}
1+
{"id":"MPY-V5CEK24WDD27","status":"WAITING","amount":{"total":8000,"gross":8000,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"boleto":{"expirationDate":"2017-09-30","lineCode":"23793.3912660000.13014077001.747904672980000008000","logoUri":"http://","instructionLines":{"first":"Primeiralinhaseinstrução","second":"Segundalinhaseinstrução","third":"Terceiralinhaseinstrução"}},"method":"BOLETO"},"payments":[{"id":"PAY-ATNIHH3XI4KJ","status":"WAITING","delayCapture":false,"amount":{"total":4000,"gross":4000,"fees":0,"refunds":0,"liquid":4000,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"boleto":{"expirationDate":"2017-09-30","lineCode":"23793.3912660000.13014077001.747904672980000008000","logoUri":"http://","instructionLines":{"first":"Primeiralinhaseinstrução","second":"Segundalinhaseinstrução","third":"Terceiralinhaseinstrução"}},"method":"BOLETO"},"fees":[{"type":"TRANSACTION","amount":0}],"events":[{"type":"PAYMENT.CREATED","createdAt":"2017-09-29T10:33:46.000-03"},{"type":"PAYMENT.WAITING","createdAt":"2017-09-29T10:33:46.000-03"}],"receivers":[{"moipAccount":{"id":"MPA-E3C8493A06AE","login":"marcos150895@gmail.com","fullname":"MarcosSantanaSantos"},"type":"PRIMARY","amount":{"total":3500,"refunds":0}},{"moipAccount":{"id":"MPA-8D5DBB4EF8B8","login":"caio.gaspar@moip.com.br","fullname":"CaioGaspar"},"type":"SECONDARY","amount":{"total":500,"fees":0,"refunds":0},"feePayor":false}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-ATNIHH3XI4KJ"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-U15QTT5DPYSZ","title":"ORD-U15QTT5DPYSZ"}},"createdAt":"2017-09-29T10:33:46.000-03","updatedAt":"2017-09-29T10:33:46.000-03"},{"id":"PAY-4YIMXKU1SNHW","status":"WAITING","delayCapture":false,"amount":{"total":4000,"gross":4000,"fees":0,"refunds":0,"liquid":4000,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"boleto":{"expirationDate":"2017-09-30","lineCode":"23793.3912660000.13014077001.747904672980000008000","logoUri":"http://","instructionLines":{"first":"Primeiralinhaseinstrução","second":"Segundalinhaseinstrução","third":"Terceiralinhaseinstrução"}},"method":"BOLETO"},"fees":[{"type":"TRANSACTION","amount":0}],"events":[{"type":"PAYMENT.CREATED","createdAt":"2017-09-29T10:33:46.000-03"},{"type":"PAYMENT.WAITING","createdAt":"2017-09-29T10:33:46.000-03"}],"receivers":[{"moipAccount":{"id":"MPA-8D5DCB4EF8B8","login":"test@moip.com.br","fullname":"MoipTest"},"type":"PRIMARY","amount":{"total":4000,"refunds":0}}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-4YIMXKU1SNHW"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-Q3R12CHPQPGO","title":"ORD-Q3R12CHPQPGO"}},"createdAt":"2017-09-29T10:33:46.000-03","updatedAt":"2017-09-29T10:33:46.000-03"}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/multipayments/MPY-V5CEK24WDD27"},"multiorder":{"href":"https://sandbox.moip.com.br/v2/multiorders/MOR-R0T7IYR36W3T"},"checkout":{"payBoleto":{"printHref":"https://checkout-sandbox.moip.com.br/boleto/MPY-V5CEK24WDD27/print","redirectHref":"https://checkout-sandbox.moip.com.br/boleto/MPY-V5CEK24WDD27"}}}}

0 commit comments

Comments
 (0)