mercadopago / sdk-go

Mercado Pago's Official Go Lang
MIT License
14 stars 4 forks source link

Invalid sandbox init point link #59

Closed Unknowns24 closed 5 months ago

Unknowns24 commented 5 months ago

Hello, Im facing an issue with the sandobox init point link returned by preferences module.

This is the code that I`ve been used.


func (m *mp) GenerateOrder(orderId string, shipmentPrice float64, items []preference.ItemRequest) (*preference.Response, error) {
    cfg, err := mpConfig.New(config.ENV.MP_API_TOKEN)
    if err != nil {
        return nil, err
    }

    expirationDate := time.Now().Add(time.Hour)

    req := preference.Request{
        // Backend url to update order status
        NotificationURL: fmt.Sprintf("%s/payment/mp-webhook", config.ENV.APP_API_DOMAIN),

        // frontend urls to informate the user about the payment status
        BackURLs: &preference.BackURLsRequest{
            Success: fmt.Sprintf("%s/orden/%s/pago/exitoso", config.ENV.APP_DOMAIN, orderId),
            Failure: fmt.Sprintf("%s/orden/%s/pago/fallido", config.ENV.APP_DOMAIN, orderId),
            Pending: fmt.Sprintf("%s/orden/%s/pago/pendiente", config.ENV.APP_DOMAIN, orderId),
        },

        // Order expire
        Expires:          true,
        DateOfExpiration: &expirationDate,

        // Exclude cash payments
        PaymentMethods: &preference.PaymentMethodsRequest{
            ExcludedPaymentTypes: []preference.ExcludedPaymentTypeRequest{
                {ID: "ticket"},
            },
        },

        // Add items to the request
        Items: items,
    }

    // Add shipment method to the request
    if shipmentPrice > 0 {
        req.Shipments = &preference.ShipmentsRequest{
            Cost:        shipmentPrice,
            LocalPickup: false,
        }
    }

    // Create a new mp client
    client := preference.NewClient(cfg)
    pref, err := client.Create(context.Background(), req)
    if err != nil {
        return nil, err
    }

    // Return payment link
    return pref, nil
}

This code returns a response like:

{
        "payer": {
            "phone": {
                "area_code": "",
                "number": ""
            },
            "identification": {
                "type": "",
                "number": ""
            },
            "address": {
                "zip_code": "",
                "street_name": "",
                "street_number": ""
            },
            "date_created": "0001-01-01T00:00:00Z",
            "last_purchase": "0001-01-01T00:00:00Z",
            "name": "",
            "surname": "",
            "email": ""
        },
        "payment_methods": {
            "excluded_payment_methods": [
                {
                    "id": ""
                }
            ],
            "excluded_payment_types": [
                {
                    "id": "ticket"
                }
            ],
            "default_payment_method_id": "",
            "installments": 0,
            "default_installments": 0
        },
        "back_urls": {
            "success": "https://x.com.ar/orden/38f09516-b5e5-4d94-a3f2-4d7f683078b4/pago/exitoso",
            "pending": "https://x.com.ar/orden/38f09516-b5e5-4d94-a3f2-4d7f683078b4/pago/pendiente",
            "failure": "https://x.com.ar/orden/38f09516-b5e5-4d94-a3f2-4d7f683078b4/pago/fallido"
        },
        "shipments": {
            "receiver_address": {
                "address": {
                    "zip_code": "",
                    "street_name": "",
                    "street_number": ""
                },
                "country_name": "",
                "state_name": "",
                "floor": "",
                "apartment": "",
                "city_name": ""
            },
            "free_methods": null,
            "mode": "not_specified",
            "dimensions": "",
            "default_shipping_method": "",
            "cost": 2349.99,
            "local_pickup": false,
            "free_shipping": false,
            "express_shipment": false
        },
        "differential_pricing": {
            "id": 0
        },
        "date_of_expiration": "2024-04-08T23:37:10.493Z",
        "expiration_date_from": "0001-01-01T00:00:00Z",
        "expiration_date_to": "0001-01-01T00:00:00Z",
        "last_updated": "0001-01-01T00:00:00Z",
        "date_created": "2024-04-08T18:37:10.728-04:00",
        "taxes": null,
        "tracks": null,
        "items": [
            {
                "id": "",
                "title": "Marucha",
                "description": "x1.250000 kg",
                "currency_id": "ARS",
                "picture_url": "",
                "category_id": "",
                "unit_price": 6875.25,
                "quantity": 1
            }
        ],
        "id": "1762264666-7af9208d-8da0-40ff-b093-72b1e378d176",
        "client_id": "<CLIENT_ID>",
        "notification_url": "https://x.com.ar/payment/mp-webhook",
        "statement_descriptor": "",
        "marketplace": "NONE",
        "external_reference": "",
        "additional_info": "",
        "auto_return": "",
        "operation_type": "regular_payment",
        "init_point": "https://www.mercadopago.com.ar/checkout/v1/redirect?pref_id=1762264666-7af9208d-8da0-40ff-b093-72b1e378d176",
        "sandbox_init_point": "https://sandbox.mercadopago.com.ar/checkout/v1/redirect?pref_id=1762264666-7af9208d-8da0-40ff-b093-72b1e378d176",
        "site_id": "MLA",
        "marketplace_fee": 0,
        "collector_id": 1762264666,
        "expires": true,
        "binary_mode": false,
        "processing_modes": null,
        "metadata": {}
    }

But there is no way that checkout succeed in the init point or sandbox init point: Captura de pantalla 2024-04-08 194437

Unknowns24 commented 5 months ago

P.S: I`m using the API Key of a test seller account.

renanneri01 commented 5 months ago

Hi, the error occurs because you are accessing with the logged in user who created the preference. If you try to log out, or open it in an incognito tab, you should be able to access it.

Tks

Unknowns24 commented 5 months ago

Hi,

No. I'm accessing it in a private tab. I have already try to access with a test buyer account too

Unknowns24 commented 5 months ago

I'm implementing Checkout API product. Do I have to change this to checkout pro?

renanneri01 commented 5 months ago

There is no need to make changes. When integrating with Checkout API, the init point generated is for Checkout PRO.

renanneri01 commented 5 months ago

I simulated your case, and got the same error. Using an anonymous tab, it was possible to access the init point

Unknowns24 commented 5 months ago

Do you have any clue of what could have happened? The error come off when I try to pay with any method.

Because in private tab I can access de checkout init point but every payment method that I have tried fails. (Using APRO as user name with the specified data)

renanneri01 commented 5 months ago

This wouldn't be a problem with the SDK integration, so I can't help you much here. I advise you to contact support: https://www.mercadopago.com.ar/developers/en/support/center