Created
January 25, 2019 12:50
-
-
Save Ebaneck/8ce1f3030a565071c27daf42cd57b68c to your computer and use it in GitHub Desktop.
sample use of the monetbil api for charging customers upon booking
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
| 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