From 7874a7ed2e539f0fd66cdfd2a69e4871fbfef26b Mon Sep 17 00:00:00 2001 From: Caio Gaspar Date: Mon, 2 Oct 2017 13:38:42 -0300 Subject: [PATCH] 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 --- src/Resource/Payment.php | 6 +++--- tests/Resource/PaymentTest.php | 29 +++++++++++++++++++++++++++++ tests/TestCase.php | 4 ++++ tests/jsons/multipayment/get.json | 1 + tests/jsons/payment/get.json | 1 + 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 tests/jsons/multipayment/get.json create mode 100644 tests/jsons/payment/get.json diff --git a/src/Resource/Payment.php b/src/Resource/Payment.php index a6d5893..2985f58 100644 --- a/src/Resource/Payment.php +++ b/src/Resource/Payment.php @@ -152,11 +152,11 @@ public function execute() */ public function get($id_moip) { - if ($this->order !== null) { - return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id_moip)); + if ($this->isMultipayment($id_moip)) { + return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $id_moip)); } - return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $id_moip)); + return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id_moip)); } /** diff --git a/tests/Resource/PaymentTest.php b/tests/Resource/PaymentTest.php index 52081ae..611d41f 100644 --- a/tests/Resource/PaymentTest.php +++ b/tests/Resource/PaymentTest.php @@ -153,4 +153,33 @@ public function testCancelPreAuthorizedPayment() $this->assertEquals('CANCELLED', $cancelled_payment->getStatus()); } + + public function testGetPayment() + { + $this->mockHttpSession($this->body_order); + $order = $this->createOrder()->create(); + $this->mockHttpSession($this->body_cc_pay_pci); + $payment = $order->payments()->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer())->execute(); + + $this->mockHttpSession($this->body_get_pay); + $payment_get = $this->moip->payments()->get($payment->getId()); + + $this->assertEquals($payment_get->getAmount()->total, 102470); + $this->assertEquals($payment_get->getFundingInstrument()->method, 'CREDIT_CARD'); + $this->assertEquals($payment_get->getInstallmentCount(), 1); + } + + public function testGetMultiPayment() + { + $this->mockHttpSession($this->body_multiorder); + $order = $this->createMultiorder()->create(); + $this->mockHttpSession($this->body_cc_multipay); + $payment = $order->multipayments()->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer())->execute(); + + $this->mockHttpSession($this->body_get_multipay); + $payment_get = $this->moip->payments()->get($payment->getId()); + + $this->assertEquals($payment_get->getAmount()->total, 77000); + $this->assertNotNull($payment_get->getPayments()); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 62bc3c6..1eb09e5 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -171,6 +171,10 @@ public function __construct() $this->body_cancel_pay = $this->readJsonFile('jsons/payment/cancel_pre_authorized'); $this->body_cancel_multipay = $this->readJsonFile('jsons/multipayment/cancel_pre_authorized'); + + $this->body_get_pay = $this->readJsonFile('jsons/payment/get'); + + $this->body_get_multipay = $this->readJsonFile('jsons/multipayment/get'); } /** diff --git a/tests/jsons/multipayment/get.json b/tests/jsons/multipayment/get.json new file mode 100644 index 0000000..138b46d --- /dev/null +++ b/tests/jsons/multipayment/get.json @@ -0,0 +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"}}} \ No newline at end of file diff --git a/tests/jsons/payment/get.json b/tests/jsons/payment/get.json new file mode 100644 index 0000000..bbceb7d --- /dev/null +++ b/tests/jsons/payment/get.json @@ -0,0 +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"} \ No newline at end of file