Exemplo n.º 1
0
 public void ConfigEnvironment()
 {
     _api = new CieloApi(CieloEnvironment.Sandbox, Merchant.Sandbox);
     _validExpirationDate   = new DateTime(DateTime.Now.Year + 1, 12, 1);
     _invalidExpirationDate = new DateTime(DateTime.Now.Year - 1, 12, 1);
 }
Exemplo n.º 2
0
        ProcessPaymentResult IPaymentMethod.ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            //var model = new PaymentInfoModel
            //{
            //    CardholderName = processPaymentRequest.CreditCardName,
            //    CardNumber = processPaymentRequest.CreditCardNumber,
            //    CardCode = processPaymentRequest.CreditCardCvv2,
            //    ExpireMonth = processPaymentRequest.CreditCardExpireMonth.ToString(),
            //    ExpireYear = processPaymentRequest.CreditCardExpireYear.ToString(),
            //    ParcelsQtd = processPaymentRequest.ParcelsQtd.ToString()
            //};

            Merchant prd = new Merchant(
                Guid.Parse(_CieloPaymentSettings.MerchantID),
                _CieloPaymentSettings.MerchantKey);

            api = new CieloApi(CieloEnvironment.Production, prd);

            var customer = new Customer(name: processPaymentRequest.CreditCardName);

            DateTime dtExpire = new DateTime(processPaymentRequest.CreditCardExpireYear, processPaymentRequest.CreditCardExpireMonth, 01);

            var creditCard = new CreditCard(
                cardNumber: processPaymentRequest.CreditCardNumber,
                holder: processPaymentRequest.CreditCardName,
                expirationDate: dtExpire,
                securityCode: processPaymentRequest.CreditCardCvv2,
                brand: CardBrand.Visa);

            var payment = new ApiCielo.Payment(
                amount: processPaymentRequest.OrderTotal,
                currency: ApiCielo.Currency.BRL,
                installments: processPaymentRequest.ParcelsQtd,
                capture: true,
                softDescriptor: "ECommerce",
                creditCard: creditCard);

            /* store order number */
            var merchantOrderId = new Random().Next();

            var transaction = new Transaction(
                merchantOrderId: merchantOrderId.ToString(),
                customer: customer,
                payment: payment
                );

            Transaction          returnTransaction = api.CreateTransaction(Guid.NewGuid(), transaction);
            ProcessPaymentResult result            = new ProcessPaymentResult();

            switch (returnTransaction.Payment.Status)
            {
            case ApiCielo.Status.Aborted:

                break;

            case ApiCielo.Status.Authorized:
                result.NewPaymentStatus = PaymentStatus.Authorized;
                break;

            case ApiCielo.Status.Denied:
                result.NewPaymentStatus = PaymentStatus.Pending;
                break;

            case ApiCielo.Status.NotFinished:
                result.NewPaymentStatus = PaymentStatus.Pending;
                break;

            case ApiCielo.Status.PaymentConfirmed:
                result.NewPaymentStatus = PaymentStatus.Paid;
                break;

            case ApiCielo.Status.Pending:
                result.NewPaymentStatus = PaymentStatus.Pending;
                break;

            case ApiCielo.Status.Refunded:
                result.NewPaymentStatus = PaymentStatus.Refunded;
                break;

            case ApiCielo.Status.Scheduled:
                result.NewPaymentStatus = PaymentStatus.Pending;
                break;

            case ApiCielo.Status.Voided:
                result.NewPaymentStatus = PaymentStatus.Voided;
                break;

            default:
                result.AddError("Não Suportado");
                break;
            }

            result.AuthorizationTransactionId     = returnTransaction.Payment.PaymentId.ToString();
            result.AuthorizationTransactionCode   = returnTransaction.Payment.AuthorizationCode;
            result.AuthorizationTransactionResult = returnTransaction.Payment.ReturnMessage;

            //  result.CaptureTransactionId =

            return(result); // new ProcessPaymentResult { Errors = new[] { "Impmentar " } };
        }