Skip to content

Instantly share code, notes, and snippets.

@Ebaneck
Created January 25, 2019 12:50
Show Gist options
  • Select an option

  • Save Ebaneck/8ce1f3030a565071c27daf42cd57b68c to your computer and use it in GitHub Desktop.

Select an option

Save Ebaneck/8ce1f3030a565071c27daf42cd57b68c to your computer and use it in GitHub Desktop.
sample use of the monetbil api for charging customers upon booking
require 'rubygems'
require 'httparty'
require 'pp'
require 'json'
class ReservationsController < ApplicationController
before_action :authenticate_user!
before_action :set_reservation, only: [:approve, :decline]
PAYMENT_URL = "https://api.monetbil.com/widget/v2.1/seriv-key-goes-here"
def charge(room, reservation)
@notify_url = "some_url"
@item_ref = "pass the hotel name here"
body = {
amount: "1000",
notify_url: "enter notification url here"
}.to_json
headers = {"Content-Type" => "application/json" }
response = HTTParty.post("#{PAYMENT_URL}", :headers => headers, body: body)
puts response.code
puts response.body
#puts response.headers.inspect
data = JSON.parse(response.body)
@payment_url = data['payment_url']
redirect_to @payment_url
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment