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
data/SDKDemo.rb ADDED
@@ -0,0 +1,464 @@
1
+ # To Run this Demo , Just type command "ruby SDKDemo.rb" in command line of root folder of this project
2
+
3
+ require 'CroemincRubyGem'
4
+
5
+ puts 'Croeminc - CLIENT SDK'
6
+ puts 'RUBY VERSION: ' + RUBY_VERSION.to_s
7
+
8
+ CroemincGateway = CroemincGateway.new("SANDBOX", "100177", "100177001", "AERT99HY")
9
+ CroemincGateway.Culture = "es"
10
+
11
+ #Customer Operations
12
+ customerOps = CustomerOperations.new(CroemincGateway)
13
+
14
+ #saveCustomer:
15
+ #identifier = "851848912" #"851848913"
16
+ identifier = "777BETA888"
17
+
18
+ def GetCustomerByIdentifier(identifer,metroPG)
19
+ custSearch = CustomerSearch.new
20
+ custSearchOpts = CustomerSearchOption.new
21
+
22
+ custSearch.UniqueIdentifier = identifer
23
+
24
+ custSearchOpts.IncludeAll = false
25
+ custSearchOpts.IncludeAssociatedEntities = true
26
+ custSearchOpts.IncludeCardInstruments = true
27
+ custSearchOpts.IncludePaymentInstructions = true
28
+
29
+ custSearch.SearchOption = custSearchOpts
30
+
31
+ custMgr = CustomerManager.new(metroPG)
32
+
33
+ foundCustomersList = custMgr.SearchCustomer(custSearch)
34
+
35
+ customer = Customer.new
36
+ customer = foundCustomersList[0];
37
+
38
+ #puts customer.instance_variable_get("@firstName")
39
+ #customer.CreditCards = customer.from_json!(customer.instance_variable_get("@creditCards"))
40
+ #puts customer.instance_variable_get("@creditCards")[0]
41
+ #puts '---------------------------------------------------------------------------'
42
+
43
+ #customer.CustomerEntities = customer.from_json!(customer.instance_variable_get("@customerEntities"))
44
+ # puts customer.instance_variable_get("@customerEntities")
45
+
46
+ # puts '---------------------------------------------------------------------------'
47
+
48
+ return customer
49
+ end
50
+
51
+ def SaveCustomer(identifier,metroPG)
52
+
53
+ cust = Customer.new
54
+ cust.Company = "BETA"
55
+ cust.Created = "7/14/2016"
56
+ cust.Email = "beta@croem.net"
57
+ cust.FirstName = "Beta"
58
+ cust.LastName = "gema"
59
+ cust.Username = "rays"
60
+ cust.Website = "www.beta.com"
61
+ cust.UniqueIdentifier = identifier
62
+
63
+ customFields = Hash.new
64
+ customFields = { "RACE" => "ORC", "CLASS" => "PALA" }
65
+
66
+ puts customFields
67
+
68
+ cust.CustomFields = customFields
69
+
70
+ custMgr = CustomerManager.new(metroPG)
71
+ resModel = Customer.new
72
+ resModel = custMgr.SaveCustomer(cust)
73
+
74
+ puts 'RESULT - Save Customer:'
75
+ puts JSON.dump resModel.to_h
76
+ end
77
+
78
+ customerOps.SaveCustomer(identifier)
79
+
80
+ #search Customer by Identifier
81
+ customerOps.SearchCustomerByIdentifier(identifier)
82
+
83
+ #search Customer by First Name
84
+ customerOps.SearchCustomerByFirstName('alpha')
85
+
86
+ #Update Customer Name
87
+ customerOps.UpdateCustomerName(identifier, 'Zeeshan1', 'Mustafa1')
88
+
89
+ #Add Card to customer
90
+ customerOps.AddCardToCustomer(identifier)
91
+
92
+ def AddCardToCustomer(identifier,metroPG)
93
+ custMgr = CustomerManager.new(metroPG)
94
+ customer = Customer.new
95
+ customer = custMgr.GetCustomerByIdentifier(identifier)
96
+
97
+ #puts customer.instance_variable_get("@firstName")
98
+
99
+ card = CreditCard.new
100
+ card.CardholderName = "NOUMAN CROEM"
101
+ card.Status = "Active"
102
+
103
+ card.SetExpiration("05", "2028")
104
+
105
+ card.Number = "4111111111111111"
106
+
107
+ #custom Fields for Card
108
+ customFields = {}
109
+ customFields.store("TrustLevel", "5")
110
+ customFields.store("AllowSwipe", "true")
111
+
112
+ card.CustomFields = customFields
113
+ card.CustomerId = customer.getCustomerId #.instance_variable_get("@customerId")
114
+
115
+ #add card to list. Becaue customer object holds list of it's associated cards
116
+ creditCards = []
117
+ creditCards << card
118
+
119
+ #attach cards to customers
120
+ customer.CreditCards = creditCards
121
+
122
+ resultCustomer = Customer.new
123
+ resultCustomer = custMgr.UpdateCustomer(customer)
124
+
125
+ puts 'RESULT - Add Cards To Customer:'
126
+ puts JSON.dump resultCustomer.to_h
127
+ end
128
+
129
+ def AddAccountToCustomer(identifier,metroPG)
130
+ customer = Customer.new
131
+ customer = GetCustomerByIdentifier(identifier,metroPG)
132
+
133
+ account = CustomerEntity.new
134
+ account.AccountNumber = "2203215668441"
135
+ account.CustomerId = customer.getCustomerId #.instance_variable_get("@customerId")
136
+ account.FriendlyName = "BETA 1"
137
+ account.ServiceTypeName = "PREPAID"
138
+ account.Status = "Active"
139
+
140
+ accounts = []
141
+ accounts << account
142
+
143
+ customer.CustomerEntities = accounts
144
+
145
+ custMgr = CustomerManager.new(metroPG)
146
+ resultCustomer = Customer.new
147
+ resultCustomer = custMgr.UpdateCustomer(customer)
148
+
149
+ puts 'RESULT - Add Account To Customer:'
150
+ puts JSON.dump resultCustomer.to_h
151
+
152
+ puts 'Customer Entity Response:'
153
+ if(resultCustomer.getCustomerEntities[0] && resultCustomer.getCustomerEntities[0].getResponseDetails)
154
+
155
+ customerEntityResponse = resultCustomer.getCustomerEntities[0].getResponseDetails
156
+ puts "Success: "
157
+ puts customerEntityResponse.getIsSuccess
158
+
159
+ puts "Response Summary: "
160
+ puts customerEntityResponse.getResponseSummary
161
+
162
+ if(customerEntityResponse.getValidationErrors)
163
+ validationErrs = customerEntityResponse.getValidationErrors
164
+
165
+ #puts "Error Summary:"
166
+ #puts validationErrs.getErrorSummary
167
+ #puts "Error Description: "
168
+ #puts validationErrs.getErrorDescription
169
+ #puts "Error Details:"
170
+
171
+ if(validationErrs.getErrorDetails)
172
+
173
+ validationErrs.getErrorDetails.each do |ed|
174
+
175
+ puts "Error Summary:"
176
+ puts ed.getErrorSummary
177
+ puts "Error Description: "
178
+ puts ed.getErrorDescription
179
+
180
+ end
181
+
182
+ end
183
+
184
+ end
185
+
186
+ end
187
+ end
188
+
189
+ #Add Account to Customer
190
+ customerOps.AddAccountToCustomer(identifier)
191
+
192
+ #Update Customer Acount
193
+ customerOps.UpdateAccount(identifier)
194
+
195
+ #Add PaymentInstruction
196
+ # customerOps.AddPaymentInstructionToCustomer(identifier)
197
+
198
+ SaveCustomer(identifier,CroemincGateway)
199
+ AddCardToCustomer(identifier,CroemincGateway)
200
+ AddAccountToCustomer(identifier,CroemincGateway)
201
+ ###############################################
202
+ #############Transaction#########################
203
+ transactionOps = TransactionOperations.new(CroemincGateway)
204
+
205
+ #Perform Sale
206
+ customerId = "12968"
207
+ transactionOps.PerformSale(customerId)
208
+
209
+ #Perform PreAuthorization
210
+ transactionOps.PerformPreAuthorization(customerId)
211
+
212
+ #Perfrom Adjustment
213
+ transactionOps.PerformAdjustment(customerId)
214
+
215
+ #Perfrom Rebill
216
+ transactionOps.PerformRebill(customerId)
217
+
218
+ #Perfomr Refund
219
+ transactionOps.PerformRefund(customerId)
220
+
221
+ #Search Transactions
222
+ transactionOps.SearchTransactions(customerId)
223
+
224
+ #Update Transaction
225
+ transactionOps.PerformUpdateTransaction(customerId)
226
+
227
+ def PerformSale(customerId,mpago)
228
+
229
+ tranxRequest = Transaction.new
230
+ customer = Customer.new
231
+
232
+ #card Info
233
+ creditCards = []
234
+ card = CreditCard.new
235
+ card.Token = "A2478342-617A-4EE5-BC1B-ECD3D132D9CF"
236
+ creditCards << card
237
+
238
+ #Account Info
239
+ accounts = []
240
+ account = CustomerEntity.new
241
+ account.Id = "10752"
242
+ accounts << account
243
+
244
+ #customer Info
245
+ customer.CustomerId = customerId
246
+ customer.CreditCards = creditCards
247
+ #customer.CustomerEntities = accounts
248
+
249
+ #Transaction Info
250
+ tranxRequest.CustomerData = customer
251
+ tranxRequest.Amount = 1.00
252
+ tranxRequest.OrderTrackingNumber = "777AAAAA"
253
+
254
+ tranxMgr = TransactionManager.new(mpago)
255
+ responseTranxModel = tranxMgr.Sale(tranxRequest)
256
+
257
+
258
+ puts 'RESULT - Perform Sale:'
259
+ responseDetails = responseTranxModel.getResponseDetails
260
+
261
+ if(responseDetails && responseDetails.getIsSuccess == true)
262
+ puts 'Transaction Processed Successfullly. Transaction Id: ' + responseDetails.getTransactionId
263
+
264
+ #example accessing inner models
265
+ if(responseTranxModel.getCustomerData)
266
+ customerCards = responseTranxModel.getCustomerData.getCreditCards
267
+ puts customerCards[0].getCardHolder
268
+ end
269
+
270
+
271
+ else
272
+ puts responseDetails.getResponseSummary
273
+ end
274
+
275
+ if(responseDetails.getValidationErrors)
276
+ vErrors = responseDetails.getValidationErrors
277
+ if(vErrors.getErrorDetails)
278
+
279
+ vErrors.getErrorDetails.each do |ed|
280
+
281
+ puts "Error Summary:"
282
+ puts ed.getErrorSummary
283
+ puts "Error Description: "
284
+ puts ed.getErrorDescription
285
+
286
+ end
287
+
288
+ end
289
+ end
290
+ end
291
+
292
+ def PerformPreAuthorization(customerId,mpago)
293
+
294
+ tranxRequest = Transaction.new
295
+ customer = Customer.new
296
+
297
+ #card Info
298
+ creditCards = []
299
+ card = CreditCard.new
300
+ card.Token = "A2478342-617A-4EE5-BC1B-ECD3D132D9CF"
301
+ creditCards << card
302
+
303
+ #Account Info
304
+ accounts = []
305
+ account = CustomerEntity.new
306
+ account.Id = "9680"
307
+ accounts << account
308
+
309
+ #customer Info
310
+ customer.CustomerId = customerId
311
+ customer.CreditCards = creditCards
312
+ #customer.CustomerEntities = accounts
313
+
314
+ #Transaction Info
315
+ tranxRequest.CustomerData = customer
316
+ tranxRequest.Amount = 1.00
317
+ tranxRequest.OrderTrackingNumber = "777AAAAA"
318
+
319
+ tranxMgr = TransactionManager.new(mpago)
320
+ responseTranxModel = tranxMgr.PreAuthorization(tranxRequest)
321
+
322
+
323
+ puts 'RESULT - PreAuthorization:'
324
+ responseDetails = responseTranxModel.getResponseDetails
325
+
326
+ if(responseDetails.getIsSuccess == true)
327
+ puts 'Transaction Processed Successfullly. Transaction Id: ' + responseDetails.getTransactionId
328
+ @preAuth_TransactionId = responseDetails.getTransactionId
329
+ else
330
+ puts responseDetails.getResponseSummary
331
+ end
332
+ end
333
+
334
+ def PerformRebill(customerId,mpago)
335
+
336
+ tranxRequest = Transaction.new
337
+ customer = Customer.new
338
+
339
+ #card Info
340
+ creditCards = []
341
+ card = CreditCard.new
342
+ card.Token = "A2478342-617A-4EE5-BC1B-ECD3D132D9CF"
343
+ creditCards << card
344
+
345
+ #Account Info
346
+ accounts = []
347
+ account = CustomerEntity.new
348
+ account.Id = "9680"
349
+ accounts << account
350
+
351
+ #customer Info
352
+ customer.CustomerId = customerId
353
+ customer.CreditCards = creditCards
354
+ customer.CustomerEntities = accounts
355
+
356
+ #Transaction Info
357
+ tranxRequest.CustomerData = customer
358
+ tranxRequest.Amount = 1.00
359
+ tranxRequest.OrderTrackingNumber = "777AAAAA"
360
+
361
+ tranxMgr = TransactionManager.new(mpago)
362
+ responseTranxModel = tranxMgr.Rebill(tranxRequest)
363
+
364
+
365
+ puts 'RESULT - Rebill:'
366
+ responseDetails = responseTranxModel.getResponseDetails
367
+
368
+ if(responseDetails.getIsSuccess == true)
369
+ puts 'Transaction Processed Successfullly. Transaction Id: ' + responseDetails.getTransactionId
370
+ else
371
+ puts responseDetails.getResponseSummary
372
+ end
373
+ end
374
+
375
+ def PerformAdjustment(customerId,mpago)
376
+
377
+ tranxRequest = Transaction.new
378
+ tranxRequest.TransactionId = @preAuth_TransactionId
379
+ tranxRequest.Amount = 1.00
380
+
381
+ tranxMgr = TransactionManager.new(mpago)
382
+ responseTranxModel = tranxMgr.Adjustment(tranxRequest)
383
+
384
+ puts 'RESULT - Adjustment:'
385
+ responseDetails = responseTranxModel.getResponseDetails
386
+
387
+ if(responseDetails.getIsSuccess == true)
388
+ puts 'Transaction Processed Successfullly. Transaction Id: ' + responseDetails.getTransactionId
389
+ else
390
+ puts responseDetails.getResponseSummary
391
+ end
392
+ end
393
+
394
+ def PerformRefund(customerId,mpago)
395
+
396
+ tranxRequest = Transaction.new
397
+ tranxRequest.TransactionId = @preAuth_TransactionId
398
+ tranxRequest.Amount = 1.00
399
+
400
+ tranxMgr = TransactionManager.new(mpago)
401
+ responseTranxModel = tranxMgr.Refund(tranxRequest)
402
+
403
+ puts 'RESULT - Refund:'
404
+ responseDetails = responseTranxModel.getResponseDetails
405
+
406
+ if(responseDetails.getIsSuccess == true)
407
+ puts 'Transaction Processed Successfullly. Transaction Id: ' + responseDetails.getTransactionId
408
+ else
409
+ puts responseDetails.getResponseSummary
410
+ end
411
+ end
412
+
413
+ def SearchTransactions(cutomerId,mpago)
414
+
415
+ searchRequest = TransactionSearchRequest.new
416
+ searchRequest.Amount = AmountRangeFilter.new.Between(0.00, 2.00)
417
+ searchRequest.CardHolderName = TextFilter.new.StartsWith("ZEE")
418
+
419
+ #searchRequest.TransactionId = "102747816"
420
+
421
+ searchRequest.CustomerId = cutomerId
422
+
423
+ tranxMgr = TransactionManager.new(mpago)
424
+ transactions = tranxMgr.SearchTransaction(searchRequest)
425
+
426
+ transactions.each do |tranx|
427
+ puts tranx.getTransactionId + " - " + tranx.getAmount.to_s + " - " + tranx.getCreditCardDetail.to_json
428
+ end
429
+ end
430
+
431
+ def PerformUpdateTransaction(customerId,mpago)
432
+
433
+ tranxRequest = Transaction.new
434
+ tranxRequest.ThirdPartyDescription = "Account Payment ABC123"
435
+ tranxRequest.ThirdPartyStatus = "POSTED"
436
+ tranxRequest.TransactionId = "102747859"
437
+
438
+
439
+ tranxMgr = TransactionManager.new(mpago)
440
+ responseTranxModel = tranxMgr.UpdateTransaction(tranxRequest)
441
+
442
+ puts 'RESULT - Update Transaction:'
443
+ responseDetails = responseTranxModel.getResponseDetails
444
+
445
+ if(responseDetails.getIsSuccess == true)
446
+ puts 'Transaction Updated Successfullly. Transaction Id: ' + responseDetails.getTransactionId
447
+ else
448
+ puts responseDetails.getResponseSummary
449
+ end
450
+ end
451
+
452
+ #PerformSale(customerId,CroemincGateway)
453
+ #PerformPreAuthorization(customerId,CroemincGateway)
454
+ #PerformRebill(customerId,CroemincGateway)
455
+ #PerformRefund(customerId,CroemincGateway)
456
+ #SearchTransactions(customerId,CroemincGateway)
457
+ #PerformUpdateTransaction(customerId,CroemincGateway)
458
+
459
+
460
+
461
+
462
+
463
+
464
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "CroemincRubyGem"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ class EnvironmentType
2
+ ENVIRONMENT_TYPES = [SANDBOX = 'SANDBOX', PRODUCTION = 'PRODUCTION']
3
+ end