Skip to content

Instantly share code, notes, and snippets.

@juong89
Last active February 1, 2016 02:26
Show Gist options
  • Save juong89/014ed634abfbaaba9c71 to your computer and use it in GitHub Desktop.
Save juong89/014ed634abfbaaba9c71 to your computer and use it in GitHub Desktop.
BillPlz API using Ruby
class PaymentsController < ApplicationController
def index
url_collection = 'https://www.billplz.com/api/v2/collections'
url_bill = 'https://www.billplz.com/api/v2/bills'
api_key = 'YOUR-API-SECRECT-KEY' #You can get the secret key in your billplz's setting account
title = "Anything to explainn about your bill"
#Create collection ID
@collection = HTTParty.post(url_collection.to_str,
:body => { :title => title }.to_json,
:basic_auth => { :username => api_key },
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
#Create Bill
@bill = HTTParty.post(url_bill.to_str,
:body => { :collection_id => @collection.parsed_response["id"], :email=> "email@gmail.com", :name=> "John Smith", :amount=> "260", :callback_url=> "YOUR RETURN URL"}.to_json,
:basic_auth => { :username => api_key },
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
redirect_to @bill.parsed_response["url"]
end
def get_bill
url_bill = "https://www.billplz.com/api/v2/bills/#{params[:billplz][:id]}"
api_key = 'YOUR-API-SECRECT-KEY' #You can get the secret key in your billplz's setting account
@get_bill = HTTParty.get(url_bill,
:basic_auth => { :username => api_key },
:headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
@paid = @get_bill.parsed_response["paid"]
#others data you can check at billplz api
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment