class Compropago::Client

Constants

BASE_URI

Public Class Methods

new(api_key='', options={}) click to toggle source
# File lib/compropago/client.rb, line 9
def initialize(api_key='', options={})
  @api_key = api_key

  #defaults
  options[:base_uri] ||= BASE_URI
  @base_uri = options[:base_uri]
end

Public Instance Methods

create_charge(product_price, product_name, customer_name, customer_email, payment_type, product_id=nil, image_url=nil) click to toggle source
# File lib/compropago/client.rb, line 17
def create_charge(product_price, product_name, customer_name, customer_email, payment_type, product_id=nil, image_url=nil)
  uri = URI.parse(BASE_URI+'/charges')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Post.new(uri.request_uri)
  request.basic_auth @api_key, ''
  params = { "product_price" => product_price,
                          "product_name" => product_name,
                          "customer_name" => customer_name,
                          "customer_email" => customer_email,
                          "payment_type" => payment_type,
                          "product_id" => product_id,
                  "image_url" => image_url
                  }
  request.set_form_data(params)
  http.request(request)
end
send_payment_instructions(payment_id, customer_phone, customer_company_phone) click to toggle source
# File lib/compropago/client.rb, line 46
def send_payment_instructions(payment_id, customer_phone, customer_company_phone)
  uri = URI.parse(BASE_URI+'/charges/'+payment_id.to_s+'/sms')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Post.new(uri.request_uri)
  request.basic_auth @api_key, ''
  params = { "payment_id" => payment_id.to_s,
                          "customer_phone" => customer_phone.to_s,
                          "customer_company_phone" => customer_company_phone
                  }
  request.set_form_data(params)
  http.request(request)
end
verify_charge(payment_id) click to toggle source
# File lib/compropago/client.rb, line 36
def verify_charge(payment_id)
  uri = URI.parse(BASE_URI+'/charges/'+payment_id)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request = Net::HTTP::Get.new(uri.request_uri)
  request.basic_auth @api_key, ''
  http.request(request)
end