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 'capture' method to allow multipayments
Browse files Browse the repository at this point in the history
changed 'capture' method to allow multipayments
  • Loading branch information
caiogaspar committed Oct 2, 2017
1 parent ae1e26a commit 32d70e7
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 200 deletions.
18 changes: 10 additions & 8 deletions src/Resource/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,29 +604,31 @@ public function setEscrow($description)
*/
public function capture()
{
if (is_null($this->order)) {
throw new \Exception('Sorry, multipayment capture is not available on this version');
if (!$this->isMultipayment($this->getId())) {
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'capture');
} else {
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $this->getId(), 'capture');
}
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'capture');

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

return $this->populate($response);
}

/**
* Avoid a pre-authorized amount on a credit card payment.
* Cancel a pre-authorized amount on a credit card payment.
*
* @throws \Exception
*
* @return Payment
*/
public function avoid()
public function cancel()
{
if (is_null($this->order)) {
throw new \Exception('Sorry, multipayment capture is not available on this version');
if (!$this->isMultipayment($this->getId())) {
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'void');
} else {
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::MULTI_PAYMENTS_PATH, $this->getId(), 'void');
}
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $this->getId(), 'void');

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

Expand Down
38 changes: 35 additions & 3 deletions tests/Resource/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function testMultipaymentCreditCardPCI()
{
$this->mockHttpSession($this->body_multiorder);
$order = $this->createMultiorder()->create();
$this->mockHttpSession($this->body_cc_pay_pci);
$cc = '5555666677778884';
$this->mockHttpSession($this->body_cc_multipay);
$cc = '4012001037141112';
$payment = $order->multipayments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer())->execute();

$first6 = $payment->getPayments()[0]->fundingInstrument->creditCard->first6;
Expand All @@ -85,8 +85,40 @@ public function testMultipaymentBillet()
{
$this->mockHttpSession($this->body_multiorder);
$order = $this->createMultiorder()->create();
$this->mockHttpSession($this->body_billet_pay);
$this->mockHttpSession($this->body_billet_multipay);
$payment = $order->multipayments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->execute();
$this->assertNotEmpty($payment->getFundingInstrument()->boleto);
}

public function testCapturePreAuthorizedPayment()
{
$this->mockHttpSession($this->body_order);
$order = $this->createOrder()->create();
$this->mockHttpSession($this->body_cc_delay_capture);
$payment = $order->payments()
->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer(), false)
->setDelayCapture(true)
->execute();

$this->mockHttpSession($this->body_capture_pay);
$captured_payment = $payment->capture();

$this->assertEquals('AUTHORIZED', $captured_payment->getStatus());
}

public function testCapturePreAuthorizedMultiPayment()
{
$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())
->setDelayCapture(true)
->execute();

$this->mockHttpSession($this->body_capture_multipay);
$captured_payment = $payment->capture();

$this->assertEquals('AUTHORIZED', $captured_payment->getStatus());
}
}
10 changes: 10 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public function __construct()

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

$this->body_billet_multipay = $this->readJsonFile('jsons/multipayment/create_billet');

$this->body_cc_multipay = $this->readJsonFile('jsons/multipayment/create_cc');

$this->body_refund_full_bankaccount = $this->readJsonFile('jsons/refund/full_bankaccount');

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

$this->body_multiorder = $this->readJsonFile('jsons/multiorder/create');

$this->body_cc_delay_capture = $this->readJsonFile('jsons/payment/create_cc_delay_capture');

$this->body_capture_pay = $this->readJsonFile('jsons/payment/capture');

$this->body_capture_multipay = $this->readJsonFile('jsons/multipayment/capture');
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/jsons/multipayment/capture.json
Original file line number Diff line number Diff line change
@@ -0,0 +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"}}}
190 changes: 1 addition & 189 deletions tests/jsons/multipayment/create_billet.json
Original file line number Diff line number Diff line change
@@ -1,189 +1 @@
{
"id": "MPY-V5CEK24WDD27",
"status": "WAITING",
"amount": {
"total": 8000,
"gross": 8000,
"currency": "BRL"
},
"installmentCount": 1,
"fundingInstrument": {
"boleto": {
"expirationDate": "2017-09-30",
"lineCode": "23793.39126 60000.130140 77001.747904 6 72980000008000",
"logoUri": "http://",
"instructionLines": {
"first": "Primeira linha se instrução",
"second": "Segunda linha se instrução",
"third": "Terceira linha se instruçã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.39126 60000.130140 77001.747904 6 72980000008000",
"logoUri": "http://",
"instructionLines": {
"first": "Primeira linha se instrução",
"second": "Segunda linha se instrução",
"third": "Terceira linha se instruçã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": "Marcos Santana Santos"
},
"type": "PRIMARY",
"amount": {
"total": 3500,
"refunds": 0
}
},
{
"moipAccount": {
"id": "MPA-8D5DBB4EF8B8",
"login": "caio.gaspar@moip.com.br",
"fullname": "Caio Gaspar"
},
"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.39126 60000.130140 77001.747904 6 72980000008000",
"logoUri": "http://",
"instructionLines": {
"first": "Primeira linha se instrução",
"second": "Segunda linha se instrução",
"third": "Terceira linha se instruçã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-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-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"
}
}
}
}
{"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"}}}}
Loading

0 comments on commit 32d70e7

Please sign in to comment.