Skip to content

Instantly share code, notes, and snippets.

@bondarolik
Created June 27, 2016 17:38
Show Gist options
  • Save bondarolik/7b6efac3c8b1112b8f8986aa01980cd9 to your computer and use it in GitHub Desktop.
Save bondarolik/7b6efac3c8b1112b8f8986aa01980cd9 to your computer and use it in GitHub Desktop.
How to verify Mercadopago payment status and update it remotly
def check_payment_status
# Prepare for search collection
search_hash = { external_reference: params[:id] }
####################################### INIT MERCADOPAGO API
client_id = 'xxxxx'
client_secret = 'xxxxxxx'
mp_client = MercadoPago::Client.new(client_id, client_secret)
hash = mp_client.search(search_hash)
@mp_payment_status = hash['results'][0]['collection']['status']
@mp_payment_id = hash['results'][0]['collection']['id']
order_id = Mercadopago.find_by_ordercode(params[:id])
@reference = params[:id]
@order_id = if order_id.present? then order_id.order_id else "0" end
end
def update_payment_status
@order = Order.find(params[:id])
@order.order_status_id = 2
@order.save
@mercadopago = Mercadopago.find_by_ordercode(params[:ordercode])
@mercadopago.payment_status = "PAGADO"
@mercadopago.payment_id = params[:payment_id]
@mercadopago.save
#redirect_to payments_admin_index_path, notice: "El cobro por #{params[:ordercode]} ha sido actualizado correctamente. Revise su pedido."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment