require “net/https”

require “uri”

data =

data[“charge”] =

data[“charge”][“amount”] = amount_to_charge

data[“charge”][“memo”] = ‘This is the description of the one time charge.’


you can create hash using

data = {

“charge” =>{

“amount”  => amount_to_change,

“memo”    => ‘This is the description of the one time charge.’



url = “https://#{Chargify.subdomain}{}/charges.json”

#chargify.subdomain  is subdomain name assigned to your api is Subscription id

uri = URI.parse(url)

http =, uri.port)

http.use_ssl = true

http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request =, initheader = {‘Content-Type’ =>’application/json’})

request.body = data.to_json

request.basic_auth(“#{Chargify.api_key}”, “x”)

response = http.request(request)

if response.code != ‘201’

subscription_errors = response.to_json

error_message = ‘Sorry! We were unable to change your subscription.

flash[:error] = error_message




Chargify API : Charge card using Basic authentication and Post Request

Leave a Reply

Your email address will not be published.