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:.
- #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:
133 134 135 |
# File 'lib/veritrans/client.rb', line 133 def billing_address_different_with_shipping_address @customer_specification_flag end |
#billing_address_different_with_shipping_address=(flag) ⇒ Object
:nodoc:
138 139 140 |
# File 'lib/veritrans/client.rb', line 138 def billing_address_different_with_shipping_address=(flag) @customer_specification_flag = customer_specification_flag end |
#error_payment_return_url ⇒ Object
:nodoc:
113 114 115 |
# File 'lib/veritrans/client.rb', line 113 def error_payment_return_url return Client.config["error_payment_return_url"] end |
#finish_payment_return_url ⇒ Object
:nodoc:
118 119 120 |
# File 'lib/veritrans/client.rb', line 118 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 |
# 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 @commodity.class == Array commodity = @commodity.collect do |data| if data.keys.index "COMMODITY_QTY" data["COMMODITY_NUM"] = data["COMMODITY_QTY"] data.delete "COMMODITY_QTY" end if data.keys.index "COMMODITY_PRICE" data["COMMODITY_UNIT"] = data["COMMODITY_PRICE"] data.delete "COMMODITY_PRICE" end uri = Addressable::URI.new uri.query_values = data uri.query end 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 # puts query_string delete_keys @resp[:url] = @resp[:url].to_s @token = parse_body(@resp[:body]) end |
#merchant_hash_key ⇒ Object
:nodoc:
103 104 105 |
# File 'lib/veritrans/client.rb', line 103 def merchant_hash_key return Client.config["merchant_hash_key"] end |
#merchant_hash_key=(new_merchant_hash_key) ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/veritrans/client.rb', line 108 def merchant_hash_key= new_merchant_hash_key Client.config["merchant_hash_key"] = new_merchant_hash_key end |
#merchant_id ⇒ Object
:nodoc:
93 94 95 |
# File 'lib/veritrans/client.rb', line 93 def merchant_id return Client.config["merchant_id"] end |
#merchant_id=(new_merchant_id) ⇒ Object
:nodoc:
98 99 100 |
# File 'lib/veritrans/client.rb', line 98 def merchant_id= new_merchant_id Client.config["merchant_id"] = new_merchant_id end |
#redirect_url ⇒ Object
88 89 90 |
# File 'lib/veritrans/client.rb', line 88 def redirect_url "#{server_host}/web1/paymentStart.action" end |
#required_shipping_address ⇒ Object
:nodoc:
143 144 145 |
# File 'lib/veritrans/client.rb', line 143 def required_shipping_address @shipping_flag end |
#required_shipping_address=(flag) ⇒ Object
:nodoc:
148 149 150 |
# File 'lib/veritrans/client.rb', line 148 def required_shipping_address=(flag) @shipping_flag = flag end |
#server_host ⇒ Object
:nodoc:
84 85 86 |
# File 'lib/veritrans/client.rb', line 84 def server_host return Client.config["server_host"] ? Client.config["server_host"] : Config::SERVER_HOST end |
#token ⇒ Object
:nodoc:
128 129 130 |
# File 'lib/veritrans/client.rb', line 128 def token return @token end |
#unfinish_payment_return_url ⇒ Object
:nodoc:
123 124 125 |
# File 'lib/veritrans/client.rb', line 123 def unfinish_payment_return_url return Client.config["unfinish_payment_return_url"] end |