Class: CustomerOperations

Inherits:
Object
  • Object
show all
Defined in:
lib/Test/customer_operations.rb

Instance Method Summary collapse

Constructor Details

#initialize(metropaGatewayObj) ⇒ CustomerOperations

Returns a new instance of CustomerOperations.



14
15
16
# File 'lib/Test/customer_operations.rb', line 14

def initialize(metropaGatewayObj)
  @CroemincGateway = metropaGatewayObj
end

Instance Method Details

#AddAccountToCustomer(identifier) ⇒ Object



236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/Test/customer_operations.rb', line 236

def AddAccountToCustomer(identifier)


  customer = Customer.new
  customer = GetCustomerByIdentifier(identifier)

   = CustomerEntity.new
  .AccountNumber = "1230008"
  .CustomerId = customer.getCustomerId #.instance_variable_get("@customerId")
  .FriendlyName = "ZEEACC1"
  .ServiceTypeName = "PREPAID"
  .Status = "Active"

  accounts = []
  accounts << 

  customer.CustomerEntities = accounts

  custMgr = CustomerManager.new(@CroemincGateway)
  resultCustomer = Customer.new
  resultCustomer = custMgr.UpdateCustomer(customer)

  puts 'RESULT - Add Account To Customer:'
  puts JSON.dump resultCustomer.to_h

  puts 'Customer Entity Response:'
  if(resultCustomer.getCustomerEntities[0] && resultCustomer.getCustomerEntities[0].getResponseDetails)

    customerEntityResponse = resultCustomer.getCustomerEntities[0].getResponseDetails
    puts "Success: "
    puts customerEntityResponse.getIsSuccess

    puts "Response Summary: "
    puts customerEntityResponse.getResponseSummary

    if(customerEntityResponse.getValidationErrors)
      validationErrs = customerEntityResponse.getValidationErrors

      #puts "Error Summary:"
      #puts validationErrs.getErrorSummary
      #puts "Error Description: "
      #puts validationErrs.getErrorDescription
      #puts "Error Details:"

      if(validationErrs.getErrorDetails)

        validationErrs.getErrorDetails.each do |ed|

          puts "Error Summary:"
          puts ed.getErrorSummary
          puts "Error Description: "
          puts ed.getErrorDescription

        end

      end

    end

  end

end

#AddCardToCustomer(identifier) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/Test/customer_operations.rb', line 195

def AddCardToCustomer(identifier)

  customer = Customer.new
  customer = GetCustomerByIdentifier(identifier)

  #puts customer.instance_variable_get("@firstName")

  card = CreditCard.new
  card.CardholderName = "ZEESHAN MUSTAFA"
  card.Status = "Active"

  card.SetExpiration("05", "2019")

  card.Number = "4111111111111111"

  #custom Fields for Card
  customFields = {}
  customFields.store("TrustLevel", "5")
  customFields.store("AllowSwipe", "true")

  card.CustomFields = customFields
  card.CustomerId = customer.getCustomerId #.instance_variable_get("@customerId")

  #add card to list. Becaue customer object holds list of it's associated cards
  creditCards = []
  creditCards << card

  #attach cards to customers
  customer.CreditCards = creditCards

  custMgr = CustomerManager.new(@CroemincGateway)
  resultCustomer = Customer.new
  resultCustomer = custMgr.UpdateCustomer(customer)

  puts 'RESULT - Add Cards To Customer:'
  puts JSON.dump resultCustomer.to_h


end

#AddPaymentInstructionToCustomer(identifier) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/Test/customer_operations.rb', line 321

def AddPaymentInstructionToCustomer(identifier)

  customer = Customer.new
  customer = GetCustomerByIdentifier(identifier)

  accounts = customer.getCustomerEntities #instance_variable_get("@customerEntities")
  cards = customer.getCreditCards #instance_variable_get("@creditCards")


  card = CreditCard.new
  card = cards[0]

   = CustomerEntity.new
   = accounts[0]

  puts card.getToken                #.instance_variable_get("@token")
  puts .getAccountNumber       #instance_variable_get("@accountNumber")

  instruction = Instruction.new
  instruction.InstrumentToken = card.getToken                   #.instance_variable_get("@token")
  instruction.CustomerEntityValue = .getAccountNumber         #.instance_variable_get("@accountNumber")
  instruction.ScheduleDay = "15"
  instruction.ExpirationDate = "08/01/2016 12:00:00"
  instruction.CustomerId = customer.getCustomerId     #instance_variable_get("@customerId")
  instruction.Status = "Active"

  instuctions = []
  instuctions << instruction

  customer.PaymentInstructions = instuctions

  custMgr = CustomerManager.new(@CroemincGateway)
  resultCustomer = Customer.new
  resultCustomer = custMgr.UpdateCustomer(customer)

  puts 'RESULT - Add Instructions To Customer:'
  puts resultCustomer.to_json

end

#GetCustomerByIdentifier(identifer) ⇒ Object



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/Test/customer_operations.rb', line 361

def GetCustomerByIdentifier(identifer)
  custSearch = CustomerSearch.new
  custSearchOpts = CustomerSearchOption.new

  custSearch.UniqueIdentifier = identifer

  custSearchOpts.IncludeAll = false
  custSearchOpts.IncludeAssociatedEntities = true
  custSearchOpts.IncludeCardInstruments = true
  custSearchOpts.IncludePaymentInstructions = true

  custSearch.SearchOption = custSearchOpts

  custMgr = CustomerManager.new(@CroemincGateway)

  foundCustomersList = custMgr.SearchCustomer(custSearch)

  customer = Customer.new
  customer = foundCustomersList[0];

  #puts customer.instance_variable_get("@firstName")
  #customer.CreditCards = customer.from_json!(customer.instance_variable_get("@creditCards"))
  #puts customer.instance_variable_get("@creditCards")[0]
  #puts '---------------------------------------------------------------------------'

  #customer.CustomerEntities = customer.from_json!(customer.instance_variable_get("@customerEntities"))
 # puts customer.instance_variable_get("@customerEntities")

 # puts '---------------------------------------------------------------------------'

  return customer
end

#SaveCustomer(identifier) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/Test/customer_operations.rb', line 18

def SaveCustomer(identifier)

  cust = Customer.new
  cust.Company = "ALPHA"
  cust.Created = "7/14/2016"
  cust.Email = "[email protected]"
  cust.FirstName = "Alpha"
  cust.LastName = "alph"
  cust.Username = "alpha123111"
  cust.Website = "www.alpha.com"
  cust.UniqueIdentifier = identifier

  customFields = Hash.new
  customFields = { "RACE" => "ORC", "CLASS" => "PALA" }

  puts customFields

  cust.CustomFields = customFields

  custMgr = CustomerManager.new(@CroemincGateway)
  resModel = Customer.new
  resModel = custMgr.SaveCustomer(cust)

  puts 'RESULT - Save Customer:'
  puts JSON.dump resModel.to_h

end

#SearchCustomerByFirstName(firstName) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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/Test/customer_operations.rb', line 100

def SearchCustomerByFirstName(firstName)


  custSearch = CustomerSearch.new
  custSearchOpts = CustomerSearchOption.new

  custSearchOpts.IncludeAll = false
  custSearchOpts.IncludeAssociatedEntities = true
  custSearchOpts.IncludeCardInstruments = true
  custSearchOpts.IncludePaymentInstructions = true
  custSearchOpts.IncludeCustomFields = true

  custSearch.SearchOption = custSearchOpts

  custSearch.FirstName = TextFilter.new.StartsWith(firstName)

  #puts 'OP: ' + custSearch.instance_variable_get("@firstName").instance_variable_get("@operation")

  custMgr = CustomerManager.new(@CroemincGateway)
  resModel = custMgr.SearchCustomer(custSearch)

  puts 'RESULT - Search Customer By First Name:'

  resModel.each {
      |x|

    #example display customer as json
    puts x.to_h

    #example get custom field by name
    if(x.getCustomFields())

      custField = x.getCustomFields()
      puts custField["RACE"]

    end


    #example get services
    if(x.getCustomerEntities[0] && x.getCustomerEntities[0].getEntityBeneficiary)
      firstService = x.getCustomerEntities[0].getEntityBeneficiary.getServices[0]
    end

    if(firstService)
      puts "ServiceName: " + firstService.getName

      if(firstService.getCustomFields)
        puts "Custom Fields: "
        firstService.getCustomFields.each do |k,v|
          puts k + " :" + v
        end
      end

    end

  }

end

#SearchCustomerByIdentifier(identifier) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/Test/customer_operations.rb', line 46

def SearchCustomerByIdentifier(identifier)


  custSearch = CustomerSearch.new
  custSearchOpts = CustomerSearchOption.new

  custSearch.UniqueIdentifier = identifier

  custSearchOpts.IncludeAll = false
  custSearchOpts.IncludeAssociatedEntities = true
  custSearchOpts.IncludeCardInstruments = true
  custSearchOpts.IncludePaymentInstructions = true

  custSearch.SearchOption = custSearchOpts

  custMgr = CustomerManager.new(@CroemincGateway)
  resModel = Customer.new

  customersList = custMgr.SearchCustomer(custSearch)

  puts 'RESULT - Search Customer By Identifier:'

  customersList.each {

    #Display CustomerModel as JSON
    |x| puts JSON.dump x.to_h

    #response Details
    puts 'Response Details:'
    puts JSON.dump x.getResponseDetails.to_h


    #example for getting other properties

    puts "Is Success:"
    puts x.getResponseDetails.getIsSuccess

    puts 'Response Summary: '
    puts x.getResponseDetails.getResponseSummary

    puts "Validation Errors: "
    puts JSON.dump x.getResponseDetails.getValidationErrors.to_h

    puts "Error Summary: "
    puts x.getResponseDetails.getValidationErrors.getErrorSummary

    puts "Error Details: "
    puts x.getResponseDetails.getValidationErrors.getErrorDescription


  }

end

#UpdateAccount(identifier) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/Test/customer_operations.rb', line 299

def UpdateAccount(identifier)

  customer = Customer.new
  customer = GetCustomerByIdentifier(identifier)

  accounts = customer.getCustomerEntities #instance_variable_get("@customerEntities")
  puts 'Updating Account: ' + accounts[0].getAccountNumber #accounts[0].instance_variable_get("@accountNumber")


  accounts[0].FriendlyName = "Friendly Test"
  accounts[0].Status = "Active"

  custoMgr = CustomerManager.new(@CroemincGateway)
  resultCustomer = Customer.new
  resultCustomer = custoMgr.UpdateCustomer(customer)

  puts 'RESULT - Update Customer Account Update:'
  puts JSON.dump resultCustomer.to_h

end

#UpdateCustomerName(identifier, firstName, lastName) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/Test/customer_operations.rb', line 159

def UpdateCustomerName(identifier, firstName, lastName)

  cust = Customer.new
  cust.UniqueIdentifier = identifier
  cust.FirstName = firstName
  cust.LastName = lastName

  custMgr = CustomerManager.new(@CroemincGateway)
  resModel = Customer.new
  resModel = custMgr.UpdateCustomer(cust)

  puts 'RESULT - Update Customer:'
  puts resModel.getFirstName + " " + resModel.getLastName
  puts JSON.dump resModel.to_h

  #response Details
  puts 'Response Details:'
  puts JSON.dump resModel.getResponseDetails.to_h

  puts "Is Success:"
  puts resModel.getResponseDetails.getIsSuccess

  puts 'Response Summary: '
  puts resModel.getResponseDetails.getResponseSummary

  puts "Validation Errors: "
  puts JSON.dump resModel.getResponseDetails.getValidationErrors.to_h

  puts "Error Summary: "
  puts resModel.getResponseDetails.getValidationErrors.getErrorSummary

  puts "Error Details: "
  puts resModel.getResponseDetails.getValidationErrors.getErrorDescription

end