Class: VtwebJson::Client
Constant Summary
Constants included from Config
VtwebJson::Config::BILLING_DIFFERENT_WITH_SHIPPING, VtwebJson::Config::GET_TOKENS_URL, VtwebJson::Config::REDIRECTION_URL, VtwebJson::Config::VTWEB_SERVER
Instance Method Summary collapse
- #_error_payment_return_url ⇒ Object
- #_finish_payment_return_url ⇒ Object
- #_merchant_hash_key ⇒ Object
- #_merchant_id ⇒ Object
- #_unfinish_payment_return_url ⇒ Object
-
#build_json ⇒ Object
Build JSON from defined params.
-
#initialize(&block) ⇒ Client
constructor
A new instance of Client.
-
#merchanthash ⇒ Object
Calculate Merchant Hash.
- #redirection_url ⇒ Object
-
#tokens ⇒ Object
Get Token.
-
#vtweb_server ⇒ Object
Define params.
Methods included from Config
Constructor Details
#initialize(&block) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vtweb_json.rb', line 16 def initialize(&block) class <<self self end.class_eval do attr_accessor :version, :merchant_id, :merchant_hash_key, :order_id, :billing_different_with_shipping, :required_shipping_address, :repeat_line, :item_id, :item_name1, :item_name2, :price, :quantity, :shipping_address1, :shipping_address2, :shipping_city, :shipping_country_code, :shipping_first_name, :shipping_last_name, :shipping_phone, :shipping_postal_code, :email, :payment_methods, :enable_3d_secure, :address1, :address2, :city, :country_code, :first_name, :last_name, :phone, :postal_code, :finish_payment_return_url, :error_payment_return_url, :unfinish_payment_return_url, :bank, :installment_banks, :installment_terms, :point_banks, :promo_bins, :items end end |
Instance Method Details
#_error_payment_return_url ⇒ Object
47 48 49 |
# File 'lib/vtweb_json.rb', line 47 def _error_payment_return_url return Client.config["error_payment_return_url"] end |
#_finish_payment_return_url ⇒ Object
51 52 53 |
# File 'lib/vtweb_json.rb', line 51 def _finish_payment_return_url return Client.config["finish_payment_return_url"] end |
#_merchant_hash_key ⇒ Object
43 44 45 |
# File 'lib/vtweb_json.rb', line 43 def _merchant_hash_key return Client.config["merchant_hash_key"] end |
#_merchant_id ⇒ Object
39 40 41 |
# File 'lib/vtweb_json.rb', line 39 def _merchant_id return Client.config["merchant_id"] end |
#_unfinish_payment_return_url ⇒ Object
55 56 57 |
# File 'lib/vtweb_json.rb', line 55 def _unfinish_payment_return_url return Client.config["unfinish_payment_return_url"] end |
#build_json ⇒ Object
Build JSON from defined params
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 126 127 128 129 130 131 |
# File 'lib/vtweb_json.rb', line 67 def build_json Jbuilder.encode do |json| # Required Params json.version 1 json.merchant_id _merchant_id json.merchanthash merchanthash json.order_id self.order_id json.billing_different_with_shipping self.billing_different_with_shipping json.required_shipping_address self.required_shipping_address json.repeat_line self.items.length item_id = [] item_name1 = [] item_name2 = [] price = [] quantity = [] self.items.each do |item| item_id << item['item_id'] json.item_id item_id item_name1 << item['item_name1'] json.item_name1 item_name1 item_name2 << item['item_name2'] json.item_name2 item_name2 price << item['price'] json.price price quantity << item['quantity'] json.quantity quantity end # Required if required_shipping_address = 1 json.shipping_address1 self.shipping_address1 json.shipping_address2 self.shipping_address2 json.shipping_city self.shipping_city json.shipping_country_code self.shipping_country_code json.shipping_first_name self.shipping_first_name json.shipping_last_name self.shipping_last_name json.shipping_phone self.shipping_phone json.shipping_postal_code self.shipping_postal_code json.email self.email # Optional Params json.payment_methods self.payment_methods json.enable_3d_secure self.enable_3d_secure json.address1 self.address1 json.address2 self.address2 json.city self.city json.country_code self.country_code json.first_name self.first_name json.last_name self.last_name json.phone self.phone json.postal_code self.postal_code json.finish_payment_return_url _finish_payment_return_url json.error_payment_return_url _error_payment_return_url json.unfinish_payment_return_url _unfinish_payment_return_url json.bank self.bank json.installment_banks self.installment_banks json.installment_terms self.installment_terms json.point_banks self.point_banks json.promo_bins self.promo_bins end end |
#merchanthash ⇒ Object
Calculate Merchant Hash
61 62 63 |
# File 'lib/vtweb_json.rb', line 61 def merchanthash return MerchantHashGenerator::generate(_merchant_id, _merchant_hash_key, self.order_id); end |
#redirection_url ⇒ Object
35 36 37 |
# File 'lib/vtweb_json.rb', line 35 def redirection_url "#{vtweb_server}#{Config::REDIRECTION_URL}" end |
#tokens ⇒ Object
Get Token
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/vtweb_json.rb', line 135 def tokens conn = Faraday.new(:url => vtweb_server) do |faraday| faraday.adapter Faraday.default_adapter end response = conn.post do |request| request.url GET_TOKENS_URL request.headers['Content-Type'] = 'application/json' request.headers['Accept'] = 'application/json' request.body = build_json end end |
#vtweb_server ⇒ Object
Define params
31 32 33 |
# File 'lib/vtweb_json.rb', line 31 def vtweb_server return Client.config["vtweb_server"] ? Client.config["vtweb_server"] : Config::VTWEB_SERVER end |