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::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
# 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

Instance Method Details

#billing_different_with_shippingObject



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

def billing_different_with_shipping
  @billing_different_with_shipping
end

#billing_different_with_shipping=(flag) ⇒ Object



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

def billing_different_with_shipping=(flag)
  @billing_different_with_shipping = billing_different_with_shipping
end

#error_payment_return_urlObject



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

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

#finish_payment_return_urlObject



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

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

#get_keysObject



29
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
# 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_keyObject



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

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

#merchant_hash_key=(new_merchant_hash_key) ⇒ Object



132
133
134
# 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_idObject



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

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

#merchant_id=(new_merchant_id) ⇒ Object



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

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

#redirection_urlObject



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

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

#required_shipping_addressObject



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

def required_shipping_address
  @required_shipping_address
end

#required_shipping_address=(flag) ⇒ Object



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

def required_shipping_address=(flag)
  @required_shipping_address = flag
end

#tokenObject



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

def token
  return @token
end

#unfinish_payment_return_urlObject



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

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

#versionObject



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

def version
  return 1
end

#vtweb_serverObject



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

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