Last active
February 1, 2016 02:26
BillPlz API using Ruby
This file contains 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
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