class Vtweb::Client

Public Class Methods

new(&block) click to toggle source
# File lib/vtweb.rb, line 19
def initialize(&block)
  class <<self
    self
  end.class_eval do
    attr_accessor(:item, *PostParams::AllParam) 
  end

  self.billing_different_with_shipping = Config::BILLING_DIFFERENT_WITH_SHIPPING 
end

Public Instance Methods

billing_different_with_shipping() click to toggle source
# File lib/vtweb.rb, line 152
def billing_different_with_shipping
  @billing_different_with_shipping
end
billing_different_with_shipping=(flag) click to toggle source
# File lib/vtweb.rb, line 156
def billing_different_with_shipping=(flag)
  @billing_different_with_shipping = billing_different_with_shipping
end
error_payment_return_url() click to toggle source
# File lib/vtweb.rb, line 136
def error_payment_return_url
  return Client.config["error_payment_return_url"]
end
finish_payment_return_url() click to toggle source
# File lib/vtweb.rb, line 140
def finish_payment_return_url
  return Client.config["finish_payment_return_url"]
end
get_keys() click to toggle source
# File lib/vtweb.rb, line 29
def get_keys
  init_instance

  if billing_different_with_shipping.to_i == 0 && required_shipping_address.to_i == 0
    raise "required_shipping_address must be 1"
  end

  params = prepare_params(PostParams::ServerParams,PostParams::AllParam)
  
  # Payment Options
  if !params[:promo_bins].blank?
    params.merge!({ "promo_bins[]" => params[:promo_bins]})
    params.delete :promo_bins
  end

  if !params[:point_banks].blank?
    params.merge!({ "point_banks[]" => params[:point_banks]})
    params.delete :point_banks
  end

  if !params[:installment_banks].blank?
    params.merge!({ "installment_banks[]" => params[:installment_banks]})
    params.delete :installment_banks
  end

  if !params[:installment_terms].blank?
    params.merge!({ "installment_terms" => params[:installment_terms].to_json })
    params.delete :installment_terms
  end
  
  if !params[:payment_methods].blank?
    params.merge!({ "payment_methods[]" => params[:payment_methods]})
    params.delete :payment_methods
  end

  # Items
  item = @item.collect do |data|
    data.keys.map do |key|
      if key.downcase == "item_id"
        data["item_id[]"] = data[key]            
      end
    
      if key.downcase == "price"
        data["price[]"] = data[key]
      end

      if key.downcase == "quantity"
        data["quantity[]"] = data[key]
      end

      if key.downcase == "item_name1"
        data["item_name1[]"] = data[key]
      end

      if key.downcase == "item_name2"
        data["item_name2[]"] = data[key]
      end

      data.delete key
    end        

    orders_uri = Addressable::URI.new
    orders_uri.query_values = data
    orders_uri.query
    
  end

  uri = Addressable::URI.new
  uri.query_values = params
  query_string = "#{uri.query}&repeat_line=#{item.length}&#{item.join('&')}"
    
  conn = Faraday.new(:url => vtweb_server)
  @resp = conn.post do |req|
    req.url(Config::GET_TOKENS_URL)
    req.body = query_string
  end.env

  delete_keys
  @resp[:url] = @resp[:url].to_s

  @token = JSON.parse(@resp[:body])
end
merchant_hash_key() click to toggle source
# File lib/vtweb.rb, line 128
def merchant_hash_key
  return Client.config["merchant_hash_key"]
end
merchant_hash_key=(new_merchant_hash_key) click to toggle source
# File lib/vtweb.rb, line 132
def merchant_hash_key= new_merchant_hash_key
  Client.config["merchant_hash_key"] = new_merchant_hash_key
end
merchant_id() click to toggle source
# File lib/vtweb.rb, line 120
def merchant_id
  return Client.config["merchant_id"]
end
merchant_id=(new_merchant_id) click to toggle source
# File lib/vtweb.rb, line 124
def merchant_id= new_merchant_id
  Client.config["merchant_id"] = new_merchant_id
end
redirection_url() click to toggle source
# File lib/vtweb.rb, line 116
def redirection_url
  "#{vtweb_server}#{Config::REDIRECTION_URL}"
end
required_shipping_address() click to toggle source
# File lib/vtweb.rb, line 160
def required_shipping_address
  @required_shipping_address
end
required_shipping_address=(flag) click to toggle source
# File lib/vtweb.rb, line 164
def required_shipping_address=(flag)
  @required_shipping_address = flag
end
token() click to toggle source
# File lib/vtweb.rb, line 148
def token
  return @token
end
unfinish_payment_return_url() click to toggle source
# File lib/vtweb.rb, line 144
def unfinish_payment_return_url
  return Client.config["unfinish_payment_return_url"]
end
version() click to toggle source
# File lib/vtweb.rb, line 168
def version
  return 1
end
vtweb_server() click to toggle source
# File lib/vtweb.rb, line 112
def vtweb_server
  return Client.config["vtweb_server"] ? Client.config["vtweb_server"] : Config::VTWEB_SERVER
end

Private Instance Methods

delete_keys() click to toggle source
# File lib/vtweb.rb, line 197
def delete_keys
  @resp.delete(:ssl)
  @resp.delete(:request)
  @resp.delete(:response)
  @resp.delete(:request_headers)
  @resp.delete(:parallel_manager)
end
init_instance() click to toggle source
# File lib/vtweb.rb, line 184
def init_instance
  @token = nil
end
merchanthash() click to toggle source
# File lib/vtweb.rb, line 174
def merchanthash
  return MerchantHashGenerator::generate(merchant_id, merchant_hash_key, order_id);
end
parse_body(body) click to toggle source
# File lib/vtweb.rb, line 178
def parse_body(body)
  arrs = body.split("\r\n")
  arrs = arrs[-2,2] if arrs.length > 1
  return Hash[arrs.collect{|x|x.split("=")}]
end
prepare_params(*arg) click to toggle source
# File lib/vtweb.rb, line 188
def prepare_params(*arg)
  params = {}
  arg.flatten.each do |key|
    value = self.send(key)
    params[key.downcase] = value if value 
  end
  return params
end