From e510d0c23c77b726de1bd543776d91077af102dd Mon Sep 17 00:00:00 2001 From: Andre Walker Date: Thu, 15 Feb 2024 18:23:13 -0300 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20salva=20informa=C3=A7=C3=B5es=20de?= =?UTF-8?q?=20boleto=20e=20pix=20sempre=20que=20houver?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Gateways/IuguGateway.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Gateways/IuguGateway.php b/src/Gateways/IuguGateway.php index 43dfbfc..db8fcf2 100644 --- a/src/Gateways/IuguGateway.php +++ b/src/Gateways/IuguGateway.php @@ -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; @@ -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; From 9d85243220c7ddabe7da85f607d471822720ebe2 Mon Sep 17 00:00:00 2001 From: Andre Walker Date: Thu, 15 Feb 2024 18:35:42 -0300 Subject: [PATCH 2/2] =?UTF-8?q?test:=20verifica=20dados=20de=20boleto=20e?= =?UTF-8?q?=20pix=20se=20for=20um=20m=C3=A9todo=20de=20pagamento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/Builders/InvoiceBuilderTest.php | 44 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/tests/Unit/Builders/InvoiceBuilderTest.php b/tests/Unit/Builders/InvoiceBuilderTest.php index e61625a..ca265d0 100644 --- a/tests/Unit/Builders/InvoiceBuilderTest.php +++ b/tests/Unit/Builders/InvoiceBuilderTest.php @@ -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; + })); + } } } } @@ -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' => [