FriendsOfBotble / fob-mercadopago

MIT License
1 stars 0 forks source link

Assistance Needed: Missing Address (Zip Code, Street Name) and Picture URL for MercadoPago Integration HONZEM #2

Open naustagic opened 5 days ago

naustagic commented 5 days ago

Hello,

I'm encountering issues with the MercadoPago payment integration due to missing fields in our system. Specifically, when processing payments, we’re required to provide zip_code, street_name, and picture_url fields, but these are currently unavailable in the customer and product data. This results in the following errors:

Undefined array key "zip_code"
Undefined array key "street_name"
Undefined array key "picture_url"

platform/plugins/fob-mercadopago/src/MercadoPagoPayment.php

        $data = apply_filters(PAYMENT_FILTER_PAYMENT_DATA, [], $request);
        try {
            /** @var Preference $preference */
            $preference = app(MercadoPagoClient::class)
                ->createPreference([
                    'external_reference' => $data['order_id'][0],
                    'auto_return' => 'all',
                    'installments' => 1,
                    'default_installments' => 1,
                    'items' => array_map(fn ($item) => [
                        'id' => Arr::get($item, 'id'),
                        'title' => Arr::get($item, 'name'),
                        'picture_url' => Arr::get($item, 'image'),
                        'currency_id' => Arr::get($item, 'currency'),
                        'quantity' => (int) $quantity = Arr::get($item, 'qty'),
                        'unit_price' => Arr::get($item, 'price_per_order') / $quantity,
                    ], $data['products']),
                    'payer' => [
                        'name' => $data['address']['name'],
                        'email' => $data['address']['email'],
                        'phone' => [
                            'number' => $data['address']['phone'],
                        ],
                    ],
                    'back_urls' => [
                        'success' => route('payment.mercadopago.callback'),
                        'failure' => route('payment.mercadopago.callback'),
                        'pending' => route('payment.mercadopago.callback'),
                    ],
                    'notification_url' => route('payment.mercadopago.webhook'),
                    'address' => [
                        'zip_code' => $data['address']['zip_code'] ?? 'none',
                        'street_name' => $data['address']['address'] ?? 'none',
                    ],
                    'metadata' => [
                        'order_id' => $data['order_id'],
                        'customer_id' => $data['customer_id'],
                        'customer_type' => $data['customer_type'],
                        'checkout_token' => $data['checkout_token'],
                    ],
                ]);
            echo view('plugins/fob-mercadopago::checkout', [
                'preferenceId' => $preference->id,
                'publicKey' => get_payment_setting('public_key', 'mercadopago'),
                'locale' => $this->getLocale(),
            ])->render();
            exit();
        } catch (MPApiException $e) {
            return [
                'error' => true,
                'message' => 'API error: ' . $e->getApiResponse()->getContent()['message'] ?? $e->getMessage(),
            ];
        }
    }

Since our customer/agent registration and product data do not currently include these fields, we're unable to populate them when creating the payment request for MercadoPago. Could you please provide guidance on how we can address this? Additionally, would it be possible for the development team to add these fields to the system or suggest an alternative solution to ensure compatibility with MercadoPago’s requirements?

datlechin commented 5 days ago

The payment gateway is currently only compatible with e-commerce scripts.

naustagic commented 4 days ago

The payment gateway is currently only compatible with e-commerce scripts.

thanks for the answer. I really need this integration with Homzen, wouldn't there be a simple way (I know it's never that simple) to make it work in Homzen?