Skip to content

Commit

Permalink
fix: readiciona ChargingException e gatewayAdicionalOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewalkermo committed Jan 31, 2024
1 parent ed45344 commit 71d93cc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Gateways/IuguGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Potelo\MultiPayment\Contracts\Gateway;
use Potelo\MultiPayment\Models\InvoiceItem;
use Potelo\MultiPayment\Exceptions\GatewayException;
use Potelo\MultiPayment\Exceptions\ChargingException;
use Potelo\MultiPayment\Exceptions\GatewayNotAvailableException;
use Potelo\MultiPayment\Exceptions\ModelAttributeValidationException;

Expand Down Expand Up @@ -47,6 +48,7 @@ public function __construct()
/**
* @inheritDoc
* @throws ModelAttributeValidationException
* @throws \Potelo\MultiPayment\Exceptions\ChargingException
*/
public function createInvoice(Invoice $invoice): Invoice
{
Expand Down Expand Up @@ -74,19 +76,28 @@ public function createInvoice(Invoice $invoice): Invoice
}
}

if (!empty($invoice->gatewayAdicionalOptions)) {
foreach ($invoice->gatewayAdicionalOptions as $option => $value) {
$iuguInvoiceData[$option] = $value;
}
}

if (!empty($invoice->paymentMethod) && $invoice->paymentMethod == Invoice::PAYMENT_METHOD_CREDIT_CARD) {
if (empty($invoice->creditCard->id)) {
$invoice->creditCard = $this->createCreditCard($invoice->creditCard);
}
$iuguInvoiceData['customer_payment_method_id'] = $invoice->creditCard->id;

try {
$iuguCharge = \Iugu_Charge::create($iuguInvoiceData);
} catch (\Exception $e) {
throw new GatewayException($e->getMessage());
}
if ($iuguCharge->errors) {
throw new GatewayException('Error charging invoice', $iuguCharge->errors);
} elseif (!$iuguCharge->success) {
$exception = new ChargingException('Error charging invoice: ' . $iuguCharge->info_message);
$exception->chargeResponse = $iuguCharge;
throw $exception;
}
$iuguInvoice = $iuguCharge->invoice();
} else {
Expand Down

0 comments on commit 71d93cc

Please sign in to comment.