Beispiel #1
0
        public IActionResult Charge(PayModelView model)
        {
            var customers = new CustomerService();
            var customer  = customers.Create(new CustomerCreateOptions
            {
                Name   = model.Name,
                Email  = model.Email,
                Source = model.Token
            });
            var service = new OrderService();
            var options = service.Create(new OrderCreateOptions
            {
                Currency = "usd",
                Email    = model.Email,
                Items    = new List <OrderItemOptions> {
                    new OrderItemOptions {
                        Type     = model.Type,
                        Parent   = "sku_GLdbjkfZychwTo",
                        Quantity = model.Quantity,
                    },
                },
                Shipping = new ShippingOptions
                {
                    Name    = model.Name,
                    Address = new AddressOptions
                    {
                        Line1      = model.Line1,
                        City       = model.City,
                        State      = model.State,
                        Country    = "US",
                        PostalCode = model.PostalCode,
                    },
                }
            });

            var optionpay = new OrderPayOptions
            {
                Customer = customer.Id,
            };

            service.Pay(
                options.Id,
                optionpay
                );

            return(View());
        }
Beispiel #2
0
        public IActionResult Complete(PayModelView pay)
        {
            WorldpayRestClient restClient = new WorldpayRestClient("https://api.worldpay.com/v1", _settings.ServiceKey);

            var orderRequest = new OrderRequest()
            {
                token             = pay.Token,
                amount            = Convert.ToInt32(pay.Total),
                currencyCode      = CurrencyCode.GBP.ToString(),
                name              = "test name",
                orderDescription  = "Order description",
                customerOrderCode = "Order code"
            };

            var address = new Address()
            {
                address1    = "123 House Road",
                address2    = "A village",
                city        = "London",
                countryCode = CountryCode.GB.ToString(),
                postalCode  = "EC1 1AA"
            };

            orderRequest.billingAddress = address;

            try
            {
                OrderResponse orderResponse = restClient.GetOrderService().Create(orderRequest);
                Console.WriteLine("Order code: " + orderResponse.orderCode);
            }
            catch (WorldpayException e)
            {
                Console.WriteLine("Error code:" + e.apiError.customCode);
                Console.WriteLine("Error description: " + e.apiError.description);
                Console.WriteLine("Error message: " + e.apiError.message);
            }

            return(View());
        }