Skip to content

Instantly share code, notes, and snippets.

@jogam5
Created April 8, 2015 16:17
Show Gist options
  • Save jogam5/9a06217b8ed7c77f1ed8 to your computer and use it in GitHub Desktop.
Save jogam5/9a06217b8ed7c77f1ed8 to your computer and use it in GitHub Desktop.
Webhook Ruby
skip_before_action :verify_authenticity_token, only: [:webhook] #si usas Rails4
require 'compropago'
def webhook
event_json = JSON.parse(request.body.read)
Compropago.api_key = ENV['COMPROPAGO_PUBLIC_API_KEY']
begin
Compropago::Charge.create({ product_price: event_json["total_price"],
product_name: event_json["order_number"].to_s,
customer_name: event_json["customer"]["name"],
customer_email: event_json["customer"]["email"],
payment_type: "OXXO"})
render :status => 200, :json => event_json
rescue JSON::ParserError => e
puts 'error raised'
render :status => 501, :json => {result:false}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment