Module: Wavecrest
- Defined in:
- lib/wavecrest.rb,
lib/wavecrest/version.rb,
lib/wavecrest/configuration.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
"0.0.19"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Class Method Summary collapse
- .activate(user_id, proxy, payload) ⇒ Object
- .auth ⇒ Object
- .auth_need? ⇒ Boolean
- .auth_token ⇒ Object
- .balance(user_id, proxy) ⇒ Object
- .card_status ⇒ Object
- .card_unload(user_id, proxy, payload) ⇒ Object
- .cardholder(user_id, proxy) ⇒ Object
- .change_user_password(user_id, payload) ⇒ Object
- .configure {|configuration| ... } ⇒ Object
- .countries ⇒ Object
- .details(user_id, proxy) ⇒ Object
- .load_money(user_id, proxy, params = {}) ⇒ Object
- .prefunding_account(currency = 'EUR') ⇒ Object
- .prefunding_accounts ⇒ Object
- .prefunding_transactions(account_id) ⇒ Object
- .replace(user_id, proxy, payload) ⇒ Object
- .request_card(params) ⇒ Object
- .send_request(method, path, params = {}) ⇒ Object
- .transactions(user_id, proxy, count: 100, offset: 0) ⇒ Object
- .transfer(user_id, proxy, payload) ⇒ Object
- .update_card(user_id, proxy, payload) ⇒ Object
- .update_status(user_id, proxy, payload) ⇒ Object
- .upload_docs(user_id, payload) ⇒ Object
- .user_details(user_id) ⇒ Object
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/wavecrest.rb', line 11 def configuration @configuration end |
Class Method Details
.activate(user_id, proxy, payload) ⇒ Object
178 179 180 |
# File 'lib/wavecrest.rb', line 178 def self.activate user_id, proxy, payload send_request :post, "/users/#{user_id}/cards/#{proxy}/activate", payload end |
.auth ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/wavecrest.rb', line 82 def self.auth url = configuration.endpoint + "/v3/services/authenticator" headers = { "DeveloperId" => configuration.user, "DeveloperPassword" => configuration.password, "X-Method-Override" => 'login', accept: :json, content_type: :json } RestClient.proxy = configuration.proxy if configuration.proxy request = RestClient::Request.new(method: :post, url: url, headers: headers) response = request.execute.body data = JSON.parse response ENV['_WAVECREST_AUTH_TOKEN'] = data["token"] ENV['_WAVECREST_AUTH_TOKEN_ISSUED'] = Time.now.to_i.to_s # puts "WC Authenticated: #{data["token"]}" end |
.auth_need? ⇒ Boolean
75 76 77 78 79 80 |
# File 'lib/wavecrest.rb', line 75 def self.auth_need? auth_token_issied_at = Time.at ENV['_WAVECREST_AUTH_TOKEN_ISSUED'].to_i # puts "WC current auth token: #{auth_token}, issued: #{auth_token_issied_at}" return true unless auth_token return true if auth_token_issied_at.kind_of?(Time) and auth_token_issied_at + 1.hour < Time.now end |
.auth_token ⇒ Object
71 72 73 |
# File 'lib/wavecrest.rb', line 71 def self.auth_token ENV['_WAVECREST_AUTH_TOKEN'] end |
.balance(user_id, proxy) ⇒ Object
150 151 152 153 |
# File 'lib/wavecrest.rb', line 150 def self.balance user_id, proxy resp = send_request :get, "/users/#{user_id}/cards/#{proxy}/balance" resp['avlBal'].to_i end |
.card_status ⇒ Object
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 |
# File 'lib/wavecrest.rb', line 35 def self.card_status [ "READY_TO_ACTIVE", "READY_FOR_AE", "Intermediate_Assignment", "ACTIVE", "EXPIRED", "LOST", "STOLEN", "DESTROYED", "DAMAGED", "DORMANT", "CLOSED", "REPLACED", "SUSPENDED", "SACTIVE", "REVOKED", "CCLOSED", "MBCLOSED", "FRAUD", "PFRAUD", "CHARGEOFF", "DECEASED", "WARNING", "MUCLOSED", "VOID", "NONRENEWAL", "LAST_STMT", "INACTIVE", "BLOCKED", "DEACTIVATE", "ENABLE", "UNSUSPEND" ] end |
.card_unload(user_id, proxy, payload) ⇒ Object
214 215 216 |
# File 'lib/wavecrest.rb', line 214 def self.card_unload user_id, proxy, payload send_request :post, "/users/#{user_id}/cards/#{proxy}/purchase", payload end |
.cardholder(user_id, proxy) ⇒ Object
182 183 184 |
# File 'lib/wavecrest.rb', line 182 def self.cardholder user_id, proxy send_request :get, "/users/#{user_id}/cards/#{proxy}/cardholderinfo" end |
.change_user_password(user_id, payload) ⇒ Object
206 207 208 |
# File 'lib/wavecrest.rb', line 206 def self.change_user_password user_id, payload send_request :post, "/users/#{user_id}/createPassword", payload end |
.configure {|configuration| ... } ⇒ Object
15 16 17 18 |
# File 'lib/wavecrest.rb', line 15 def self.configure self.configuration ||= Wavecrest::Configuration.new yield(configuration) end |
.countries ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/wavecrest.rb', line 20 def self.countries %w( AX AL AD AI AG AR AM AW AU AT AZ BS BH BB BY BE BZ BM BT BQ BA BR BN BG CA KY CL CN CO CR HR CY CZ DK DM DO EC SV EE FK FO FI FR GF GE DE GI GR GL GD GP GT GG GY HK HU IS ID IE IM IL IT JM JP JE JO KZ KR QZ KW LV LI LT LU MK MY MV MT MQ MU MX MD MC MN ME MA NP NL NZ NI NO OM PA PG PY PE PH PL PT QA RO RU BL KN LC MF VC SM SA RS SC SG SX SK SI SB ZA ES SR SE CH TW TH TT TR TC UA AE GB UY VG ) end |
.details(user_id, proxy) ⇒ Object
156 157 158 |
# File 'lib/wavecrest.rb', line 156 def self.details user_id, proxy send_request :get, "/users/#{user_id}/cards/#{proxy}/carddetails" end |
.load_money(user_id, proxy, params = {}) ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/wavecrest.rb', line 141 def self.load_money(user_id, proxy, params= {}) default_params = { "channelType" => "1", "agentId" => configuration.partner_id } payload = default_params.merge params send_request :post, "/users/#{user_id}/cards/#{proxy}/load", payload end |
.prefunding_account(currency = 'EUR') ⇒ Object
165 166 167 |
# File 'lib/wavecrest.rb', line 165 def self.prefunding_account(currency='EUR') send_request :post, "/businesspartners/#{configuration.partner_id}/balance", currency: currency end |
.prefunding_accounts ⇒ Object
169 170 171 172 |
# File 'lib/wavecrest.rb', line 169 def self.prefunding_accounts resp = send_request :get, "/businesspartners/#{configuration.partner_id}/txnaccounts" resp['txnAccountList'] end |
.prefunding_transactions(account_id) ⇒ Object
174 175 176 |
# File 'lib/wavecrest.rb', line 174 def self.prefunding_transactions(account_id) send_request :get, "/businesspartners/#{configuration.partner_id}/transactionaccounts/#{account_id}/transfers" end |
.replace(user_id, proxy, payload) ⇒ Object
198 199 200 |
# File 'lib/wavecrest.rb', line 198 def self.replace user_id, proxy, payload send_request :post, "/users/#{user_id}/cards/#{proxy}/replace", payload end |
.request_card(params) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/wavecrest.rb', line 130 def self.request_card(params) default_params = { "cardProgramId" => "0", "Businesspartnerid" => configuration.partner_id, "channelType" => "1", "localeTime" => Time.now } payload = default_params.merge params send_request :post, "/cards", payload end |
.send_request(method, path, params = {}) ⇒ Object
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 |
# File 'lib/wavecrest.rb', line 103 def self.send_request method, path, params={} auth if auth_need? url = configuration.endpoint + "/v3/services" + path payload = params.to_json headers = { "DeveloperId" => configuration.user, "DeveloperPassword" => configuration.password, "AuthenticationToken" => auth_token, accept: :json, content_type: :json } begin RestClient.proxy = configuration.proxy if configuration.proxy # puts "WC request: #{method} #{url}" request = RestClient::Request.new(method: method, url: url, payload: payload, headers: headers) response = request.execute.body RestClient.proxy = nil JSON.parse response rescue => e # puts e.message, e.response return JSON.parse e.response end end |
.transactions(user_id, proxy, count: 100, offset: 0) ⇒ Object
160 161 162 163 |
# File 'lib/wavecrest.rb', line 160 def self.transactions user_id, proxy, count: 100, offset: 0 payload = {txnCount: count, offset: offset} send_request :post, "/users/#{user_id}/cards/#{proxy}/transactions", payload end |
.transfer(user_id, proxy, payload) ⇒ Object
202 203 204 |
# File 'lib/wavecrest.rb', line 202 def self.transfer user_id, proxy, payload send_request :post, "/cards/#{proxy}/transfers", payload end |
.update_card(user_id, proxy, payload) ⇒ Object
210 211 212 |
# File 'lib/wavecrest.rb', line 210 def self.update_card user_id, proxy, payload send_request :post, "/users/#{user_id}/cards/#{proxy}/", payload end |
.update_status(user_id, proxy, payload) ⇒ Object
190 191 192 |
# File 'lib/wavecrest.rb', line 190 def self.update_status user_id, proxy, payload send_request :post, "/users/#{user_id}/cards/#{proxy}/status", payload end |
.upload_docs(user_id, payload) ⇒ Object
186 187 188 |
# File 'lib/wavecrest.rb', line 186 def self.upload_docs user_id, payload send_request :post, "/users/#{user_id}/kyc", payload end |
.user_details(user_id) ⇒ Object
194 195 196 |
# File 'lib/wavecrest.rb', line 194 def self.user_details user_id send_request :get, "/users/#{user_id}" end |