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

Commit

Permalink
feat(Payment): changed 'get' method to allow get a payment without ge…
Browse files Browse the repository at this point in the history
…t an order first

changed 'get' method to allow get a payment without get an order first
  • Loading branch information
caiogaspar committed Oct 2, 2017
1 parent f805c2d commit 7874a7e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Resource/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/Resource/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
4 changes: 4 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/jsons/multipayment/get.json
Original file line number Diff line number Diff line change
@@ -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"}}}
1 change: 1 addition & 0 deletions tests/jsons/payment/get.json
Original file line number Diff line number Diff line change
@@ -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"}

0 comments on commit 7874a7e

Please sign in to comment.