mundipagg_sdk 1.0.3 → 1.2.3rc

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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -61
  3. data/lib/gateway/Address/billing_address.rb +34 -32
  4. data/lib/gateway/Address/buyer_address.rb +39 -36
  5. data/lib/gateway/Address/delivery_address.rb +34 -32
  6. data/lib/gateway/BoletoTransaction/boleto_transaction.rb +41 -43
  7. data/lib/gateway/BoletoTransaction/boleto_transaction_options.rb +17 -14
  8. data/lib/gateway/BoletoTransaction/boleto_transaction_report_file.rb +22 -19
  9. data/lib/gateway/CreditCardTransaction/credit_card.rb +30 -29
  10. data/lib/gateway/CreditCardTransaction/credit_card_transaction.rb +33 -31
  11. data/lib/gateway/CreditCardTransaction/credit_card_transaction_options.rb +28 -26
  12. data/lib/gateway/CreditCardTransaction/credit_card_transaction_report_file.rb +31 -28
  13. data/lib/gateway/CreditCardTransaction/manage_credit_card_transaction.rb +14 -11
  14. data/lib/gateway/CreditCardTransaction/retry_sale_credit_card_transaction.rb +14 -12
  15. data/lib/gateway/Gateway.rb +621 -441
  16. data/lib/gateway/InstantBuyData/create_instant_buy_data_request.rb +31 -0
  17. data/lib/gateway/InstantBuyData/update_instant_buy_data_request.rb +11 -0
  18. data/lib/gateway/Merchant/merchant.rb +12 -10
  19. data/lib/gateway/OnlineDebit/online_debit_transaction_report_file.rb +21 -18
  20. data/lib/gateway/Order/order.rb +13 -10
  21. data/lib/gateway/Order/order_transaction_report_file.rb +8 -5
  22. data/lib/gateway/Parsers/boleto_transaction_parser.rb +33 -30
  23. data/lib/gateway/Parsers/credit_card_transaction_parser.rb +42 -39
  24. data/lib/gateway/Parsers/header_parser.rb +16 -13
  25. data/lib/gateway/Parsers/online_debit_transaction_parser.rb +32 -29
  26. data/lib/gateway/Parsers/trailer_parser.rb +16 -14
  27. data/lib/gateway/Person/buyer.rb +32 -32
  28. data/lib/gateway/Person/create_buyer_request.rb +23 -0
  29. data/lib/gateway/Person/person.rb +48 -46
  30. data/lib/gateway/Recurrency/recurrency.rb +24 -22
  31. data/lib/gateway/Sale/create_sale_request.rb +37 -35
  32. data/lib/gateway/Sale/manage_sale_request.rb +18 -16
  33. data/lib/gateway/Sale/query_sale_request.rb +37 -35
  34. data/lib/gateway/Sale/request_data.rb +21 -19
  35. data/lib/gateway/Sale/retry_sale_options.rb +15 -13
  36. data/lib/gateway/Sale/retry_sale_request.rb +23 -22
  37. data/lib/gateway/Sale/sale_data.rb +30 -32
  38. data/lib/gateway/Sale/sale_order_data.rb +18 -16
  39. data/lib/gateway/SalesOption.rb +19 -17
  40. data/lib/gateway/ShoppingCart/shopping_cart.rb +27 -25
  41. data/lib/gateway/ShoppingCart/shopping_cart_item.rb +24 -22
  42. data/lib/gateway/Trailer.rb +8 -5
  43. data/lib/gateway/header.rb +7 -4
  44. data/lib/gateway/post_notification.rb +31 -28
  45. data/lib/gateway/transaction_report_file.rb +47 -44
  46. data/lib/mundipagg_sdk.rb +62 -70
  47. data/mundipagg_sdk.gemspec +19 -19
  48. data/spec/integration/gateway_spec.rb +1022 -733
  49. data/spec/integration/test_helper.rb +68 -68
  50. metadata +7 -21
  51. data/lib/gateway/AntiFraud/anti_fraud_analysis_result.rb +0 -47
  52. data/lib/gateway/AntiFraud/query_sale_anti_fraud_analysis_data.rb +0 -51
  53. data/lib/gateway/AntiFraud/query_sale_anti_fraud_analysis_history_data.rb +0 -41
  54. data/lib/gateway/BaseRequest.rb +0 -11
  55. data/lib/gateway/BaseResponse.rb +0 -17
  56. data/lib/gateway/BoletoTransaction/boleto_transaction_data.rb +0 -44
  57. data/lib/gateway/BoletoTransaction/boleto_transaction_result.rb +0 -35
  58. data/lib/gateway/CreditCardTransaction/credit_card_transaction_data.rb +0 -104
  59. data/lib/gateway/ErrorItem.rb +0 -17
  60. data/lib/gateway/ErrorReport.rb +0 -18
  61. data/lib/gateway/InstantBuy/credit_card_data.rb +0 -41
  62. data/lib/gateway/InstantBuy/get_instant_buy_data_response.rb +0 -18
  63. data/lib/gateway/Sale/create_sale_response.rb +0 -25
  64. data/lib/gateway/Sale/manage_sale_response.rb +0 -15
  65. data/lib/gateway/Sale/query_sale_response.rb +0 -18
  66. data/lib/gateway/Sale/retry_sale_response.rb +0 -14
  67. data/lib/gateway/address.rb +0 -25
@@ -1,20 +1,23 @@
1
- class BoletoTransactionReportFile
2
- attr_accessor :Order
3
- attr_accessor :TransactionKey
4
- attr_accessor :TransactionReference
5
- attr_accessor :Status
6
- attr_accessor :NossoNumero
7
- attr_accessor :BankNumber
8
- attr_accessor :Agency
9
- attr_accessor :Account
10
- attr_accessor :BarCode
11
- attr_accessor :ExpirationDate
12
- attr_accessor :AmountInCents
13
- attr_accessor :AmountPaidInCents
14
- attr_accessor :PaymentDate
15
- attr_accessor :CreditDate
16
-
17
- def initialize
18
- @Order = OrderTransactionReportFile.new
19
- end
1
+ module Gateway
2
+
3
+ class BoletoTransactionReportFile
4
+ attr_accessor :Order
5
+ attr_accessor :TransactionKey
6
+ attr_accessor :TransactionReference
7
+ attr_accessor :Status
8
+ attr_accessor :NossoNumero
9
+ attr_accessor :BankNumber
10
+ attr_accessor :Agency
11
+ attr_accessor :Account
12
+ attr_accessor :BarCode
13
+ attr_accessor :ExpirationDate
14
+ attr_accessor :AmountInCents
15
+ attr_accessor :AmountPaidInCents
16
+ attr_accessor :PaymentDate
17
+ attr_accessor :CreditDate
18
+
19
+ def initialize
20
+ @Order = OrderTransactionReportFile.new
21
+ end
22
+ end
20
23
  end
@@ -1,30 +1,31 @@
1
- class CreditCard
2
-
3
- attr_accessor :InstantBuyKey
4
-
5
- attr_accessor :CreditCardNumber
6
-
7
- attr_accessor :HolderName
8
-
9
- attr_accessor :SecurityCode
10
-
11
- attr_accessor :ExpMonth
12
-
13
- attr_accessor :ExpYear
14
-
15
- attr_accessor :CreditCardBrand
16
-
17
- attr_accessor :BillingAddress
18
-
19
- def initialize
20
- @BillingAddress = BillingAddress.new
21
- end
22
-
23
- def to_json
24
- hash = {}
25
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
26
- hash
27
- end
28
-
29
-
1
+ module Gateway
2
+
3
+ class CreditCard
4
+
5
+ attr_accessor :InstantBuyKey
6
+
7
+ attr_accessor :CreditCardNumber
8
+
9
+ attr_accessor :HolderName
10
+
11
+ attr_accessor :SecurityCode
12
+
13
+ attr_accessor :ExpMonth
14
+
15
+ attr_accessor :ExpYear
16
+
17
+ attr_accessor :CreditCardBrand
18
+
19
+ attr_accessor :BillingAddress
20
+
21
+ def initialize
22
+ @BillingAddress = BillingAddress.new
23
+ end
24
+
25
+ def to_json
26
+ hash = {}
27
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
28
+ hash
29
+ end
30
+ end
30
31
  end
@@ -1,32 +1,34 @@
1
- class CreditCardTransaction
2
-
3
- attr_accessor :CreditCard
4
-
5
- attr_accessor :Options
6
-
7
- attr_accessor :Recurrency
8
-
9
- attr_accessor :AmountInCents
10
-
11
- attr_accessor :InstallmentCount
12
-
13
- attr_accessor :CreditCardOperation
14
-
15
- attr_accessor :TransactionReference
16
-
17
- attr_accessor :TransactionDateInMerchant
18
-
19
-
20
- def initialize
21
- @Options = CreditCardTransactionOptions.new
22
- @Recurrency = Recurrency.new
23
- @CreditCard = CreditCard.new
24
- end
25
-
26
- def to_json
27
- hash = {}
28
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
29
- hash
30
- end
31
-
1
+ module Gateway
2
+
3
+ class CreditCardTransaction
4
+
5
+ attr_accessor :CreditCard
6
+
7
+ attr_accessor :Options
8
+
9
+ attr_accessor :Recurrency
10
+
11
+ attr_accessor :AmountInCents
12
+
13
+ attr_accessor :InstallmentCount
14
+
15
+ attr_accessor :CreditCardOperation
16
+
17
+ attr_accessor :TransactionReference
18
+
19
+ attr_accessor :TransactionDateInMerchant
20
+
21
+
22
+ def initialize
23
+ @Options = CreditCardTransactionOptions.new
24
+ @Recurrency = Recurrency.new
25
+ @CreditCard = CreditCard.new
26
+ end
27
+
28
+ def to_json
29
+ hash = {}
30
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
31
+ hash
32
+ end
33
+ end
32
34
  end
@@ -1,27 +1,29 @@
1
- class CreditCardTransactionOptions
2
-
3
- attr_accessor :PaymentMethodCode
4
-
5
- attr_accessor :CurrencyIso
6
-
7
- attr_accessor :IataAmountInCents
8
-
9
- attr_accessor :CaptureDelayInMinutes
10
-
11
- attr_accessor :MerchantCategoryCode
12
-
13
- attr_accessor :SoftDescriptorText
14
-
15
- attr_accessor :InterestRate
16
-
17
- attr_accessor :ExtendedLimitEnabled
18
-
19
- attr_accessor :ExtendedLimitCode
20
-
21
- def to_json
22
- hash = {}
23
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
24
- hash
25
- end
26
-
1
+ module Gateway
2
+
3
+ class CreditCardTransactionOptions
4
+
5
+ attr_accessor :PaymentMethodCode
6
+
7
+ attr_accessor :CurrencyIso
8
+
9
+ attr_accessor :IataAmountInCents
10
+
11
+ attr_accessor :CaptureDelayInMinutes
12
+
13
+ attr_accessor :MerchantCategoryCode
14
+
15
+ attr_accessor :SoftDescriptorText
16
+
17
+ attr_accessor :InterestRate
18
+
19
+ attr_accessor :ExtendedLimitEnabled
20
+
21
+ attr_accessor :ExtendedLimitCode
22
+
23
+ def to_json
24
+ hash = {}
25
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
26
+ hash
27
+ end
28
+ end
27
29
  end
@@ -1,29 +1,32 @@
1
- class CreditCardTransactionReportFile
2
- attr_accessor :Order
3
- attr_accessor :TransactionKey
4
- attr_accessor :TransactionKeyToAcquirer
5
- attr_accessor :CreditCardTransactionReference
6
- attr_accessor :CreditCardBrand
7
- attr_accessor :CreditCardNumber
8
- attr_accessor :InstallmentCount
9
- attr_accessor :AcquirerName
10
- attr_accessor :Status
11
- attr_accessor :AmountInCents
12
- attr_accessor :IataAmountInCents
13
- attr_accessor :AuthorizationCode
14
- attr_accessor :TransactionIdentifier
15
- attr_accessor :UniqueSequentialNumber
16
- attr_accessor :AuthorizedAmountInCents
17
- attr_accessor :CapturedAmountInCents
18
- attr_accessor :VoidedAmountInCents
19
- attr_accessor :RefundedAmountInCents
20
- attr_accessor :AcquirerAuthorizationReturnCode
21
- attr_accessor :AuthorizedDate
22
- attr_accessor :CapturedDate
23
- attr_accessor :VoidedDate
24
- attr_accessor :LastProbeDate
25
-
26
- def initialize
27
- @Order = OrderTransactionReportFile.new
28
- end
1
+ module Gateway
2
+
3
+ class CreditCardTransactionReportFile
4
+ attr_accessor :Order
5
+ attr_accessor :TransactionKey
6
+ attr_accessor :TransactionKeyToAcquirer
7
+ attr_accessor :CreditCardTransactionReference
8
+ attr_accessor :CreditCardBrand
9
+ attr_accessor :CreditCardNumber
10
+ attr_accessor :InstallmentCount
11
+ attr_accessor :AcquirerName
12
+ attr_accessor :Status
13
+ attr_accessor :AmountInCents
14
+ attr_accessor :IataAmountInCents
15
+ attr_accessor :AuthorizationCode
16
+ attr_accessor :TransactionIdentifier
17
+ attr_accessor :UniqueSequentialNumber
18
+ attr_accessor :AuthorizedAmountInCents
19
+ attr_accessor :CapturedAmountInCents
20
+ attr_accessor :VoidedAmountInCents
21
+ attr_accessor :RefundedAmountInCents
22
+ attr_accessor :AcquirerAuthorizationReturnCode
23
+ attr_accessor :AuthorizedDate
24
+ attr_accessor :CapturedDate
25
+ attr_accessor :VoidedDate
26
+ attr_accessor :LastProbeDate
27
+
28
+ def initialize
29
+ @Order = OrderTransactionReportFile.new
30
+ end
31
+ end
29
32
  end
@@ -1,12 +1,15 @@
1
- # classe para usar nos metodos de cancel e capture
2
- class ManageCreditCardTransaction
3
- attr_accessor :AmountInCents
4
- attr_accessor :TransactionKey
5
- attr_accessor :TransactionReference
6
-
7
- def to_json
8
- hash = {}
9
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
10
- hash
11
- end
1
+ module Gateway
2
+
3
+ # classe para usar nos metodos de cancel e capture
4
+ class ManageCreditCardTransaction
5
+ attr_accessor :AmountInCents
6
+ attr_accessor :TransactionKey
7
+ attr_accessor :TransactionReference
8
+
9
+ def to_json
10
+ hash = {}
11
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
12
+ hash
13
+ end
14
+ end
12
15
  end
@@ -1,13 +1,15 @@
1
- class RetrySaleCreditCardTransaction
2
-
3
- attr_accessor :TransactionKey
4
-
5
- attr_accessor :SecurityCode
6
-
7
- def to_json
8
- hash = {}
9
- instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
10
- hash
11
- end
12
-
1
+ module Gateway
2
+
3
+ class RetrySaleCreditCardTransaction
4
+
5
+ attr_accessor :TransactionKey
6
+
7
+ attr_accessor :SecurityCode
8
+
9
+ def to_json
10
+ hash = {}
11
+ instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
12
+ hash
13
+ end
14
+ end
13
15
  end
@@ -1,441 +1,621 @@
1
- require_relative '../../lib/mundipagg_sdk'
2
-
3
- class Gateway
4
-
5
- attr_reader :serviceEnvironment
6
-
7
- attr_reader :merchantKey
8
-
9
- def initialize(environment=:staging, merchantKey)
10
- @serviceEnvironment = environment
11
- @merchantKey = merchantKey
12
- @@SERVICE_HEADERS = {:MerchantKey => "#{@merchantKey}", :Accept => 'application/json', :"Content-Type" => 'application/json'}
13
- end
14
-
15
- # URL de producao
16
- @@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com'
17
-
18
- # URL de homologacao
19
- @@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com'
20
-
21
- # URL de sandbox
22
- @@SERVICE_URL_SANDBOX = 'https://sandbox.mundipaggone.com'
23
-
24
- # URL do postnotification de producao
25
- @@SERVICE_URL_NOTIFICATION_PRODUCTION = 'https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
26
-
27
- # URL do postnotification de sandbox
28
- @@SERVICE_URL_NOTIFICATION_SANDBOX = 'https://apisandbox.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
29
-
30
- # permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
31
- def Query(querySaleRequestEnum, key)
32
- # try, tenta fazer o request
33
- begin
34
- # se for homologacao faz a chamada por aqui
35
- if @serviceEnvironment == :staging
36
- getRequest(@@SERVICE_URL_STAGING + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
37
-
38
- # se for producao, faz a chamada por aqui
39
- elsif @serviceEnvironment == :production
40
- getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
41
-
42
- # se for sandbox
43
- elsif @serviceEnvironment == :sandbox
44
- getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
45
- end
46
-
47
- # se der algum erro, trata aqui
48
- rescue Exception => e
49
- return e.message
50
- end
51
- end
52
-
53
- # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
54
- def CreateSale(createSaleRequest)
55
-
56
- saleHash = createSaleRequest.to_json
57
-
58
- saleHash['BoletoTransactionCollection'] = []
59
-
60
- saleHash['CreditCardTransactionCollection'] = []
61
-
62
- saleHash['ShoppingCartCollection'] = []
63
-
64
- begin
65
- # transforma a colecao de boleto em json
66
- if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
67
- saleHash['BoletoTransactionCollection'] = nil
68
-
69
- else
70
- createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
71
- b = boleto.to_json
72
- saleHash['BoletoTransactionCollection'] << b
73
-
74
- if boleto.Options.to_json.any?
75
- boleto_options = boleto.Options.to_json
76
- saleHash['BoletoTransactionCollection'][index]['Options'] = boleto_options
77
- else
78
- saleHash['BoletoTransactionCollection'][index]['Options'] = nil
79
- end
80
-
81
- if boleto.BillingAddress.to_json.any?
82
- boleto_billing_address = boleto.BillingAddress.to_json
83
- saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = boleto_billing_address
84
- else
85
- saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = nil
86
- end
87
- end
88
- end
89
-
90
- # transforma a colecao de cartao de credito em json
91
- if createSaleRequest.CreditCardTransactionCollection.any? == false || createSaleRequest.CreditCardTransactionCollection.nil?
92
- saleHash['CreditCardTransactionCollection'] = nil
93
- else
94
- createSaleRequest.CreditCardTransactionCollection.each_with_index do |creditCard, index|
95
- c = creditCard.to_json
96
- saleHash['CreditCardTransactionCollection'] << c
97
-
98
- if creditCard.Options.to_json.any?
99
- credit_card_options = creditCard.Options.to_json
100
- saleHash['CreditCardTransactionCollection'][index]['Options'] = credit_card_options
101
- else
102
- saleHash['CreditCardTransactionCollection'][index]['Options'] = nil
103
- end
104
-
105
- if creditCard.Recurrency.to_json.any?
106
- credit_card_recurrency = creditCard.Recurrency.to_json
107
- saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
108
- else
109
- saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
110
- end
111
-
112
- if creditCard.CreditCard.to_json.any?
113
- credit_card_item = creditCard.CreditCard.to_json
114
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
115
-
116
- if creditCard.CreditCard.BillingAddress.to_json.any?
117
- credit_card_billing_address = creditCard.CreditCard.BillingAddress.to_json
118
- saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = credit_card_billing_address
119
- else
120
- saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
121
- end
122
-
123
- else
124
- saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
125
- end
126
- end
127
- end
128
-
129
- # transforma a colecao de shoppingcart em json
130
- if createSaleRequest.ShoppingCartCollection.any? == false || createSaleRequest.ShoppingCartCollection.nil?
131
- saleHash['ShoppingCartCollection'] = nil
132
- else
133
- createSaleRequest.ShoppingCartCollection.each_with_index do |shoppingCart, index|
134
- s = shoppingCart.to_json
135
- saleHash['ShoppingCartCollection'] << s
136
-
137
- if shoppingCart.DeliveryAddress.to_json.any?
138
- delivery_address = shoppingCart.DeliveryAddress.to_json
139
- saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = delivery_address
140
- else
141
- saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = nil
142
- end
143
-
144
- if shoppingCart.ShoppingCartItemCollection.any?
145
- shoppingCart.ShoppingCartItemCollection.each_with_index do |cartItem, cartIndex|
146
- item = cartItem.to_json
147
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'][cartIndex] = item
148
- end
149
- else
150
- saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
151
- end
152
- end
153
- end
154
-
155
- # transforma objeto options em json
156
- if createSaleRequest.Options.to_json.any?
157
- o = createSaleRequest.Options.to_json
158
- saleHash['Options'] = o
159
- else
160
- saleHash['Options'] = nil
161
- end
162
-
163
- # transforma objeto order em json
164
- if createSaleRequest.Order.to_json.any?
165
- order = createSaleRequest.Order.to_json
166
- saleHash['Order'] = order
167
- else
168
- saleHash['Order'] = nil
169
- end
170
-
171
- # transforma objeto merchant em json
172
- if createSaleRequest.Merchant.to_json.any?
173
- merchant = createSaleRequest.Merchant.to_json
174
- saleHash['Merchant'] = merchant
175
- else
176
- saleHash['Merchant'] = nil
177
- end
178
-
179
- # transforma objeto request data em json
180
- if createSaleRequest.RequestData.to_json.any?
181
- request_data = createSaleRequest.RequestData.to_json
182
- saleHash['RequestData'] = request_data
183
- else
184
- saleHash['RequestData'] = nil
185
- end
186
-
187
- # transforma o objeto Buyer em json
188
- if createSaleRequest.Buyer.AddressCollection.any?
189
- b = createSaleRequest.Buyer.to_json
190
- saleHash['Buyer'] = b
191
-
192
- saleHash['Buyer']['AddressCollection'] = []
193
- createSaleRequest.Buyer.AddressCollection.each do |address|
194
- a = address.to_json
195
- saleHash['Buyer']['AddressCollection'] << a
196
- end
197
- else
198
- buyer_hash = createSaleRequest.Buyer.to_json
199
- buyer_hash.delete('AddressCollection')
200
- if buyer_hash.blank? == false
201
- b = createSaleRequest.Buyer.to_json
202
- saleHash['Buyer'] = b
203
- saleHash['Buyer']['AddressCollection'] = nil
204
- else
205
- saleHash['Buyer'] = nil
206
- end
207
- end
208
-
209
- rescue Exception => e
210
- return e.message
211
- end
212
-
213
- if @serviceEnvironment == :staging
214
- url = @@SERVICE_URL_STAGING + '/Sale/'
215
- elsif @serviceEnvironment == :production
216
- url = @@SERVICE_URL_PRODUCTION + '/Sale/'
217
- elsif @serviceEnvironment == :sandbox
218
- url = @@SERVICE_URL_SANDBOX + '/Sale/'
219
- end
220
- postRequest(saleHash.to_json, url)
221
- end
222
-
223
- # permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
224
- def Retry(retrySaleRequest)
225
- saleHash = retrySaleRequest.to_json
226
- saleHash['RetrySaleCreditCardTransactionCollection'] = []
227
-
228
- begin
229
- if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
230
- retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
231
- r = retrySale.to_json
232
- saleHash['RetrySaleCreditCardTransactionCollection'] << r
233
- end
234
- end
235
- if retrySaleRequest.Options.to_json.any?
236
- retry_options = retrySaleRequest.Options.to_json
237
- saleHash['Options'] = retry_options
238
- else
239
- saleHash['Options'] = nil
240
- end
241
- rescue Exception => e
242
- return e.message
243
- end
244
- if @serviceEnvironment == :staging
245
- url = @@SERVICE_URL_STAGING + '/Sale/Retry'
246
- elsif @serviceEnvironment == :production
247
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
248
- elsif @serviceEnvironment == :sandbox
249
- url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
250
- end
251
- postRequest(saleHash.to_json, url)
252
- end
253
-
254
- # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
255
- def Cancel(cancelSaleRequest)
256
- saleHash = cancelSaleRequest.to_json
257
- saleHash['CreditCardTransactionCollection'] = []
258
-
259
- begin
260
- if cancelSaleRequest.CreditCardTransactionCollection != nil
261
- cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
262
- c = creditCard.to_json
263
- saleHash['CreditCardTransactionCollection'] << c
264
- end
265
- end
266
- rescue Exception => e
267
- return e.message
268
- end
269
- if @serviceEnvironment == :staging
270
- url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
271
- elsif @serviceEnvironment == :production
272
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
273
- elsif @serviceEnvironment == :sandbox
274
- url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
275
- end
276
- postRequest(saleHash.to_json, url)
277
- end
278
-
279
- # confirmacao de uma transacao de cartao de credito que ja fora autorizada
280
- def Capture(captureRequest)
281
- saleHash = captureRequest.to_json
282
- saleHash['CreditCardTransactionCollection'] = []
283
-
284
- begin
285
- if captureRequest.CreditCardTransactionCollection != nil
286
- captureRequest.CreditCardTransactionCollection.each do |creditCard|
287
- c = creditCard.to_json
288
- saleHash['CreditCardTransactionCollection'] << c
289
- end
290
- end
291
- rescue Exception => e
292
- return e.message
293
- end
294
- if @serviceEnvironment == :staging
295
- url = @@SERVICE_URL_STAGING + '/Sale/Capture'
296
- elsif @serviceEnvironment == :production
297
- url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
298
- elsif @serviceEnvironment == :sandbox
299
- url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
300
- end
301
- postRequest(saleHash.to_json, url)
302
- end
303
-
304
- # faz um parse do xml de post notificaton
305
- def ParseXmlToNotification(xml)
306
- begin
307
- response = PostNotification.ParseNotification(xml)
308
- rescue Exception => err
309
- return err.message
310
- end
311
-
312
- return response
313
- end
314
-
315
- # faz uma requisicao e retorna uma string com o transaction report file
316
- def TransactionReportFile(date)
317
- begin
318
- if @serviceEnvironment == :staging
319
- url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
320
- elsif @serviceEnvironment == :production
321
- url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
322
- elsif @serviceEnvironment == :sandbox
323
- url = @@SERVICE_URL_NOTIFICATION_SANDBOX + date.strftime("%Y%m%d")
324
- end
325
-
326
- response = getReportFile(url)
327
-
328
- rescue RestClient::ExceptionWithResponse => err
329
- return err.response
330
- end
331
- return response
332
- end
333
-
334
- # faz o download do transaction report file e salva no computador em .txt
335
- def TransactionReportFileDownloader(date, file_name, path)
336
- begin
337
- path = path + file_name + '.txt'
338
-
339
- response = TransactionReportFile(date)
340
-
341
- File.write(path, response)
342
- rescue RestClient::ExceptionWithResponse => err
343
- return err.response
344
- end
345
- end
346
-
347
- # faz o parse da string recebida do transaction report file e retorna um hash
348
- def TransactionReportFileParser(file_to_parse)
349
- transaction_report_file = TransactionReportFile.new
350
- begin
351
- response = transaction_report_file.TransactionReportFileParser(file_to_parse)
352
- rescue Exception => err
353
- return err
354
- end
355
- return response
356
- end
357
-
358
- # faz uma requisicao com instant buy key
359
- def InstantBuyKey(instant_buy_key)
360
- # try, tenta fazer o request
361
- begin
362
-
363
- # se for homologacao faz a chamada por aqui
364
- if @serviceEnvironment == :staging
365
- getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
366
-
367
- # se for producao, faz a chamada por aqui
368
- elsif @serviceEnvironment == :production
369
- getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
370
-
371
- # se for sandbox
372
- elsif @serviceEnvironment == :sandbox
373
- getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
374
- end
375
-
376
- # se der algum erro, trata aqui
377
- rescue Exception => e
378
- return e.message
379
- end
380
- end
381
-
382
- # faz uma requisicao com buyer key
383
- def BuyerKey(buyer_key)
384
- # try, tenta fazer o request
385
- begin
386
-
387
- # se for homologacao faz a chamada por aqui
388
- if @serviceEnvironment == :staging
389
- response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + buyer_key + '/BuyerKey')
390
-
391
- # se for producao, faz a chamada por aqui
392
- elsif @serviceEnvironment == :production
393
- response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + buyer_key + '/BuyerKey')
394
-
395
- # se for sandbox, faz a chamada por aqui
396
- elsif @serviceEnvironment == :sandbox
397
- response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + buyer_key + '/BuyerKey')
398
- end
399
-
400
- # se der algum erro, trata aqui
401
- rescue Exception => e
402
- return e.message
403
- end
404
-
405
- # se nao houver erros, retorna o objeto
406
- response
407
- end
408
-
409
- # funcao de post generica
410
- def postRequest(payload, url)
411
- response = nil
412
- begin
413
- response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
414
- rescue RestClient::ExceptionWithResponse => err
415
- return err.response
416
- end
417
- json_response = JSON.load response
418
- json_response
419
- end
420
-
421
- # funcao get generica
422
- def getRequest(url)
423
- response = nil
424
- begin
425
- response = RestClient.get(url, headers=@@SERVICE_HEADERS)
426
- rescue RestClient::ExceptionWithResponse => err
427
- return err.response
428
- end
429
- json_response = JSON.load response
430
- json_response
431
- end
432
-
433
- def getReportFile(url)
434
- begin
435
- response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
436
- rescue RestClient::ExceptionWithResponse => err
437
- return err.response
438
- end
439
- return response
440
- end
441
- end
1
+ require_relative '../../lib/mundipagg_sdk'
2
+ module Gateway
3
+
4
+ class Gateway
5
+ extend Gem::Deprecate
6
+
7
+ attr_reader :serviceEnvironment
8
+
9
+ attr_reader :merchantKey
10
+
11
+ def initialize(environment=:sandbox, merchantKey)
12
+ @serviceEnvironment = environment
13
+ @merchantKey = merchantKey
14
+ @@SERVICE_HEADERS = {:MerchantKey => "#{@merchantKey}", :Accept => 'application/json', :"Content-Type" => 'application/json'}
15
+ end
16
+
17
+ # URL de producao
18
+ @@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com'
19
+
20
+ # URL de homologacao
21
+ @@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com'
22
+
23
+ # URL de sandbox
24
+ @@SERVICE_URL_SANDBOX = 'https://sandbox.mundipaggone.com'
25
+
26
+ # URL do postnotification de producao
27
+ @@SERVICE_URL_NOTIFICATION_PRODUCTION = 'https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
28
+
29
+ # URL do postnotification de sandbox
30
+ @@SERVICE_URL_NOTIFICATION_SANDBOX = 'https://apisandbox.mundipaggone.com/TransactionReportFile/GetStream?fileDate='
31
+
32
+ # permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
33
+ def Query(querySaleRequestEnum, key)
34
+ # try, tenta fazer o request
35
+ begin
36
+ # se for homologacao faz a chamada por aqui
37
+ if @serviceEnvironment == :staging
38
+ getRequest(@@SERVICE_URL_STAGING + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
39
+
40
+ # se for producao, faz a chamada por aqui
41
+ elsif @serviceEnvironment == :production
42
+ getRequest(@@SERVICE_URL_PRODUCTION + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
43
+
44
+ # se for sandbox
45
+ elsif @serviceEnvironment == :sandbox
46
+ getRequest(@@SERVICE_URL_SANDBOX + '/Sale/Query/' + querySaleRequestEnum + '=' + key)
47
+ end
48
+
49
+ # se der algum erro, trata aqui
50
+ rescue Exception => e
51
+ return e.message
52
+ end
53
+ end
54
+
55
+ # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
56
+ def CreateSale(createSaleRequest)
57
+
58
+ saleHash = createSaleRequest.to_json
59
+
60
+ saleHash['BoletoTransactionCollection'] = []
61
+
62
+ saleHash['CreditCardTransactionCollection'] = []
63
+
64
+ saleHash['ShoppingCartCollection'] = []
65
+
66
+ begin
67
+ # transforma a colecao de boleto em json
68
+ if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
69
+ saleHash['BoletoTransactionCollection'] = nil
70
+
71
+ else
72
+ createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
73
+ b = boleto.to_json
74
+ saleHash['BoletoTransactionCollection'] << b
75
+
76
+ if boleto.Options.to_json.any?
77
+ boleto_options = boleto.Options.to_json
78
+ saleHash['BoletoTransactionCollection'][index]['Options'] = boleto_options
79
+ else
80
+ saleHash['BoletoTransactionCollection'][index]['Options'] = nil
81
+ end
82
+
83
+ if boleto.BillingAddress.to_json.any?
84
+ boleto_billing_address = boleto.BillingAddress.to_json
85
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = boleto_billing_address
86
+ else
87
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = nil
88
+ end
89
+ end
90
+ end
91
+
92
+ # transforma a colecao de cartao de credito em json
93
+ if createSaleRequest.CreditCardTransactionCollection.any? == false || createSaleRequest.CreditCardTransactionCollection.nil?
94
+ saleHash['CreditCardTransactionCollection'] = nil
95
+ else
96
+ createSaleRequest.CreditCardTransactionCollection.each_with_index do |creditCard, index|
97
+ c = creditCard.to_json
98
+ saleHash['CreditCardTransactionCollection'] << c
99
+
100
+ if creditCard.Options.to_json.any?
101
+ credit_card_options = creditCard.Options.to_json
102
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = credit_card_options
103
+ else
104
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = nil
105
+ end
106
+
107
+ if creditCard.Recurrency.to_json.any?
108
+ credit_card_recurrency = creditCard.Recurrency.to_json
109
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
110
+ else
111
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
112
+ end
113
+
114
+ if creditCard.CreditCard.to_json.any?
115
+ credit_card_item = creditCard.CreditCard.to_json
116
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
117
+
118
+ if creditCard.CreditCard.BillingAddress.to_json.any?
119
+ credit_card_billing_address = creditCard.CreditCard.BillingAddress.to_json
120
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = credit_card_billing_address
121
+ else
122
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
123
+ end
124
+
125
+ else
126
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
127
+ end
128
+ end
129
+ end
130
+
131
+ # transforma a colecao de shoppingcart em json
132
+ if createSaleRequest.ShoppingCartCollection.any? == false || createSaleRequest.ShoppingCartCollection.nil?
133
+ saleHash['ShoppingCartCollection'] = nil
134
+ else
135
+ createSaleRequest.ShoppingCartCollection.each_with_index do |shoppingCart, index|
136
+ s = shoppingCart.to_json
137
+ saleHash['ShoppingCartCollection'] << s
138
+
139
+ if shoppingCart.DeliveryAddress.to_json.any?
140
+ delivery_address = shoppingCart.DeliveryAddress.to_json
141
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = delivery_address
142
+ else
143
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = nil
144
+ end
145
+
146
+ if shoppingCart.ShoppingCartItemCollection.any?
147
+ shoppingCart.ShoppingCartItemCollection.each_with_index do |cartItem, cartIndex|
148
+ item = cartItem.to_json
149
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'][cartIndex] = item
150
+ end
151
+ else
152
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
153
+ end
154
+ end
155
+ end
156
+
157
+ # transforma objeto options em json
158
+ if createSaleRequest.Options.to_json.any?
159
+ o = createSaleRequest.Options.to_json
160
+ saleHash['Options'] = o
161
+ else
162
+ saleHash['Options'] = nil
163
+ end
164
+
165
+ # transforma objeto order em json
166
+ if createSaleRequest.Order.to_json.any?
167
+ order = createSaleRequest.Order.to_json
168
+ saleHash['Order'] = order
169
+ else
170
+ saleHash['Order'] = nil
171
+ end
172
+
173
+ # transforma objeto merchant em json
174
+ if createSaleRequest.Merchant.to_json.any?
175
+ merchant = createSaleRequest.Merchant.to_json
176
+ saleHash['Merchant'] = merchant
177
+ else
178
+ saleHash['Merchant'] = nil
179
+ end
180
+
181
+ # transforma objeto request data em json
182
+ if createSaleRequest.RequestData.to_json.any?
183
+ request_data = createSaleRequest.RequestData.to_json
184
+ saleHash['RequestData'] = request_data
185
+ else
186
+ saleHash['RequestData'] = nil
187
+ end
188
+
189
+ # transforma o objeto Buyer em json
190
+ if createSaleRequest.Buyer.AddressCollection.any?
191
+ b = createSaleRequest.Buyer.to_json
192
+ saleHash['Buyer'] = b
193
+
194
+ saleHash['Buyer']['AddressCollection'] = []
195
+ createSaleRequest.Buyer.AddressCollection.each do |address|
196
+ a = address.to_json
197
+ saleHash['Buyer']['AddressCollection'] << a
198
+ end
199
+ else
200
+ buyer_hash = createSaleRequest.Buyer.to_json
201
+ buyer_hash.delete('AddressCollection')
202
+ if buyer_hash.blank? == false
203
+ b = createSaleRequest.Buyer.to_json
204
+ saleHash['Buyer'] = b
205
+ saleHash['Buyer']['AddressCollection'] = nil
206
+ else
207
+ saleHash['Buyer'] = nil
208
+ end
209
+ end
210
+
211
+ rescue Exception => e
212
+ return e.message
213
+ end
214
+
215
+ if @serviceEnvironment == :staging
216
+ url = @@SERVICE_URL_STAGING + '/Sale/'
217
+ elsif @serviceEnvironment == :production
218
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/'
219
+ elsif @serviceEnvironment == :sandbox
220
+ url = @@SERVICE_URL_SANDBOX + '/Sale/'
221
+ end
222
+ postRequest(saleHash.to_json, url)
223
+ end
224
+
225
+ # permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
226
+ def Retry(retrySaleRequest)
227
+ saleHash = retrySaleRequest.to_json
228
+ saleHash['RetrySaleCreditCardTransactionCollection'] = []
229
+
230
+ begin
231
+ if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
232
+ retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
233
+ r = retrySale.to_json
234
+ saleHash['RetrySaleCreditCardTransactionCollection'] << r
235
+ end
236
+ end
237
+ if retrySaleRequest.Options.to_json.any?
238
+ retry_options = retrySaleRequest.Options.to_json
239
+ saleHash['Options'] = retry_options
240
+ else
241
+ saleHash['Options'] = nil
242
+ end
243
+ rescue Exception => e
244
+ return e.message
245
+ end
246
+ if @serviceEnvironment == :staging
247
+ url = @@SERVICE_URL_STAGING + '/Sale/Retry'
248
+ elsif @serviceEnvironment == :production
249
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/Retry'
250
+ elsif @serviceEnvironment == :sandbox
251
+ url = @@SERVICE_URL_SANDBOX + '/Sale/Retry'
252
+ end
253
+ postRequest(saleHash.to_json, url)
254
+ end
255
+
256
+ # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
257
+ def Cancel(cancelSaleRequest)
258
+ saleHash = cancelSaleRequest.to_json
259
+ saleHash['CreditCardTransactionCollection'] = []
260
+
261
+ begin
262
+ if cancelSaleRequest.CreditCardTransactionCollection != nil
263
+ cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
264
+ c = creditCard.to_json
265
+ saleHash['CreditCardTransactionCollection'] << c
266
+ end
267
+ end
268
+ rescue Exception => e
269
+ return e.message
270
+ end
271
+ if @serviceEnvironment == :staging
272
+ url = @@SERVICE_URL_STAGING + '/Sale/Cancel'
273
+ elsif @serviceEnvironment == :production
274
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/Cancel'
275
+ elsif @serviceEnvironment == :sandbox
276
+ url = @@SERVICE_URL_SANDBOX + '/Sale/Cancel'
277
+ end
278
+ postRequest(saleHash.to_json, url)
279
+ end
280
+
281
+ # confirmacao de uma transacao de cartao de credito que ja fora autorizada
282
+ def Capture(captureRequest)
283
+ saleHash = captureRequest.to_json
284
+ saleHash['CreditCardTransactionCollection'] = []
285
+
286
+ begin
287
+ if captureRequest.CreditCardTransactionCollection != nil
288
+ captureRequest.CreditCardTransactionCollection.each do |creditCard|
289
+ c = creditCard.to_json
290
+ saleHash['CreditCardTransactionCollection'] << c
291
+ end
292
+ end
293
+ rescue Exception => e
294
+ return e.message
295
+ end
296
+ if @serviceEnvironment == :staging
297
+ url = @@SERVICE_URL_STAGING + '/Sale/Capture'
298
+ elsif @serviceEnvironment == :production
299
+ url = @@SERVICE_URL_PRODUCTION + '/Sale/Capture'
300
+ elsif @serviceEnvironment == :sandbox
301
+ url = @@SERVICE_URL_SANDBOX + '/Sale/Capture'
302
+ end
303
+ postRequest(saleHash.to_json, url)
304
+ end
305
+
306
+ # faz um parse do xml de post notificaton
307
+ def ParseXmlToNotification(xml)
308
+ begin
309
+ response = PostNotification.ParseNotification(xml)
310
+ rescue Exception => err
311
+ return err.message
312
+ end
313
+
314
+ return response
315
+ end
316
+
317
+ # faz uma requisicao e retorna uma string com o transaction report file
318
+ def TransactionReportFile(date)
319
+ begin
320
+ if @serviceEnvironment == :staging
321
+ url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
322
+ elsif @serviceEnvironment == :production
323
+ url = @@SERVICE_URL_NOTIFICATION_PRODUCTION + date.strftime("%Y%m%d")
324
+ elsif @serviceEnvironment == :sandbox
325
+ url = @@SERVICE_URL_NOTIFICATION_SANDBOX + date.strftime("%Y%m%d")
326
+ end
327
+
328
+ response = getReportFile(url)
329
+
330
+ rescue RestClient::ExceptionWithResponse => err
331
+ return err.response
332
+ end
333
+ return response
334
+ end
335
+
336
+ # faz o download do transaction report file e salva no computador em .txt
337
+ def TransactionReportFileDownloader(date, file_name, path)
338
+ begin
339
+ path = path + file_name + '.txt'
340
+
341
+ response = TransactionReportFile(date)
342
+
343
+ File.write(path, response)
344
+ rescue RestClient::ExceptionWithResponse => err
345
+ return err.response
346
+ end
347
+ end
348
+
349
+ # faz o parse da string recebida do transaction report file e retorna um hash
350
+ def TransactionReportFileParser(file_to_parse)
351
+ transaction_report_file = TransactionReportFile.new
352
+ begin
353
+ response = transaction_report_file.TransactionReportFileParser(file_to_parse)
354
+ rescue Exception => err
355
+ return err
356
+ end
357
+ return response
358
+ end
359
+
360
+ # DEPRECATED
361
+ def InstantBuyKey(instant_buy_key)
362
+ GetCreditCard(instant_buy_key)
363
+ end
364
+ deprecate :InstantBuyKey, :GetCreditCard, 2016, 04
365
+
366
+ # DEPRECATED
367
+ def BuyerKey(buyer_key)
368
+ GetCreditCardWithBuyerKey(buyer_key)
369
+ end
370
+ deprecate :BuyerKey, :GetCreditCardWithBuyerKey, 2016, 04
371
+
372
+ # faz um get credit card com buyer key
373
+ def GetCreditCardWithBuyerKey(buyer_key)
374
+ # try, tenta fazer o request
375
+ begin
376
+
377
+ # se for homologacao faz a chamada por aqui
378
+ if @serviceEnvironment == :staging
379
+ response = getRequest(@@SERVICE_URL_STAGING + '/CreditCard/BuyerKey=' + buyer_key)
380
+
381
+ # se for producao, faz a chamada por aqui
382
+ elsif @serviceEnvironment == :production
383
+ response = getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/BuyerKey=' + buyer_key)
384
+
385
+ # se for sandbox, faz a chamada por aqui
386
+ elsif @serviceEnvironment == :sandbox
387
+ response = getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/BuyerKey=' + buyer_key)
388
+ end
389
+
390
+ # se der algum erro, trata aqui
391
+ rescue Exception => e
392
+ return e.message
393
+ end
394
+
395
+ # se nao houver erros, retorna o objeto
396
+ response
397
+ end
398
+
399
+ # Faz um get no cartão de crédito
400
+ def GetCreditCard(instant_buy_key)
401
+ # try, tenta fazer o request
402
+ begin
403
+ # se for homologacao faz a chamada por aqui
404
+ if @serviceEnvironment == :staging
405
+ getRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
406
+
407
+ # se for producao, faz a chamada por aqui
408
+ elsif @serviceEnvironment == :production
409
+ getRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
410
+
411
+ # se for sandbox
412
+ elsif @serviceEnvironment == :sandbox
413
+ getRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
414
+ end
415
+
416
+ # se der algum erro, trata aqui
417
+ rescue Exception => e
418
+ return e.message
419
+ end
420
+ end
421
+
422
+ # Cria um cartão de crédito
423
+ def CreateCreditCard(create_instant_buy_data)
424
+ sale_hash = create_instant_buy_data.to_json
425
+ begin
426
+ if create_instant_buy_data.BillingAddress.to_json.any?
427
+ sale_hash['BillingAddress'] = create_instant_buy_data.BillingAddress.to_json
428
+ else
429
+ sale_hash['BillingAddress'] = nil
430
+ end
431
+
432
+ # se for homologacao faz a chamada por aqui
433
+ if @serviceEnvironment == :staging
434
+ url = @@SERVICE_URL_STAGING + '/CreditCard/'
435
+
436
+ # se for producao, faz a chamada por aqui
437
+ elsif @serviceEnvironment == :production
438
+ url = @@SERVICE_URL_PRODUCTION + '/CreditCard/'
439
+
440
+ # se for sandbox, faz a chamada por aqui
441
+ elsif @serviceEnvironment == :sandbox
442
+ url = @@SERVICE_URL_SANDBOX + '/CreditCard/'
443
+ end
444
+
445
+ response = postRequest(sale_hash.to_json, url)
446
+
447
+ # se der algum erro, trata aqui
448
+ rescue Exception => e
449
+ return e.message
450
+ end
451
+ # se nao houver erros, retorna o objeto
452
+ response
453
+ end
454
+
455
+ # Atualiza o cartão de crédito
456
+ def UpdateCreditCard(instant_buy_key, update_instant_buy_data_request)
457
+ begin
458
+ sale_hash = update_instant_buy_data_request.to_json
459
+
460
+ # se for homologacao faz a chamada por aqui
461
+ if @serviceEnvironment == :staging
462
+ url = @@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key
463
+
464
+ # se for producao, faz a chamada por aqui
465
+ elsif @serviceEnvironment == :production
466
+ url = @@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key
467
+
468
+ # se for sandbox, faz a chamada por aqui
469
+ elsif @serviceEnvironment == :sandbox
470
+ url = @@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key
471
+ end
472
+
473
+ response = patchRequest(sale_hash.to_json, url)
474
+ # se der algum erro, trata aqui
475
+ rescue Exception => e
476
+ return e.message
477
+ end
478
+ # se nao houver erros, retorna o objeto
479
+ response
480
+ end
481
+
482
+ # Deleta um cartão de crédito
483
+ def DeleteCreditCard(instant_buy_key)
484
+ # try, tenta fazer o request
485
+ begin
486
+ # se for homologacao faz a chamada por aqui
487
+ if @serviceEnvironment == :staging
488
+ deleteRequest(@@SERVICE_URL_STAGING + '/CreditCard/' + instant_buy_key)
489
+
490
+ # se for producao, faz a chamada por aqui
491
+ elsif @serviceEnvironment == :production
492
+ deleteRequest(@@SERVICE_URL_PRODUCTION + '/CreditCard/' + instant_buy_key)
493
+
494
+ # se for sandbox
495
+ elsif @serviceEnvironment == :sandbox
496
+ deleteRequest(@@SERVICE_URL_SANDBOX + '/CreditCard/' + instant_buy_key)
497
+ end
498
+
499
+ # se der algum erro, trata aqui
500
+ rescue Exception => e
501
+ return e.message
502
+ end
503
+ end
504
+
505
+ # Busca um buyer
506
+ def GetBuyer(buyer_key)
507
+ # try, tenta fazer o request
508
+ begin
509
+
510
+ # se for homologacao faz a chamada por aqui
511
+ if @serviceEnvironment == :staging
512
+ response = getRequest(@@SERVICE_URL_STAGING + '/Buyer/' + buyer_key)
513
+
514
+ # se for producao, faz a chamada por aqui
515
+ elsif @serviceEnvironment == :production
516
+ response = getRequest(@@SERVICE_URL_PRODUCTION + '/Buyer/' + buyer_key)
517
+
518
+ # se for sandbox, faz a chamada por aqui
519
+ elsif @serviceEnvironment == :sandbox
520
+ response = getRequest(@@SERVICE_URL_SANDBOX + '/Buyer/' + buyer_key)
521
+ end
522
+
523
+ # se der algum erro, trata aqui
524
+ rescue Exception => e
525
+ return e.message
526
+ end
527
+
528
+ # se nao houver erros, retorna o objeto
529
+ response
530
+ end
531
+
532
+ # Cria um buyer
533
+ def CreateBuyer(buyer_request)
534
+ sale_hash = buyer_request.to_json
535
+ sale_hash['AddressCollection'] = []
536
+ begin
537
+ if buyer_request.AddressCollection.any? == false || buyer_request.AddressCollection.nil?
538
+ sale_hash['AddressCollection'] = nil
539
+ else
540
+ buyer_request.AddressCollection.each do |address|
541
+ a = address.to_json
542
+ sale_hash['AddressCollection'] << a
543
+ end
544
+ end
545
+
546
+ # se for homologacao faz a chamada por aqui
547
+ if @serviceEnvironment == :staging
548
+ url = @@SERVICE_URL_STAGING + '/Buyer/'
549
+
550
+ # se for producao, faz a chamada por aqui
551
+ elsif @serviceEnvironment == :production
552
+ url = @@SERVICE_URL_PRODUCTION + '/Buyer/'
553
+
554
+ # se for sandbox, faz a chamada por aqui
555
+ elsif @serviceEnvironment == :sandbox
556
+ url = @@SERVICE_URL_SANDBOX + '/Buyer/'
557
+ end
558
+
559
+ response = postRequest(sale_hash.to_json, url)
560
+ rescue Exception => e
561
+ return e.message
562
+ end
563
+ response
564
+ end
565
+
566
+ # funcao de post generica
567
+ def postRequest(payload, url)
568
+ response = nil
569
+ begin
570
+ response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
571
+ rescue RestClient::ExceptionWithResponse => err
572
+ return err.response
573
+ end
574
+ json_response = JSON.load response
575
+ json_response
576
+ end
577
+
578
+ # funcao patch generica
579
+ def patchRequest(payload, url)
580
+ begin
581
+ response = RestClient.patch(url, payload, headers=@@SERVICE_HEADERS)
582
+ rescue RestClient::ExceptionWithResponse => err
583
+ return err.response
584
+ end
585
+ json_response = JSON.load response
586
+ json_response
587
+ end
588
+
589
+ # funcao de delete generica
590
+ def deleteRequest(url)
591
+ begin
592
+ response = RestClient.delete(url, headers=@@SERVICE_HEADERS)
593
+ rescue RestClient::ExceptionWithResponse => err
594
+ return err.response
595
+ end
596
+ json_response = JSON.load response
597
+ json_response
598
+ end
599
+
600
+ # funcao get generica
601
+ def getRequest(url)
602
+ response = nil
603
+ begin
604
+ response = RestClient.get(url, headers=@@SERVICE_HEADERS)
605
+ rescue RestClient::ExceptionWithResponse => err
606
+ return err.response
607
+ end
608
+ json_response = JSON.load response
609
+ json_response
610
+ end
611
+
612
+ def getReportFile(url)
613
+ begin
614
+ response = RestClient.get(url, headers={:MerchantKey => "#{@merchantKey}"})
615
+ rescue RestClient::ExceptionWithResponse => err
616
+ return err.response
617
+ end
618
+ return response
619
+ end
620
+ end
621
+ end