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

Commit

Permalink
test(Payment): Added tests to multipayment
Browse files Browse the repository at this point in the history
Added tests to multipayment
  • Loading branch information
caiogaspar committed Oct 2, 2017
1 parent c860b75 commit ae1e26a
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Resource/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ protected function populate(stdClass $response)
$payment->data->amount->currency = $this->getIfSet('currency', $response->amount);
$payment->data->installmentCount = $this->getIfSet('installmentCount', $response);
$payment->data->fundingInstrument = $this->getIfSet('fundingInstrument', $response);
$payment->data->payments = $this->getIfSet('payments', $response);
$payment->data->escrows = $this->getIfSet('escrows', $response);
$payment->data->fees = $this->getIfSet('fees', $response);
$payment->data->refunds = $this->getIfSet('refunds', $response);
Expand Down Expand Up @@ -340,6 +341,16 @@ public function getInstallmentCount()
return $this->data->installmentCount;
}

/**
* Get payments.
*
* @return array
*/
public function getPayments()
{
return $this->getIfSet('payments');
}

/**
* Set means of payment.
*
Expand Down Expand Up @@ -641,4 +652,9 @@ public function authorize($amount = null)

return false;
}

private function isMultipayment($paymentId)
{
return 0 === strpos($paymentId, 'MPY');
}
}
29 changes: 29 additions & 0 deletions tests/Resource/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,33 @@ public function testShouldCreateEscrowPaymentWithCreditCard()
->execute();
$this->assertEquals('teste de descricao', $payment->getEscrow()->description);
}

/**
* MoipTest creating a credit card multipayment, passing all credit card data.
*/
public function testMultipaymentCreditCardPCI()
{
$this->mockHttpSession($this->body_multiorder);
$order = $this->createMultiorder()->create();
$this->mockHttpSession($this->body_cc_pay_pci);
$cc = '5555666677778884';
$payment = $order->multipayments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer())->execute();

$first6 = $payment->getPayments()[0]->fundingInstrument->creditCard->first6;
$last4 = $payment->getPayments()[0]->fundingInstrument->creditCard->last4;
$this->assertEquals($first6, substr($cc, 0, 6));
$this->assertEquals($last4, substr($cc, -4));
}

/**
* MoipTest creating a billet multipayment.
*/
public function testMultipaymentBillet()
{
$this->mockHttpSession($this->body_multiorder);
$order = $this->createMultiorder()->create();
$this->mockHttpSession($this->body_billet_pay);
$payment = $order->multipayments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->execute();
$this->assertNotEmpty($payment->getFundingInstrument()->boleto);
}
}
44 changes: 44 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ public function __construct()
$this->body_list_webhook_all_filters = $this->readJsonFile('jsons/webhooks/get_all_filters');

$this->body_notification_list = $this->readJsonFile('jsons/notification/list');

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

/**
Expand Down Expand Up @@ -279,6 +281,48 @@ public function createOrder()
return $order;
}

/**
* Creates a multiorder.
*
* @return Multiorders
*/
public function createMultiorder()
{
if ($this->sandbox_mock == self::SANDBOX) {
$this->last_ord_id = uniqid('MOR-');
} else {
$this->last_ord_id = 'meu_id_pedido';
}

$order = $this->moip->orders()->setOwnId(uniqid())
->addItem("bicicleta 1",1, "sku1", 10000)
->addItem("bicicleta 2",1, "sku2", 11000)
->addItem("bicicleta 3",1, "sku3", 12000)
->addItem("bicicleta 4",1, "sku4", 13000)
->setShippingAmount(3000)
->setAddition(1000)
->setDiscount(5000)
->setCustomer($this->createCustomer())
->addReceiver('MPA-VB5OGTVPCI52', 'PRIMARY', NULL);

$order2 = $this->moip->orders()->setOwnId(uniqid())
->addItem("bicicleta 1",1, "sku1", 10000)
->addItem("bicicleta 2",1, "sku2", 11000)
->addItem("bicicleta 3",1, "sku3", 12000)
->setShippingAmount(3000)
->setAddition(1000)
->setDiscount(5000)
->setCustomer($this->createCustomer())
->addReceiver('MPA-IFYRB1HBL73Z', 'PRIMARY', NULL);

$multiorder = $this->moip->multiorders()
->setOwnId(uniqid())
->addOrder($order)
->addOrder($order2);

return $multiorder;
}

/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
Expand Down
1 change: 1 addition & 0 deletions tests/jsons/multiorder/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"id":"MOR-J1G1C9W4P1SD","ownId":"meu_multiorder_id","status":"CREATED","createdAt":"2017-09-29T10:26:21.266-03","updatedAt":"","amount":{"total":8000,"gross":8000,"currency":"BRL"},"orders":[{"id":"ORD-740WQDF7K50X","ownId":"pedido_1_id","status":"CREATED","platform":"V2","createdAt":"2017-09-29T10:26:21.266-03","updatedAt":"2017-09-29T10:26:21.266-03","amount":{"paid":0,"total":4000,"fees":0,"refunds":0,"liquid":0,"otherReceivers":3500,"currency":"BRL","subtotals":{"shipping":2000,"addition":0,"discount":0,"items":2000}},"items":[{"product":"Camisa Verde e Amarelo - Brasil","price":2000,"detail":"Seleção Brasileira","quantity":1}],"customer":{"id":"CUS-02ZE76RXIG24","ownId":"customer[1234]","fullname":"Joao Sousa","createdAt":"2017-06-21T11:02:24.000-03","birthDate":"1988-12-30","email":"joao.sousa@email.com","fundingInstrument":{"creditCard":{"id":"CRC-UARTCOXFHAQI","brand":"VISA","first6":"401200","last4":"1112","store":true},"method":"CREDIT_CARD"},"phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"taxDocument":{"type":"CPF","number":"22222222222"},"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"moipAccount":{"id":"MPA-PQ0H8UZYNNWY"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/customers/CUS-02ZE76RXIG24"},"hostedAccount":{"redirectHref":"https://hostedaccount-sandbox.moip.com.br?token=22e9ac2f-3cbd-4fa1-b143-8c0277565b39&id=CUS-02ZE76RXIG24&mpa=MPA-8D5DBB4EF8B8"}},"fundingInstruments":[{"creditCard":{"id":"CRC-UARTCOXFHAQI","brand":"VISA","first6":"401200","last4":"1112","store":true},"method":"CREDIT_CARD"}]},"payments":[],"escrows":[],"refunds":[],"entries":[],"events":[{"type":"ORDER.CREATED","createdAt":"2017-09-29T10:26:21.266-03","description":""}],"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,"refunds":0}}],"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-740WQDF7K50X"}}},{"id":"ORD-JR07AW1L8BZS","ownId":"pedido_2_id","status":"CREATED","platform":"V2","createdAt":"2017-09-29T10:26:21.279-03","updatedAt":"2017-09-29T10:26:21.279-03","amount":{"paid":0,"total":4000,"fees":0,"refunds":0,"liquid":0,"otherReceivers":0,"currency":"BRL","subtotals":{"shipping":3000,"addition":0,"discount":0,"items":1000}},"items":[{"product":"Camisa Preta - Alemanha","price":1000,"detail":"Camiseta da Copa 2014","quantity":1}],"customer":{"id":"CUS-02ZE76RXIG24","ownId":"customer[1234]","fullname":"Joao Sousa","createdAt":"2017-06-21T11:02:24.000-03","birthDate":"1988-12-30","email":"joao.sousa@email.com","fundingInstrument":{"creditCard":{"id":"CRC-UARTCOXFHAQI","brand":"VISA","first6":"401200","last4":"1112","store":true},"method":"CREDIT_CARD"},"phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"taxDocument":{"type":"CPF","number":"22222222222"},"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"moipAccount":{"id":"MPA-PQ0H8UZYNNWY"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/customers/CUS-02ZE76RXIG24"},"hostedAccount":{"redirectHref":"https://hostedaccount-sandbox.moip.com.br?token=22e9ac2f-3cbd-4fa1-b143-8c0277565b39&id=CUS-02ZE76RXIG24&mpa=MPA-8D5DBB4EF8B8"}},"fundingInstruments":[{"creditCard":{"id":"CRC-UARTCOXFHAQI","brand":"VISA","first6":"401200","last4":"1112","store":true},"method":"CREDIT_CARD"}]},"payments":[],"escrows":[],"refunds":[],"entries":[],"events":[{"type":"ORDER.CREATED","createdAt":"2017-09-29T10:26:21.279-03","description":""}],"receivers":[{"moipAccount":{"id":"MPA-8D5DBB4EF8B8","login":"caio.gaspar@moip.com.br","fullname":"Caio Gaspar"},"type":"PRIMARY","amount":{"total":4000,"fees":0,"refunds":0},"feePayor":true}],"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-JR07AW1L8BZS"}}}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/orders/MOR-J1G1C9W4P1SD"},"checkout":{"payCreditCard":{"redirectHref":"https://checkout-sandbox.moip.com.br/creditcard/MOR-J1G1C9W4P1SD"},"payBoleto":{"redirectHref":"https://checkout-sandbox.moip.com.br/boleto/MOR-J1G1C9W4P1SD"},"payOnlineBankDebitItau":{"redirectHref":"https://checkout-sandbox.moip.com.br/debit/itau/MOR-J1G1C9W4P1SD"}}}}
189 changes: 189 additions & 0 deletions tests/jsons/multipayment/create_billet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"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"
}
}
}
}

0 comments on commit ae1e26a

Please sign in to comment.