require_relative '../../lib/mundipagg_sdk' require_relative 'test_helper' merchant_key = '85328786-8BA6-420F-9948-5352F5A183EB' gateway = Gateway.new(:sandbox, merchant_key) RSpec.describe Gateway do it 'should create a sale with boleto' do createSaleRequest = CreateSaleRequest.new boletoTransaction = BoletoTransaction.new boletoTransaction.AmountInCents = 100 boletoTransaction.BankNumber = '237' boletoTransaction.DocumentNumber = '12345678901' boletoTransaction.Instructions = 'Pagar antes do vencimento' boletoTransaction.TransactionReference = 'BoletoTest#Ruby01' boletoTransaction.Options.CurrencyIso = 'BRL' boletoTransaction.Options.DaysToAddInBoletoExpirationDate = 5 createSaleRequest.BoletoTransactionCollection << boletoTransaction response = gateway.CreateSale(createSaleRequest) expect(response[:ErrorReport]).to eq nil end it 'should create a sale with credit card' do createSaleRequest = CreateSaleRequest.new buyerAddress = BuyerAddress.new buyerAddress.AddressType = 'Residential' buyerAddress.City = 'Rio de Janeiro' buyerAddress.Complement = '10 Andar' buyerAddress.Country = 'Brazil' buyerAddress.District = 'Centro' buyerAddress.Number = '199' buyerAddress.State = 'RJ' buyerAddress.Street = 'Rua da Quitanda' buyerAddress.ZipCode = '20091005' creditCardTransaction = CreditCardTransaction.new creditCardTransaction.AmountInCents = 100 creditCardTransaction.InstallmentCount = 1 creditCardTransaction.TransactionReference = 'CreditCard One RubySDK Test' creditCardTransaction.Options.PaymentMethodCode = 1 creditCardTransaction.Options.SoftDescriptorText = 'My Store Name' creditCardTransaction.CreditCard.CreditCardNumber = '5453010000066167' creditCardTransaction.CreditCard.ExpMonth = 5 creditCardTransaction.CreditCard.ExpYear = 18 creditCardTransaction.CreditCard.HolderName = 'Maria do Carmo' creditCardTransaction.CreditCard.SecurityCode = '123' creditCardTransaction.CreditCard.CreditCardBrand = 'Mastercard' creditCardTransaction.CreditCard.BillingAddress.City = 'Rio de Janeiro' creditCardTransaction.CreditCard.BillingAddress.Complement = '10 Andar' creditCardTransaction.CreditCard.BillingAddress.Country = 'Brazil' creditCardTransaction.CreditCard.BillingAddress.District = 'Centro' creditCardTransaction.CreditCard.BillingAddress.Number = '199' creditCardTransaction.CreditCard.BillingAddress.State = 'RJ' creditCardTransaction.CreditCard.BillingAddress.Street = 'Rua da Quitanda' creditCardTransaction.CreditCard.BillingAddress.ZipCode = '20091005' createSaleRequest.CreditCardTransactionCollection << creditCardTransaction createSaleRequest.Buyer.Birthdate = Date.new(2001, 9, 26).strftime("%Y-%m-%dT%H:%M:%S") createSaleRequest.Buyer.BuyerCategory = 'Normal' createSaleRequest.Buyer.Email = 'mundiBuyer@mundi.com.br' createSaleRequest.Buyer.EmailType = 'Personal' createSaleRequest.Buyer.Gender = 'M' createSaleRequest.Buyer.HomePhone = '22222222' createSaleRequest.Buyer.MobilePhone = '988888888' createSaleRequest.Buyer.WorkPhone = '25555555' createSaleRequest.Buyer.CreateDateInMerchant = (Date.parse(Time.now.to_s)).strftime("%Y-%m-%dT%H:%M:%S") createSaleRequest.Buyer.LastBuyerUpdateInMerchant = (Date.parse(Time.now.to_s)).strftime("%Y-%m-%dT%H:%M:%S") createSaleRequest.Buyer.DocumentNumber = '51212382749' createSaleRequest.Buyer.DocumentType = 'CPF' createSaleRequest.Buyer.Name = 'Jose da Silva Ramos' createSaleRequest.Buyer.PersonType = 'Person' createSaleRequest.Buyer.AddressCollection << buyerAddress response = gateway.CreateSale(createSaleRequest) expect(response[:ErrorReport]).to eq nil end it 'should create a sale with all types of transactions and all fields filled' do # creates boleto transaction object boletoTransaction = BoletoTransaction.new # 100 reais in cents boletoTransaction.AmountInCents = 10000 boletoTransaction.BankNumber = '237' boletoTransaction.BillingAddress.City = 'Tatooine' boletoTransaction.BillingAddress.Complement = '' boletoTransaction.BillingAddress.Country = 'Brazil' boletoTransaction.BillingAddress.District = 'Mos Eisley' boletoTransaction.BillingAddress.Number = '123' boletoTransaction.BillingAddress.State = 'RJ' boletoTransaction.BillingAddress.Street = 'Mos Eisley Cantina' boletoTransaction.BillingAddress.ZipCode = '20001000' boletoTransaction.DocumentNumber = '12345678901' boletoTransaction.Instructions = 'Pagar antes do vencimento' boletoTransaction.Options.CurrencyIso = 'BRL' boletoTransaction.Options.DaysToAddInBoletoExpirationDate = 5 boletoTransaction.TransactionReference = 'NumeroDaTransacao' # create credit card transaction object creditCardTransaction = CreditCardTransaction.new # 100 reais in cents creditCardTransaction.AmountInCents = 10000 creditCardTransaction.CreditCard.BillingAddress.City = 'Tatooine' creditCardTransaction.CreditCard.BillingAddress.Complement = '' creditCardTransaction.CreditCard.BillingAddress.Country = 'Brazil' creditCardTransaction.CreditCard.BillingAddress.District = 'Mos Eisley' creditCardTransaction.CreditCard.BillingAddress.Number = '123' creditCardTransaction.CreditCard.BillingAddress.State = 'RJ' creditCardTransaction.CreditCard.BillingAddress.Street = 'Mos Eisley Cantina' creditCardTransaction.CreditCard.BillingAddress.ZipCode = '20001000' creditCardTransaction.CreditCard.CreditCardBrand = 'Visa' creditCardTransaction.CreditCard.CreditCardNumber = '4111111111111111' creditCardTransaction.CreditCard.ExpMonth = 10 creditCardTransaction.CreditCard.ExpYear = 22 creditCardTransaction.CreditCard.HolderName = 'LUKE SKYWALKER' creditCardTransaction.CreditCard.SecurityCode = '123' creditCardTransaction.CreditCardOperation = 'AuthOnly' creditCardTransaction.InstallmentCount = 1 creditCardTransaction.Options.CurrencyIso = 'BRL' creditCardTransaction.Options.PaymentMethodCode = 1 creditCardTransaction.Options.SoftDescriptorText = 'Jedi Mega Store' shoppingCartItem = ShoppingCartItemCollection.new shoppingCartItem.Description = 'Red Lightsaber' shoppingCartItem.DiscountAmountInCents = 0 shoppingCartItem.ItemReference = 'NumeroDoProduto' shoppingCartItem.Name = 'Lightsaber' shoppingCartItem.Quantity = 1 shoppingCartItem.TotalCostInCents = 18000 shoppingCartItem.UnitCostInCents = 18000 shoppingCartCollection = ShoppingCartCollection.new shoppingCartCollection.DeliveryAddress.City = 'Galaxy far far away' shoppingCartCollection.DeliveryAddress.Complement = 'Bridge' shoppingCartCollection.DeliveryAddress.Country = 'Brazil' shoppingCartCollection.DeliveryAddress.District = 'Command Room' shoppingCartCollection.DeliveryAddress.Number = '321' shoppingCartCollection.DeliveryAddress.State = 'RJ' shoppingCartCollection.DeliveryAddress.Street = 'Death Star' shoppingCartCollection.DeliveryAddress.ZipCode = '10002000' shoppingCartCollection.DeliveryDeadline = DateTime.new(2015, 12, 14, 18, 36, 45).strftime("%Y-%m-%dT%H:%M:%S") shoppingCartCollection.EstimatedDeliveryDate = DateTime.new(2015, 12, 14, 18, 36, 45).strftime("%Y-%m-%dT%H:%M:%S") shoppingCartCollection.FreighCostInCents = 2000 shoppingCartCollection.ShippingCompany = 'Empire' shoppingCartCollection.ShoppingCartItemCollection << shoppingCartItem # creates request object for transaction creation createSaleRequest = CreateSaleRequest.new # adds to the boleto transaction collection createSaleRequest.BoletoTransactionCollection << boletoTransaction buyerAddress = BuyerAddress.new buyerAddress.AddressType = 'Residential' buyerAddress.City = 'Tatooine' buyerAddress.Complement = '' buyerAddress.Country = 'Brazil' buyerAddress.District = 'Mos Eisley' buyerAddress.Number = '123' buyerAddress.State = 'RJ' buyerAddress.Street = 'Mos Eisley Cantina' buyerAddress.ZipCode = '20001000' createSaleRequest.Buyer.AddressCollection << buyerAddress createSaleRequest.Buyer.Birthdate = DateTime.new(1990,8,20,0,0,0).strftime("%Y-%m-%dT%H:%M:%S") createSaleRequest.Buyer.BuyerCategory = 'Normal' createSaleRequest.Buyer.BuyerReference = 'C3PO' createSaleRequest.Buyer.CreateDateInMerchant = DateTime.new(2015,12,11,18,36,45).strftime("%Y-%m-%dT%H:%M:%S") createSaleRequest.Buyer.DocumentNumber = '12345678901' createSaleRequest.Buyer.DocumentType = 'CPF' createSaleRequest.Buyer.Email = 'lskywalker@r2d2.com' createSaleRequest.Buyer.EmailType = 'Personal' createSaleRequest.Buyer.FacebookId = 'lukeskywalker8917' createSaleRequest.Buyer.Gender = 'M' createSaleRequest.Buyer.HomePhone = '(21)123456789' createSaleRequest.Buyer.MobilePhone = '(21)987654321' createSaleRequest.Buyer.Name = 'Luke Skywalker' createSaleRequest.Buyer.PersonType = 'Person' createSaleRequest.Buyer.TwitterId = '@lukeskywalker8917' createSaleRequest.Buyer.WorkPhone = '(21)28467902' # adds to the credit card transaction collection createSaleRequest.CreditCardTransactionCollection << creditCardTransaction createSaleRequest.Merchant.MerchantReference = 'IdDaLojaPlataforma' createSaleRequest.Options.AntiFraudServiceCode = 0 createSaleRequest.Options.CurrencyIso = 'BRL' createSaleRequest.Options.IsAntiFraudEnabled = true createSaleRequest.Options.Retries = 1 createSaleRequest.Order.OrderReference = 'NumeroDoPedido' createSaleRequest.RequestData.EcommerceCategory = 'B2C' createSaleRequest.RequestData.IpAddress = '127.0.0.1' createSaleRequest.RequestData.Origin = 'SiteDeCompra' createSaleRequest.RequestData.SessionId = 'IdSesssaoNoSite' # adds shopping cart collection in the request createSaleRequest.ShoppingCartCollection << shoppingCartCollection # make the request and returns a response hash response = gateway.CreateSale(createSaleRequest) expect(response[:ErrorReport]).to eq nil end it 'should create an anti fraud transaction' do # create credit card transaction object creditCardTransaction = CreditCardTransaction.new # 100 reais in cents creditCardTransaction.AmountInCents = 10000 creditCardTransaction.CreditCard.BillingAddress.City = 'Tatooine' creditCardTransaction.CreditCard.BillingAddress.Complement = '' creditCardTransaction.CreditCard.BillingAddress.Country = 'Brazil' creditCardTransaction.CreditCard.BillingAddress.District = 'Mos Eisley' creditCardTransaction.CreditCard.BillingAddress.Number = '123' creditCardTransaction.CreditCard.BillingAddress.State = 'RJ' creditCardTransaction.CreditCard.BillingAddress.Street = 'Mos Eisley Cantina' creditCardTransaction.CreditCard.BillingAddress.ZipCode = '20001000' creditCardTransaction.CreditCard.CreditCardBrand = 'Visa' creditCardTransaction.CreditCard.CreditCardNumber = '4111111111111111' creditCardTransaction.CreditCard.ExpMonth = 10 creditCardTransaction.CreditCard.ExpYear = 22 creditCardTransaction.CreditCard.HolderName = 'LUKE SKYWALKER' creditCardTransaction.CreditCard.SecurityCode = '123' creditCardTransaction.InstallmentCount = 1 shoppingCartItem = ShoppingCartItemCollection.new shoppingCartItem.Description = 'Red Lightsaber' shoppingCartItem.DiscountAmountInCents = 0 shoppingCartItem.ItemReference = 'NumeroDoProduto' shoppingCartItem.Name = 'Lightsaber' shoppingCartItem.Quantity = 1 shoppingCartItem.TotalCostInCents = 18000 shoppingCartItem.UnitCostInCents = 0 shoppingCartCollection = ShoppingCartCollection.new shoppingCartCollection.DeliveryAddress.City = 'Galaxy far far away' shoppingCartCollection.DeliveryAddress.Complement = 'Bridge' shoppingCartCollection.DeliveryAddress.Country = 'Brazil' shoppingCartCollection.DeliveryAddress.District = 'Command Room' shoppingCartCollection.DeliveryAddress.Number = '321' shoppingCartCollection.DeliveryAddress.State = 'RJ' shoppingCartCollection.DeliveryAddress.Street = 'Death Star' shoppingCartCollection.DeliveryAddress.ZipCode = '10002000' shoppingCartCollection.FreighCostInCents = 2000 shoppingCartCollection.ShoppingCartItemCollection << shoppingCartItem # creates request object for transaction creation createSaleRequest = CreateSaleRequest.new buyerAddress = BuyerAddress.new buyerAddress.AddressType = 'Residential' buyerAddress.City = 'Tatooine' buyerAddress.Complement = '' buyerAddress.Country = 'Brazil' buyerAddress.District = 'Mos Eisley' buyerAddress.Number = '123' buyerAddress.State = 'RJ' buyerAddress.Street = 'Mos Eisley Cantina' buyerAddress.ZipCode = '20001000' createSaleRequest.Buyer.AddressCollection << buyerAddress createSaleRequest.Buyer.Birthdate = DateTime.new(1990,8,20,0,0,0).strftime("%Y-%m-%dT%H:%M:%S") createSaleRequest.Buyer.BuyerReference = 'C3PO' createSaleRequest.Buyer.DocumentNumber = '12345678901' createSaleRequest.Buyer.DocumentType = 'CPF' createSaleRequest.Buyer.Email = 'lskywalker@r2d2.com' createSaleRequest.Buyer.EmailType = 'Personal' createSaleRequest.Buyer.Gender = 'M' createSaleRequest.Buyer.HomePhone = '(21)123456789' createSaleRequest.Buyer.MobilePhone = '(21)987654321' createSaleRequest.Buyer.Name = 'Luke Skywalker' createSaleRequest.Buyer.PersonType = 'Person' createSaleRequest.Buyer.WorkPhone = '(21)28467902' # adds to the credit card transaction collection createSaleRequest.CreditCardTransactionCollection << creditCardTransaction createSaleRequest.Options.IsAntiFraudEnabled = true createSaleRequest.Order.OrderReference = 'NumeroDoPedido' # adds shopping cart collection in the request createSaleRequest.ShoppingCartCollection << shoppingCartCollection # make the request and returns a response hash response = gateway.CreateSale(createSaleRequest) expect(response[:ErrorReport]).to eq nil end it 'should consult the order with order key' do querySaleRequest = QuerySaleRequest.new createSaleRequest = CreateSaleRequest.new boletoTransaction = BoletoTransaction.new boletoTransaction.AmountInCents = 100 boletoTransaction.BankNumber = '237' boletoTransaction.DocumentNumber = '12345678901' boletoTransaction.Instructions = 'Pagar antes do vencimento' boletoTransaction.TransactionReference = 'BoletoTest#Ruby01' boletoTransaction.Options.CurrencyIso = 'BRL' boletoTransaction.Options.DaysToAddInBoletoExpirationDate = 5 createSaleRequest.BoletoTransactionCollection << boletoTransaction boleto_response = gateway.CreateSale(createSaleRequest) querySaleRequest.OrderKey = boleto_response['OrderResult']['OrderKey'] responseQuery = gateway.Query(QuerySaleRequest.QuerySaleRequestEnum[:OrderKey], querySaleRequest.OrderKey) orderKey = responseQuery["SaleDataCollection"][0]["OrderData"]["OrderKey"] expect(orderKey).to eq querySaleRequest.OrderKey end it 'should consult the order with order reference' do querySaleRequest = QuerySaleRequest.new createSaleRequest = CreateSaleRequest.new boletoTransaction = BoletoTransaction.new boletoTransaction.AmountInCents = 100 boletoTransaction.BankNumber = '237' boletoTransaction.DocumentNumber = '12345678901' boletoTransaction.Instructions = 'Pagar antes do vencimento' boletoTransaction.TransactionReference = 'BoletoTest#Ruby01' boletoTransaction.Options.CurrencyIso = 'BRL' boletoTransaction.Options.DaysToAddInBoletoExpirationDate = 5 createSaleRequest.Order.OrderReference = 'RubyOrderReferenceUnitTest' createSaleRequest.BoletoTransactionCollection << boletoTransaction boleto_response = gateway.CreateSale(createSaleRequest) querySaleRequest.OrderReference = boleto_response['OrderResult']['OrderReference'] responseQuery = gateway.Query(QuerySaleRequest.QuerySaleRequestEnum[:OrderReference], querySaleRequest.OrderReference) orderReference = responseQuery["SaleDataCollection"][0]["OrderData"]["OrderReference"] expect(orderReference).to eq querySaleRequest.OrderReference end it 'should do a retry method' do retrySaleRequest = RetrySaleRequest.new retrySaleCreditCardTransactionItem = RetrySaleCreditCardTransaction.new createSaleRequest = CreateSaleRequest.new creditCardTransactionItem = CreditCardTransaction.new creditCardTransactionItem.AmountInCents = 100 creditCardTransactionItem.CreditCard.CreditCardBrand = 'Visa' creditCardTransactionItem.CreditCard.CreditCardNumber = '41111111111111' creditCardTransactionItem.CreditCard.ExpMonth = 10 creditCardTransactionItem.CreditCard.ExpYear = 19 creditCardTransactionItem.CreditCard.HolderName = 'Maria do Carmo' creditCardTransactionItem.CreditCard.SecurityCode = '123' creditCardTransactionItem.CreditCardOperation = 'AuthAndCapture' creditCardTransactionItem.InstallmentCount = 1 creditCardTransactionItem.Options.CurrencyIso = 'BRL' creditCardTransactionItem.Options.PaymentMethodCode = 1 creditCardTransactionItem.TransactionReference = 'RubySDK-RetryTest' createSaleRequest.CreditCardTransactionCollection << creditCardTransactionItem createSaleRequest.Order.OrderReference = 'RubySDK-RetryTest' # cria o pedido que sera usado para retentativa responseCreate = gateway.CreateSale(createSaleRequest) # pega o orderkey e o transaction key da resposta que sao necessarios para fazer a retentativa orderKey = responseCreate["OrderResult"]["OrderKey"] transactionKey = responseCreate['CreditCardTransactionResultCollection'][0]['TransactionKey'] # monta o objeto de retentativa retrySaleCreditCardTransactionItem.SecurityCode = '123' retrySaleCreditCardTransactionItem.TransactionKey = transactionKey retrySaleRequest.OrderKey = orderKey retrySaleRequest.RetrySaleCreditCardTransactionCollection << retrySaleCreditCardTransactionItem # faz a requisicao de retentativa response = gateway.Retry(retrySaleRequest) # espera que o transaction key seja igual, significa que foi tudo ok no teste responseTransactionKey = response['CreditCardTransactionResultCollection'][0]['TransactionKey'] expect(responseTransactionKey).to eq transactionKey end it 'should do a retry method with only order key' do createSaleRequest = CreateSaleRequest.new creditCardTransactionItem = CreditCardTransaction.new creditCardTransactionItem.AmountInCents = 100 creditCardTransactionItem.CreditCard.CreditCardBrand = 'Visa' creditCardTransactionItem.CreditCard.CreditCardNumber = '41111111111111' creditCardTransactionItem.CreditCard.ExpMonth = 10 creditCardTransactionItem.CreditCard.ExpYear = 22 creditCardTransactionItem.CreditCard.HolderName = 'Maria do Carmo' creditCardTransactionItem.CreditCard.SecurityCode = '123' creditCardTransactionItem.CreditCardOperation = 'AuthAndCapture' creditCardTransactionItem.TransactionReference = 'RubySDK-RetryTest' createSaleRequest.CreditCardTransactionCollection << creditCardTransactionItem createSaleRequest.Order.OrderReference = 'RubySDK-RetryTest' # cria o pedido que sera usado para retentativa responseCreate = gateway.CreateSale(createSaleRequest) # pega o orderkey e o transaction key da resposta que sao necessarios para fazer a retentativa orderKey = responseCreate["OrderResult"]["OrderKey"] transactionKey = responseCreate['CreditCardTransactionResultCollection'][0]['TransactionKey'] retrySaleRequest = RetrySaleRequest.new # monta o objeto de retentativa retrySaleRequest.OrderKey = orderKey # faz a requisicao de retentativa response = gateway.Retry(retrySaleRequest) expect(response['ErrorReport']).to eq nil end it 'should cancel a transaction' do createSaleRequest = CreateSaleRequest.new creditCardTransactionItem = CreditCardTransaction.new creditCardTransactionItem.AmountInCents = 100 creditCardTransactionItem.CreditCard.CreditCardBrand = 'Visa' creditCardTransactionItem.CreditCard.CreditCardNumber = '41111111111111' creditCardTransactionItem.CreditCard.ExpMonth = 10 creditCardTransactionItem.CreditCard.ExpYear = 19 creditCardTransactionItem.CreditCard.HolderName = 'Maria do Carmo' creditCardTransactionItem.CreditCard.SecurityCode = '123' creditCardTransactionItem.CreditCardOperation = 'AuthAndCapture' creditCardTransactionItem.InstallmentCount = 1 creditCardTransactionItem.Options.CurrencyIso = 'BRL' creditCardTransactionItem.Options.PaymentMethodCode = 1 creditCardTransactionItem.TransactionReference = 'RubySDK-CancelTest' createSaleRequest.CreditCardTransactionCollection << creditCardTransactionItem createSaleRequest.Order.OrderReference = 'RubySDK-CancelTest' # cria o pedido que sera usado para cancelamento responseCreate = gateway.CreateSale(createSaleRequest) # pega o orderkey e o transaction key da resposta que sao necessarios para fazer o cancelamento orderKey = responseCreate["OrderResult"]["OrderKey"] transactionKey = responseCreate['CreditCardTransactionResultCollection'][0]['TransactionKey'] # itens necessarios para cancelamento da transacao de cartao de credito cancelCreditCardTransactionItem = ManageCreditCardTransaction.new cancelCreditCardTransactionItem.AmountInCents = 100 cancelCreditCardTransactionItem.TransactionKey = transactionKey cancelCreditCardTransactionItem.TransactionReference = 'RubySDK-CancelTest' # monta o objeto para cancelamento de transacao cancelSaleRequest = ManageSaleRequest.new cancelSaleRequest.OrderKey = orderKey cancelSaleRequest.CreditCardTransactionCollection << cancelCreditCardTransactionItem response = gateway.Cancel(cancelSaleRequest) expect(response[:ErrorReport]).to eq nil end it 'should capture a transaction' do createSaleRequest = CreateSaleRequest.new creditCardTransactionItem = CreditCardTransaction.new creditCardTransactionItem.AmountInCents = 100 creditCardTransactionItem.CreditCard.CreditCardBrand = 'Visa' creditCardTransactionItem.CreditCard.CreditCardNumber = '41111111111111' creditCardTransactionItem.CreditCard.ExpMonth = 10 creditCardTransactionItem.CreditCard.ExpYear = 19 creditCardTransactionItem.CreditCard.HolderName = 'Maria do Carmo' creditCardTransactionItem.CreditCard.SecurityCode = '123' creditCardTransactionItem.CreditCardOperation = 'AuthAndCapture' creditCardTransactionItem.InstallmentCount = 1 creditCardTransactionItem.Options.CurrencyIso = 'BRL' creditCardTransactionItem.Options.PaymentMethodCode = 1 creditCardTransactionItem.TransactionReference = 'RubySDK-CaptureTest' createSaleRequest.CreditCardTransactionCollection << creditCardTransactionItem createSaleRequest.Order.OrderReference = 'RubySDK-CaptureTest' # cria o pedido que sera usado para captura responseCreate = gateway.CreateSale(createSaleRequest) # pega o orderkey e o transaction key da resposta que sao necessarios para fazer a captura orderKey = responseCreate["OrderResult"]["OrderKey"] transactionKey = responseCreate['CreditCardTransactionResultCollection'][0]['TransactionKey'] # itens necessarios para captura da transacao de cartao de credito captureCreditCardTransactionItem = ManageCreditCardTransaction.new captureCreditCardTransactionItem.AmountInCents = 100 captureCreditCardTransactionItem.TransactionKey = transactionKey captureCreditCardTransactionItem.TransactionReference = 'RubySDK-CaptureTest' # monta o objeto para cancelamento de transacao captureSaleRequest = ManageSaleRequest.new captureSaleRequest.OrderKey = orderKey captureSaleRequest.CreditCardTransactionCollection << captureCreditCardTransactionItem response = gateway.Capture(captureSaleRequest) # espera que o ErrorReport seja nulo, significa que foi tudo ok na transação expect(response['ErrorReport']).to eq nil end it 'should do a parse xml to notification interpretation' do creditCardTransactionItem = CreditCardTransaction.new creditCardTransactionItem.AmountInCents = 100 creditCardTransactionItem.TransactionReference = 'Ruby PostNotification Test' creditCardTransactionItem.InstallmentCount = 1 creditCardTransactionItem.CreditCardOperation = 'AuthAndCapture' creditCardTransactionItem.CreditCard.CreditCardBrand = 'Visa' creditCardTransactionItem.CreditCard.CreditCardNumber = '4111111111111111' creditCardTransactionItem.CreditCard.HolderName = 'Bruce Wayne' creditCardTransactionItem.CreditCard.SecurityCode = '123' creditCardTransactionItem.CreditCard.ExpMonth = 5 creditCardTransactionItem.CreditCard.ExpYear = 20 creditCardTransactionItem.Options.PaymentMethodCode = 1 createSaleRequest = CreateSaleRequest.new createSaleRequest.CreditCardTransactionCollection << creditCardTransactionItem response_hash = gateway.CreateSale(createSaleRequest) credit_card_result = response_hash['CreditCardTransactionResultCollection'][0] expect(credit_card_result['Success']).to eq true # expect(credit_card_result['CreditCardOperation']).to eq 'AuthOnly' # expect(credit_card_result['CreditCardTransactionStatus']).to eq 'AuthorizedPendingCapture' captureCreditCardTransactionItem = ManageCreditCardTransaction.new captureCreditCardTransactionItem.AmountInCents = creditCardTransactionItem.AmountInCents captureCreditCardTransactionItem.TransactionKey = credit_card_result['TransactionKey'] captureCreditCardTransactionItem.TransactionReference = creditCardTransactionItem.TransactionReference captureSale = ManageSaleRequest.new captureSale.OrderKey = response_hash['OrderResult']['OrderKey'] captureSale.CreditCardTransactionCollection << captureCreditCardTransactionItem captureResponse = gateway.Capture(captureSale) expect(captureResponse['ErrorReport']).to eq nil xml = TestHelper.CreateFakePostNotification(response_hash, captureResponse) response = gateway.ParseXmlToNotification(xml) expect(response.nil?).to eq false end it 'should do a parse on online debit xml' do xml = ' 500 0 500 0 2013-02-08T00:00:00 0123456789 2012-11-06T08:55:49.753 4111D523-9A83-4BE3-94D2-160F1BC9C4BD B2E32108 Generated Paid Simulator 2000 2000 2000 Visa 2012-11-06T10:52:55.93 123456 351FC96A-7F42-4269-AF3C-1E3C179C1CD0 24de0432 123456 AuthorizedPendingCapture Captured 100 0 2013-06-27T19:46:46.87 fb3f158a-0309-4ae3-b8ef-3c5ac2d603d2 30bfee13-c908-4e3b-9f70-1f84dbe79fbf OpenedPendingPayment NotPaid B1B1092C-8681-40C2-A734-500F22683D9B 18471F05-9F6D-4497-9C24-D60D5BBB6BBE 64a85875 Paid ' response = gateway.ParseXmlToNotification(xml) expect(response.nil?).to eq false end it 'should bring the transaction report file' do date = Date.new(2015, 9, 19) result = gateway.TransactionReportFile(date) split_commas = result.split(',') expect(split_commas[1]).to eq '20150919' end it 'should parse the transaction report file received' do date = Date.new(2015, 9, 19) request_to_parse = gateway.TransactionReportFile(date) result = gateway.TransactionReportFileParser(request_to_parse) expect(result['Header'].TransactionProcessedDate).to eq '20150919' end it 'should save the transaction report file at selected path' do date = Date.new(2015, 9, 19) file = Tempfile.new('Test') gateway.TransactionReportFileDownloader(date, 'Test', file.path) file_path = file.path.to_s + 'Test.txt' file_exist = File.exist?(file_path) file.close file.unlink expect(file_exist).to eq true end it 'should consult transaction with instant buy key' do credit_card_transaction = CreditCardTransaction.new credit_card_transaction.CreditCard.CreditCardNumber = '4111111111111111' credit_card_transaction.CreditCard.CreditCardBrand = 'Visa' credit_card_transaction.CreditCard.ExpMonth = 10 credit_card_transaction.CreditCard.ExpYear = 2018 credit_card_transaction.CreditCard.SecurityCode = '123' credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker' credit_card_transaction.AmountInCents = 100 sale_request = CreateSaleRequest.new sale_request.CreditCardTransactionCollection << credit_card_transaction sale_response = gateway.CreateSale(sale_request) expect(sale_response['ErrorReport']).to eq nil instant_buy_key = sale_response['CreditCardTransactionResultCollection'][0]['CreditCard']['InstantBuyKey'] response = gateway.InstantBuyKey(instant_buy_key) expect(response['ErrorReport']).to eq nil end it 'should consult transaction with buyer key' do credit_card_transaction = CreditCardTransaction.new credit_card_transaction.CreditCard.CreditCardNumber = '4111111111111111' credit_card_transaction.CreditCard.CreditCardBrand = 'Visa' credit_card_transaction.CreditCard.ExpMonth = 10 credit_card_transaction.CreditCard.ExpYear = 2018 credit_card_transaction.CreditCard.SecurityCode = '123' credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker' credit_card_transaction.AmountInCents = 100 sale_request = CreateSaleRequest.new sale_request.Buyer.Name = 'Anakin Skywalker' sale_request.Buyer.Birthdate = Date.new(1994, 9, 26).strftime("%Y-%m-%dT%H:%M:%S") sale_request.Buyer.DocumentNumber = '12345678901' sale_request.Buyer.DocumentType = 'CPF' sale_request.Buyer.PersonType = 'Person' sale_request.Buyer.Gender = 'M' sale_request.CreditCardTransactionCollection << credit_card_transaction sale_response = gateway.CreateSale(sale_request) expect(sale_response['ErrorReport']).to eq nil response = gateway.BuyerKey(sale_response['BuyerKey']) expect(response['ErrorReport']).to eq nil end it 'should do a credit card transaction with instant buy key' do credit_card_transaction = CreditCardTransaction.new credit_card_transaction.CreditCard.CreditCardNumber = '4111111111111111' credit_card_transaction.CreditCard.CreditCardBrand = 'Visa' credit_card_transaction.CreditCard.ExpMonth = 10 credit_card_transaction.CreditCard.ExpYear = 2018 credit_card_transaction.CreditCard.SecurityCode = '123' credit_card_transaction.CreditCard.HolderName = 'Luke Skywalker' credit_card_transaction.AmountInCents = 100 sale_request = CreateSaleRequest.new sale_request.CreditCardTransactionCollection << credit_card_transaction sale_response = gateway.CreateSale(sale_request) expect(sale_response['ErrorReport']).to eq nil instant_buy_key = sale_response['CreditCardTransactionResultCollection'][0]['CreditCard']['InstantBuyKey'] # coleta dados do cartao creditCardTransaction = CreditCardTransaction.new creditCardTransaction.AmountInCents = 100 creditCardTransaction.CreditCard.InstantBuyKey = instant_buy_key # cria a transacao createSaleRequest = CreateSaleRequest.new createSaleRequest.CreditCardTransactionCollection << creditCardTransaction # faz a requisicao de criação de transacao, retorna um hash com a resposta response = gateway.CreateSale(createSaleRequest) expect(response['ErrorReport']).to eq nil end end