public void CreateTransactionTest()
        {
            TransactionService target = new TransactionService();
            TransactionRequest request = new TransactionRequest()
            {
                Buyer = new Domain.Account.Customer()
                {
                    Address = new Domain.Account.Address()
                    {
                        address = "Rua teste teste",
                        City = "Cidade Modelo",
                        Complement = "Apto 123",
                        Neighborhood = "Bairro de Teste",
                        Number = "123",
                        State = StateEnum.MINAS_GERAIS,
                        ZipCode = "38408-266"
                    },
                    BirthDate = new DateTime(1986, 07, 21),
                    CellPhone = "3499265135",
                    CompanyName = "Empresa X",
                    Cnpj = "72139715000130",
                    Cpf = "85082236504",
                    Gender = GenderEnum.MALE,
                    IssueRgDate = new DateTime(2010, 06, 25),
                    Mail = "*****@*****.**",
                    Name = "Bruno Aparecido Capel Moretti",
                    OrganConsignorRg = "SSP",
                    Phone = "3432558584",
                    Rg = "13194030",
                    SearchToken = String.Empty,
                    StateConsignorRg = StateEnum.MINAS_GERAIS
                },
                PaymentMethod = new PaymentMethod(PaymentMethodEnum.BB_ONLINE_TRANSFER),
                Products = new List<Product>() { { new Product("1236456", "Produto de teste 1", 5, new Decimal(15.25), "Produto exemplo") } },
                SellerMail = "*****@*****.**",
                OrderId = "123456",
                Free = "Texto livre para o usuário...",
                Freight = new Decimal(10.50),
                FreightType = FreightTypeEnum.SEDEX,
                Discount = new Decimal(1.95),
                Addition = new Decimal(2.65),
                UrlReturn = "retorno.pagamentodigital.com.br",
                UrlNotification = "aviso.pagamentodigital.com.br",
                Installments = 1,
                Currency = CurrencyEnum.REAL,
                AcceptedContract = true,
                ViewedContract = true
            };

            OAuthRequestData oauth = new OAuthRequestData("437f7c3021a87ebf1cefb17be66e3fb72fa8dd51");

            TransactionResponse actual = null;
            try
            {
                actual = target.CreateTransaction(request, oauth);
                Assert.IsNotNull(actual);
            }
            catch (ServiceException ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private static TransactionRequest GenerateTransactionRequest()
        {
            TransactionRequest transactionRequest = new TransactionRequest()
            {
                SellerMail = SELLER_MAIL,
                OrderId = "12353",
                Free = "Texto livre",
                Freight = new Decimal(random.Next(99)),
                FreightType = FREIGHT_TYPE,
                Discount = new Decimal(random.Next(9)),
                Addition = new Decimal(random.Next(9)),
                UrlReturn = "retorno.pagamentodigital.com.br",
                UrlNotification = "aviso.pagamentodigital.com.br",
                Installments = 1,
                Currency = CURRENCY,
                ViewedContract = true,
                AcceptedContract = true,
                PaymentMethod = new PaymentMethod(PaymentMethodEnum.VISA),
                Buyer = GenerateCustomer(),
                Products = GenerateProducts(1),
                PlatformId = 422,
                CreditCard = GenerateCreditCard()

                /*DependentTransactions = new List<DependentTransaction>()
                {
                    new DependentTransaction(){ Email="*****@*****.**", Value = new Decimal(100.99) },
                    new DependentTransaction(){ Email="*****@*****.**", Value = new Decimal(99.99) }
                }*/
            };

            return transactionRequest;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Cria uma transação a partir dos dados informados.
        /// </summary>
        /// <param name="request">Objeto que contém informações para a criação da transação.</param>
        /// <param name="oauth">Objeto que contém informações de autenticação para consumir o serviço.</param>
        /// <returns>Objeto que contém informações de status da transação criada.</returns>
        public TransactionResponse CreateTransaction(TransactionRequest request, OAuthRequestData oauth)
        {
            string data = JsonConvert.SerializeObject(request,
                Formatting.None,
                new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver(),
                    Converters = new List<JsonConverter>() {
                        { new BooleanConverter() },
                        { new DateTimeConverter() }
                    }
                });

            HttpClientResponse response = this.HttpClient.Post(
                ConfigUtil.UriTransactionCreateService,
                this.GetParams(data),
                this.GetOAuthHeader(oauth));

            if (response.HttpStatus != HttpStatusCode.OK)
            {
                // ErrorList
                throw new ServiceException(JsonConvert.DeserializeObject<ErrorList>(response.ResponseBody));
            }

            return JsonConvert.DeserializeObject<TransactionResponse>(response.ResponseBody);
        }