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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.idea/.gitignore +3 -0
  4. data/.idea/.rakeTasks +7 -0
  5. data/.idea/MetropagoRubyGem.iml +19 -0
  6. data/.idea/inspectionProfiles/Project_Default.xml +6 -0
  7. data/.idea/metropago-gateway-rubygem-sdk.iml +19 -0
  8. data/.idea/misc.xml +7 -0
  9. data/.idea/modules.xml +8 -0
  10. data/.idea/vcs.xml +6 -0
  11. data/.rspec +3 -0
  12. data/.travis.yml +7 -0
  13. data/CODE_OF_CONDUCT.md +74 -0
  14. data/CroemincRubyGem.gemspec +42 -0
  15. data/Gemfile +4 -0
  16. data/Gemfile.lock +35 -0
  17. data/LICENSE.txt +21 -0
  18. data/Rakefile +6 -0
  19. data/SDKDemo.rb +464 -0
  20. data/bin/console +14 -0
  21. data/bin/setup +8 -0
  22. data/lib/Catalogs/environment_type.rb +3 -0
  23. data/lib/Certificates/ca-bundle.crt +3866 -0
  24. data/lib/Config/application.yml +2 -0
  25. data/lib/CroemincRubyGem/version.rb +3 -0
  26. data/lib/CroemincRubyGem.rb +13 -0
  27. data/lib/Entities/ach.rb +37 -0
  28. data/lib/Entities/address.rb +97 -0
  29. data/lib/Entities/amount_range_filter.rb +60 -0
  30. data/lib/Entities/base_entity.rb +15 -0
  31. data/lib/Entities/beneficiary.rb +89 -0
  32. data/lib/Entities/credit_card.rb +150 -0
  33. data/lib/Entities/customer.rb +218 -0
  34. data/lib/Entities/customer_entity.rb +130 -0
  35. data/lib/Entities/customer_entity_response.rb +79 -0
  36. data/lib/Entities/customer_response.rb +90 -0
  37. data/lib/Entities/customer_search.rb +80 -0
  38. data/lib/Entities/customer_search_option.rb +55 -0
  39. data/lib/Entities/date_range_filter.rb +59 -0
  40. data/lib/Entities/instruction.rb +136 -0
  41. data/lib/Entities/instruction_response.rb +63 -0
  42. data/lib/Entities/instrument.rb +73 -0
  43. data/lib/Entities/instrument_response.rb +70 -0
  44. data/lib/Entities/request_model.rb +80 -0
  45. data/lib/Entities/response_model.rb +39 -0
  46. data/lib/Entities/service.rb +70 -0
  47. data/lib/Entities/text_filter.rb +45 -0
  48. data/lib/Entities/transaction.rb +162 -0
  49. data/lib/Entities/transaction_options.rb +49 -0
  50. data/lib/Entities/transaction_response.rb +79 -0
  51. data/lib/Entities/transaction_search_request.rb +57 -0
  52. data/lib/Entities/validation_error.rb +60 -0
  53. data/lib/Entities/wallet.rb +20 -0
  54. data/lib/Gateway/croeminc_gateway.rb +56 -0
  55. data/lib/Helpers/api_helper.rb +96 -0
  56. data/lib/Helpers/jso_nable.rb +56 -0
  57. data/lib/Helpers/model_parser.rb +235 -0
  58. data/lib/Managers/customer_manager.rb +148 -0
  59. data/lib/Managers/transaction_manager.rb +264 -0
  60. data/lib/MetropagoRubyGem/version.rb +3 -0
  61. data/lib/Test/customer_operations.rb +395 -0
  62. data/lib/Test/transaction_operations.rb +259 -0
  63. metadata +146 -0
@@ -0,0 +1,264 @@
1
+ require_relative '../Entities/transaction'
2
+ require_relative '../Entities/transaction_response'
3
+ require_relative '../Entities/request_model'
4
+ require_relative '../Entities/response_model'
5
+ require_relative '../Entities/address'
6
+ require_relative '../Entities/customer_entity'
7
+ require_relative '../Entities/credit_card'
8
+ require_relative '../Entities/customer'
9
+ require_relative '../Helpers/model_parser'
10
+ require 'json'
11
+ class TransactionManager
12
+
13
+ def initialize(CroemincGatewayObject)
14
+ @CroemincGatewayObject = CroemincGatewayObject
15
+ end
16
+
17
+ #Sale
18
+ def Sale(transactionRequest)
19
+
20
+ tranxOptions = TransactionOptions.new
21
+ tranxOptions.Operation = "Sale"
22
+ transactionRequest.TransactOptions = tranxOptions
23
+ return PerformTransaction(transactionRequest)
24
+
25
+ end
26
+
27
+ #Rebill
28
+ def Rebill(transactionRequest)
29
+
30
+ tranxOptions = TransactionOptions.new
31
+ tranxOptions.Operation = "Rebill"
32
+ transactionRequest.TransactOptions = tranxOptions
33
+ return PerformTransaction(transactionRequest)
34
+
35
+ end
36
+
37
+ #PreAuthorization
38
+ def PreAuthorization(transactionRequest)
39
+
40
+ tranxOptions = TransactionOptions.new
41
+ tranxOptions.Operation = "PreAuthorization"
42
+ transactionRequest.TransactOptions = tranxOptions
43
+ return PerformTransaction(transactionRequest)
44
+
45
+ end
46
+
47
+ #Adjustment
48
+ def Adjustment(transactionRequest)
49
+
50
+ tranxOptions = TransactionOptions.new
51
+ tranxOptions.Operation = "Adjustment"
52
+ transactionRequest.TransactOptions = tranxOptions
53
+ return PerformTransaction(transactionRequest)
54
+
55
+ end
56
+
57
+ #Refund
58
+ def Refund(transactionRequest)
59
+
60
+ tranxOptions = TransactionOptions.new
61
+ tranxOptions.Operation = "Refund"
62
+ transactionRequest.TransactOptions = tranxOptions
63
+ return PerformTransaction(transactionRequest)
64
+
65
+ end
66
+
67
+ #Search Transactions
68
+ def SearchTransaction(transactionSearchRequest)
69
+ reqData = CreateRequestObject(transactionSearchRequest)
70
+ apiHelper = APIHelper.new
71
+ responseModel = ResponseModel.new
72
+
73
+ responseModel = apiHelper.SendAPIRequest(reqData, @CroemincGatewayObject.instance_variable_get("@gatewayURL") + "Transaction/SearchTransaction")
74
+ if (responseModel && responseModel.instance_variable_get("@responseMessage"))
75
+ transactionsLst = ParseTransactionSearchResult(responseModel)
76
+ end
77
+
78
+ return transactionsLst
79
+ end
80
+
81
+ #Update Transaction
82
+ def UpdateTransaction(transactionRequest)
83
+
84
+ reqData = CreateRequestObject(transactionRequest)
85
+ apiHelper = APIHelper.new
86
+ responseModel = ResponseModel.new
87
+ responseModel = apiHelper.SendAPIRequest(reqData, @CroemincGatewayObject.instance_variable_get("@gatewayURL") + "Transaction/UpdateTransactionStatus")
88
+
89
+ responseTranxObject = Transaction.new
90
+
91
+ if (responseModel && responseModel.instance_variable_get("@responseMessage"))
92
+ responseMsg = responseModel.instance_variable_get("@responseMessage")
93
+ responseMsgParced = JSON.parse(responseMsg)
94
+ responseTranxObject = ParseTransactionObject(responseMsgParced)
95
+ end
96
+
97
+ return responseTranxObject
98
+
99
+ end
100
+
101
+ #Private Methods
102
+ private
103
+ def PerformTransaction(transactionObject)
104
+
105
+ reqData = CreateRequestObject(transactionObject)
106
+ apiHelper = APIHelper.new
107
+ responseModel = ResponseModel.new
108
+ responseModel = apiHelper.SendAPIRequest(reqData, @CroemincGatewayObject.instance_variable_get("@gatewayURL") + "Transaction/PerformTransaction")
109
+
110
+ responseTranxObject = Transaction.new
111
+
112
+ if (responseModel && responseModel.instance_variable_get("@responseMessage"))
113
+ responseMsg = responseModel.instance_variable_get("@responseMessage")
114
+ responseMsgParced = JSON.parse(responseMsg)
115
+ responseTranxObject = ParseTransactionObject(responseMsgParced)
116
+ end
117
+
118
+ return responseTranxObject
119
+
120
+ end
121
+
122
+ def CreateRequestObject(object)
123
+ requestData = RequestModel.new
124
+ requestData.TerminalId = @CroemincGatewayObject.instance_variable_get("@terminalId")
125
+ requestData.Identification = @CroemincGatewayObject.instance_variable_get("@merchantId")
126
+ requestData.SDKVersion = @CroemincGatewayObject.instance_variable_get("@sdkVersion")
127
+ requestData.Culture = @CroemincGatewayObject.instance_variable_get("@culture")
128
+ requestData.MerchantId = @CroemincGatewayObject.instance_variable_get("@merchantId")
129
+ requestData.EnableLogs = @CroemincGatewayObject.instance_variable_get("@enableLogs")
130
+ requestData.RequestMessage = JSON.dump object.to_h
131
+
132
+ #puts requestData.instance_variable_get("@requestMessage")
133
+
134
+ return requestData
135
+
136
+ end
137
+
138
+ def ParseTransactionObject(responseMsgParced)
139
+
140
+ modelParsingHelper = ModelParser.new
141
+
142
+ #puts responseMsgParced
143
+ transaction = Transaction.new(responseMsgParced)
144
+
145
+
146
+ #parse and populate TransactionResponse
147
+ if(transaction.instance_variable_get("@responseDetails"))
148
+ responseDetails = transaction.instance_variable_get("@responseDetails")
149
+ responseDet = TransactionResponse.new(responseDetails)
150
+
151
+
152
+ #parse TransactionResponse -> ValidationErrors
153
+ validationErrsHashed = responseDet.getValidationErrors
154
+ validationErrors = ValidationError.new(validationErrsHashed)
155
+
156
+ if(validationErrors.instance_variable_get("@errorDetails"))
157
+
158
+ errDetailsArr = validationErrors.instance_variable_get("@errorDetails")
159
+ if(errDetailsArr)
160
+
161
+ validationErrsList = []
162
+ errDetailsArr.each do |ed|
163
+
164
+ vErr = ValidationError.new(ed)
165
+ validationErrsList << vErr
166
+
167
+ end
168
+
169
+ validationErrors.ErrorDetails = validationErrsList
170
+
171
+ end
172
+
173
+ end
174
+
175
+ responseDet.ValidationErrors = validationErrors
176
+
177
+ transaction.ResponseDetails = responseDet
178
+ end
179
+
180
+
181
+
182
+ #Parse and populate CustomerData
183
+ transaction.CustomerData = modelParsingHelper.ParseCustomerObject(transaction.getCustomerData)
184
+
185
+ #Parse and populate billing Addresses
186
+ if(transaction.getBillingAddress)
187
+
188
+ ba = transaction.getBillingAddress
189
+
190
+ buffBillAddr = Address.new(ba)
191
+
192
+ transaction.BillingAddress = buffBillAddr
193
+ end
194
+
195
+ #Parse and populate shipping Addresses
196
+ if(transaction.getShippingAddress)
197
+
198
+ sa = transaction.getShippingAddress
199
+ buffShipAddr = Address.new(sa)
200
+
201
+ transaction.ShippingAddress = buffShipAddr
202
+ end
203
+
204
+ #Parse and populate CreditCards
205
+ if(transaction.getCreditCardDetail)
206
+ #puts 'Has Creditcards'
207
+
208
+ cardDetail = transaction.getCreditCardDetail
209
+
210
+ buffCard = CreditCard.new(cardDetail)
211
+
212
+ transaction.CreditCardDetail = buffCard
213
+
214
+ end
215
+
216
+
217
+ #Parse and populate Accounts
218
+ if(transaction.getCustomerEntityDetail)
219
+ #puts 'Has Accounts'
220
+
221
+ accountsDet = transaction.getCustomerEntityDetail
222
+
223
+ buffAccount = CustomerEntity.new(accountsDet)
224
+
225
+ #parse beneficiary and services
226
+ benificHashed = buffAccount.instance_variable_get("@entityBeneficiary")
227
+ accBeneficiary = modelParsingHelper.ParseCustomerBeneficiary(benificHashed)
228
+
229
+ buffAccount.EntityBeneficiary = accBeneficiary
230
+
231
+ entityRespHashed = buffAccount.instance_variable_get("@responseDetails")
232
+ custEntResponse = modelParsingHelper.ParseCustomerEntityResponse(entityRespHashed)
233
+
234
+ buffAccount.ResponseDetails = custEntResponse
235
+
236
+ transaction.CustomerEntityDetail = buffAccount
237
+
238
+ end
239
+
240
+ return transaction
241
+
242
+ end
243
+
244
+ def ParseTransactionSearchResult(responseModel)
245
+
246
+ responseMsg = responseModel.instance_variable_get("@responseMessage")
247
+ transactionsArray = JSON.parse(responseMsg)
248
+
249
+ transactionsList = []
250
+
251
+ modelParsingHelper = ModelParser.new
252
+
253
+ transactionsArray.each do |tranx|
254
+
255
+ #creatd transaction object with tranx
256
+ transaction = ParseTransactionObject(tranx)
257
+
258
+ transactionsList << transaction
259
+ end
260
+
261
+ return transactionsList
262
+ end
263
+
264
+ end
@@ -0,0 +1,3 @@
1
+ module CroemincRubyGem
2
+ VERSION = "0.1.2".freeze
3
+ end
@@ -0,0 +1,395 @@
1
+ require_relative '../Entities/customer'
2
+ require_relative '../Gateway/Croeminc_gateway'
3
+ require_relative '../Managers/customer_manager'
4
+ require_relative '../Entities/customer_search'
5
+ require_relative '../Entities/customer_search_option'
6
+ require_relative '../Entities/text_filter'
7
+ require_relative '../Entities/validation_error'
8
+ require_relative '../Entities/customer_entity_response'
9
+ require_relative '../Entities/customer_entity'
10
+
11
+ class CustomerOperations
12
+
13
+
14
+ def initialize(metropaGatewayObj)
15
+ @CroemincGateway = metropaGatewayObj
16
+ end
17
+
18
+ def SaveCustomer(identifier)
19
+
20
+ cust = Customer.new
21
+ cust.Company = "ALPHA"
22
+ cust.Created = "7/14/2016"
23
+ cust.Email = "alpha1@croem.net"
24
+ cust.FirstName = "Alpha"
25
+ cust.LastName = "alph"
26
+ cust.Username = "alpha123111"
27
+ cust.Website = "www.alpha.com"
28
+ cust.UniqueIdentifier = identifier
29
+
30
+ customFields = Hash.new
31
+ customFields = { "RACE" => "ORC", "CLASS" => "PALA" }
32
+
33
+ puts customFields
34
+
35
+ cust.CustomFields = customFields
36
+
37
+ custMgr = CustomerManager.new(@CroemincGateway)
38
+ resModel = Customer.new
39
+ resModel = custMgr.SaveCustomer(cust)
40
+
41
+ puts 'RESULT - Save Customer:'
42
+ puts JSON.dump resModel.to_h
43
+
44
+ end
45
+
46
+ def SearchCustomerByIdentifier(identifier)
47
+
48
+
49
+ custSearch = CustomerSearch.new
50
+ custSearchOpts = CustomerSearchOption.new
51
+
52
+ custSearch.UniqueIdentifier = identifier
53
+
54
+ custSearchOpts.IncludeAll = false
55
+ custSearchOpts.IncludeAssociatedEntities = true
56
+ custSearchOpts.IncludeCardInstruments = true
57
+ custSearchOpts.IncludePaymentInstructions = true
58
+
59
+ custSearch.SearchOption = custSearchOpts
60
+
61
+ custMgr = CustomerManager.new(@CroemincGateway)
62
+ resModel = Customer.new
63
+
64
+ customersList = custMgr.SearchCustomer(custSearch)
65
+
66
+ puts 'RESULT - Search Customer By Identifier:'
67
+
68
+ customersList.each {
69
+
70
+ #Display CustomerModel as JSON
71
+ |x| puts JSON.dump x.to_h
72
+
73
+ #response Details
74
+ puts 'Response Details:'
75
+ puts JSON.dump x.getResponseDetails.to_h
76
+
77
+
78
+ #example for getting other properties
79
+
80
+ puts "Is Success:"
81
+ puts x.getResponseDetails.getIsSuccess
82
+
83
+ puts 'Response Summary: '
84
+ puts x.getResponseDetails.getResponseSummary
85
+
86
+ puts "Validation Errors: "
87
+ puts JSON.dump x.getResponseDetails.getValidationErrors.to_h
88
+
89
+ puts "Error Summary: "
90
+ puts x.getResponseDetails.getValidationErrors.getErrorSummary
91
+
92
+ puts "Error Details: "
93
+ puts x.getResponseDetails.getValidationErrors.getErrorDescription
94
+
95
+
96
+ }
97
+
98
+ end
99
+
100
+ def SearchCustomerByFirstName(firstName)
101
+
102
+
103
+ custSearch = CustomerSearch.new
104
+ custSearchOpts = CustomerSearchOption.new
105
+
106
+ custSearchOpts.IncludeAll = false
107
+ custSearchOpts.IncludeAssociatedEntities = true
108
+ custSearchOpts.IncludeCardInstruments = true
109
+ custSearchOpts.IncludePaymentInstructions = true
110
+ custSearchOpts.IncludeCustomFields = true
111
+
112
+ custSearch.SearchOption = custSearchOpts
113
+
114
+ custSearch.FirstName = TextFilter.new.StartsWith(firstName)
115
+
116
+ #puts 'OP: ' + custSearch.instance_variable_get("@firstName").instance_variable_get("@operation")
117
+
118
+ custMgr = CustomerManager.new(@CroemincGateway)
119
+ resModel = custMgr.SearchCustomer(custSearch)
120
+
121
+ puts 'RESULT - Search Customer By First Name:'
122
+
123
+ resModel.each {
124
+ |x|
125
+
126
+ #example display customer as json
127
+ puts x.to_h
128
+
129
+ #example get custom field by name
130
+ if(x.getCustomFields())
131
+
132
+ custField = x.getCustomFields()
133
+ puts custField["RACE"]
134
+
135
+ end
136
+
137
+
138
+ #example get services
139
+ if(x.getCustomerEntities[0] && x.getCustomerEntities[0].getEntityBeneficiary)
140
+ firstService = x.getCustomerEntities[0].getEntityBeneficiary.getServices[0]
141
+ end
142
+
143
+ if(firstService)
144
+ puts "ServiceName: " + firstService.getName
145
+
146
+ if(firstService.getCustomFields)
147
+ puts "Custom Fields: "
148
+ firstService.getCustomFields.each do |k,v|
149
+ puts k + " :" + v
150
+ end
151
+ end
152
+
153
+ end
154
+
155
+ }
156
+
157
+ end
158
+
159
+ def UpdateCustomerName(identifier, firstName, lastName)
160
+
161
+ cust = Customer.new
162
+ cust.UniqueIdentifier = identifier
163
+ cust.FirstName = firstName
164
+ cust.LastName = lastName
165
+
166
+ custMgr = CustomerManager.new(@CroemincGateway)
167
+ resModel = Customer.new
168
+ resModel = custMgr.UpdateCustomer(cust)
169
+
170
+ puts 'RESULT - Update Customer:'
171
+ puts resModel.getFirstName + " " + resModel.getLastName
172
+ puts JSON.dump resModel.to_h
173
+
174
+ #response Details
175
+ puts 'Response Details:'
176
+ puts JSON.dump resModel.getResponseDetails.to_h
177
+
178
+ puts "Is Success:"
179
+ puts resModel.getResponseDetails.getIsSuccess
180
+
181
+ puts 'Response Summary: '
182
+ puts resModel.getResponseDetails.getResponseSummary
183
+
184
+ puts "Validation Errors: "
185
+ puts JSON.dump resModel.getResponseDetails.getValidationErrors.to_h
186
+
187
+ puts "Error Summary: "
188
+ puts resModel.getResponseDetails.getValidationErrors.getErrorSummary
189
+
190
+ puts "Error Details: "
191
+ puts resModel.getResponseDetails.getValidationErrors.getErrorDescription
192
+
193
+ end
194
+
195
+ def AddCardToCustomer(identifier)
196
+
197
+ customer = Customer.new
198
+ customer = GetCustomerByIdentifier(identifier)
199
+
200
+ #puts customer.instance_variable_get("@firstName")
201
+
202
+ card = CreditCard.new
203
+ card.CardholderName = "ZEESHAN MUSTAFA"
204
+ card.Status = "Active"
205
+
206
+ card.SetExpiration("05", "2019")
207
+
208
+ card.Number = "4111111111111111"
209
+
210
+ #custom Fields for Card
211
+ customFields = {}
212
+ customFields.store("TrustLevel", "5")
213
+ customFields.store("AllowSwipe", "true")
214
+
215
+ card.CustomFields = customFields
216
+ card.CustomerId = customer.getCustomerId #.instance_variable_get("@customerId")
217
+
218
+ #add card to list. Becaue customer object holds list of it's associated cards
219
+ creditCards = []
220
+ creditCards << card
221
+
222
+ #attach cards to customers
223
+ customer.CreditCards = creditCards
224
+
225
+ custMgr = CustomerManager.new(@CroemincGateway)
226
+ resultCustomer = Customer.new
227
+ resultCustomer = custMgr.UpdateCustomer(customer)
228
+
229
+ puts 'RESULT - Add Cards To Customer:'
230
+ puts JSON.dump resultCustomer.to_h
231
+
232
+
233
+ end
234
+
235
+
236
+ def AddAccountToCustomer(identifier)
237
+
238
+
239
+ customer = Customer.new
240
+ customer = GetCustomerByIdentifier(identifier)
241
+
242
+ account = CustomerEntity.new
243
+ account.AccountNumber = "1230008"
244
+ account.CustomerId = customer.getCustomerId #.instance_variable_get("@customerId")
245
+ account.FriendlyName = "ZEEACC1"
246
+ account.ServiceTypeName = "PREPAID"
247
+ account.Status = "Active"
248
+
249
+ accounts = []
250
+ accounts << account
251
+
252
+ customer.CustomerEntities = accounts
253
+
254
+ custMgr = CustomerManager.new(@CroemincGateway)
255
+ resultCustomer = Customer.new
256
+ resultCustomer = custMgr.UpdateCustomer(customer)
257
+
258
+ puts 'RESULT - Add Account To Customer:'
259
+ puts JSON.dump resultCustomer.to_h
260
+
261
+ puts 'Customer Entity Response:'
262
+ if(resultCustomer.getCustomerEntities[0] && resultCustomer.getCustomerEntities[0].getResponseDetails)
263
+
264
+ customerEntityResponse = resultCustomer.getCustomerEntities[0].getResponseDetails
265
+ puts "Success: "
266
+ puts customerEntityResponse.getIsSuccess
267
+
268
+ puts "Response Summary: "
269
+ puts customerEntityResponse.getResponseSummary
270
+
271
+ if(customerEntityResponse.getValidationErrors)
272
+ validationErrs = customerEntityResponse.getValidationErrors
273
+
274
+ #puts "Error Summary:"
275
+ #puts validationErrs.getErrorSummary
276
+ #puts "Error Description: "
277
+ #puts validationErrs.getErrorDescription
278
+ #puts "Error Details:"
279
+
280
+ if(validationErrs.getErrorDetails)
281
+
282
+ validationErrs.getErrorDetails.each do |ed|
283
+
284
+ puts "Error Summary:"
285
+ puts ed.getErrorSummary
286
+ puts "Error Description: "
287
+ puts ed.getErrorDescription
288
+
289
+ end
290
+
291
+ end
292
+
293
+ end
294
+
295
+ end
296
+
297
+ end
298
+
299
+ def UpdateAccount(identifier)
300
+
301
+ customer = Customer.new
302
+ customer = GetCustomerByIdentifier(identifier)
303
+
304
+ accounts = customer.getCustomerEntities #instance_variable_get("@customerEntities")
305
+ puts 'Updating Account: ' + accounts[0].getAccountNumber #accounts[0].instance_variable_get("@accountNumber")
306
+
307
+
308
+ accounts[0].FriendlyName = "Friendly Test"
309
+ accounts[0].Status = "Active"
310
+
311
+ custoMgr = CustomerManager.new(@CroemincGateway)
312
+ resultCustomer = Customer.new
313
+ resultCustomer = custoMgr.UpdateCustomer(customer)
314
+
315
+ puts 'RESULT - Update Customer Account Update:'
316
+ puts JSON.dump resultCustomer.to_h
317
+
318
+ end
319
+
320
+
321
+ def AddPaymentInstructionToCustomer(identifier)
322
+
323
+ customer = Customer.new
324
+ customer = GetCustomerByIdentifier(identifier)
325
+
326
+ accounts = customer.getCustomerEntities #instance_variable_get("@customerEntities")
327
+ cards = customer.getCreditCards #instance_variable_get("@creditCards")
328
+
329
+
330
+ card = CreditCard.new
331
+ card = cards[0]
332
+
333
+ account = CustomerEntity.new
334
+ account = accounts[0]
335
+
336
+ puts card.getToken #.instance_variable_get("@token")
337
+ puts account.getAccountNumber #instance_variable_get("@accountNumber")
338
+
339
+ instruction = Instruction.new
340
+ instruction.InstrumentToken = card.getToken #.instance_variable_get("@token")
341
+ instruction.CustomerEntityValue = account.getAccountNumber #.instance_variable_get("@accountNumber")
342
+ instruction.ScheduleDay = "15"
343
+ instruction.ExpirationDate = "08/01/2016 12:00:00"
344
+ instruction.CustomerId = customer.getCustomerId #instance_variable_get("@customerId")
345
+ instruction.Status = "Active"
346
+
347
+ instuctions = []
348
+ instuctions << instruction
349
+
350
+ customer.PaymentInstructions = instuctions
351
+
352
+ custMgr = CustomerManager.new(@CroemincGateway)
353
+ resultCustomer = Customer.new
354
+ resultCustomer = custMgr.UpdateCustomer(customer)
355
+
356
+ puts 'RESULT - Add Instructions To Customer:'
357
+ puts resultCustomer.to_json
358
+
359
+ end
360
+
361
+ def GetCustomerByIdentifier(identifer)
362
+ custSearch = CustomerSearch.new
363
+ custSearchOpts = CustomerSearchOption.new
364
+
365
+ custSearch.UniqueIdentifier = identifer
366
+
367
+ custSearchOpts.IncludeAll = false
368
+ custSearchOpts.IncludeAssociatedEntities = true
369
+ custSearchOpts.IncludeCardInstruments = true
370
+ custSearchOpts.IncludePaymentInstructions = true
371
+
372
+ custSearch.SearchOption = custSearchOpts
373
+
374
+ custMgr = CustomerManager.new(@CroemincGateway)
375
+
376
+ foundCustomersList = custMgr.SearchCustomer(custSearch)
377
+
378
+ customer = Customer.new
379
+ customer = foundCustomersList[0];
380
+
381
+ #puts customer.instance_variable_get("@firstName")
382
+ #customer.CreditCards = customer.from_json!(customer.instance_variable_get("@creditCards"))
383
+ #puts customer.instance_variable_get("@creditCards")[0]
384
+ #puts '---------------------------------------------------------------------------'
385
+
386
+ #customer.CustomerEntities = customer.from_json!(customer.instance_variable_get("@customerEntities"))
387
+ # puts customer.instance_variable_get("@customerEntities")
388
+
389
+ # puts '---------------------------------------------------------------------------'
390
+
391
+ return customer
392
+ end
393
+
394
+
395
+ end