Closed j0sephandres1987 closed 9 years ago
Hi Joseph,
I'm not sure if you indeed have a problem or not. Are you trying to use the Client.new but always the server respond a 500 error?.
The problem there is, this lib don't have a Client class inside the MercadoPago module. In fact the lib don't have a MercadoPago module. The module name is Mercadopago, maybe you are confuse with another gem. This is an extract from the documentation:
For normal use
mp_client = Mercadopago::Sdk.new(client_id, client_secret)
Accept a optional parameter true or false to activate sandbox mode
sandbox_client = Mercadopago::Sdk.new(client_id, client_secret, true)
I think the best here is read the actual documentation of this gem.
Right, the Clien class it is from another gem, sorry but still following the intruccions gaven here it doesn't works for me
Excellent now we are in the same page, what is the problem?. When you use the Mercadopago::Sdk.new(client_id, client_secret) you get an error? Can you paste the error?
----------------------------------In the controller:----------------------------
client_id = 'XXXX'
client_secret = 'XXXX'
mp_client = Mercadopago::Sdk.new(client_id, client_secret)
data = {
:items => [
{
:title => "Title of product",
:currency_id => "VEF",
:unit_price => 2000.50,
:quantity => 2,
}
]
}
@preference = mp_client.create_checkout_preference(data)
---------------------in the view------------------------------------------- Pay
-------------------------the error--------------------------------- 500 Error interno del servidor El Servidor Web no puede realizar esta solicitud. Por favor, inténtelo de nuevo más tarde.
Ok, the respond to that petition is:
@preference = mp_client.create_checkout_preference(data)
=> {"message"=>"currency_id invalid",
"error"=>"invalid_items",
"status"=>400,
"cause"=>[],
:code=>400}
I think that maybe your client_id and secret are from another country and not from Venezuela and Therefore the API don't let you use VEF like currency_id. You have to be sure that your client_id and secret are for mercadopago Venezuela in order to use 'VEF'.
Check here if you are using the correct credentials.
i'm forn colombia
def mercado_pago_checkout client_id = 'xxxx' client_secret = 'xxxx'
mp_client = Mercadopago::Sdk.new(client_id, client_secret)
data = {
:items => [
{
:title => "Title of product",
:currency_id => "COP",
:unit_price => 2000.50,
:quantity => 2,
}
]
}
preference = mp_client.create_checkout_preference(data)
return preference
end
but still: 500 Error interno del servidor
i tried the php class from the official api and it works perfectly. but in my rails app don't
But the error in rails is related to that?, because i use your credential and test with your data and get.
{"collector_id"=>152760780,
"operation_type"=>"regular_payment",
"items"=>[{"id"=>"", "title"=>"Title of product", "description"=>"", "category_id"=>"", "picture_url"=>"", "currency_id"=>"COP", "quantity"=>2, "unit_price"=>2000.5}],
"payer"=>
{"name"=>"",
"surname"=>"",
"email"=>"",
"date_created"=>"",
"phone"=>{"area_code"=>"", "number"=>""},
"identification"=>{"type"=>"", "number"=>""},
"address"=>{"street_name"=>"", "street_number"=>nil, "zip_code"=>""}},
"back_urls"=>{"success"=>"", "pending"=>"", "failure"=>""},
"auto_return"=>"",
"payment_methods"=>
{"excluded_payment_methods"=>[{"id"=>""}], "excluded_payment_types"=>[{"id"=>""}], "installments"=>nil, "default_payment_method_id"=>nil, "default_installments"=>nil},
"client_id"=>"963",
"marketplace"=>"NONE",
"marketplace_fee"=>0,
"shipments"=>{"receiver_address"=>{"zip_code"=>"", "street_number"=>nil, "street_name"=>"", "floor"=>"", "apartment"=>""}},
"notification_url"=>nil,
"external_reference"=>"",
"additional_info"=>"",
"expires"=>false,
"expiration_date_from"=>nil,
"expiration_date_to"=>nil,
"date_created"=>"2015-09-29T00:37:48.632-04:00",
"id"=>"152760780-894359e4-37b7-4e70-bba8-7e8b880ebfcf",
"init_point"=>"https://www.mercadopago.com/mco/checkout/start?pref_id=152760780-894359e4-37b7-4e70-bba8-7e8b880ebfcf",
"sandbox_init_point"=>"https://sandbox.mercadopago.com/mco/checkout/pay?pref_id=152760780-894359e4-37b7-4e70-bba8-7e8b880ebfcf",
:code=>201}
well, the screen that shows the 500 error is not a typical rails error page, it's not from my app in fact
How do you usually get to rectify that response?
Can't you paste the rails log? in that way i can maybe see the error.
I just use your credentials from the console, and work like you see. In fact i just copy and paste your code.
there is not rails log as usual when you get an error, this is the screen
The error most be in the RubyMine console log. Or in the app folder on logs/development. Rails always has a log for the application on development with all the details.
a lot of: Started GET "/store/show_cart" for 127.0.0.1 at 2015-09-28 23:39:23 -0500 Processing by StoreController#show_cart as HTML Completed 500 Internal Server Error in 5ms
in chrome console: Failed to load resource: the server responded with a status of 500 (Internal Server Error)
you have your log level in :debug? inside the config/enviorments/development.rb? If you set the app for :debug you can see a better track of the error.
For more info debugging a Rails App
yes, config.assets.debug = true
No, that variable set the debug on the assets precompilation system. That is not the debug level of the app in self.
The variable is this.
# See everything in the log (default is :info)
config.log_level = :debug
after add config.log_level = :debug and restart the server: Started GET "/store/show_cart" for 127.0.0.1 at 2015-09-29 00:01:53 -0500 Processing by StoreController#show_cart as HTML Completed 500 Internal Server Error in 7ms , it is the same log
In the same environment that the application is running? i think the application is running on production and the configuration is in development
"Rails 4.1.8 application starting in development on http://0.0.0.0:3000"
start Rails console, and test the same code in the console. In that way we can see the error that return mercadopago (if rails log is not returning anything).
Ok, something very rare, when I intentionally added a syntax error. no longer get a screen normal rails with the description and log the error, but this although in the rails console log it shows the real error.
And what is the real error? You don't have another application running in the port 3000 by any chance?
I mean aside the issue of mercadopago, any error, not shown in the framework itself but the screen i don't know where it comes from.
running the code on the console, it works perfectly, I get the response data as indicated the gem intructions
It have to be a syntax error. The strange is that the Ruby Server is not taking the configuration. Because that error 500 is like a full HTML error and that error only is for production, the normal rails error show the trace error. I don't know if this variable is set to false in some place in your config/environment or config/application, but in development that variable must be true.
config.consider_all_requests_local = false
solved!!! delete the others MercadoPago gems that had installed, the folders, the files from the rails folder installation, all that, and now it works, Thank you for all of your help, I really appreciate,
Perfect!!! Excellent, your welcome the is no problem. I will close the issue. If you have another problem with the gem you can start another issue.
Have fun with the code and the force be with you
thanks
My mistake begins very early, mp_client = MercadoPago::Client.new(client_id, client_secret) i enter my clien_id and my client_secret but it's returned a 500 error.
PS: I'm working on a ruby on rails app.