Class: Vtweb::Client

Inherits:
Object
  • Object
show all
Includes:
Config
Defined in:
lib/vtweb.rb

Constant Summary

Constants included from Config

Vtweb::Config::BILLING_DIFFERENT_WITH_SHIPPING, Vtweb::Config::GET_TOKENS_URL, Vtweb::Config::PAYMENT_TYPE, Vtweb::Config::REDIRECTION_URL, Vtweb::Config::VTWEB_SERVER

Instance Method Summary collapse

Methods included from Config

included

Constructor Details

#initialize(&block) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
25
26
27
28
# 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 
  self.payment_type                    = Config::PAYMENT_TYPE
end

Instance Method Details

#billing_different_with_shippingObject



153
154
155
# File 'lib/vtweb.rb', line 153

def billing_different_with_shipping
  @billing_different_with_shipping
end

#billing_different_with_shipping=(flag) ⇒ Object



157
158
159
# File 'lib/vtweb.rb', line 157

def billing_different_with_shipping=(flag)
  @billing_different_with_shipping = billing_different_with_shipping
end

#error_payment_return_urlObject



137
138
139
# File 'lib/vtweb.rb', line 137

def error_payment_return_url
  return Client.config["error_payment_return_url"]
end

#finish_payment_return_urlObject



141
142
143
# File 'lib/vtweb.rb', line 141

def finish_payment_return_url
  return Client.config["finish_payment_return_url"]
end

#get_keysObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vtweb.rb', line 30

def get_keys
  init_instance

  if billing_different_with_shipping == "0" && required_shipping_address == "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 = parse_body(@resp[:body])
end

#merchant_hash_keyObject



129
130
131
# File 'lib/vtweb.rb', line 129

def merchant_hash_key
  return Client.config["merchant_hash_key"]
end

#merchant_hash_key=(new_merchant_hash_key) ⇒ Object



133
134
135
# File 'lib/vtweb.rb', line 133

def merchant_hash_key= new_merchant_hash_key
  Client.config["merchant_hash_key"] = new_merchant_hash_key
end

#merchant_idObject



121
122
123
# File 'lib/vtweb.rb', line 121

def merchant_id
  return Client.config["merchant_id"]
end

#merchant_id=(new_merchant_id) ⇒ Object



125
126
127
# File 'lib/vtweb.rb', line 125

def merchant_id= new_merchant_id
  Client.config["merchant_id"] = new_merchant_id
end

#new_apiObject



169
170
171
# File 'lib/vtweb.rb', line 169

def new_api
  return true
end

#redirection_urlObject



117
118
119
# File 'lib/vtweb.rb', line 117

def redirection_url
  "#{vtweb_server}#{Config::REDIRECTION_URL}"
end

#required_shipping_addressObject



161
162
163
# File 'lib/vtweb.rb', line 161

def required_shipping_address
  @required_shipping_address
end

#required_shipping_address=(flag) ⇒ Object



165
166
167
# File 'lib/vtweb.rb', line 165

def required_shipping_address=(flag)
  @required_shipping_address = flag
end

#tokenObject



149
150
151
# File 'lib/vtweb.rb', line 149

def token
  return @token
end

#unfinish_payment_return_urlObject



145
146
147
# File 'lib/vtweb.rb', line 145

def unfinish_payment_return_url
  return Client.config["unfinish_payment_return_url"]
end

#vtweb_serverObject



113
114
115
# File 'lib/vtweb.rb', line 113

def vtweb_server
  return Client.config["vtweb_server"] ? Client.config["vtweb_server"] : Config::VTWEB_SERVER
end