Skip to content

Commit

Permalink
Merge pull request #37 from Potelo/fix-pix-info
Browse files Browse the repository at this point in the history
carrega dados de boleto e pix sempre que existir na fatura
  • Loading branch information
andrewalkermo authored Feb 15, 2024
2 parents afcfc06 + 9d85243 commit fa9c3c5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/Gateways/IuguGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ public function createInvoice(Invoice $invoice): Invoice
$invoice->status = $this->iuguStatusToMultiPayment($iuguInvoice->status);
$invoice->amount = $iuguInvoice->total_cents;

if (!empty($invoice->paymentMethod) && $invoice->paymentMethod == Invoice::PAYMENT_METHOD_BANK_SLIP) {
if (!empty($iuguInvoice->bank_slip)) {
$invoice->bankSlip = new BankSlip();
$invoice->bankSlip->url = $iuguInvoice->secure_url . '.pdf';
$invoice->bankSlip->number = $iuguInvoice->bank_slip->digitable_line;
$invoice->bankSlip->barcodeData = $iuguInvoice->bank_slip->barcode_data;
$invoice->bankSlip->barcodeImage = $iuguInvoice->bank_slip->barcode;
} elseif (!empty($invoice->paymentMethod) && $invoice->paymentMethod == Invoice::PAYMENT_METHOD_PIX) {
}
if (!empty($iuguInvoice->pix)) {
$invoice->pix = new Pix();
$invoice->pix->qrCodeImageUrl = $iuguInvoice->pix->qrcode;
$invoice->pix->qrCodeText = $iuguInvoice->pix->qrcode_text;
Expand Down Expand Up @@ -461,7 +462,8 @@ private function parseInvoice($iuguInvoice, ?Invoice $invoice = null): Invoice
$invoice->bankSlip->number = $iuguInvoice->bank_slip->digitable_line;
$invoice->bankSlip->barcodeData = $iuguInvoice->bank_slip->barcode_data;
$invoice->bankSlip->barcodeImage = $iuguInvoice->bank_slip->barcode;
} elseif (!empty($iuguInvoice->pix)) {
}
if (!empty($iuguInvoice->pix)) {
$invoice->pix = new Pix();
$invoice->pix->qrCodeImageUrl = $iuguInvoice->pix->qrcode;
$invoice->pix->qrCodeText = $iuguInvoice->pix->qrcode_text;
Expand Down
44 changes: 38 additions & 6 deletions tests/Unit/Builders/InvoiceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,34 @@ public function testShouldCreateInvoice(string $gateway, array $data): void
$this->assertNotEmpty($invoice->creditCard->id);
}

if ((isset($data['paymentMethod']) && $data['paymentMethod'] === 'bank_slip') || (isset($data['gatewayAdicionalOptions']) && in_array('payable_with', $data['gatewayAdicionalOptions']) && in_array('bank_slip', $data['gatewayAdicionalOptions']['payable_with']))) {
$this->assertNotEmpty($invoice->bankSlip);
$this->assertNotEmpty($invoice->bankSlip->url);
$this->assertNotEmpty($invoice->bankSlip->number);
$this->assertNotEmpty($invoice->bankSlip->barcodeData);
$this->assertNotEmpty($invoice->bankSlip->barcodeImage);
}

if ((isset($data['paymentMethod']) && $data['paymentMethod'] === 'pix') || (isset($data['gatewayAdicionalOptions']) && in_array('payable_with', $data['gatewayAdicionalOptions']) && in_array('pix', $data['gatewayAdicionalOptions']['payable_with']))) {
$this->assertNotEmpty($invoice->pix);
$this->assertNotEmpty($invoice->pix->qrCodeImageUrl);
$this->assertNotEmpty($invoice->pix->qrCodeText);
}

if (isset($data['gatewayAdicionalOptions'])) {
$this->assertEquals($data['gatewayAdicionalOptions'], $invoice->gatewayAdicionalOptions);
if ($gateway == 'iugu') {
foreach ($invoice->gatewayAdicionalOptions as $key => $value) {
$this->assertNotEmpty(array_filter($invoice->original->variables, function ($variable) use ($key, $value) {
return $variable->variable == $key && $variable->value == $value;
}));
if (in_array('payable_with', $data['gatewayAdicionalOptions']) && $gateway == 'iugu') {
foreach ($invoice->original->payable_with as $value) {
$this->assertContains($value, $data['gatewayAdicionalOptions']['payable_with']);
}
}
if (in_array('expires_in', $data['gatewayAdicionalOptions'])) {
$this->assertEquals($data['gatewayAdicionalOptions'], $invoice->gatewayAdicionalOptions);
if ($gateway == 'iugu') {
foreach ($invoice->gatewayAdicionalOptions as $key => $value) {
$this->assertNotEmpty(array_filter($invoice->original->variables, function ($variable) use ($key, $value) {
return $variable->variable == $key && $variable->value == $value;
}));
}
}
}
}
Expand Down Expand Up @@ -204,6 +225,17 @@ public function shouldCreateInvoiceDataProvider(): array
]
]
],
'iugu - without payment method - with payable_with' => [
'gateway' => 'iugu',
'data' => [
'expiresAt' => Carbon::now()->addWeekday()->format('Y-m-d'),
'items' => [['description' => 'Teste', 'quantity' => 1, 'price' => 10000,]],
'customer' => self::customerWithAddress(),
'gatewayAdicionalOptions' => [
'payable_with' => ['bank_slip', 'pix'],
]
]
],
'iugu - company with address without payment method' => [
'gateway' => 'iugu',
'data' => [
Expand Down

0 comments on commit fa9c3c5

Please sign in to comment.