Class: Veritrans::Client
- Inherits:
-
Object
- Object
- Veritrans::Client
- Includes:
- Config
- Defined in:
- lib/veritrans/client.rb
Overview
:nodoc:
Constant Summary
Constants included from Config
Veritrans::Config::CARD_CAPTURE_FLAG, Veritrans::Config::CHARGES_URL, Veritrans::Config::CUSTOMER_SPECIFICATION_FLAG, Veritrans::Config::PAYMENT_REDIRECT_URL, Veritrans::Config::REQUEST_KEY_URL, Veritrans::Config::SERVER_HOST, Veritrans::Config::SETTLEMENT_TYPE_CARD, Veritrans::Config::TOKENS_URL, Veritrans::Config::VOID_URL
Instance Method Summary collapse
-
#billing_address_different_with_shipping_address ⇒ Object
:nodoc:.
-
#billing_address_different_with_shipping_address=(flag) ⇒ Object
:nodoc:.
-
#error_payment_return_url ⇒ Object
:nodoc:.
-
#finish_payment_return_url ⇒ Object
:nodoc:.
-
#get_keys ⇒ Object
Example:.
-
#initialize(&block) ⇒ Client
constructor
constructor to create instance of Veritrans::Client.
-
#merchant_hash_key ⇒ Object
:nodoc:.
-
#merchant_hash_key=(new_merchant_hash_key) ⇒ Object
:nodoc:.
-
#merchant_id ⇒ Object
:nodoc:.
-
#merchant_id=(new_merchant_id) ⇒ Object
:nodoc:.
- #new_api ⇒ Object
- #redirect_url ⇒ Object
-
#required_shipping_address ⇒ Object
:nodoc:.
-
#required_shipping_address=(flag) ⇒ Object
:nodoc:.
-
#server_host ⇒ Object
:nodoc:.
-
#token ⇒ Object
:nodoc:.
-
#unfinish_payment_return_url ⇒ Object
:nodoc:.
Methods included from Config
Constructor Details
#initialize(&block) ⇒ Client
constructor to create instance of Veritrans::Client
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/veritrans/client.rb', line 9 def initialize(&block) class <<self self end.class_eval do attr_accessor(:commodity, *PostData::PostParam) end # return-back to merchant-web self.customer_specification_flag = Config::CUSTOMER_SPECIFICATION_FLAG self.settlement_type = Config::SETTLEMENT_TYPE_CARD # if block_given? # yield(self) #self.instance_eval(&block) # return self.get_keys # end end |
Instance Method Details
#billing_address_different_with_shipping_address ⇒ Object
:nodoc:
177 178 179 |
# File 'lib/veritrans/client.rb', line 177 def billing_address_different_with_shipping_address @customer_specification_flag end |
#billing_address_different_with_shipping_address=(flag) ⇒ Object
:nodoc:
182 183 184 |
# File 'lib/veritrans/client.rb', line 182 def billing_address_different_with_shipping_address=(flag) @customer_specification_flag = customer_specification_flag end |
#error_payment_return_url ⇒ Object
:nodoc:
157 158 159 |
# File 'lib/veritrans/client.rb', line 157 def error_payment_return_url return Client.config["error_payment_return_url"] end |
#finish_payment_return_url ⇒ Object
:nodoc:
162 163 164 |
# File 'lib/veritrans/client.rb', line 162 def finish_payment_return_url return Client.config["finish_payment_return_url"] end |
#get_keys ⇒ Object
Example:
client = Veritrans::Client.new
client.order_id = "dummy#{(0...12).map{65.+(rand(25))}.join}"
client.session_id = "session#{(0...12).map{65.+(rand(25))}.join}"
client.gross_amount = "10"
client.commodity = [{
"COMMODITY_ID" => "IDxx1",
"COMMODITY_UNIT" => "10",
"COMMODITY_NUM" => "1",
"COMMODITY_NAME1" => "Waterbotle",
"COMMODITY_NAME2" => "Waterbottle in Indonesian"}]
client.get_keys
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/veritrans/client.rb', line 41 def get_keys init_instance if customer_specification_flag == "0" && shipping_flag == "0" raise "required_shipping_address must be '1'" end params = prepare_params(PostData::ServerParam,PostData::PostParam) 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 commodity = @commodity.collect do |data| data.keys.map do |key| if key.downcase == "commodity_id" data["item_id[]"] = data[key] end if key.downcase == "commodity_unit" data["price[]"] = data[key] end if key.downcase == "commodity_num" data["quantity[]"] = data[key] end if key.downcase == "commodity_name1" data["item_name1[]"] = data[key] end if key.downcase == "commodity_name2" data["item_name2[]"] = data[key] end data.delete key end # construct commodity orders_uri = Addressable::URI.new orders_uri.query_values = data # return list of commodity as query string format orders_uri.query end uri = Addressable::URI.new uri.query_values = params query_string = "#{uri.query}&repeat_line=#{commodity.length}&#{commodity.join('&')}" conn = Faraday.new(:url => server_host) @resp = conn.post do |req| req.url(Config::REQUEST_KEY_URL) req.body = query_string end.env delete_keys @resp[:url] = @resp[:url].to_s if version.to_i == 1 @token = JSON.parse(@resp[:body]) else @token = parse_body(@resp[:body]) end end |
#merchant_hash_key ⇒ Object
:nodoc:
147 148 149 |
# File 'lib/veritrans/client.rb', line 147 def merchant_hash_key return Client.config["merchant_hash_key"] end |
#merchant_hash_key=(new_merchant_hash_key) ⇒ Object
:nodoc:
152 153 154 |
# File 'lib/veritrans/client.rb', line 152 def merchant_hash_key= new_merchant_hash_key Client.config["merchant_hash_key"] = new_merchant_hash_key end |
#merchant_id ⇒ Object
:nodoc:
137 138 139 |
# File 'lib/veritrans/client.rb', line 137 def merchant_id return Client.config["merchant_id"] end |
#merchant_id=(new_merchant_id) ⇒ Object
:nodoc:
142 143 144 |
# File 'lib/veritrans/client.rb', line 142 def merchant_id= new_merchant_id Client.config["merchant_id"] = new_merchant_id end |
#new_api ⇒ Object
196 197 198 |
# File 'lib/veritrans/client.rb', line 196 def new_api return true end |
#redirect_url ⇒ Object
132 133 134 |
# File 'lib/veritrans/client.rb', line 132 def redirect_url "#{server_host}/web1/paymentStart.action" end |
#required_shipping_address ⇒ Object
:nodoc:
187 188 189 |
# File 'lib/veritrans/client.rb', line 187 def required_shipping_address @shipping_flag end |
#required_shipping_address=(flag) ⇒ Object
:nodoc:
192 193 194 |
# File 'lib/veritrans/client.rb', line 192 def required_shipping_address=(flag) @shipping_flag = flag end |
#server_host ⇒ Object
:nodoc:
128 129 130 |
# File 'lib/veritrans/client.rb', line 128 def server_host return Client.config["server_host"] ? Client.config["server_host"] : Config::SERVER_HOST end |
#token ⇒ Object
:nodoc:
172 173 174 |
# File 'lib/veritrans/client.rb', line 172 def token return @token end |
#unfinish_payment_return_url ⇒ Object
:nodoc:
167 168 169 |
# File 'lib/veritrans/client.rb', line 167 def unfinish_payment_return_url return Client.config["unfinish_payment_return_url"] end |