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

Commit 7874a7e

Browse files
committed
feat(Payment): changed 'get' method to allow get a payment without get an order first
changed 'get' method to allow get a payment without get an order first
1 parent f805c2d commit 7874a7e

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

src/Resource/Payment.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ public function execute()
152152
*/
153153
public function get($id_moip)
154154
{
155-
if ($this->order !== null) {
156-
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id_moip));
155+
if ($this->isMultipayment($id_moip)) {
156+
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $id_moip));
157157
}
158158

159-
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $id_moip));
159+
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id_moip));
160160
}
161161

162162
/**

tests/Resource/PaymentTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,33 @@ public function testCancelPreAuthorizedPayment()
153153

154154
$this->assertEquals('CANCELLED', $cancelled_payment->getStatus());
155155
}
156+
157+
public function testGetPayment()
158+
{
159+
$this->mockHttpSession($this->body_order);
160+
$order = $this->createOrder()->create();
161+
$this->mockHttpSession($this->body_cc_pay_pci);
162+
$payment = $order->payments()->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer())->execute();
163+
164+
$this->mockHttpSession($this->body_get_pay);
165+
$payment_get = $this->moip->payments()->get($payment->getId());
166+
167+
$this->assertEquals($payment_get->getAmount()->total, 102470);
168+
$this->assertEquals($payment_get->getFundingInstrument()->method, 'CREDIT_CARD');
169+
$this->assertEquals($payment_get->getInstallmentCount(), 1);
170+
}
171+
172+
public function testGetMultiPayment()
173+
{
174+
$this->mockHttpSession($this->body_multiorder);
175+
$order = $this->createMultiorder()->create();
176+
$this->mockHttpSession($this->body_cc_multipay);
177+
$payment = $order->multipayments()->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer())->execute();
178+
179+
$this->mockHttpSession($this->body_get_multipay);
180+
$payment_get = $this->moip->payments()->get($payment->getId());
181+
182+
$this->assertEquals($payment_get->getAmount()->total, 77000);
183+
$this->assertNotNull($payment_get->getPayments());
184+
}
156185
}

tests/TestCase.php

+4
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ public function __construct()
171171
$this->body_cancel_pay = $this->readJsonFile('jsons/payment/cancel_pre_authorized');
172172

173173
$this->body_cancel_multipay = $this->readJsonFile('jsons/multipayment/cancel_pre_authorized');
174+
175+
$this->body_get_pay = $this->readJsonFile('jsons/payment/get');
176+
177+
$this->body_get_multipay = $this->readJsonFile('jsons/multipayment/get');
174178
}
175179

176180
/**

tests/jsons/multipayment/get.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"MPY-BTFCRTZYEVXU","status":"IN_ANALYSIS","amount":{"total":77000,"gross":77000,"currency":"BRL"},"installmentCount":1,"payments":[{"id":"PAY-51DUCPZH7T4O","status":"AUTHORIZED","delayCapture":false,"amount":{"total":45000,"gross":45000,"fees":3369,"refunds":0,"liquid":41631,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"creditCard":{"id":"CRC-YIWYYPV0W6KJ","brand":"VISA","first6":"401200","last4":"1112","store":true,"holder":{"birthdate":"1989-06-01","birthDate":"1989-06-01","taxDocument":{"type":"CPF","number":"22222222222"},"fullname":"Jose Silva"}},"method":"CREDIT_CARD"},"fees":[{"type":"TRANSACTION","amount":3369}],"events":[{"type":"PAYMENT.AUTHORIZED","createdAt":"2017-10-02T11:49:29.000-03"},{"type":"PAYMENT.CREATED","createdAt":"2017-10-02T11:49:28.000-03"},{"type":"PAYMENT.IN_ANALYSIS","createdAt":"2017-10-02T11:49:28.000-03"},{"type":"PAYMENT.WAITING","createdAt":"2017-10-02T11:49:28.000-03"}],"receivers":[{"moipAccount":{"id":"MPA-VB5OGTVPCI52","login":"lojista_1@labs.moip.com.br","fullname":"Chris Coyier Moip"},"type":"PRIMARY","amount":{"total":45000,"refunds":0}}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-51DUCPZH7T4O"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-8AHAZIHUH2SH","title":"ORD-8AHAZIHUH2SH"}},"createdAt":"2017-10-02T11:49:28.000-03","updatedAt":"2017-10-02T11:49:29.000-03"},{"id":"PAY-AVX93WB7A10U","status":"AUTHORIZED","delayCapture":false,"amount":{"total":32000,"gross":32000,"fees":2407,"refunds":0,"liquid":29593,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"creditCard":{"id":"CRC-KW5IN75IRUHT","brand":"VISA","first6":"401200","last4":"1112","store":true,"holder":{"birthdate":"1989-06-01","birthDate":"1989-06-01","taxDocument":{"type":"CPF","number":"22222222222"},"fullname":"Jose Silva"}},"method":"CREDIT_CARD"},"fees":[{"type":"TRANSACTION","amount":2407}],"events":[{"type":"PAYMENT.AUTHORIZED","createdAt":"2017-10-02T11:49:29.000-03"},{"type":"PAYMENT.CREATED","createdAt":"2017-10-02T11:49:28.000-03"},{"type":"PAYMENT.IN_ANALYSIS","createdAt":"2017-10-02T11:49:28.000-03"},{"type":"PAYMENT.WAITING","createdAt":"2017-10-02T11:49:28.000-03"}],"receivers":[{"moipAccount":{"id":"MPA-IFYRB1HBL73Z","login":"lojista_3@labs.moip.com.br","fullname":"Lojista 3 Moip"},"type":"PRIMARY","amount":{"total":32000,"refunds":0}}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-AVX93WB7A10U"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-6RX3N3FK37XE","title":"ORD-6RX3N3FK37XE"}},"createdAt":"2017-10-02T11:49:28.000-03","updatedAt":"2017-10-02T11:49:29.000-03"}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/multipayments/MPY-BTFCRTZYEVXU"},"multiorder":{"href":"https://sandbox.moip.com.br/v2/multiorders/MOR-QVK65HN7MF34"}}}

tests/jsons/payment/get.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"PAY-KT5OSI01X8QU","status":"SETTLED","delayCapture":true,"amount":{"total":102470,"gross":102470,"fees":7622,"refunds":0,"liquid":94848,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"creditCard":{"id":"CRC-Y193W7M06F08","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":7622}],"events":[{"type":"PAYMENT.SETTLED","createdAt":"2017-09-06T00:22:25.000-03"},{"type":"PAYMENT.AUTHORIZED","createdAt":"2017-09-04T14:25:11.000-03"},{"type":"PAYMENT.PRE_AUTHORIZED","createdAt":"2017-09-04T14:17:35.000-03"},{"type":"PAYMENT.CREATED","createdAt":"2017-09-04T14:17:34.000-03"},{"type":"PAYMENT.IN_ANALYSIS","createdAt":"2017-09-04T14:17:34.000-03"}],"receivers":[{"moipAccount":{"id":"MPA-CULBBYHD11","login":"integracao@labs.moip.com.br","fullname":"Moip SandBox"},"type":"PRIMARY","amount":{"total":102470,"fees":7622,"refunds":0},"feePayor":true}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-KT5OSI01X8QU"},"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-5N85DL9MNDSS","title":"ORD-5N85DL9MNDSS"}},"createdAt":"2017-09-04T14:17:34.000-03","updatedAt":"2017-09-06T00:22:25.000-03"}

0 commit comments

Comments
 (0)