Module: Wavecrest

Defined in:
lib/wavecrest.rb,
lib/wavecrest/version.rb,
lib/wavecrest/exception.rb,
lib/wavecrest/configuration.rb

Defined Under Namespace

Classes: Configuration, Exception

Constant Summary collapse

VERSION =
"0.0.22"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

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



209
210
211
# File 'lib/wavecrest.rb', line 209

def self.activate user_id, proxy, payload
  send_request :post, "/users/#{user_id}/cards/#{proxy}/activate", payload
end

.authObject



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
# File 'lib/wavecrest.rb', line 82

def self.auth
  url = URI("#{configuration.endpoint}/v3/services/authenticator")

  if configuration.proxy
    proxy_uri = URI.parse(configuration.proxy)
    http = Net::HTTP.new(url.host, url.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
  else
    http = Net::HTTP.new(url.host, url.port)
  end

  if url.scheme == 'https'
    http.use_ssl = true
  end

  request = Net::HTTP::Post.new(url.request_uri)
  request.add_field('Content-Type', 'application/json')
  request.add_field('Accept', 'application/json')
  request.add_field('DeveloperId', configuration.user)
  request.add_field('DeveloperPassword', configuration.password)
  request.add_field('X-Method-Override', 'login')

  response = http.request(request)
  data = JSON.parse response.body
  ENV['_WAVECREST_AUTH_TOKEN'] = data["token"]
  ENV['_WAVECREST_AUTH_TOKEN_ISSUED'] = Time.now.to_i.to_s
end

.auth_need?Boolean

Returns:

  • (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_tokenObject



71
72
73
# File 'lib/wavecrest.rb', line 71

def self.auth_token
  ENV['_WAVECREST_AUTH_TOKEN']
end

.balance(user_id, proxy) ⇒ Object



181
182
183
184
# File 'lib/wavecrest.rb', line 181

def self.balance user_id, proxy
  resp = send_request :get, "/users/#{user_id}/cards/#{proxy}/balance"
  resp['avlBal'].to_i
end

.card_statusObject



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



245
246
247
# File 'lib/wavecrest.rb', line 245

def self.card_unload user_id, proxy, payload
  send_request :post, "/users/#{user_id}/cards/#{proxy}/purchase", payload
end

.cardholder(user_id, proxy) ⇒ Object



213
214
215
# File 'lib/wavecrest.rb', line 213

def self.cardholder user_id, proxy
  send_request :get, "/users/#{user_id}/cards/#{proxy}/cardholderinfo"
end

.change_user_password(user_id, payload) ⇒ Object



237
238
239
# File 'lib/wavecrest.rb', line 237

def self.change_user_password user_id, payload
  send_request :post, "/users/#{user_id}/createPassword", payload
end

.configure {|configuration| ... } ⇒ Object

Yields:



15
16
17
18
# File 'lib/wavecrest.rb', line 15

def self.configure
  self.configuration ||= Wavecrest::Configuration.new
  yield(configuration)
end

.countriesObject



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



187
188
189
# File 'lib/wavecrest.rb', line 187

def self.details user_id, proxy
  send_request :get, "/users/#{user_id}/cards/#{proxy}/carddetails"
end

.load_money(user_id, proxy, params = {}) ⇒ Object



172
173
174
175
176
177
178
179
# File 'lib/wavecrest.rb', line 172

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



196
197
198
# File 'lib/wavecrest.rb', line 196

def self.(currency='EUR')
  send_request :post, "/businesspartners/#{configuration.partner_id}/balance", currency: currency
end

.prefunding_accountsObject



200
201
202
203
# File 'lib/wavecrest.rb', line 200

def self.prefunding_accounts
  resp = send_request :get, "/businesspartners/#{configuration.partner_id}/txnaccounts"
  resp['txnAccountList']
end

.prefunding_transactions(account_id) ⇒ Object



205
206
207
# File 'lib/wavecrest.rb', line 205

def self.prefunding_transactions()
  send_request :get, "/businesspartners/#{configuration.partner_id}/transactionaccounts/#{account_id}/transfers"
end

.replace(user_id, proxy, payload) ⇒ Object



229
230
231
# File 'lib/wavecrest.rb', line 229

def self.replace user_id, proxy, payload
  send_request :post, "/users/#{user_id}/cards/#{proxy}/replace", payload
end

.request_card(params) ⇒ Object



161
162
163
164
165
166
167
168
169
170
# File 'lib/wavecrest.rb', line 161

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/wavecrest.rb', line 110

def self.send_request method, path, params={}
  auth if auth_need?

  # path must begin with slash
  url = URI(configuration.endpoint + "/v3/services" + path)

  # Build the connection
  if configuration.proxy
    proxy_uri = URI.parse(configuration.proxy)
    http = Net::HTTP.new(url.host, url.port, proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
  else
    http = Net::HTTP.new(url.host, url.port)
  end

  if url.scheme == 'https'
    http.use_ssl = true
  end

  if method == :get
    request = Net::HTTP::Get.new(url.request_uri)
  elsif method == :post
    request = Net::HTTP::Post.new(url.request_uri)
  elsif method == :delete
    request = Net::HTTP::Delete.new(url.request_uri)
  elsif method == :put
    request = Net::HTTP::Put.new(url.request_uri)
  else
    raise 'Unsupported request method'
  end

  unless method == :get
    request.body = params.to_json
  end

  request.add_field('Content-Type', 'application/json')
  request.add_field('Accept', 'application/json')
  request.add_field('DeveloperId', configuration.user)
  request.add_field('DeveloperPassword', configuration.password)
  request.add_field('AuthenticationToken', auth_token)

  begin
    response = http.request(request)
    JSON.parse response.body
  rescue => e
    # puts e.message, e.response
    return JSON.parse e.response
  end
end

.transactions(user_id, proxy, count: 100, offset: 0) ⇒ Object



191
192
193
194
# File 'lib/wavecrest.rb', line 191

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



233
234
235
# File 'lib/wavecrest.rb', line 233

def self.transfer user_id, proxy, payload
  send_request :post, "/cards/#{proxy}/transfers", payload
end

.update_card(user_id, proxy, payload) ⇒ Object



241
242
243
# File 'lib/wavecrest.rb', line 241

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



221
222
223
# File 'lib/wavecrest.rb', line 221

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



217
218
219
# File 'lib/wavecrest.rb', line 217

def self.upload_docs user_id, payload
  send_request :post, "/users/#{user_id}/kyc", payload
end

.user_details(user_id) ⇒ Object



225
226
227
# File 'lib/wavecrest.rb', line 225

def self.user_details user_id
  send_request :get, "/users/#{user_id}"
end