lightrail_client 1.1.1 → 2.0.0beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/lightrail_client.rb +1 -12
- data/lib/lightrail_client/errors.rb +0 -16
- data/lib/lightrail_client/shopper_token_factory.rb +4 -11
- data/lib/lightrail_client/version.rb +1 -1
- metadata +5 -16
- data/lib/lightrail_client/account.rb +0 -93
- data/lib/lightrail_client/card.rb +0 -40
- data/lib/lightrail_client/code.rb +0 -30
- data/lib/lightrail_client/connection.rb +0 -51
- data/lib/lightrail_client/constants.rb +0 -23
- data/lib/lightrail_client/contact.rb +0 -93
- data/lib/lightrail_client/lightrail_object.rb +0 -10
- data/lib/lightrail_client/ping.rb +0 -11
- data/lib/lightrail_client/transaction.rb +0 -77
- data/lib/lightrail_client/validator.rb +0 -317
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e30747a8e405655c72ec010cab80c24067b366ace6ed38796b29737b1edfe0e8
|
4
|
+
data.tar.gz: 712921a9561b7abe9c262b87e4e25f5adf9a62c3606dd955d0a746eb6d513ef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da3a014cdc39b47aa21446c4f7f5c5bb2fb3f8a7b75c628918d1bd7d14e8d52272ca4a7b165a02077a5796615e7514fdd19499db005175613505d31113fe8082
|
7
|
+
data.tar.gz: 7b9e7af56d31dcf249c9c4b35baa27fdc030d4293bdd76027e328cef7abcd19384586daf086dbb1bbf6534d2fc0e8af5bdb206bd8912ae5c0e51e290208dd3d6
|
data/lib/lightrail_client.rb
CHANGED
@@ -7,23 +7,12 @@ require "base64"
|
|
7
7
|
|
8
8
|
require "lightrail_client/version"
|
9
9
|
|
10
|
-
require "lightrail_client/constants"
|
11
10
|
require "lightrail_client/errors"
|
12
|
-
require "lightrail_client/validator"
|
13
|
-
require "lightrail_client/connection"
|
14
11
|
require "lightrail_client/shopper_token_factory"
|
15
12
|
|
16
|
-
require "lightrail_client/lightrail_object"
|
17
|
-
require "lightrail_client/ping"
|
18
|
-
require "lightrail_client/transaction"
|
19
|
-
require "lightrail_client/card"
|
20
|
-
require "lightrail_client/code"
|
21
|
-
require "lightrail_client/contact"
|
22
|
-
require "lightrail_client/account"
|
23
|
-
|
24
13
|
module Lightrail
|
25
14
|
class << self
|
26
15
|
attr_accessor :api_base, :api_key, :shared_secret
|
27
16
|
end
|
28
|
-
@api_base = 'https://api.lightrail.com/
|
17
|
+
@api_base = 'https://api.lightrail.com/v2'
|
29
18
|
end
|
@@ -9,25 +9,9 @@ module Lightrail
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
class AuthorizationError < LightrailError
|
13
|
-
end
|
14
|
-
|
15
|
-
class InsufficientValueError < LightrailError
|
16
|
-
end
|
17
|
-
|
18
12
|
class BadParameterError < LightrailError
|
19
13
|
end
|
20
14
|
|
21
|
-
class CouldNotFindObjectError < LightrailError
|
22
|
-
end
|
23
|
-
|
24
|
-
class IdempotencyError < LightrailError
|
25
|
-
end
|
26
|
-
|
27
|
-
class ThirdPartyPaymentError < LightrailError
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
15
|
class LightrailArgumentError < ArgumentError
|
32
16
|
end
|
33
17
|
|
@@ -1,21 +1,12 @@
|
|
1
1
|
module Lightrail
|
2
2
|
class ShopperTokenFactory
|
3
|
-
def self.generate (
|
3
|
+
def self.generate (contactId, options=nil)
|
4
4
|
raise Lightrail::BadParameterError.new("Lightrail::api_key is not set") unless Lightrail::api_key
|
5
5
|
raise Lightrail::BadParameterError.new("Lightrail::shared_secret is not set") unless Lightrail::shared_secret
|
6
6
|
|
7
|
-
raise Lightrail::BadParameterError.new("Must provide a
|
8
|
-
Lightrail::Validator.has_valid_contact_id?(contact) ||
|
9
|
-
Lightrail::Validator.has_valid_user_supplied_id?(contact))
|
7
|
+
raise Lightrail::BadParameterError.new("Must provide a contactId to generate a shopper token") unless contactId
|
10
8
|
|
11
9
|
g = {}
|
12
|
-
if Lightrail::Validator.has_valid_or_empty_shopper_id?(contact)
|
13
|
-
g['shi'] = Lightrail::Validator.get_shopper_id(contact)
|
14
|
-
elsif Lightrail::Validator.has_valid_contact_id?(contact)
|
15
|
-
g['coi'] = Lightrail::Validator.get_contact_id(contact)
|
16
|
-
elsif Lightrail::Validator.has_valid_user_supplied_id?(contact)
|
17
|
-
g['cui'] = Lightrail::Validator.get_user_supplied_id(contact)
|
18
|
-
end
|
19
10
|
|
20
11
|
validity_in_seconds = 43200
|
21
12
|
metadata = nil
|
@@ -42,6 +33,8 @@ module Lightrail
|
|
42
33
|
|
43
34
|
g['gui'] = payload['g']['gui']
|
44
35
|
g['gmi'] = payload['g']['gmi']
|
36
|
+
g['coi'] = contactId
|
37
|
+
g['tmi'] = payload['g']['tmi']
|
45
38
|
|
46
39
|
iat = Time.now.to_i
|
47
40
|
payload = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lightrail_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lightrail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,18 +140,8 @@ files:
|
|
140
140
|
- bin/console
|
141
141
|
- bin/setup
|
142
142
|
- lib/lightrail_client.rb
|
143
|
-
- lib/lightrail_client/account.rb
|
144
|
-
- lib/lightrail_client/card.rb
|
145
|
-
- lib/lightrail_client/code.rb
|
146
|
-
- lib/lightrail_client/connection.rb
|
147
|
-
- lib/lightrail_client/constants.rb
|
148
|
-
- lib/lightrail_client/contact.rb
|
149
143
|
- lib/lightrail_client/errors.rb
|
150
|
-
- lib/lightrail_client/lightrail_object.rb
|
151
|
-
- lib/lightrail_client/ping.rb
|
152
144
|
- lib/lightrail_client/shopper_token_factory.rb
|
153
|
-
- lib/lightrail_client/transaction.rb
|
154
|
-
- lib/lightrail_client/validator.rb
|
155
145
|
- lib/lightrail_client/version.rb
|
156
146
|
- lightrail_client.gemspec
|
157
147
|
homepage: https://www.lightrail.com/
|
@@ -170,14 +160,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
160
|
version: '0'
|
171
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
162
|
requirements:
|
173
|
-
- - "
|
163
|
+
- - ">"
|
174
164
|
- !ruby/object:Gem::Version
|
175
|
-
version:
|
165
|
+
version: 1.3.1
|
176
166
|
requirements: []
|
177
167
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.7.8
|
179
169
|
signing_key:
|
180
170
|
specification_version: 4
|
181
171
|
summary: A client library for the Lightrail API
|
182
172
|
test_files: []
|
183
|
-
has_rdoc:
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Account < Lightrail::LightrailObject
|
3
|
-
def self.create(account_params)
|
4
|
-
validated_params = Lightrail::Validator.set_params_for_account_create!(account_params)
|
5
|
-
|
6
|
-
# Make sure contact exists first
|
7
|
-
contact_id = Lightrail::Validator.get_contact_id(validated_params)
|
8
|
-
shopper_id = Lightrail::Validator.get_shopper_id(validated_params)
|
9
|
-
|
10
|
-
if contact_id
|
11
|
-
contact = Lightrail::Contact.retrieve_by_contact_id(contact_id)
|
12
|
-
if shopper_id && (contact['userSuppliedId'] != shopper_id)
|
13
|
-
raise Lightrail::LightrailArgumentError.new("Account creation error: you've specified both a contactId and a shopperId for this account, but the contact with that contactId has a different shopperId.")
|
14
|
-
end
|
15
|
-
|
16
|
-
elsif shopper_id
|
17
|
-
contact = Lightrail::Contact.retrieve_or_create_by_shopper_id(shopper_id)
|
18
|
-
end
|
19
|
-
|
20
|
-
# If the contact already has an account in that currency, return it
|
21
|
-
account_card = Lightrail::Account.retrieve({contact_id: contact['contactId'], currency: validated_params[:currency]})
|
22
|
-
return account_card['cardId'] if account_card
|
23
|
-
|
24
|
-
params_with_contact_id = validated_params.clone
|
25
|
-
params_with_contact_id[:contactId] = contact['contactId']
|
26
|
-
response = Lightrail::Connection.send :make_post_request_and_parse_response, "cards", params_with_contact_id
|
27
|
-
response['card']
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.retrieve(account_retrieval_params)
|
31
|
-
new_params = account_retrieval_params.clone
|
32
|
-
currency = new_params[:currency] || new_params['currency']
|
33
|
-
Lightrail::Validator.validate_currency!(currency)
|
34
|
-
Lightrail::Validator.set_contactId_from_contact_or_shopper_id!(new_params, new_params)
|
35
|
-
contact_id = new_params[:contactId]
|
36
|
-
response = Lightrail::Connection.send :make_get_request_and_parse_response, "cards?cardType=ACCOUNT_CARD&contactId=#{CGI::escape(contact_id)}¤cy=#{CGI::escape(currency)}"
|
37
|
-
response['cards'][0]
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.charge(charge_params)
|
41
|
-
params_with_account_card_id = self.replace_contact_id_or_shopper_id_with_card_id(charge_params)
|
42
|
-
Lightrail::Card.charge(params_with_account_card_id)
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.simulate_charge(charge_params)
|
46
|
-
params_with_account_card_id = self.replace_contact_id_or_shopper_id_with_card_id(charge_params)
|
47
|
-
Lightrail::Card.simulate_charge(params_with_account_card_id)
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.fund(fund_params)
|
51
|
-
params_with_account_card_id = self.replace_contact_id_or_shopper_id_with_card_id(fund_params)
|
52
|
-
Lightrail::Card.fund(params_with_account_card_id)
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.get_account_details(account_details_params)
|
56
|
-
params_with_account_card_id = self.replace_contact_id_or_shopper_id_with_card_id(account_details_params)
|
57
|
-
Lightrail::Card.get_details(params_with_account_card_id[:card_id])
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.get_maximum_account_value(max_account_value_params)
|
61
|
-
params_with_account_card_id = self.replace_contact_id_or_shopper_id_with_card_id(max_account_value_params)
|
62
|
-
Lightrail::Card.get_maximum_value(params_with_account_card_id[:card_id])
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def self.replace_contact_id_or_shopper_id_with_card_id(transaction_params)
|
69
|
-
contact_id = Lightrail::Contact.get_contact_id_from_id_or_shopper_id(transaction_params)
|
70
|
-
|
71
|
-
if contact_id
|
72
|
-
account_card_id = self.retrieve({contact_id: contact_id, currency: transaction_params[:currency]})['cardId']
|
73
|
-
elsif !Lightrail::Validator.has_valid_card_id?(transaction_params)
|
74
|
-
raise Lightrail::LightrailArgumentError.new("Method replace_contact_id_or_shopper_id_with_card_id could not find contact - no contact_id or shopper_id in transaction_params: #{transaction_params.inspect}")
|
75
|
-
end
|
76
|
-
|
77
|
-
params_with_card_id = transaction_params.clone
|
78
|
-
params_with_card_id[:card_id] = account_card_id if account_card_id
|
79
|
-
params_with_card_id.delete(:contact_id)
|
80
|
-
params_with_card_id.delete(:shopper_id)
|
81
|
-
params_with_card_id
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.set_account_card_type(create_account_params)
|
85
|
-
if (create_account_params['cardType'] && create_account_params['cardType'] != 'ACCOUNT_CARD') ||
|
86
|
-
(create_account_params[:cardType] && create_account_params[:cardType] != 'ACCOUNT_CARD')
|
87
|
-
raise Lightrail::LightrailArgumentError.new("Cannot create account card if cardType set to value other than 'ACCOUNT_CARD': #{create_account_params.inspect}")
|
88
|
-
end
|
89
|
-
create_account_params[:cardType] = 'ACCOUNT_CARD'
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Card < Lightrail::LightrailObject
|
3
|
-
|
4
|
-
def self.create(create_params)
|
5
|
-
params_for_create = Lightrail::Validator.set_params_for_card_create!(create_params)
|
6
|
-
response = Lightrail::Connection.send :make_post_request_and_parse_response, "cards", params_for_create
|
7
|
-
response['card']
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.charge(charge_params)
|
11
|
-
Lightrail::Transaction.charge_card(charge_params, false)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.simulate_charge(charge_params)
|
15
|
-
params_for_simulation = Lightrail::Validator.set_nsf_for_simulate!(charge_params)
|
16
|
-
Lightrail::Transaction.charge_card(params_for_simulation, true)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.fund(fund_params)
|
20
|
-
Lightrail::Transaction.fund_card(fund_params)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.get_maximum_value(card_id)
|
24
|
-
card_details = self.get_details(card_id)
|
25
|
-
maximum_value = 0
|
26
|
-
card_details['valueStores'].each do |valueStore|
|
27
|
-
if valueStore['state'] == 'ACTIVE'
|
28
|
-
maximum_value += valueStore['value']
|
29
|
-
end
|
30
|
-
end
|
31
|
-
maximum_value
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.get_details(card_id)
|
35
|
-
response = Lightrail::Connection.make_get_request_and_parse_response("cards/#{CGI::escape(card_id)}/details")
|
36
|
-
response['details']
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Code
|
3
|
-
|
4
|
-
def self.charge(charge_params)
|
5
|
-
Lightrail::Transaction.charge_code(charge_params, false)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.simulate_charge(charge_params)
|
9
|
-
params_for_simulation = Lightrail::Validator.set_nsf_for_simulate!(charge_params)
|
10
|
-
Lightrail::Transaction.charge_code(params_for_simulation, true)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.get_maximum_value(code)
|
14
|
-
code_details = self.get_details(code)
|
15
|
-
maximum_value = 0
|
16
|
-
code_details['valueStores'].each do |valueStore|
|
17
|
-
if valueStore['state'] == 'ACTIVE'
|
18
|
-
maximum_value += valueStore['value']
|
19
|
-
end
|
20
|
-
end
|
21
|
-
maximum_value
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.get_details(code)
|
25
|
-
response = Lightrail::Connection.make_get_request_and_parse_response("codes/#{CGI::escape(code)}/details")
|
26
|
-
response['details']
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Connection
|
3
|
-
def self.connection
|
4
|
-
conn = Faraday.new Lightrail.api_base, ssl: {version: :TLSv1_2}
|
5
|
-
conn.headers['Content-Type'] = 'application/json; charset=utf-8'
|
6
|
-
conn.headers['Authorization'] = "Bearer #{Lightrail.api_key}"
|
7
|
-
conn.headers['User-Agent'] = "Lightrail-Ruby/#{Gem.loaded_specs['lightrail_client'].version.version}"
|
8
|
-
conn
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.ping
|
12
|
-
self.make_get_request_and_parse_response('ping')
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.make_post_request_and_parse_response (url, body)
|
16
|
-
resp = Lightrail::Connection.connection.post do |req|
|
17
|
-
req.url url
|
18
|
-
req.body = JSON.generate(body)
|
19
|
-
end
|
20
|
-
self.handle_response(resp)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.make_get_request_and_parse_response (url)
|
24
|
-
resp = Lightrail::Connection.connection.get {|req| req.url url}
|
25
|
-
self.handle_response(resp)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.handle_response(response)
|
29
|
-
body = JSON.parse(response.body) || {}
|
30
|
-
message = body['message'] || ''
|
31
|
-
case response.status
|
32
|
-
when 200...300
|
33
|
-
JSON.parse(response.body)
|
34
|
-
when 400
|
35
|
-
if (message =~ /insufficient value/i)
|
36
|
-
raise Lightrail::InsufficientValueError.new(message, response)
|
37
|
-
else
|
38
|
-
raise Lightrail::BadParameterError.new(message, response)
|
39
|
-
end
|
40
|
-
when 401, 403
|
41
|
-
raise Lightrail::AuthorizationError.new(message, response)
|
42
|
-
when 404
|
43
|
-
raise Lightrail::CouldNotFindObjectError.new(message, response)
|
44
|
-
when 409
|
45
|
-
raise Lightrail::BadParameterError.new(message, response)
|
46
|
-
else
|
47
|
-
raise LightrailError.new("Server responded with: (#{response.status}) #{message}", response)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Constants
|
3
|
-
|
4
|
-
code_keys_sym = [:code, :lightrail_code]
|
5
|
-
card_id_keys_sym = [:cardId, :card_id, :lightrail_card_id]
|
6
|
-
contact_id_keys_sym = [:contactId, :contact_id, :lightrail_contact_id]
|
7
|
-
shopper_id_keys_sym = [:shopperId, :shopper_id, :lightrail_shopper_id]
|
8
|
-
user_supplied_id_keys_sym = [:userSuppliedId, :user_supplied_id, :lightrail_user_supplied_id, :idempotency_key]
|
9
|
-
transaction_id_keys_sym = [:transactionId, :transaction_id, :lightrail_transaction_id]
|
10
|
-
|
11
|
-
LIGHTRAIL_CODE_KEYS = code_keys_sym + code_keys_sym.map {|code_key| code_key.to_s}
|
12
|
-
LIGHTRAIL_CARD_ID_KEYS = card_id_keys_sym + card_id_keys_sym.map {|card_id_key| card_id_key.to_s}
|
13
|
-
LIGHTRAIL_CONTACT_ID_KEYS = contact_id_keys_sym + contact_id_keys_sym.map {|contact_id_key| contact_id_key.to_s}
|
14
|
-
LIGHTRAIL_SHOPPER_ID_KEYS = shopper_id_keys_sym + shopper_id_keys_sym.map {|shopper_id_key| shopper_id_key.to_s}
|
15
|
-
LIGHTRAIL_USER_SUPPLIED_ID_KEYS = user_supplied_id_keys_sym + user_supplied_id_keys_sym.map {|user_supplied_id_key| user_supplied_id_key.to_s}
|
16
|
-
LIGHTRAIL_TRANSACTION_ID_KEYS = transaction_id_keys_sym + transaction_id_keys_sym.map {|transaction_id_key| transaction_id_key.to_s}
|
17
|
-
|
18
|
-
LIGHTRAIL_PAYMENT_METHODS = self::LIGHTRAIL_CODE_KEYS + self::LIGHTRAIL_CARD_ID_KEYS + self::LIGHTRAIL_CONTACT_ID_KEYS + self::LIGHTRAIL_SHOPPER_ID_KEYS
|
19
|
-
|
20
|
-
LIGHTRAIL_TRANSACTION_TYPES = [:code_drawdown, :card_id_drawdown, :code_pending, :card_id_pending, :fund_card, :refund, :capture, :void]
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Contact < Lightrail::LightrailObject
|
3
|
-
|
4
|
-
def self.create(create_params)
|
5
|
-
params_with_user_supplied_id = self.set_user_supplied_id_for_contact_create(create_params)
|
6
|
-
params_with_name_if_present = self.set_name_if_present(params_with_user_supplied_id)
|
7
|
-
response = Lightrail::Connection.send :make_post_request_and_parse_response, "contacts", params_with_name_if_present
|
8
|
-
response['contact']
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.retrieve_by_shopper_id(shopper_id)
|
12
|
-
response = Lightrail::Connection.send :make_get_request_and_parse_response, "contacts?userSuppliedId=#{CGI::escape(shopper_id)}"
|
13
|
-
response['contacts'][0]
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.retrieve_by_contact_id(contact_id)
|
17
|
-
response = Lightrail::Connection.send :make_get_request_and_parse_response, "contacts/#{CGI::escape(contact_id)}"
|
18
|
-
response['contact']
|
19
|
-
end
|
20
|
-
|
21
|
-
# Utility methods
|
22
|
-
|
23
|
-
def self.retrieve_or_create_by_shopper_id(shopper_id)
|
24
|
-
contact = self.retrieve_by_shopper_id(shopper_id)
|
25
|
-
if !contact
|
26
|
-
contact = self.create({shopper_id: shopper_id})
|
27
|
-
end
|
28
|
-
contact
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.get_contact_id_from_id_or_shopper_id(charge_params)
|
32
|
-
if Lightrail::Validator.has_valid_contact_id?(charge_params)
|
33
|
-
return Lightrail::Validator.get_contact_id(charge_params)
|
34
|
-
end
|
35
|
-
|
36
|
-
if Lightrail::Validator.has_valid_shopper_id?(charge_params)
|
37
|
-
shopper_id = Lightrail::Validator.get_shopper_id(charge_params)
|
38
|
-
contact = self.get_by_shopper_id(shopper_id)
|
39
|
-
if (!contact.nil? && !contact.empty? && contact['contactId'])
|
40
|
-
return contact['contactId']
|
41
|
-
else
|
42
|
-
return nil
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
return nil
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def self.get_contact_id_from_shopper_id(shopper_id)
|
52
|
-
contact = self.retrieve_by_shopper_id(shopper_id)
|
53
|
-
contact['contactId']
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.set_user_supplied_id_for_contact_create(create_params)
|
57
|
-
params_with_user_supplied_id = create_params.clone
|
58
|
-
shopper_id = Lightrail::Validator.get_shopper_id(create_params) || nil
|
59
|
-
user_supplied_id = Lightrail::Validator.get_user_supplied_id(create_params) || nil
|
60
|
-
|
61
|
-
if !(shopper_id || user_supplied_id)
|
62
|
-
raise Lightrail::LightrailArgumentError.new("Must provide one of shopper_id or user_supplied_id to create new Contact")
|
63
|
-
elsif (shopper_id && user_supplied_id)
|
64
|
-
raise Lightrail::LightrailArgumentError.new("Must provide only one of shopper_id or user_supplied_id to create new Contact")
|
65
|
-
end
|
66
|
-
|
67
|
-
if shopper_id
|
68
|
-
params_with_user_supplied_id[:userSuppliedId] ||= shopper_id
|
69
|
-
elsif user_supplied_id
|
70
|
-
params_with_user_supplied_id[:userSuppliedId] ||= user_supplied_id
|
71
|
-
end
|
72
|
-
|
73
|
-
params_with_user_supplied_id
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.set_name_if_present(create_params)
|
77
|
-
params_with_name = create_params.clone
|
78
|
-
params_with_name[:firstName] ||= params_with_name[:first_name]
|
79
|
-
params_with_name[:lastName] ||= params_with_name[:last_name]
|
80
|
-
params_with_name
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.get_by_id(contact_id)
|
84
|
-
response = Lightrail::Connection.make_get_request_and_parse_response("contacts/#{CGI::escape(contact_id)}")
|
85
|
-
response['contact']
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.get_by_shopper_id(shopper_id)
|
89
|
-
response = Lightrail::Connection.make_get_request_and_parse_response("contacts?userSuppliedId=#{CGI::escape(shopper_id)}")
|
90
|
-
response['contacts'][0]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Ping < Lightrail::LightrailObject
|
3
|
-
attr_accessor :username, :mode, :scopes, :roles, :effectiveScopes
|
4
|
-
|
5
|
-
def self.ping
|
6
|
-
response = Lightrail::Connection.ping
|
7
|
-
Lightrail::Validator.validate_ping_response!(response)
|
8
|
-
self.new(response['user'])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Transaction < Lightrail::LightrailObject
|
3
|
-
attr_accessor :transactionId, :value, :userSuppliedId, :dateCreated, :transactionType, :transactionAccessMethod, :giftbitUserId, :cardId, :currency, :codeLastFour, :metadata, :parentTransactionId
|
4
|
-
|
5
|
-
def self.charge_code(transaction_params, simulate)
|
6
|
-
transaction_type = transaction_params[:pending] ? :code_pending : :code_drawdown
|
7
|
-
self.create(transaction_params, transaction_type, simulate)
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.charge_card(transaction_params, simulate)
|
11
|
-
transaction_type = transaction_params[:pending] ? :card_id_pending : :card_id_drawdown
|
12
|
-
self.create(transaction_params, transaction_type, simulate)
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.fund_card(transaction_params)
|
16
|
-
self.create(transaction_params, :card_id_fund, false)
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def self.refund (original_transaction_info, new_request_body={})
|
21
|
-
handle_transaction(original_transaction_info, 'refund', new_request_body)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.void (original_transaction_info, new_request_body={})
|
25
|
-
handle_transaction(original_transaction_info, 'void', new_request_body)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.capture (original_transaction_info, new_request_body={})
|
29
|
-
handle_transaction(original_transaction_info, 'capture', new_request_body)
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
# def self.simulate(transaction_params, transaction_type)
|
35
|
-
# transaction_params_for_lightrail = Lightrail::Validator.send("set_params_for_#{transaction_type}!", transaction_params)
|
36
|
-
# response = self.post_transaction(transaction_params_for_lightrail, true)
|
37
|
-
# end
|
38
|
-
|
39
|
-
def self.create(transaction_params, transaction_type, simulate)
|
40
|
-
transaction_params_for_lightrail = Lightrail::Validator.send("set_params_for_#{transaction_type}!", transaction_params)
|
41
|
-
response = self.post_transaction(transaction_params_for_lightrail, simulate)
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.handle_transaction (original_transaction_info, action, new_request_body={})
|
45
|
-
transaction_params_for_lightrail = Lightrail::Validator.set_params_for_acting_on_existing_transaction!(original_transaction_info, new_request_body)
|
46
|
-
response = self.act_on_transaction(transaction_params_for_lightrail, action)
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.post_transaction(transaction_params, simulate)
|
50
|
-
dry_run = simulate ? '/dryRun' : ''
|
51
|
-
response = {}
|
52
|
-
if (transaction_params[:code])
|
53
|
-
code = transaction_params.delete(:code)
|
54
|
-
response = Lightrail::Connection.send :make_post_request_and_parse_response, "codes/#{CGI::escape(code)}/transactions#{dry_run}", transaction_params
|
55
|
-
elsif (transaction_params[:cardId])
|
56
|
-
card_id = transaction_params.delete(:cardId)
|
57
|
-
response = Lightrail::Connection.send :make_post_request_and_parse_response, "cards/#{CGI::escape(card_id)}/transactions#{dry_run}", transaction_params
|
58
|
-
else
|
59
|
-
raise Lightrail::LightrailArgumentError.new("Lightrail code or cardId required to post a transaction: #{transaction_params.inspect}")
|
60
|
-
end
|
61
|
-
response['transaction']
|
62
|
-
end
|
63
|
-
|
64
|
-
def self.act_on_transaction(transaction_params, action)
|
65
|
-
response = {}
|
66
|
-
if (transaction_params[:cardId])
|
67
|
-
card_id = transaction_params.delete(:cardId)
|
68
|
-
transaction_id = transaction_params.delete(:transactionId)
|
69
|
-
response = Lightrail::Connection.send :make_post_request_and_parse_response, "cards/#{CGI::escape(card_id)}/transactions/#{CGI::escape(transaction_id)}/#{action}", transaction_params
|
70
|
-
else
|
71
|
-
raise Lightrail::LightrailArgumentError.new("Lightrail cardId required to act on an existing transaction: #{transaction_params.inspect}")
|
72
|
-
end
|
73
|
-
response['transaction']
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
@@ -1,317 +0,0 @@
|
|
1
|
-
module Lightrail
|
2
|
-
class Validator
|
3
|
-
def self.set_params_for_code_drawdown!(charge_params)
|
4
|
-
validated_params = charge_params.clone
|
5
|
-
begin
|
6
|
-
return validated_params if ((validated_params.is_a? Hash) &&
|
7
|
-
self.set_code!(validated_params, validated_params) &&
|
8
|
-
self.validate_amount!(validated_params[:amount] || validated_params[:value]) &&
|
9
|
-
self.validate_currency!(validated_params[:currency]) &&
|
10
|
-
self.get_or_set_userSuppliedId!(validated_params))
|
11
|
-
rescue Lightrail::LightrailArgumentError
|
12
|
-
end
|
13
|
-
raise Lightrail::LightrailArgumentError.new("Invalid charge_params for set_params_for_code_drawdown!: #{charge_params.inspect}")
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.set_params_for_code_pending!(charge_params)
|
17
|
-
begin
|
18
|
-
validated_params = self.set_params_for_code_drawdown!(charge_params)
|
19
|
-
validated_params[:pending] = true
|
20
|
-
return validated_params
|
21
|
-
rescue Lightrail::LightrailError
|
22
|
-
end
|
23
|
-
raise Lightrail::LightrailArgumentError.new("Invalid charge_params for set_params_for_code_pending!: #{charge_params.inspect}")
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.set_params_for_card_id_drawdown!(charge_params)
|
27
|
-
validated_params = charge_params.clone
|
28
|
-
begin
|
29
|
-
return validated_params if ((validated_params.is_a? Hash) &&
|
30
|
-
(self.set_cardId!(validated_params, validated_params) ||
|
31
|
-
Lightrail::Account.replace_contact_id_or_shopper_id_with_card_id(validated_params)) &&
|
32
|
-
self.validate_amount!(validated_params[:amount] || validated_params[:value]) &&
|
33
|
-
self.validate_currency!(validated_params[:currency]) &&
|
34
|
-
self.get_or_set_userSuppliedId!(validated_params))
|
35
|
-
rescue Lightrail::LightrailArgumentError
|
36
|
-
end
|
37
|
-
raise Lightrail::LightrailArgumentError.new("Invalid charge_params for set_params_for_card_id_drawdown!: #{charge_params.inspect}")
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.set_params_for_card_id_fund!(fund_params)
|
41
|
-
validated_params = fund_params.clone
|
42
|
-
begin
|
43
|
-
return validated_params if ((validated_params.is_a? Hash) &&
|
44
|
-
(self.set_cardId!(validated_params, validated_params) ||
|
45
|
-
Lightrail::Account.replace_contact_id_or_shopper_id_with_card_id(validated_params)) &&
|
46
|
-
self.validate_amount!(validated_params[:amount] || validated_params[:value]) &&
|
47
|
-
self.validate_currency!(validated_params[:currency]) &&
|
48
|
-
self.get_or_set_userSuppliedId!(validated_params))
|
49
|
-
rescue Lightrail::LightrailArgumentError
|
50
|
-
end
|
51
|
-
raise Lightrail::LightrailArgumentError.new("Invalid fund_params for set_params_for_card_id_fund!: #{fund_params.inspect}")
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.set_params_for_card_create!(create_params)
|
55
|
-
validated_params = create_params.clone
|
56
|
-
begin
|
57
|
-
return validated_params if ((validated_params.is_a? Hash) &&
|
58
|
-
self.validate_currency!(validated_params[:currency]) &&
|
59
|
-
self.has_valid_user_supplied_id?(validated_params) &&
|
60
|
-
validated_params[:userSuppliedId] ||= self.get_user_supplied_id(create_params))
|
61
|
-
rescue Lightrail::LightrailArgumentError
|
62
|
-
end
|
63
|
-
raise Lightrail::LightrailArgumentError.new("Invalid create_params for set_params_for_card_create!!: #{create_params.inspect}")
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.set_params_for_account_create!(create_account_params)
|
67
|
-
validated_params = create_account_params.clone
|
68
|
-
|
69
|
-
begin
|
70
|
-
return validated_params if ((validated_params.is_a? Hash) &&
|
71
|
-
self.set_userSuppliedId_from_existing!(validated_params, validated_params) &&
|
72
|
-
(self.has_valid_shopper_id?(validated_params) || self.has_valid_contact_id?(validated_params)) &&
|
73
|
-
self.validate_currency!(validated_params[:currency]) &&
|
74
|
-
Lightrail::Account.set_account_card_type(validated_params))
|
75
|
-
rescue Lightrail::LightrailArgumentError
|
76
|
-
end
|
77
|
-
raise Lightrail::LightrailArgumentError.new("Invalid create_account_params for set_params_for_account_create!: #{create_account_params.inspect}")
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.set_nsf_for_simulate!(charge_params)
|
81
|
-
params_for_simulate = charge_params.clone
|
82
|
-
if (!params_for_simulate.key?([:nsf]) && !params_for_simulate.key?(['nsf']))
|
83
|
-
params_for_simulate[:nsf] = false
|
84
|
-
end
|
85
|
-
params_for_simulate
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.set_params_for_card_id_pending!(charge_params)
|
89
|
-
begin
|
90
|
-
validated_params = self.set_params_for_card_id_drawdown!(charge_params)
|
91
|
-
validated_params[:pending] = true
|
92
|
-
return validated_params
|
93
|
-
rescue Lightrail::LightrailError
|
94
|
-
end
|
95
|
-
raise Lightrail::LightrailArgumentError.new("Invalid charge_params for set_params_for_card_id_pending!!: #{charge_params.inspect}")
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.set_params_for_acting_on_existing_transaction!(original_transaction, new_request_body={})
|
99
|
-
validated_params = new_request_body.clone
|
100
|
-
validated_params[:original_transaction] = original_transaction
|
101
|
-
begin
|
102
|
-
return validated_params if ((validated_params.is_a? Hash) &&
|
103
|
-
(validated_params[:original_transaction].is_a? Hash) &&
|
104
|
-
self.set_cardId!(validated_params, validated_params[:original_transaction]) &&
|
105
|
-
self.set_transactionId!(validated_params, validated_params[:original_transaction]) &&
|
106
|
-
self.get_or_set_userSuppliedId!(validated_params))
|
107
|
-
rescue Lightrail::LightrailArgumentError
|
108
|
-
end
|
109
|
-
raise Lightrail::LightrailArgumentError.new("Invalid params for set_params_for_acting_on_existing_transaction!: original_transaction: #{original_transaction.inspect}; new_request_body: #{new_request_body.inspect}")
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
def self.validate_charge_object! (charge_params)
|
114
|
-
begin
|
115
|
-
return true if (self.set_params_for_code_drawdown!(charge_params) if self.has_valid_code?(charge_params)) ||
|
116
|
-
(self.set_params_for_card_id_drawdown!(charge_params) if (self.has_valid_card_id?(charge_params) || self.has_valid_contact_id?(charge_params) || self.has_valid_shopper_id?(charge_params)))
|
117
|
-
rescue Lightrail::LightrailArgumentError
|
118
|
-
end
|
119
|
-
raise Lightrail::LightrailArgumentError.new("Invalid charge_params: #{charge_params.inspect}")
|
120
|
-
end
|
121
|
-
|
122
|
-
def self.validate_transaction_response! (transaction_response)
|
123
|
-
begin
|
124
|
-
return true if (transaction_response.is_a? Hash) &&
|
125
|
-
self.has_valid_transaction_id?(transaction_response) &&
|
126
|
-
self.has_valid_card_id?(transaction_response)
|
127
|
-
rescue Lightrail::LightrailArgumentError
|
128
|
-
end
|
129
|
-
raise Lightrail::LightrailArgumentError.new("Invalid transaction_response: #{transaction_response.inspect}")
|
130
|
-
end
|
131
|
-
|
132
|
-
def self.validate_fund_object! (fund_params)
|
133
|
-
begin
|
134
|
-
return true if (self.set_params_for_card_id_fund!(fund_params) if (self.has_valid_card_id?(fund_params) ||
|
135
|
-
self.has_valid_contact_id?(fund_params) || self.has_valid_shopper_id?(fund_params)))
|
136
|
-
rescue Lightrail::LightrailArgumentError
|
137
|
-
end
|
138
|
-
raise Lightrail::LightrailArgumentError.new("Invalid fund_params: #{fund_params.inspect}")
|
139
|
-
end
|
140
|
-
|
141
|
-
def self.validate_ping_response! (ping_response)
|
142
|
-
begin
|
143
|
-
return true if ((ping_response.is_a? Hash) &&
|
144
|
-
(ping_response['user'].is_a? Hash) &&
|
145
|
-
!ping_response['user'].empty? &&
|
146
|
-
self.validate_username!(ping_response['user']['username']))
|
147
|
-
rescue Lightrail::LightrailArgumentError
|
148
|
-
end
|
149
|
-
raise Lightrail::LightrailArgumentError.new("Invalid ping_response: #{ping_response.inspect}")
|
150
|
-
end
|
151
|
-
|
152
|
-
|
153
|
-
def self.validate_card_id! (card_id)
|
154
|
-
return true if ((card_id.is_a? String) && ((/\A[A-Z0-9\-]+\z/i =~ card_id).is_a? Integer))
|
155
|
-
raise Lightrail::LightrailArgumentError.new("Invalid card_id: #{card_id.inspect}")
|
156
|
-
end
|
157
|
-
|
158
|
-
def self.validate_code! (code)
|
159
|
-
return true if ((code.is_a? String) && ((/\A[A-Z0-9\-]+\z/i =~ code).is_a? Integer))
|
160
|
-
raise Lightrail::LightrailArgumentError.new("Invalid code: #{code.inspect}")
|
161
|
-
end
|
162
|
-
|
163
|
-
def self.validate_contact_id! (contact_id)
|
164
|
-
return true if ((contact_id.is_a? String) && ((/\A[A-Z0-9\-]+\z/i =~ contact_id).is_a? Integer))
|
165
|
-
raise Lightrail::LightrailArgumentError.new("Invalid contact_id: #{contact_id.inspect}")
|
166
|
-
end
|
167
|
-
|
168
|
-
def self.validate_shopper_id! (shopper_id)
|
169
|
-
return true if ((shopper_id.is_a? String) && ((/\A[A-Z0-9\-\@\.]+\z/i =~ shopper_id).is_a? Integer))
|
170
|
-
raise Lightrail::LightrailArgumentError.new("Invalid shopper_id: #{shopper_id.inspect}")
|
171
|
-
end
|
172
|
-
|
173
|
-
def self.validate_user_supplied_id! (user_supplied_id)
|
174
|
-
return true if (user_supplied_id.is_a? String)
|
175
|
-
raise Lightrail::LightrailArgumentError.new("Invalid user_supplied_id (must be a String): #{user_supplied_id.inspect} ")
|
176
|
-
end
|
177
|
-
|
178
|
-
def self.validate_transaction_id! (transaction_id)
|
179
|
-
return true if ((transaction_id.is_a? String) && !transaction_id.empty?)
|
180
|
-
raise Lightrail::LightrailArgumentError.new("Invalid transaction_id: #{transaction_id.inspect}")
|
181
|
-
end
|
182
|
-
|
183
|
-
def self.validate_amount! (amount)
|
184
|
-
return true if (amount.is_a? Integer)
|
185
|
-
raise Lightrail::LightrailArgumentError.new("Invalid amount: #{amount.inspect}")
|
186
|
-
end
|
187
|
-
|
188
|
-
def self.validate_currency! (currency)
|
189
|
-
return true if (/\A[A-Z]{3}\z/ === currency)
|
190
|
-
raise Lightrail::LightrailArgumentError.new("Invalid currency: #{currency.inspect}")
|
191
|
-
end
|
192
|
-
|
193
|
-
def self.validate_username!(username)
|
194
|
-
return true if ((username.is_a? String) && !username.empty?)
|
195
|
-
raise Lightrail::LightrailArgumentError.new("Invalid username: #{username.inspect}")
|
196
|
-
end
|
197
|
-
|
198
|
-
private
|
199
|
-
|
200
|
-
def self.set_code!(destination_params, source_params)
|
201
|
-
destination_params[:code] ||= self.has_valid_code?(source_params) ? self.get_code(source_params) : nil
|
202
|
-
end
|
203
|
-
|
204
|
-
def self.set_cardId!(destination_params, source_params)
|
205
|
-
destination_params[:cardId] ||= self.has_valid_card_id?(source_params) ? self.get_card_id(source_params) : nil
|
206
|
-
end
|
207
|
-
|
208
|
-
def self.set_transactionId!(destination_params, source_params)
|
209
|
-
destination_params[:transactionId] = self.has_valid_transaction_id?(source_params) ? self.get_transaction_id(source_params) : nil
|
210
|
-
end
|
211
|
-
|
212
|
-
def self.set_contactId_from_contact_or_shopper_id!(destination_params, source_params)
|
213
|
-
contact_id = Lightrail::Validator.has_valid_contact_id?(source_params) ? Lightrail::Validator.get_contact_id(source_params) : nil
|
214
|
-
shopper_id = Lightrail::Validator.has_valid_shopper_id?(source_params) ? Lightrail::Validator.get_shopper_id(source_params) : nil
|
215
|
-
|
216
|
-
raise Lightrail::LightrailArgumentError.new("Must set one of shopper_id or contact_id in #{source_params.inspect}.") unless shopper_id || contact_id
|
217
|
-
|
218
|
-
contact_id_from_shopper_id = shopper_id ? Lightrail::Contact.get_contact_id_from_shopper_id(shopper_id) : nil
|
219
|
-
|
220
|
-
if contact_id && contact_id_from_shopper_id && (contact_id != contact_id_from_shopper_id)
|
221
|
-
raise Lightrail::LightrailArgumentError.new("Error from set_contactId_from_contact_or_shopper_id!: received shopper_id #{shopper_id} and contact_id #{contact_id} which do not belong to the same contact.")
|
222
|
-
end
|
223
|
-
|
224
|
-
destination_params[:contactId] = contact_id || contact_id_from_shopper_id
|
225
|
-
end
|
226
|
-
|
227
|
-
def self.set_userSuppliedId_from_existing!(destination_params, source_params)
|
228
|
-
destination_params[:userSuppliedId] ||= self.has_valid_user_supplied_id?(source_params) ? self.get_user_supplied_id(source_params) : nil
|
229
|
-
end
|
230
|
-
|
231
|
-
def self.get_or_set_userSuppliedId!(charge_params)
|
232
|
-
charge_params[:userSuppliedId] ||= self.get_or_create_user_supplied_id(charge_params)
|
233
|
-
end
|
234
|
-
|
235
|
-
|
236
|
-
def self.has_valid_code?(charge_params)
|
237
|
-
code = (charge_params.respond_to? :keys) ? self.get_code(charge_params) : false
|
238
|
-
code && self.validate_code!(code)
|
239
|
-
end
|
240
|
-
|
241
|
-
def self.has_valid_card_id?(charge_params)
|
242
|
-
cardId = (charge_params.respond_to? :keys) ? self.get_card_id(charge_params) : false
|
243
|
-
cardId && self.validate_card_id!(cardId)
|
244
|
-
end
|
245
|
-
|
246
|
-
def self.has_valid_contact_id?(charge_params)
|
247
|
-
contactId = (charge_params.respond_to? :keys) ? self.get_contact_id(charge_params) : false
|
248
|
-
contactId && self.validate_contact_id!(contactId)
|
249
|
-
end
|
250
|
-
|
251
|
-
def self.has_valid_shopper_id?(charge_params)
|
252
|
-
shopperId = (charge_params.respond_to? :keys) ? self.get_shopper_id(charge_params) : false
|
253
|
-
shopperId && self.validate_shopper_id!(shopperId)
|
254
|
-
end
|
255
|
-
|
256
|
-
def self.has_valid_or_empty_shopper_id?(charge_params)
|
257
|
-
shopperId = (charge_params.respond_to? :keys) ? self.get_shopper_id(charge_params) : false
|
258
|
-
shopperId && (shopperId === '' || self.validate_shopper_id!(shopperId))
|
259
|
-
end
|
260
|
-
|
261
|
-
def self.has_valid_user_supplied_id?(params)
|
262
|
-
userSuppliedId = (params.respond_to? :keys) ? self.get_user_supplied_id(params) : false
|
263
|
-
userSuppliedId && self.validate_user_supplied_id!(userSuppliedId)
|
264
|
-
end
|
265
|
-
|
266
|
-
def self.has_valid_transaction_id?(charge_params)
|
267
|
-
transactionId = (charge_params.respond_to? :keys) ? self.get_transaction_id(charge_params) : false
|
268
|
-
transactionId && self.validate_transaction_id!(transactionId)
|
269
|
-
end
|
270
|
-
|
271
|
-
|
272
|
-
def self.get_card_id(charge_params)
|
273
|
-
card_id_key = (charge_params.keys & Lightrail::Constants::LIGHTRAIL_CARD_ID_KEYS).first
|
274
|
-
charge_params[card_id_key]
|
275
|
-
end
|
276
|
-
|
277
|
-
def self.get_code(charge_params)
|
278
|
-
code_key = (charge_params.keys & Lightrail::Constants::LIGHTRAIL_CODE_KEYS).first
|
279
|
-
charge_params[code_key]
|
280
|
-
end
|
281
|
-
|
282
|
-
def self.get_contact_id(charge_params)
|
283
|
-
contact_id_key = (charge_params.keys & Lightrail::Constants::LIGHTRAIL_CONTACT_ID_KEYS).first
|
284
|
-
charge_params[contact_id_key]
|
285
|
-
end
|
286
|
-
|
287
|
-
def self.get_shopper_id(charge_params)
|
288
|
-
shopper_id_key = (charge_params.keys & Lightrail::Constants::LIGHTRAIL_SHOPPER_ID_KEYS).first
|
289
|
-
charge_params[shopper_id_key]
|
290
|
-
end
|
291
|
-
|
292
|
-
def self.get_transaction_id(charge_params)
|
293
|
-
transaction_id_key = (charge_params.keys & Lightrail::Constants::LIGHTRAIL_TRANSACTION_ID_KEYS).first
|
294
|
-
charge_params[transaction_id_key]
|
295
|
-
end
|
296
|
-
|
297
|
-
def self.get_code_or_card_id_key(charge_params)
|
298
|
-
(charge_params.keys & Lightrail::Constants::LIGHTRAIL_PAYMENT_METHODS).first
|
299
|
-
end
|
300
|
-
|
301
|
-
def self.get_user_supplied_id(params)
|
302
|
-
user_supplied_id_key = (params.keys & Lightrail::Constants::LIGHTRAIL_USER_SUPPLIED_ID_KEYS).first
|
303
|
-
params[user_supplied_id_key]
|
304
|
-
end
|
305
|
-
|
306
|
-
def self.get_or_create_user_supplied_id(charge_params)
|
307
|
-
user_supplied_id_key = (charge_params.keys & Lightrail::Constants::LIGHTRAIL_USER_SUPPLIED_ID_KEYS).first
|
308
|
-
charge_params[user_supplied_id_key] || SecureRandom::uuid
|
309
|
-
end
|
310
|
-
|
311
|
-
def self.get_or_create_user_supplied_id_with_action_suffix(charge_params, new_user_supplied_id_base, action_suffix)
|
312
|
-
user_supplied_id_key = (charge_params.keys & Lightrail::Constants::LIGHTRAIL_USER_SUPPLIED_ID_KEYS).first
|
313
|
-
charge_params[user_supplied_id_key] || "#{new_user_supplied_id_base}-#{action_suffix}"
|
314
|
-
end
|
315
|
-
|
316
|
-
end
|
317
|
-
end
|