Created
April 8, 2015 16:17
-
-
Save jogam5/9a06217b8ed7c77f1ed8 to your computer and use it in GitHub Desktop.
Webhook Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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