CroemincRubyGem 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.idea/.gitignore +3 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/MetropagoRubyGem.iml +19 -0
- data/.idea/inspectionProfiles/Project_Default.xml +6 -0
- data/.idea/metropago-gateway-rubygem-sdk.iml +19 -0
- data/.idea/misc.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/CroemincRubyGem.gemspec +42 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/Rakefile +6 -0
- data/SDKDemo.rb +464 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/Catalogs/environment_type.rb +3 -0
- data/lib/Certificates/ca-bundle.crt +3866 -0
- data/lib/Config/application.yml +2 -0
- data/lib/CroemincRubyGem/version.rb +3 -0
- data/lib/CroemincRubyGem.rb +13 -0
- data/lib/Entities/ach.rb +37 -0
- data/lib/Entities/address.rb +97 -0
- data/lib/Entities/amount_range_filter.rb +60 -0
- data/lib/Entities/base_entity.rb +15 -0
- data/lib/Entities/beneficiary.rb +89 -0
- data/lib/Entities/credit_card.rb +150 -0
- data/lib/Entities/customer.rb +218 -0
- data/lib/Entities/customer_entity.rb +130 -0
- data/lib/Entities/customer_entity_response.rb +79 -0
- data/lib/Entities/customer_response.rb +90 -0
- data/lib/Entities/customer_search.rb +80 -0
- data/lib/Entities/customer_search_option.rb +55 -0
- data/lib/Entities/date_range_filter.rb +59 -0
- data/lib/Entities/instruction.rb +136 -0
- data/lib/Entities/instruction_response.rb +63 -0
- data/lib/Entities/instrument.rb +73 -0
- data/lib/Entities/instrument_response.rb +70 -0
- data/lib/Entities/request_model.rb +80 -0
- data/lib/Entities/response_model.rb +39 -0
- data/lib/Entities/service.rb +70 -0
- data/lib/Entities/text_filter.rb +45 -0
- data/lib/Entities/transaction.rb +162 -0
- data/lib/Entities/transaction_options.rb +49 -0
- data/lib/Entities/transaction_response.rb +79 -0
- data/lib/Entities/transaction_search_request.rb +57 -0
- data/lib/Entities/validation_error.rb +60 -0
- data/lib/Entities/wallet.rb +20 -0
- data/lib/Gateway/croeminc_gateway.rb +56 -0
- data/lib/Helpers/api_helper.rb +96 -0
- data/lib/Helpers/jso_nable.rb +56 -0
- data/lib/Helpers/model_parser.rb +235 -0
- data/lib/Managers/customer_manager.rb +148 -0
- data/lib/Managers/transaction_manager.rb +264 -0
- data/lib/MetropagoRubyGem/version.rb +3 -0
- data/lib/Test/customer_operations.rb +395 -0
- data/lib/Test/transaction_operations.rb +259 -0
- metadata +146 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../Helpers/jso_nable'
|
2
|
+
class ValidationError < JSONable
|
3
|
+
|
4
|
+
#private int Count;
|
5
|
+
#private String ErrorSummary;
|
6
|
+
#private String ErrorDescription;
|
7
|
+
#private List<ValidationError> ErrorDetails;
|
8
|
+
|
9
|
+
def initialize(h = nil)
|
10
|
+
|
11
|
+
if(h != nil)
|
12
|
+
h.each {
|
13
|
+
|k,v|
|
14
|
+
|
15
|
+
propNameFormatted = k.to_s + "="
|
16
|
+
|
17
|
+
|
18
|
+
if(ValidationError.instance_methods(false).include?(propNameFormatted.to_sym))
|
19
|
+
public_send("#{k}=",v)
|
20
|
+
end
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def Count=(count)
|
27
|
+
@count = count
|
28
|
+
end
|
29
|
+
|
30
|
+
def ErrorSummary=(errorSummary)
|
31
|
+
@errorSummary = errorSummary
|
32
|
+
end
|
33
|
+
|
34
|
+
def ErrorDescription=(errorDescription)
|
35
|
+
@errorDescription = errorDescription
|
36
|
+
end
|
37
|
+
|
38
|
+
def ErrorDetails=(errorDetails) #list<ValidationError>
|
39
|
+
@errorDetails = errorDetails
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
#Getters
|
44
|
+
def getCount
|
45
|
+
return @count
|
46
|
+
end
|
47
|
+
|
48
|
+
def getErrorSummary
|
49
|
+
return @errorSummary
|
50
|
+
end
|
51
|
+
|
52
|
+
def getErrorDescription
|
53
|
+
return @errorDescription
|
54
|
+
end
|
55
|
+
|
56
|
+
def getErrorDetails
|
57
|
+
return @errorDetails
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../Entities/instrument'
|
2
|
+
class Wallet < Instrument
|
3
|
+
|
4
|
+
def WalletNumber=(walletNumber)
|
5
|
+
@walletNumber = walletNumber
|
6
|
+
end
|
7
|
+
|
8
|
+
def WalletHolder=(walletHolder)
|
9
|
+
@walletHolder = walletHolder
|
10
|
+
end
|
11
|
+
|
12
|
+
def WalletBalance=(walletBalance) #double type
|
13
|
+
@walletBalance = walletBalance
|
14
|
+
end
|
15
|
+
|
16
|
+
#private String WalletNumber;
|
17
|
+
#private String WalletHolder;
|
18
|
+
#private double WalletBalance;
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative '../Catalogs/environment_type'
|
2
|
+
require 'yaml'
|
3
|
+
class CroemincGateway
|
4
|
+
|
5
|
+
def initialize(envrionment, merchantId, terminalId, secretKey) # terminalId, publicKey, privateKey, culture)
|
6
|
+
@envrionment = envrionment
|
7
|
+
@merchantId = merchantId
|
8
|
+
@terminalId = terminalId
|
9
|
+
@publicKey = secretKey
|
10
|
+
@privateKey = ""
|
11
|
+
@sdkVersion = "1.0"
|
12
|
+
#@culture = "en"
|
13
|
+
|
14
|
+
#set gateway API url
|
15
|
+
if(envrionment == EnvironmentType::SANDBOX.to_str)
|
16
|
+
@gatewayURL = "http://securegateway.merchantprocess.net/NeoGatewayAPI_Test/api/"
|
17
|
+
|
18
|
+
#TLS Enabled server
|
19
|
+
#@gatewayURL = "https://gateway12.merchantprocess.net/sdk/api/"
|
20
|
+
|
21
|
+
|
22
|
+
else if(envrionment == EnvironmentType::PRODUCTION.to_str)
|
23
|
+
@gatewayURL = "https://gateway.merchantprocess.net/api/prod-v1.0/api/"
|
24
|
+
|
25
|
+
else
|
26
|
+
raise "Invalid Enviroment"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
#Logs enabled?
|
32
|
+
env = 'development'
|
33
|
+
# config = YAML::load(File.open('Config/application.yml'))[env]
|
34
|
+
# if(config["enable_logs"] != nil && config["enable_logs"] == true)
|
35
|
+
# @enableLogs = true
|
36
|
+
# else
|
37
|
+
# @enableLogs = false
|
38
|
+
# end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def GatewayURL=(gatewayURL)
|
43
|
+
@gatewayURL = gatewayURL
|
44
|
+
end
|
45
|
+
|
46
|
+
def EnableLogs=(enableLogs)
|
47
|
+
@enableLogs = enableLogs
|
48
|
+
end
|
49
|
+
|
50
|
+
def Culture=(culture)
|
51
|
+
@culture = culture
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'openssl'
|
4
|
+
require 'uri'
|
5
|
+
require_relative '../Entities/request_model'
|
6
|
+
require_relative '../Entities/response_model'
|
7
|
+
class APIHelper
|
8
|
+
|
9
|
+
def SendAPIRequest(requestData, requestURL)
|
10
|
+
#response = RestClient.get requestURL, {:params => {:id => 50, 'foo' => 'bar'}}
|
11
|
+
#RestClient.post()
|
12
|
+
|
13
|
+
begin
|
14
|
+
|
15
|
+
#check if logs enabled
|
16
|
+
if(requestData.getEnableLogs == true)
|
17
|
+
@logsEnabled = true
|
18
|
+
else
|
19
|
+
@logsEnabled = false
|
20
|
+
end
|
21
|
+
|
22
|
+
#puts requestData.instance_variable_get("@requestMessage").to_json
|
23
|
+
reqJson = requestData.to_json
|
24
|
+
|
25
|
+
if(@logsEnabled == true)
|
26
|
+
LogAPIDetails("URL", requestURL.to_s)
|
27
|
+
LogAPIDetails("REQ", reqJson)
|
28
|
+
end
|
29
|
+
|
30
|
+
uri = URI(requestURL)
|
31
|
+
|
32
|
+
|
33
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
34
|
+
|
35
|
+
if(requestURL.include?("https:"))
|
36
|
+
|
37
|
+
http.use_ssl = true
|
38
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
39
|
+
|
40
|
+
#gems/certified-1.0.0/certs/ca-bundle.crt"
|
41
|
+
http.ca_file = File.expand_path("../../", __FILE__) + "/Certificates/ca-bundle.crt"
|
42
|
+
|
43
|
+
#http.ssl_version = :TLSv1_2 #TLSv1_1
|
44
|
+
http.ssl_version = :SSLv23
|
45
|
+
#:SSLv23 has fallback feature
|
46
|
+
end
|
47
|
+
|
48
|
+
req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})
|
49
|
+
req.body = reqJson #{param1: 'some value', param2: 'some other value'}.to_json
|
50
|
+
#puts req.body
|
51
|
+
|
52
|
+
#res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
53
|
+
# http.request(req)
|
54
|
+
#end
|
55
|
+
|
56
|
+
res = http.request(req)
|
57
|
+
|
58
|
+
#puts res.body
|
59
|
+
responseModel = ResponseModel.new
|
60
|
+
responseModel.from_json!(res.body) #will require same deserialization ResponseMessage prop, in corresponding manager/method
|
61
|
+
|
62
|
+
|
63
|
+
if(@logsEnabled == true)
|
64
|
+
LogAPIDetails("RES", responseModel.to_json)
|
65
|
+
end
|
66
|
+
|
67
|
+
return responseModel
|
68
|
+
|
69
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
70
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
71
|
+
puts e.http_body
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
def LogsEnabled=(logsEnabled)
|
79
|
+
@logsEnabled = logsEnabled
|
80
|
+
end
|
81
|
+
|
82
|
+
#Private Methods
|
83
|
+
private
|
84
|
+
def LogAPIDetails(type, content)
|
85
|
+
|
86
|
+
timeStamp = Time.now.strftime("%d/%m/%Y %H:%M")
|
87
|
+
logLine = timeStamp.to_s + ": " + type.to_s + ": " + content.to_s
|
88
|
+
|
89
|
+
out_file = File.new("request_logs.txt", "a")
|
90
|
+
out_file.puts(logLine)
|
91
|
+
|
92
|
+
out_file.close
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class JSONable
|
2
|
+
def to_json
|
3
|
+
hash = {}
|
4
|
+
self.instance_variables.each do |var|
|
5
|
+
hash[var] = self.instance_variable_get var
|
6
|
+
end
|
7
|
+
|
8
|
+
hash.keys.each do |k|
|
9
|
+
if(k[0,1] == '@')
|
10
|
+
#k[1] = k[1].upcase
|
11
|
+
tempUp = k[1].upcase
|
12
|
+
hash[tempUp + k[2, k.length - 1]] = hash[k]
|
13
|
+
hash.delete(k)
|
14
|
+
#puts k[0]
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
hash.to_json
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
instance_variables.map do |iv|
|
24
|
+
value = instance_variable_get(:"#{iv}")
|
25
|
+
[
|
26
|
+
iv.to_s[1..-1], # name without leading `@`
|
27
|
+
case value
|
28
|
+
when JSONable then value.to_h # Base instance? convert deeply
|
29
|
+
when Array # Array? convert elements
|
30
|
+
value.map do |e|
|
31
|
+
e.respond_to?(:to_h) ? e.to_h : e
|
32
|
+
end
|
33
|
+
else value # seems to be non-convertable, put as is
|
34
|
+
end
|
35
|
+
]
|
36
|
+
end.to_h
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
def from_json! string
|
42
|
+
JSON.load(string).each do |var, val|
|
43
|
+
|
44
|
+
#need to replace first letter with '@' + <firstletter>
|
45
|
+
|
46
|
+
fChar = "@" + var[0].downcase
|
47
|
+
varTrim = var[1..-1]
|
48
|
+
var = fChar + varTrim
|
49
|
+
#puts 'VARR: ' + var + '\n'
|
50
|
+
#puts val
|
51
|
+
|
52
|
+
self.instance_variable_set var, val
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
require_relative '../Entities/request_model'
|
2
|
+
require_relative '../Gateway/Croeminc_gateway'
|
3
|
+
require_relative '../Entities/response_model'
|
4
|
+
require_relative '../Entities/instrument_response'
|
5
|
+
require_relative '../Entities/service'
|
6
|
+
require_relative '../Entities/beneficiary'
|
7
|
+
require_relative '../Entities/customer_entity_response'
|
8
|
+
require 'json'
|
9
|
+
|
10
|
+
class ModelParser
|
11
|
+
|
12
|
+
|
13
|
+
def ParseCustomerObject(objHashed)
|
14
|
+
|
15
|
+
|
16
|
+
#puts objHashed
|
17
|
+
buffCustomer = Customer.new(objHashed)
|
18
|
+
|
19
|
+
#Parse and populate CreditCards
|
20
|
+
if(buffCustomer.instance_variable_get("@creditCards"))
|
21
|
+
#puts 'Has Creditcards'
|
22
|
+
|
23
|
+
cardsArr = buffCustomer.instance_variable_get("@creditCards")
|
24
|
+
cardsList = []
|
25
|
+
|
26
|
+
cardsArr.each do |c|
|
27
|
+
|
28
|
+
buffCard = CreditCard.new(c)
|
29
|
+
cardsList << buffCard
|
30
|
+
end
|
31
|
+
|
32
|
+
buffCustomer.CreditCards = cardsList
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
#Parse and populate Accounts
|
37
|
+
if(buffCustomer.instance_variable_get("@customerEntities"))
|
38
|
+
#puts 'Has Accounts'
|
39
|
+
|
40
|
+
accountsArr = buffCustomer.instance_variable_get("@customerEntities")
|
41
|
+
accountsList = []
|
42
|
+
|
43
|
+
accountsArr.each do |acc|
|
44
|
+
|
45
|
+
buffAccount = CustomerEntity.new(acc)
|
46
|
+
|
47
|
+
#parse beneficiary and services
|
48
|
+
benificHashed = buffAccount.instance_variable_get("@entityBeneficiary")
|
49
|
+
accBeneficiary = ParseCustomerBeneficiary(benificHashed)
|
50
|
+
|
51
|
+
buffAccount.EntityBeneficiary = accBeneficiary
|
52
|
+
|
53
|
+
entityRespHashed = buffAccount.instance_variable_get("@responseDetails")
|
54
|
+
custEntResponse = ParseCustomerEntityResponse(entityRespHashed)
|
55
|
+
|
56
|
+
buffAccount.ResponseDetails = custEntResponse
|
57
|
+
|
58
|
+
accountsList << buffAccount
|
59
|
+
|
60
|
+
end
|
61
|
+
buffCustomer.CustomerEntities = accountsList
|
62
|
+
end
|
63
|
+
|
64
|
+
#Parse and populate paymentInstructions
|
65
|
+
if(buffCustomer.instance_variable_get("@paymentInstructions"))
|
66
|
+
|
67
|
+
instructionsArr = buffCustomer.instance_variable_get("@paymentInstructions")
|
68
|
+
instructionsList = []
|
69
|
+
|
70
|
+
instructionsArr.each do |inst|
|
71
|
+
|
72
|
+
buffInstruction = Instruction.new(inst)
|
73
|
+
instructionsList << buffInstruction
|
74
|
+
|
75
|
+
end
|
76
|
+
buffCustomer.PaymentInstructions = instructionsList
|
77
|
+
end
|
78
|
+
|
79
|
+
#Parse and populate ACHs
|
80
|
+
if(buffCustomer.instance_variable_get("@aCHs"))
|
81
|
+
#puts 'Has ACHs'
|
82
|
+
|
83
|
+
achsArr = buffCustomer.instance_variable_get("@aCHs")
|
84
|
+
achsList = []
|
85
|
+
|
86
|
+
achsArr.each do |ach|
|
87
|
+
|
88
|
+
buffAch = ACH.new(ach)
|
89
|
+
|
90
|
+
resDetail = buffAch.instance_variable_get("@responseDetails")
|
91
|
+
instrumentResp = InstrumentResponse.new(resDetail)
|
92
|
+
|
93
|
+
#parse instrumentResp.ValidationErrors
|
94
|
+
valErrs = instrumentResp.instance_variable_get("@validationErrors")
|
95
|
+
instrumentResp.ValidationErrors = ValidationError.new(valErrs)
|
96
|
+
|
97
|
+
|
98
|
+
buffAch.ResponseDetails = instrumentResp
|
99
|
+
|
100
|
+
achsList << buffAch
|
101
|
+
|
102
|
+
end
|
103
|
+
buffCustomer.ACHs = achsList
|
104
|
+
end
|
105
|
+
|
106
|
+
#Parse and populate billing Addresses
|
107
|
+
if(buffCustomer.instance_variable_get("@billingAddress"))
|
108
|
+
|
109
|
+
|
110
|
+
billingAddressArr = buffCustomer.instance_variable_get("@billingAddress")
|
111
|
+
billingAddressArrList = []
|
112
|
+
|
113
|
+
billingAddressArr.each do |ba|
|
114
|
+
|
115
|
+
buffBillAddr = Address.new(ba)
|
116
|
+
billingAddressArrList << buffBillAddr
|
117
|
+
|
118
|
+
end
|
119
|
+
buffCustomer.BillingAddress = billingAddressArrList
|
120
|
+
end
|
121
|
+
|
122
|
+
#Parse and populate shipping Addresses
|
123
|
+
if(buffCustomer.instance_variable_get("@shippingAddress"))
|
124
|
+
|
125
|
+
shippingAddressArr = buffCustomer.instance_variable_get("@shippingAddress")
|
126
|
+
shippingAddressList = []
|
127
|
+
|
128
|
+
shippingAddressArr.each do |sa|
|
129
|
+
|
130
|
+
buffShipAddr = Address.new(sa)
|
131
|
+
shippingAddressList << buffShipAddr
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
buffCustomer.ShippingAddress = shippingAddressList
|
136
|
+
end
|
137
|
+
|
138
|
+
#Parse and populate ResponseDetails
|
139
|
+
if(buffCustomer.instance_variable_get("@responseDetails"))
|
140
|
+
#puts 'HAS RESPONSE DETAILS'
|
141
|
+
|
142
|
+
responseDetails = buffCustomer.instance_variable_get("@responseDetails")
|
143
|
+
buffResponseDet = CustomerResponse.new(responseDetails)
|
144
|
+
|
145
|
+
#parse inner model as well
|
146
|
+
validationErrors = buffResponseDet.instance_variable_get("@validationErrors")
|
147
|
+
buffValisationErrors = ValidationError.new(validationErrors)
|
148
|
+
buffResponseDet.ValidationErrors = buffValisationErrors
|
149
|
+
|
150
|
+
buffCustomer.ResponseDetails = buffResponseDet
|
151
|
+
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
#Parse and populate Options
|
156
|
+
if(buffCustomer.instance_variable_get("@options"))
|
157
|
+
#puts 'HAS OPTIONS'
|
158
|
+
|
159
|
+
options = buffCustomer.instance_variable_get("@options")
|
160
|
+
buffOptions = CustomerResponse.new(options)
|
161
|
+
|
162
|
+
#parse inner model as well
|
163
|
+
validationErrors = buffOptions.instance_variable_get("@validationErrors")
|
164
|
+
buffValisationErrors = ValidationError.new(validationErrors)
|
165
|
+
buffOptions.ValidationErrors = buffValisationErrors
|
166
|
+
|
167
|
+
buffCustomer.Options = buffOptions
|
168
|
+
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
return buffCustomer
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
def ParseCustomerBeneficiary(benificiaryHashed)
|
179
|
+
|
180
|
+
beneficiary = Beneficiary.new(benificiaryHashed)
|
181
|
+
|
182
|
+
#parse Services
|
183
|
+
if(beneficiary)
|
184
|
+
|
185
|
+
servicesArr = beneficiary.instance_variable_get("@services")
|
186
|
+
|
187
|
+
servicesLst = []
|
188
|
+
if(servicesArr)
|
189
|
+
servicesArr.each do |ser|
|
190
|
+
|
191
|
+
buffService = Service.new(ser)
|
192
|
+
servicesLst << buffService
|
193
|
+
|
194
|
+
end
|
195
|
+
end
|
196
|
+
beneficiary.Services = servicesLst
|
197
|
+
end
|
198
|
+
|
199
|
+
return beneficiary
|
200
|
+
end
|
201
|
+
|
202
|
+
def ParseCustomerEntityResponse(entityResponseHashed)
|
203
|
+
|
204
|
+
custEntResp = CustomerEntityResponse.new(entityResponseHashed)
|
205
|
+
|
206
|
+
validationErrs = custEntResp.instance_variable_get("@validationErrors")
|
207
|
+
|
208
|
+
respValidationErrs = ValidationError.new(validationErrs)
|
209
|
+
|
210
|
+
if(respValidationErrs.instance_variable_get("@errorDetails"))
|
211
|
+
|
212
|
+
errDetailsArr = respValidationErrs.instance_variable_get("@errorDetails")
|
213
|
+
if(errDetailsArr)
|
214
|
+
|
215
|
+
validationErrsList = []
|
216
|
+
errDetailsArr.each do |ed|
|
217
|
+
|
218
|
+
vErr = ValidationError.new(ed)
|
219
|
+
validationErrsList << vErr
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
respValidationErrs.ErrorDetails = validationErrsList
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
end
|
228
|
+
|
229
|
+
custEntResp.ValidationErrors = respValidationErrs
|
230
|
+
|
231
|
+
return custEntResp
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require_relative '../Helpers/api_helper'
|
2
|
+
require_relative '../Entities/request_model'
|
3
|
+
require_relative '../Gateway/Croeminc_gateway'
|
4
|
+
require_relative '../Entities/response_model'
|
5
|
+
require_relative '../Entities/instrument_response'
|
6
|
+
require_relative '../Entities/service'
|
7
|
+
require_relative '../Entities/beneficiary'
|
8
|
+
require_relative '../Entities/customer_entity_response'
|
9
|
+
require_relative '../Helpers/model_parser'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
class CustomerManager
|
13
|
+
def initialize(CroemincGatewayObject)
|
14
|
+
@CroemincGatewayObject = CroemincGatewayObject
|
15
|
+
end
|
16
|
+
|
17
|
+
#Save Customer
|
18
|
+
def SaveCustomer(customerObject)
|
19
|
+
|
20
|
+
return SaveCustomerInternal(customerObject)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
#Update Customer
|
25
|
+
def UpdateCustomer(customerObject)
|
26
|
+
|
27
|
+
return SaveCustomerInternal(customerObject)
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
#Search Customer
|
32
|
+
#Returns List of Customer objects
|
33
|
+
def SearchCustomer(customerFilters) #CustomerSearch type
|
34
|
+
reqData = CreateRequestObject(customerFilters)
|
35
|
+
apiHelper = APIHelper.new
|
36
|
+
responseModel = ResponseModel.new
|
37
|
+
responseModel = apiHelper.SendAPIRequest(reqData, @CroemincGatewayObject.instance_variable_get("@gatewayURL") + "Customer/GetCustomersByFilter")
|
38
|
+
|
39
|
+
#if response object is not nill, and
|
40
|
+
# response.ResponseMessage (customer model) is
|
41
|
+
# not nill, deserialize it.
|
42
|
+
|
43
|
+
if (responseModel && responseModel.instance_variable_get("@responseMessage"))
|
44
|
+
|
45
|
+
#puts "RESULT-INSIDE: " + responseModel.instance_variable_get("@responseMessage")
|
46
|
+
|
47
|
+
#Search Customers returns array of customers from API
|
48
|
+
responseMsgArr = responseModel.instance_variable_get("@responseMessage")
|
49
|
+
|
50
|
+
#if(responseMsg.instance_of? Array)
|
51
|
+
# puts "ITS ARRAY!"
|
52
|
+
#else
|
53
|
+
# puts "ITS OBJECT!"
|
54
|
+
#end
|
55
|
+
|
56
|
+
customersList = []
|
57
|
+
|
58
|
+
modelParsingHelper = ModelParser.new
|
59
|
+
|
60
|
+
objArray = JSON.parse(responseMsgArr)
|
61
|
+
objArray.each do |obj|
|
62
|
+
|
63
|
+
buffCustomer = modelParsingHelper.ParseCustomerObject(obj)
|
64
|
+
if(buffCustomer)
|
65
|
+
customersList << buffCustomer
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
return customersList
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def GetCustomerByIdentifier(identifer)
|
78
|
+
custSearch = CustomerSearch.new
|
79
|
+
custSearchOpts = CustomerSearchOption.new
|
80
|
+
|
81
|
+
custSearch.UniqueIdentifier = identifer
|
82
|
+
|
83
|
+
custSearchOpts.IncludeAll = false
|
84
|
+
custSearchOpts.IncludeAssociatedEntities = true
|
85
|
+
custSearchOpts.IncludeCardInstruments = true
|
86
|
+
custSearchOpts.IncludePaymentInstructions = true
|
87
|
+
|
88
|
+
custSearch.SearchOption = custSearchOpts
|
89
|
+
|
90
|
+
foundCustomersList = SearchCustomer(custSearch)
|
91
|
+
|
92
|
+
customer = Customer.new
|
93
|
+
customer = foundCustomersList[0];
|
94
|
+
|
95
|
+
return customer
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
#Private Methods
|
100
|
+
private
|
101
|
+
|
102
|
+
def SaveCustomerInternal(cutomerObject)
|
103
|
+
|
104
|
+
reqData = CreateRequestObject(cutomerObject)
|
105
|
+
apiHelper = APIHelper.new
|
106
|
+
responseModel = ResponseModel.new
|
107
|
+
responseModel = apiHelper.SendAPIRequest(reqData, @CroemincGatewayObject.instance_variable_get("@gatewayURL") + "Customer/SaveCustomerInformation")
|
108
|
+
|
109
|
+
modelParsingHelper = ModelParser.new
|
110
|
+
|
111
|
+
#if response object is not nill, and
|
112
|
+
# response.ResponseMessage (customer model) is
|
113
|
+
# not nill, deserialize it.
|
114
|
+
|
115
|
+
if (responseModel && responseModel.instance_variable_get("@responseMessage"))
|
116
|
+
|
117
|
+
#responseCustomerObj.from_json!(responseModel.instance_variable_get("@responseMessage"))
|
118
|
+
|
119
|
+
|
120
|
+
responseMsg = responseModel.instance_variable_get("@responseMessage")
|
121
|
+
responseCustomerHashed = JSON.parse(responseMsg)
|
122
|
+
responseCustomerObj = modelParsingHelper.ParseCustomerObject(responseCustomerHashed)
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
return responseCustomerObj
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
def CreateRequestObject(object)
|
132
|
+
requestData = RequestModel.new
|
133
|
+
requestData.TerminalId = @CroemincGatewayObject.instance_variable_get("@terminalId")
|
134
|
+
requestData.Identification = @CroemincGatewayObject.instance_variable_get("@merchantId")
|
135
|
+
requestData.SDKVersion = @CroemincGatewayObject.instance_variable_get("@sdkVersion")
|
136
|
+
requestData.Culture = @CroemincGatewayObject.instance_variable_get("@culture")
|
137
|
+
requestData.EnableLogs = @CroemincGatewayObject.instance_variable_get("@enableLogs")
|
138
|
+
requestData.RequestMessage = JSON.dump object.to_h
|
139
|
+
|
140
|
+
return requestData
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
end
|