Exemplo n.º 1
0
        private static Payment GetPayment(ILogger logger, Config config,
                                          Context context, Order order, bool validate)
        {
            var billingAddress = new Address()
            {
                city         = order.City,
                country_code = order.Country,
                line1        = order.Address1,
                postal_code  = order.PostalCode,
                state        = order.State,
            };

            var creditCard = new CreditCard()
            {
                billing_address = billingAddress,
                cvv2            = order.CVV2.ToString(),
                expire_month    = order.ExpireMonth.ToString("00"),
                expire_year     = order.ExpireYear.ToString(),
                first_name      = order.FirstName,
                last_name       = order.LastName,
                number          = order.CardNumber,
                type            = validate ? order.CardNumber.GetCardType().ToString().ToLower() : "visa"
            };

            var transactions = new List <Transaction>();

            var appInfo = new AppInfo();

            foreach (var thing in order.Details)
            {
                var transaction = new Transaction()
                {
                    amount = new Amount()
                    {
                        currency = "USD",
                        total    = thing.Total.ToString("N2"),
                        details  = new AmountDetails()
                        {
                            shipping = thing.Shipping.ToString("N2"),
                            subtotal = thing.SubTotal.ToString("N2"),
                            tax      = thing.Tax.ToString("N2")
                        }
                    },
                    description = string.Format("Order: {0}, Product: {1}",
                                                order.OrderId, appInfo.GetTitle())
                };

                transactions.Add(transaction);
            }

            var payment = new Payment()
            {
                intent = "sale",
                payer  = new Payer()
                {
                    funding_instruments = new List <FundingInstrument>()
                    {
                        new FundingInstrument()
                        {
                            credit_card = creditCard
                        }
                    },
                    payment_method = "credit_card"
                },
                transactions = transactions
            };

            return(JsonConvert.DeserializeObject <Payment>(
                       payment.Create(logger, config, context).ToJson()));
        }
Exemplo n.º 2
0
        private static Payment GetPayment(ILogger logger, Config config,
            Context context, Order order, bool validate)
        {
            var billingAddress = new Address()
            {
                city = order.City,
                country_code = order.Country,
                line1 = order.Address1,
                postal_code = order.PostalCode,
                state = order.State,
            };

            var creditCard = new CreditCard()
            {
                billing_address = billingAddress,
                cvv2 = order.CVV2.ToString(),
                expire_month = order.ExpireMonth.ToString("00"),
                expire_year = order.ExpireYear.ToString(),
                first_name = order.FirstName,
                last_name = order.LastName,
                number = order.CardNumber,
                type = validate ? order.CardNumber.GetCardType().ToString().ToLower() : "visa"
            };

            var transactions = new List<Transaction>();

            var appInfo = new AppInfo();

            foreach (var thing in order.Details)
            {
                var transaction = new Transaction()
                {
                    amount = new Amount()
                    {
                        currency = "USD",
                        total = thing.Total.ToString("N2"),
                        details = new AmountDetails()
                        {
                            shipping = thing.Shipping.ToString("N2"),
                            subtotal = thing.SubTotal.ToString("N2"),
                            tax = thing.Tax.ToString("N2")
                        }
                    },
                    description = string.Format("Order: {0}, Product: {1}",
                        order.OrderId, appInfo.GetTitle())
                };

                transactions.Add(transaction);
            }

            var payment = new Payment()
            {
                intent = "sale",
                payer = new Payer()
                {
                    funding_instruments = new List<FundingInstrument>()
                    {
                        new FundingInstrument()
                        {
                            credit_card = creditCard
                        }
                    },
                    payment_method = "credit_card"
                },
                transactions = transactions
            };

            return JsonConvert.DeserializeObject<Payment>(
                payment.Create(logger, config, context).ToJson());
        }