public void given_transaction_request_dto_with_default_field_values_when_call_get_json_then_return_json()
        {
            var transaction = new CreateTransactionRequestDto(123456, 1324567);

            var json = transaction.GetJson();

            Assert.IsTrue(json.Contains("\"trx_id\":1324567"), "Id");
            Assert.IsTrue(json.Contains("\"monto\":123456.00"), "Amount");
            Assert.IsTrue(json.StartsWith("{"), "Start Json");
            Assert.IsTrue(json.EndsWith("}"), "End Json");
        }
        public void given_transaction_request_dto_with_all_field_when_call_get_json_then_return_json_transaction()
        {
            var transaction = new CreateTransactionRequestDto(123456, 1324567)
                                  {PaymentMethod = PaymentMethod.WebpayTransbank};

            var json = transaction.GetJson();

            Assert.IsTrue(json.Contains("\"trx_id\":1324567"), "Id");
            Assert.IsTrue(json.Contains("\"monto\":123456.00"), "Amount");
            Assert.IsTrue(json.Contains("\"medio_pago\":\"003\""), "PaymentMethod");
            Assert.IsTrue(json.StartsWith("{"), "Start Json");
            Assert.IsTrue(json.EndsWith("}"), "End Json");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create the transaction in puntopago
        /// </summary>
        /// <param name="transactionDto">Data for the token that begins the payment process.</param>
        /// <returns>CreateTransactionResponseDto with contains the Token and Url for the payment process</returns>
        public CreateTransactionResponseDto CreateTransaction(CreateTransactionRequestDto transactionDto)
        {
            _logger.Debug(string.Format("Call to Create Transaction for TransactionId: {0}, and amount: {1}", transactionDto.TransactionId, transactionDto.Currency));
            var dateNow = DateTime.UtcNow;
            var message = string.Format("{0}{1}{2}{1}{3}{1}{4}", _configuration.GetCreateTransactionFunction(), "\n",
                                        transactionDto.TransactionId, transactionDto.Currency, dateNow.ToString("r"));
            _logger.Debug(string.Format("Generate message {0}, for PuntoPago", message));

            var authorization = _authorization.GetAuthorizationHeader(message);

            var response = _webExecute.Execute(_configuration.GetCreateTransactionUrl(), "POST", transactionDto.GetJson(), authorization, dateNow);
            _logger.Debug("End create transaction, start CreateTransactionResponseDto");

            var createTransactionResponseDto = new CreateTransactionResponseDto(response, _configuration);
            _logger.Info(string.Format("Create new Transaction for TransactionId: {0} with Token: {1}",
                                       createTransactionResponseDto.TransactionId, createTransactionResponseDto.Token));
            return createTransactionResponseDto;
        }