From 02b77670e20080e006fe00a0e62abe0d50b21a88 Mon Sep 17 00:00:00 2001 From: Drylian <109999325+drylian@users.noreply.github.com> Date: Thu, 25 Jan 2024 21:20:54 -0300 Subject: [PATCH] tested mercadopago routes --- .../MercadoPago/MercadoPagoExtension.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Extensions/PaymentGateways/MercadoPago/MercadoPagoExtension.php b/app/Extensions/PaymentGateways/MercadoPago/MercadoPagoExtension.php index 7f12d17b..42540e69 100644 --- a/app/Extensions/PaymentGateways/MercadoPago/MercadoPagoExtension.php +++ b/app/Extensions/PaymentGateways/MercadoPago/MercadoPagoExtension.php @@ -60,7 +60,8 @@ class MercadoPagoExtension extends AbstractExtension [ 'title' => "Order #{$payment->id} - " . $shopProduct->name, 'quantity' => 1, - 'unit_price' => $totalPriceString, + // convert shopProduct to float(this is string) + 'unit_price' => floatval($shopProduct->getTotalPrice()), 'currency_id' => $shopProduct->currency_code, ], ], @@ -72,11 +73,8 @@ class MercadoPagoExtension extends AbstractExtension ]); if ($response->successful()) { - // preferenceID - $preferenceId = $response->json()['id']; - // Redirect link - return ("https://www.mercadopago.com/checkout/v1/redirect?preference-id=" . $preferenceId); + Redirect::to($response->json()['init_point'])->send(); } else { Log::error('MercadoPago Payment: ' . $response->body()); throw new Exception('Payment failed'); @@ -178,8 +176,8 @@ class MercadoPagoExtension extends AbstractExtension if ($response->successful()) { $mercado = $response->json(); - $status = $mercado->status; - $payment = Payment::findOrFail($mercado->metadata->crtl_panel_payment_id); + $status = $mercado['status']; + $payment = Payment::findOrFail($mercado['metadata']['crtl_panel_payment_id']); $shopProduct = ShopProduct::findOrFail($payment->shop_item_product_id); if ($status == "approved") {