mundipagg_api 1.0.0

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 (66) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +191 -0
  3. data/README.md +308 -0
  4. data/lib/mundipagg/Address/billing_address.rb +32 -0
  5. data/lib/mundipagg/Address/buyer_address.rb +36 -0
  6. data/lib/mundipagg/Address/delivery_address.rb +32 -0
  7. data/lib/mundipagg/AntiFraud/anti_fraud_analysis_result.rb +47 -0
  8. data/lib/mundipagg/AntiFraud/query_sale_anti_fraud_analysis_data.rb +51 -0
  9. data/lib/mundipagg/AntiFraud/query_sale_anti_fraud_analysis_history_data.rb +41 -0
  10. data/lib/mundipagg/BaseRequest.rb +11 -0
  11. data/lib/mundipagg/BaseResponse.rb +17 -0
  12. data/lib/mundipagg/BoletoTransaction/boleto_transaction.rb +43 -0
  13. data/lib/mundipagg/BoletoTransaction/boleto_transaction_data.rb +44 -0
  14. data/lib/mundipagg/BoletoTransaction/boleto_transaction_options.rb +14 -0
  15. data/lib/mundipagg/BoletoTransaction/boleto_transaction_report_file.rb +20 -0
  16. data/lib/mundipagg/BoletoTransaction/boleto_transaction_result.rb +35 -0
  17. data/lib/mundipagg/CreditCardTransaction/credit_card.rb +30 -0
  18. data/lib/mundipagg/CreditCardTransaction/credit_card_transaction.rb +32 -0
  19. data/lib/mundipagg/CreditCardTransaction/credit_card_transaction_data.rb +104 -0
  20. data/lib/mundipagg/CreditCardTransaction/credit_card_transaction_options.rb +27 -0
  21. data/lib/mundipagg/CreditCardTransaction/credit_card_transaction_report_file.rb +29 -0
  22. data/lib/mundipagg/CreditCardTransaction/manage_credit_card_transaction.rb +12 -0
  23. data/lib/mundipagg/CreditCardTransaction/retry_sale_credit_card_transaction.rb +13 -0
  24. data/lib/mundipagg/ErrorItem.rb +17 -0
  25. data/lib/mundipagg/ErrorReport.rb +18 -0
  26. data/lib/mundipagg/InstantBuy/credit_card_data.rb +41 -0
  27. data/lib/mundipagg/InstantBuy/get_instant_buy_data_response.rb +18 -0
  28. data/lib/mundipagg/Merchant/merchant.rb +11 -0
  29. data/lib/mundipagg/MundipaggApi.rb +336 -0
  30. data/lib/mundipagg/OnlineDebit/online_debit_transaction_report_file.rb +18 -0
  31. data/lib/mundipagg/Order/order.rb +11 -0
  32. data/lib/mundipagg/Order/order_transaction_report_file.rb +6 -0
  33. data/lib/mundipagg/Parsers/boleto_transaction_parser.rb +31 -0
  34. data/lib/mundipagg/Parsers/credit_card_transaction_parser.rb +40 -0
  35. data/lib/mundipagg/Parsers/header_parser.rb +14 -0
  36. data/lib/mundipagg/Parsers/online_debit_transaction_parser.rb +30 -0
  37. data/lib/mundipagg/Parsers/trailer_parser.rb +15 -0
  38. data/lib/mundipagg/Person/buyer.rb +33 -0
  39. data/lib/mundipagg/Person/person.rb +47 -0
  40. data/lib/mundipagg/Recurrency/recurrency.rb +23 -0
  41. data/lib/mundipagg/Sale/create_sale_request.rb +36 -0
  42. data/lib/mundipagg/Sale/create_sale_response.rb +25 -0
  43. data/lib/mundipagg/Sale/manage_sale_request.rb +17 -0
  44. data/lib/mundipagg/Sale/manage_sale_response.rb +15 -0
  45. data/lib/mundipagg/Sale/query_sale_request.rb +36 -0
  46. data/lib/mundipagg/Sale/query_sale_response.rb +18 -0
  47. data/lib/mundipagg/Sale/request_data.rb +20 -0
  48. data/lib/mundipagg/Sale/retry_sale_options.rb +14 -0
  49. data/lib/mundipagg/Sale/retry_sale_request.rb +22 -0
  50. data/lib/mundipagg/Sale/retry_sale_response.rb +14 -0
  51. data/lib/mundipagg/Sale/sale_data.rb +33 -0
  52. data/lib/mundipagg/Sale/sale_order_data.rb +17 -0
  53. data/lib/mundipagg/SalesOption.rb +17 -0
  54. data/lib/mundipagg/ShoppingCart/shopping_cart.rb +26 -0
  55. data/lib/mundipagg/ShoppingCart/shopping_cart_item.rb +23 -0
  56. data/lib/mundipagg/Trailer.rb +6 -0
  57. data/lib/mundipagg/address.rb +25 -0
  58. data/lib/mundipagg/header.rb +5 -0
  59. data/lib/mundipagg/post_notification.rb +29 -0
  60. data/lib/mundipagg/transaction_report_file.rb +45 -0
  61. data/lib/mundipagg_api.rb +70 -0
  62. data/mundipagg-api.gemspec +18 -0
  63. data/spec/integration/gateway_spec.rb +521 -0
  64. data/spec/integration/test_helper.rb +69 -0
  65. data/spec/spec_helper.rb +96 -0
  66. metadata +227 -0
@@ -0,0 +1,32 @@
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
+
32
+ end
@@ -0,0 +1,104 @@
1
+ require_relative '../../mundipagg/InstantBuy/credit_card_data'
2
+ class CreditCardTransactionData
3
+ # Dados do cart�o de cr�dito
4
+ attr_accessor :CreditCard
5
+
6
+ # Status da transa��o de cart�o de cr�dito
7
+ attr_accessor :CreditCardTransactionStatus
8
+
9
+ @@CreditCardTransactionStatusEnum = {
10
+ :AuthorizedPendingCapture => '1',
11
+ :NotAuthorized => '2',
12
+ :ChargebackPreview => '3',
13
+ :RefundPreview => '4',
14
+ :DepositPreview => '5',
15
+ :Captured => '6',
16
+ :PartialCapture => '7',
17
+ :Refunded => '8',
18
+ :Voided => '9',
19
+ :Deposited => '10',
20
+ :Chargeback => '12',
21
+ :PendingVoid => '13',
22
+ :Invalid => '14',
23
+ :PartialAlthorize => '15',
24
+ :PartialRefunded => '16',
25
+ :OverCapture => '17',
26
+ :PartialVoid => '18',
27
+ :PendingRefund => '19',
28
+ :UnScheduled => '20',
29
+ :Created => '21',
30
+ :PartialAuthorized => '22',
31
+ :NotFoundInAcquirer => '23',
32
+ :PendingAuthorize => '24',
33
+ :WithError => '99'
34
+ }
35
+
36
+ # Chave da transa��o. Utilizada para identificar a transa��o de cart�o de cr�dito no gateway
37
+ attr_accessor :TransactionKey
38
+
39
+ # Identificador da transa��o gerado pela loja.
40
+ attr_accessor :TransactionIdentifier
41
+
42
+ # C�digo de autoriza��o retornado pela adquirente
43
+ attr_accessor :AcquirerAuthorizationCode
44
+
45
+ # Identificador �nico retornado pela adquirente
46
+ attr_accessor :UniqueSequentialNumber
47
+
48
+ # Valor original da transa��o em centavos
49
+ attr_accessor :AmountInCents
50
+
51
+ # Valor autorizado em centavos
52
+ attr_accessor :AuthorizedAmountInCents
53
+
54
+ # Valor capturado em centavos
55
+ attr_accessor :CapturedAmountInCents
56
+
57
+ # Valor estornado em centavos
58
+ attr_accessor :RefundedAmountInCents
59
+
60
+ # Valor cancelado em centavos
61
+ attr_accessor :VoidedAmountInCents
62
+
63
+ # Data da recorr�ncia (poder� ser futura)
64
+ attr_accessor :DueDate
65
+
66
+ # Identificador da transa��o no sistema da loja
67
+ attr_accessor :TransactionReference
68
+
69
+ # Data de cria��o da transa��o no gatewaya
70
+ attr_accessor :CreateDate
71
+
72
+ # Nome da adquirente que processou a transa��o
73
+ attr_accessor :AcquirerName
74
+
75
+ # Indica se � uma recorr�ncia
76
+ attr_accessor :IsRecurrency
77
+
78
+ # Total de parcelas na transa��o
79
+ attr_accessor :InstallmentCount
80
+
81
+ # C�digo de filia��o da loja na adquirente
82
+ attr_accessor :AffiliationCode
83
+
84
+ # C�digo do m�todo de pagamento
85
+ attr_accessor :PaymentMethodName
86
+
87
+ # Chave da transa��o na adquirente, enviada pelo gateway
88
+ attr_accessor :TransactionKeyToAcquirer
89
+
90
+ # Data limite para a captura da transa��o na adquirente
91
+ attr_accessor :CaptureExpirationDate
92
+
93
+ def initialize
94
+ @CreditCard = CreditCardData.new
95
+ @CreditCardTransactionStatus = self.CreditCardTransactionStatusEnum
96
+ end
97
+
98
+ def to_json
99
+ hash = {}
100
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
101
+ hash
102
+ end
103
+
104
+ end
@@ -0,0 +1,27 @@
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
+
27
+ end
@@ -0,0 +1,29 @@
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
29
+ end
@@ -0,0 +1,12 @@
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
12
+ end
@@ -0,0 +1,13 @@
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
+
13
+ end
@@ -0,0 +1,17 @@
1
+ class ErrorItem
2
+
3
+ attr_accessor :ErrorCode
4
+
5
+ attr_accessor :ErrorField
6
+
7
+ attr_accessor :Description
8
+
9
+ attr_accessor :SeverityCode
10
+
11
+ def to_json
12
+ hash = {}
13
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
14
+ hash
15
+ end
16
+
17
+ end
@@ -0,0 +1,18 @@
1
+ class ErrorReport
2
+
3
+ attr_accessor :Category
4
+
5
+ attr_accessor :ErrorItemCollection
6
+
7
+
8
+ def initialize
9
+ @ErrorItemCollection = Array.new;
10
+ end
11
+
12
+ def to_json
13
+ hash = {}
14
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
15
+ hash
16
+ end
17
+
18
+ end
@@ -0,0 +1,41 @@
1
+ class CreditCardData
2
+ # N�mero mascardo do cart�o de cr�dito
3
+ attr_accessor :MaskedCreditCardNumber
4
+
5
+ # Bandeira do cart�o de cr�dito
6
+ attr_accessor :CreditCardBrand
7
+
8
+ @@CreditCardBrandEnum = {
9
+ :Visa => '1',
10
+ :MasterCard => '2',
11
+ :HiperCard => '3',
12
+ :Amex => '4',
13
+ :Diners => '5',
14
+ :Elo => '6',
15
+ :Aura => '7',
16
+ :Discover => '8',
17
+ :CasaShow => '9',
18
+ :Havan => '10',
19
+ :HugCard => '11',
20
+ :AndarAki => '12',
21
+ :LeaderCard => '13',
22
+ :Submarino => '14'
23
+ }
24
+
25
+ # Chave do cart�o de cr�dito. Utilizada para identificar um cart�o de cr�dito no gateway
26
+ attr_accessor :InstantBuyerKey
27
+
28
+ # Informa se o cart�o de cr�dito expirou
29
+ attr_accessor :IsExpiredCreditCard
30
+
31
+ def initialize
32
+ @CreditCardBrand = self.CreditCardBrandEnum
33
+ end
34
+
35
+ def to_json
36
+ hash = {}
37
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
38
+ hash
39
+ end
40
+
41
+ end
@@ -0,0 +1,18 @@
1
+ class GetInstantBuyDataResponse
2
+ # Lista de cart�es de cr�dito
3
+ attr_accessor :CreditCardDataCollection
4
+
5
+ # Total de cart�es de cr�dito retornados
6
+ attr_accessor :CreditCardDataCount
7
+
8
+ def initialize
9
+ @CreditCardDataCollection = Array.new
10
+ end
11
+
12
+ def to_json
13
+ hash = {}
14
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
15
+ hash
16
+ end
17
+
18
+ end
@@ -0,0 +1,11 @@
1
+ class Merchant
2
+ # Identificador da loja na plataforma
3
+ attr_accessor :MerchantReference
4
+
5
+ def to_json
6
+ hash = {}
7
+ instance_variables.each {|var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
8
+ hash
9
+ end
10
+
11
+ end
@@ -0,0 +1,336 @@
1
+ require_relative '../../lib/mundipagg_api'
2
+
3
+ class MundipaggApi
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 production
16
+ @@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com/Sale/'
17
+
18
+ # URL de homologation
19
+ @@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com/Sale/'
20
+
21
+ # permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
22
+ def Query(querySaleRequestEnum, key)
23
+ # try, tenta fazer o request
24
+ begin
25
+
26
+ # se for homologacao faz a chamada por aqui
27
+ if @serviceEnvironment == :staging
28
+ response = RestClient.get @@SERVICE_URL_STAGING + '/Query/' + querySaleRequestEnum + '=' + key, headers=@@SERVICE_HEADERS
29
+
30
+ # se for producao, faz a chamada por aqui
31
+ elsif @serviceEnvironment == :production
32
+ response = RestClient.get @@SERVICE_URL_PRODUCTION + '/Query/' + querySaleRequestEnum + '=' + key, headers=@@SERVICE_HEADERS
33
+ end
34
+
35
+ # se der algum erro, trata aqui
36
+ rescue RestClient::ExceptionWithResponse => err
37
+ return err.response
38
+ end
39
+
40
+ # se n�o houver erros, trata o json e retorna o objeto
41
+ querySaleResponse = JSON.load response
42
+ querySaleResponse
43
+ end
44
+
45
+ # criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
46
+ def CreateSale(createSaleRequest)
47
+
48
+ saleHash = createSaleRequest.to_json
49
+
50
+ saleHash['BoletoTransactionCollection'] = []
51
+
52
+ saleHash['CreditCardTransactionCollection'] = []
53
+
54
+ saleHash['ShoppingCartCollection'] = []
55
+
56
+ begin
57
+ # transforma a colecao de boleto em json
58
+ if createSaleRequest.BoletoTransactionCollection.any? == false || createSaleRequest.BoletoTransactionCollection.nil?
59
+ saleHash['BoletoTransactionCollection'] = nil
60
+
61
+ else
62
+ createSaleRequest.BoletoTransactionCollection.each_with_index do |boleto, index|
63
+ b = boleto.to_json
64
+ saleHash['BoletoTransactionCollection'] << b
65
+
66
+ if boleto.Options.to_json.any?
67
+ boleto_options = boleto.Options.to_json
68
+ saleHash['BoletoTransactionCollection'][index]['Options'] = boleto_options
69
+ else
70
+ saleHash['BoletoTransactionCollection'][index]['Options'] = nil
71
+ end
72
+
73
+ if boleto.BillingAddress.to_json.any?
74
+ boleto_billing_address = boleto.BillingAddress.to_json
75
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = boleto_billing_address
76
+ else
77
+ saleHash['BoletoTransactionCollection'][index]['BillingAddress'] = nil
78
+ end
79
+ end
80
+ end
81
+
82
+ # transforma a colecao de cartao de credito em json
83
+ if createSaleRequest.CreditCardTransactionCollection.any? == false || createSaleRequest.CreditCardTransactionCollection.nil?
84
+ saleHash['CreditCardTransactionCollection'] = nil
85
+ else
86
+ createSaleRequest.CreditCardTransactionCollection.each_with_index do |creditCard, index|
87
+ c = creditCard.to_json
88
+ saleHash['CreditCardTransactionCollection'] << c
89
+
90
+ if creditCard.Options.to_json.any?
91
+ credit_card_options = creditCard.Options.to_json
92
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = credit_card_options
93
+ else
94
+ saleHash['CreditCardTransactionCollection'][index]['Options'] = nil
95
+ end
96
+
97
+ if creditCard.Recurrency.to_json.any?
98
+ credit_card_recurrency = creditCard.Recurrency.to_json
99
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = credit_card_recurrency
100
+ else
101
+ saleHash['CreditCardTransactionCollection'][index]['Recurrency'] = nil
102
+ end
103
+
104
+ if creditCard.CreditCard.to_json.any?
105
+ credit_card_item = creditCard.CreditCard.to_json
106
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = credit_card_item
107
+
108
+ if creditCard.CreditCard.BillingAddress.to_json.any?
109
+ credit_card_billing_address = creditCard.CreditCard.BillingAddress.to_json
110
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = credit_card_billing_address
111
+ else
112
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard']['BillingAddress'] = nil
113
+ end
114
+
115
+ else
116
+ saleHash['CreditCardTransactionCollection'][index]['CreditCard'] = nil
117
+ end
118
+ end
119
+ end
120
+
121
+ # transforma a colecao de shoppingcart em json
122
+ if createSaleRequest.ShoppingCartCollection.any? == false || createSaleRequest.ShoppingCartCollection.nil?
123
+ saleHash['ShoppingCartCollection'] = nil
124
+ else
125
+ createSaleRequest.ShoppingCartCollection.each_with_index do |shoppingCart, index|
126
+ s = shoppingCart.to_json
127
+ saleHash['ShoppingCartCollection'] << s
128
+
129
+ if shoppingCart.DeliveryAddress.to_json.any?
130
+ delivery_address = shoppingCart.DeliveryAddress.to_json
131
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = delivery_address
132
+ else
133
+ saleHash['ShoppingCartCollection'][index]['DeliveryAddress'] = nil
134
+ end
135
+
136
+ if shoppingCart.ShoppingCartItemCollection.any?
137
+ shoppingCart.ShoppingCartItemCollection.each do |cartItem|
138
+ item = cartItem.to_json
139
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] << item
140
+ end
141
+ else
142
+ saleHash['ShoppingCartCollection'][index]['ShoppingCartItemCollection'] = nil
143
+ end
144
+ end
145
+ end
146
+
147
+ # transforma objeto options em json
148
+ if createSaleRequest.Options.to_json.any?
149
+ o = createSaleRequest.Options.to_json
150
+ saleHash['Options'] = o
151
+ else
152
+ saleHash['Options'] = nil
153
+ end
154
+
155
+ # transforma objeto order em json
156
+ if createSaleRequest.Order.to_json.any?
157
+ order = createSaleRequest.Order.to_json
158
+ saleHash['Order'] = order
159
+ else
160
+ saleHash['Order'] = nil
161
+ end
162
+
163
+ # transforma objeto merchant em json
164
+ if createSaleRequest.Merchant.to_json.any?
165
+ merchant = createSaleRequest.Merchant.to_json
166
+ saleHash['Merchant'] = merchant
167
+ else
168
+ saleHash['Merchant'] = nil
169
+ end
170
+
171
+ # transforma objeto request data em json
172
+ if createSaleRequest.RequestData.to_json.any?
173
+ request_data = createSaleRequest.RequestData.to_json
174
+ saleHash['RequestData'] = request_data
175
+ else
176
+ saleHash['RequestData'] = nil
177
+ end
178
+
179
+ # transforma o objeto Buyer em json
180
+ if createSaleRequest.Buyer.to_json.any? && createSaleRequest.Buyer.AddressCollection.any?
181
+ b = createSaleRequest.Buyer.to_json
182
+ saleHash['Buyer'] = b
183
+
184
+ if createSaleRequest.Buyer.AddressCollection.any?
185
+ saleHash['Buyer']['AddressCollection'] = []
186
+ createSaleRequest.Buyer.AddressCollection.each do |address|
187
+ a = address.to_json
188
+ saleHash['Buyer']['AddressCollection'] << a
189
+ end
190
+ else
191
+ saleHash['Buyer']['AddressCollection'] = nil
192
+ end
193
+ else
194
+ saleHash['Buyer'] = nil
195
+ end
196
+ rescue Exception => e
197
+ puts e.message
198
+ end
199
+
200
+ if @serviceEnvironment == :staging
201
+ url = @@SERVICE_URL_STAGING
202
+ elsif @serviceEnvironment == :production
203
+ url = @@SERVICE_URL_PRODUCTION
204
+ end
205
+ postRequest(saleHash.to_json, url)
206
+ end
207
+
208
+ # permite forcar a retentativa manualmente de uma transacao (podendo ser tambem uma recorrencia) nao autorizada
209
+ def Retry(retrySaleRequest)
210
+ saleHash = retrySaleRequest.to_json
211
+ saleHash['RetrySaleCreditCardTransactionCollection'] = []
212
+
213
+ begin
214
+ if retrySaleRequest.RetrySaleCreditCardTransactionCollection != nil
215
+ retrySaleRequest.RetrySaleCreditCardTransactionCollection.each do |retrySale|
216
+ r = retrySale.to_json
217
+ saleHash['RetrySaleCreditCardTransactionCollection'] << r
218
+
219
+ if retrySaleRequest.Options.to_json.any?
220
+ retry_options = retrySaleRequest.Options.to_json
221
+ saleHash['Options'] = retry_options
222
+ else
223
+ saleHash['Options'] = nil
224
+ end
225
+ end
226
+ end
227
+ rescue Exception => e
228
+ puts e.message
229
+ end
230
+ if @serviceEnvironment == :staging
231
+ url = @@SERVICE_URL_STAGING + '/Retry'
232
+ elsif @serviceEnvironment == :production
233
+ url = @@SERVICE_URL_PRODUCTION + '/Retry'
234
+ end
235
+ postRequest(saleHash.to_json, url)
236
+ end
237
+
238
+ # eh uma forma de desfazer uma transação com cartao de credito mesmo a transacao sendo capturada
239
+ def Cancel(cancelSaleRequest)
240
+ saleHash = cancelSaleRequest.to_json
241
+ saleHash['CreditCardTransactionCollection'] = []
242
+
243
+ begin
244
+ if cancelSaleRequest.CreditCardTransactionCollection != nil
245
+ cancelSaleRequest.CreditCardTransactionCollection.each do |creditCard|
246
+ c = creditCard.to_json
247
+ saleHash['CreditCardTransactionCollection'] << c
248
+ end
249
+ end
250
+ rescue Exception => e
251
+ puts e.message
252
+ end
253
+ if @serviceEnvironment == :staging
254
+ url = @@SERVICE_URL_STAGING + '/Cancel'
255
+ elsif @serviceEnvironment == :production
256
+ url = @@SERVICE_URL_PRODUCTION + '/Cancel'
257
+ end
258
+ postRequest(saleHash.to_json, url)
259
+ end
260
+
261
+ # confirmacao de uma transacao de cartao de credito que ja fora autorizada
262
+ def Capture(captureRequest)
263
+ saleHash = captureRequest.to_json
264
+ saleHash['CreditCardTransactionCollection'] = []
265
+
266
+ begin
267
+ if captureRequest.CreditCardTransactionCollection != nil
268
+ captureRequest.CreditCardTransactionCollection.each do |creditCard|
269
+ c = creditCard.to_json
270
+ saleHash['CreditCardTransactionCollection'] << c
271
+ end
272
+ end
273
+ rescue Exception => e
274
+ puts e.message
275
+ end
276
+ if @serviceEnvironment == :staging
277
+ url = @@SERVICE_URL_STAGING + '/Capture'
278
+ elsif @serviceEnvironment == :production
279
+ url = @@SERVICE_URL_PRODUCTION + '/Capture'
280
+ end
281
+ postRequest(saleHash.to_json, url)
282
+ end
283
+
284
+ # faz um parse do xml de post notificaton
285
+ def ParseXmlToNotification(xml)
286
+ begin
287
+ response = PostNotification.ParseNotification(xml)
288
+ rescue Exception => err
289
+ return err.response
290
+ end
291
+
292
+ return response
293
+ end
294
+
295
+ # faz uma requisicao e retorna uma string com o transaction report file
296
+ def TransactionReportFile(date)
297
+ begin
298
+ response = RestClient.get('https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate=' + date.strftime("%Y%m%d"), headers={:MerchantKey => "#{@merchantKey}"})
299
+ rescue RestClient::ExceptionWithResponse => err
300
+ return err.response
301
+ end
302
+ return response
303
+ end
304
+
305
+ def TransactionReportFileDownloader(date, file_name, path)
306
+ begin
307
+ path = path + file_name + '.txt'
308
+ response = RestClient.get('https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate=' + date.strftime("%Y%m%d"), headers={:MerchantKey => "#{@merchantKey}"})
309
+ File.write(path, response)
310
+ rescue RestClient::ExceptionWithResponse => err
311
+ return err.response
312
+ end
313
+ end
314
+
315
+ # faz o parse da string recebida do transaction report file e retorna um hash
316
+ def TransactionReportFileParser(file_to_parse)
317
+ transaction_report_file = TransactionReportFile.new
318
+ begin
319
+ response = transaction_report_file.TransactionReportFileParser(file_to_parse)
320
+ rescue Exception=>err
321
+ return err
322
+ end
323
+ return response
324
+ end
325
+
326
+ def postRequest(payload, url)
327
+ response = nil
328
+ begin
329
+ response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
330
+ rescue RestClient::ExceptionWithResponse => err
331
+ return err.response #err.response
332
+ end
333
+ json_response = JSON.load response
334
+ json_response
335
+ end
336
+ end