public IActionResult OnPost()
        {
            ICheckoutApi checkoutApi = client.CheckoutApi;

            try
            {
                // create line items for the order
                // This example assumes the order information is retrieved and hard coded
                // You can find different ways to retrieve order information and fill in the following lineItems object.
                List <OrderLineItem> lineItems = new List <OrderLineItem>();

                Money firstLineItemBasePriceMoney = new Money.Builder()
                                                    .Amount(500L)
                                                    .Currency("USD")
                                                    .Build();

                OrderLineItem firstLineItem = new OrderLineItem.Builder("1")
                                              .Name("Test Item A")
                                              .BasePriceMoney(firstLineItemBasePriceMoney)
                                              .Build();

                lineItems.Add(firstLineItem);

                Money secondLineItemBasePriceMoney = new Money.Builder()
                                                     .Amount(1000L)
                                                     .Currency("USD")
                                                     .Build();

                OrderLineItem secondLineItem = new OrderLineItem.Builder("3")
                                               .Name("Test Item B")
                                               .BasePriceMoney(secondLineItemBasePriceMoney)
                                               .Build();

                lineItems.Add(secondLineItem);

                // create Order object with line items
                Order order = new Order.Builder(locationId)
                              .LineItems(lineItems)
                              .Build();

                // create order request with order
                CreateOrderRequest orderRequest = new CreateOrderRequest.Builder()
                                                  .Order(order)
                                                  .Build();

                // create checkout request with the previously created order
                CreateCheckoutRequest createCheckoutRequest = new CreateCheckoutRequest.Builder(
                    Guid.NewGuid().ToString(),
                    orderRequest)
                                                              .Build();

                // create checkout response, and redirect to checkout page if successful
                CreateCheckoutResponse response = checkoutApi.CreateCheckout(locationId, createCheckoutRequest);
                return(Redirect(response.Checkout.CheckoutPageUrl));
            }
            catch (ApiException e)
            {
                return(RedirectToPage("Error", new { error = e.Message }));
            }
        }
        // private readonly IPaymentMethod _paymentMethod;

        public CheckoutController(ICustomerApi customerApi, IConfigApi configApi,
                                  IPaymentApi paymentApi, ICheckoutApi checkoutApi, IOrderApi orderApi, IShippingApi shippingApi, IAuthenticationService authenticationService, ICustomerApi customerRepository, IB2BApi b2bRepository)
        {
            _customerApi           = customerApi;
            _configApi             = configApi;
            _paymentApi            = paymentApi;
            _checkoutApi           = checkoutApi;
            _orderApi              = orderApi;
            _shippingApi           = shippingApi;
            _authenticationService = authenticationService;
            _customerRepository    = customerRepository;
            _b2bRepository         = b2bRepository;
        }
 public PaymentController(ICheckoutApi checkoutApi, ISerializer serializer,
                          WalletHistoryService walletHistoryService, UsersService usersService, IOptions <AppSettings> appSettings,
                          PaymentCardsService paymentCardsService,
                          PaymentResponseService paymentResponseService, CustomerRegistrationService customerService)
 {
     _checkoutApi            = checkoutApi ?? throw new ArgumentNullException(nameof(checkoutApi));
     _serializer             = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _walletHistoryService   = walletHistoryService;
     _usersService           = usersService;
     _appSettings            = appSettings.Value;
     _paymentCardsService    = paymentCardsService;
     _paymentResponseService = paymentResponseService;
     _customerService        = customerService;
 }
        protected SandboxTestFixture(PlatformType platformType)
        {
            var logFactory = new NLogLoggerFactory();

            _log = logFactory.CreateLogger(typeof(SandboxTestFixture));
            switch (platformType)
            {
            case PlatformType.Previous:
                PreviousApi = CheckoutSdk.Builder()
                              .Previous()
                              .StaticKeys()
                              .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_PUBLIC_KEY"))
                              .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_SECRET_KEY"))
                              .Environment(Environment.Sandbox)
                              .LogProvider(logFactory)
                              .HttpClientFactory(new DefaultHttpClientFactory())
                              .Build();
                break;

            case PlatformType.Default:
                DefaultApi = CheckoutSdk.Builder().StaticKeys()
                             .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PUBLIC_KEY"))
                             .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_SECRET_KEY"))
                             .Environment(Environment.Sandbox)
                             .LogProvider(logFactory)
                             .Build();
                break;

            case PlatformType.DefaultOAuth:
                DefaultApi = CheckoutSdk.Builder().OAuth()
                             .ClientCredentials(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"),
                                                System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET"))
                             .Scopes(OAuthScope.Files, OAuthScope.Flow, OAuthScope.Fx, OAuthScope.Gateway,
                                     OAuthScope.Marketplace, OAuthScope.SessionsApp, OAuthScope.SessionsBrowser,
                                     OAuthScope.Vault, OAuthScope.PayoutsBankDetails, OAuthScope.TransfersCreate,
                                     OAuthScope.TransfersView, OAuthScope.BalancesView)
                             .Environment(Environment.Sandbox)
                             .LogProvider(logFactory)
                             .Build();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(platformType), platformType, null);
            }
        }
Пример #5
0
 public PaymentsController(ICheckoutApi checkoutApi, ISerializer serializer)
 {
     _checkoutApi = checkoutApi ?? throw new ArgumentNullException(nameof(checkoutApi));
     _serializer  = serializer ?? throw new ArgumentNullException(nameof(serializer));
 }
 public MasterCardController(ICheckoutApi checkoutApi, IOrderApi orderApi)
 {
     _checkoutApi = checkoutApi;
     _orderApi    = orderApi;
 }
Пример #7
0
        public ActionResult SquarePayment(string id)
        {
            if (id == null)
            {
                return(RedirectToAction("/Home/Login"));
            }

            Models.Order order = db.Orders.Where(i => i.ID == id).First();
            if (order == null)
            {
                return(HttpNotFound());
            }

            Models.OrderBilling billing = db.Billing.FirstOrDefault(i => i.orderId == order.orderId);
            if (billing == null)
            {
                return(HttpNotFound());
            }

            CheckoutSquare square      = new CheckoutSquare();
            ICheckoutApi   checkoutApi = square.client.CheckoutApi;

            try
            {
                // create line items for the order
                // This example assumes the order information is retrieved and hard coded
                // You can find different ways to retrieve order information and fill in the following lineItems object.
                List <OrderLineItem> lineItems = new List <OrderLineItem>();

                Money firstLineItemBasePriceMoney = new Money.Builder()
                                                    .Amount(order.billing.totalChargesSquareAPI)
                                                    .Currency("USD")
                                                    .Build();

                OrderLineItem firstLineItem = new OrderLineItem.Builder("1")
                                              .Name(order.service)
                                              .BasePriceMoney(firstLineItemBasePriceMoney)
                                              .Build();

                lineItems.Add(firstLineItem);

                // create Order object with line items
                Square.Models.Order squareOrder = new Square.Models.Order.Builder(square.locationId)
                                                  .LineItems(lineItems)
                                                  .Build();

                // create order request with order
                CreateOrderRequest orderRequest = new CreateOrderRequest.Builder()
                                                  .Order(squareOrder)
                                                  .IdempotencyKey(order.contractNumber)
                                                  .Build();

                // create checkout request with the previously created order
                CreateCheckoutRequest createCheckoutRequest = new CreateCheckoutRequest.Builder(
                    Guid.NewGuid().ToString(),
                    orderRequest)
                                                              .RedirectUrl(WebConfigurationManager.AppSettings["SQUARE_RedirectUrl"] + id)
                                                              .MerchantSupportEmail("*****@*****.**")
                                                              .PrePopulateBuyerEmail(order.email)
                                                              .Build();

                // create checkout response, and redirect to checkout page if successful
                CreateCheckoutResponse response = checkoutApi.CreateCheckout(square.locationId, createCheckoutRequest);

                // Save checkout on the base
                db.CreatePayment(order.orderId, response.Checkout.Id, "SQUARE API");

                return(Redirect(response.Checkout.CheckoutPageUrl));
            }
            catch (ApiException e)
            {
                return(RedirectToAction("Error", new { error = e.Message }));
            }
        }
 public GetPaymentTests(ApiTestFixture fixture, ITestOutputHelper outputHelper)
 {
     fixture.CaptureLogsInTestOutput(outputHelper);
     _api = fixture.Api;
 }
Пример #9
0
 public PaypalController(ICheckoutApi checkoutApi, IOrderApi orderApi)
 {
     _checkoutApi = checkoutApi;
     _orderApi    = orderApi;
 }
Пример #10
0
        private async Task ShouldMakeTamaraPayment()
        {
            ICheckoutApi previewApi = CheckoutSdk.Builder()
                                      .OAuth()
                                      .ClientCredentials(
                System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PREVIEW_OAUTH_CLIENT_ID"),
                System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PREVIEW_OAUTH_CLIENT_SECRET"))
                                      .Environment(Environment.Sandbox)
                                      .Build();

            var tamaraSource = new RequestTamaraSource();

            tamaraSource.BillingAddress = new Address
            {
                AddressLine1 = "Cecilia Chapman",
                AddressLine2 = "711-2880 Nulla St.",
                City         = "Mankato",
                State        = "Mississippi",
                Zip          = "96522",
                Country      = CountryCode.SA
            };

            var paymentRequest = new PaymentRequest
            {
                Source     = tamaraSource,
                Currency   = Currency.SAR,
                Amount     = 10000,
                Capture    = true,
                SuccessUrl = "https://testing.checkout.com/sucess",
                FailureUrl = "https://testing.checkout.com/failure",
                Reference  = "ORD-5023-4E89",
                Processing = new ProcessingSettings {
                    TaxAmount = 500, ShippingAmount = 1000
                },
                ProcessingChannelId = "pc_zs5fqhybzc2e3jmq3efvybybpq",
                Customer            = new CustomerRequest
                {
                    Name  = "Cecilia Chapman",
                    Email = "*****@*****.**",
                    Phone = new Phone {
                        CountryCode = "+966", Number = "113 496 0000"
                    }
                },
                Items = new List <Product>
                {
                    new Product
                    {
                        Name           = "Item name",
                        Quantity       = 3,
                        UnitPrice      = 100,
                        TotalAmount    = 100,
                        TaxAmount      = 19,
                        DiscountAmount = 2,
                        Reference      = "some description about item",
                        ImageUrl       = "https://some_s3bucket.com",
                        Url            = "https://some.website.com/item",
                        Sku            = "123687000111"
                    }
                }
            };

            var paymentResponse = await previewApi.PaymentsClient().RequestPayment(paymentRequest);

            paymentResponse.ShouldNotBeNull();
            paymentResponse.Id.ShouldNotBeNullOrEmpty();
            paymentResponse.Reference.ShouldNotBeNullOrEmpty();
            paymentResponse.Status.ShouldBe(PaymentStatus.Pending);
            paymentResponse.Links.ShouldNotBeEmpty();
            paymentResponse.Customer.Id.ShouldNotBeNullOrEmpty();
            paymentResponse.Customer.Name.ShouldNotBeEmpty();
            paymentResponse.Customer.Email.ShouldNotBeEmpty();
            paymentResponse.Customer.Phone.ShouldNotBeNull();
            paymentResponse.Processing.PartnerPaymentId.ShouldNotBeNull();
            paymentResponse.Links.ShouldNotBeEmpty();
        }
Пример #11
0
 public SourcesTests(ApiTestFixture fixture, ITestOutputHelper outputHelper)
 {
     fixture.CaptureLogsInTestOutput(outputHelper);
     _api = fixture.Api;
 }
Пример #12
0
 public KlarnaController(HttpContextBase httpContext, ICheckoutApi checkoutApi, IOrderApi orderApi)
 {
     _checkoutApi = checkoutApi;
     _orderApi    = orderApi;
 }
 public CustomerSourcePaymentsTests(ApiTestFixture fixture, ITestOutputHelper outputHelper)
 {
     fixture.CaptureLogsInTestOutput(outputHelper);
     _api = fixture.Api;
 }
Пример #14
0
 public WorldpayController(HttpContextBase httpContext, ICheckoutApi checkoutApi, IOrderApi orderApi)
 {
     _httpContext = httpContext;
     _checkoutApi = checkoutApi;
     _orderApi    = orderApi;
 }
Пример #15
0
 public AlternativePaymentSourcePaymentsTests(ApiTestFixture fixture, ITestOutputHelper outputHelper)
 {
     fixture.CaptureLogsInTestOutput(outputHelper);
     _api = fixture.Api;
 }
Пример #16
0
        public IActionResult OnPost()
        {
            ICheckoutApi checkoutApi = client.CheckoutApi;

            try
            {
                var rand  = new Random();
                int rand1 = rand.Next(100000, 999999);
                int id    = HttpContext.Session.GetInt32("logID").GetValueOrDefault();
                DropShipModels.User CurrUser = dbContext.Users
                                               .FirstOrDefault(user => user.UserId == id);
                if (CurrUser != null)
                {
                    var RetrievedCart = dbContext.Carts.Where(c => c.UserId == CurrUser.UserId)
                                        .Include(carts => carts.P)
                                        .ToList();
                    string OrderNumberTemp       = id.ToString() + '-' + rand1.ToString();
                    string ProductBoughtListTemp = "";

                    List <OrderLineItem> lineItems = new List <OrderLineItem>();
                    foreach (var j in RetrievedCart)
                    {
                        Money ItemPrice = new Money.Builder()
                                          .Amount(j.P.ProductPrice * 100)
                                          .Currency("USD")
                                          .Build();

                        OrderLineItem LineItem = new OrderLineItem.Builder(j.Quantity.ToString())
                                                 .Name(j.P.ProductName)
                                                 .BasePriceMoney(ItemPrice)
                                                 .Note("Order Number     " + OrderNumberTemp)
                                                 .Build();

                        lineItems.Add(LineItem);
                        dbContext.Carts.Remove(j);
                        dbContext.SaveChanges();
                        ProductBoughtListTemp += j.P.ProductName + " x " + j.Quantity + ", ";
                    }
                    ProductBoughtListTemp = ProductBoughtListTemp.Remove(ProductBoughtListTemp.Length - 1, 1);
                    ProductBoughtListTemp = ProductBoughtListTemp.Remove(ProductBoughtListTemp.Length - 1, 1);
                    DropShipModels.Order newOrder = new DropShipModels.Order();
                    newOrder.UserId            = id;
                    newOrder.OrderNumber       = OrderNumberTemp.ToString();
                    newOrder.ProductBoughtList = ProductBoughtListTemp;
                    newOrder.Filled            = false;
                    newOrder.ShippingMethod    = "Standard";
                    dbContext.Orders.Add(newOrder);
                    dbContext.SaveChanges();
                    // create line items for the order.

                    // create Order object with line items
                    Order order = new Order.Builder(locationId)
                                  .LineItems(lineItems)
                                  .Build();

                    // create order request with order
                    CreateOrderRequest orderRequest = new CreateOrderRequest.Builder()
                                                      .Order(order)
                                                      .Build();

                    // create checkout request with the previously created order
                    CreateCheckoutRequest createCheckoutRequest = new CreateCheckoutRequest.Builder(
                        Guid.NewGuid().ToString(),
                        orderRequest)
                                                                  .AskForShippingAddress(true)
                                                                  // .RedirectUrl("www.google.com")
                                                                  .PrePopulateBuyerEmail(CurrUser.Email)
                                                                  .MerchantSupportEmail("*****@*****.**")
                                                                  .Build();
                    // create checkout response, and redirect to checkout page if successful
                    CreateCheckoutResponse response = checkoutApi.CreateCheckout(locationId, createCheckoutRequest);
                    return(Redirect(response.Checkout.CheckoutPageUrl));
                }

                else
                {
                    if (HttpContext.Session.GetString("TempCart") != null)
                    {
                        var cartStr = HttpContext.Session.GetString("TempCart");
                        List <List <int> > cart1                 = JsonConvert.DeserializeObject <List <List <int> > >(cartStr);
                        string             OrderNumberTemp       = "0-" + rand1.ToString();
                        string             ProductBoughtListTemp = "";

                        List <OrderLineItem> lineItems = new List <OrderLineItem>();
                        foreach (var k in cart1)
                        {
                            string ProdName  = dbContext.Products.FirstOrDefault(p => p.ProductId == k[0]).ProductName;
                            Money  ItemPrice = new Money.Builder()
                                               .Amount(dbContext.Products.FirstOrDefault(p => p.ProductId == k[0]).ProductPrice * 100)
                                               .Currency("USD")
                                               .Build();

                            OrderLineItem LineItem = new OrderLineItem.Builder(k[1].ToString())
                                                     .Name(ProdName)
                                                     .BasePriceMoney(ItemPrice)
                                                     .Note("Order Number     " + OrderNumberTemp)
                                                     .Build();

                            lineItems.Add(LineItem);
                            ProductBoughtListTemp += ProdName + " x " + k[1].ToString() + ", ";
                        }
                        DropShipModels.User tempUser = dbContext.Users.FirstOrDefault(user => user.Password == "Temp");
                        ProductBoughtListTemp = ProductBoughtListTemp.Remove(ProductBoughtListTemp.Length - 1, 1);
                        ProductBoughtListTemp = ProductBoughtListTemp.Remove(ProductBoughtListTemp.Length - 1, 1);
                        DropShipModels.Order newOrder = new DropShipModels.Order();
                        newOrder.UserId            = tempUser.UserId;
                        newOrder.OrderNumber       = OrderNumberTemp.ToString();
                        newOrder.ProductBoughtList = ProductBoughtListTemp;
                        newOrder.Filled            = false;
                        newOrder.ShippingMethod    = "Standard";
                        dbContext.Orders.Add(newOrder);
                        dbContext.SaveChanges();
                        // create line items for the order
                        // This example assumes the order information is retrieved and hard coded
                        // You can find different ways to retrieve order information and fill in the following lineItems object.

                        // create Order object with line items
                        Order order = new Order.Builder(locationId)
                                      .LineItems(lineItems)
                                      .Build();

                        // create order request with order
                        CreateOrderRequest orderRequest = new CreateOrderRequest.Builder()
                                                          .Order(order)
                                                          .Build();
                        // create checkout request with the previously created order
                        // var tempPerson = new Person();
                        CreateCheckoutRequest createCheckoutRequest = new CreateCheckoutRequest.Builder(
                            Guid.NewGuid().ToString(),
                            orderRequest)
                                                                      .AskForShippingAddress(true)
                                                                      .MerchantSupportEmail("*****@*****.**")
                                                                      .Build();
                        // create checkout response, and redirect to checkout page if successful
                        CreateCheckoutResponse response = checkoutApi.CreateCheckout(locationId, createCheckoutRequest);
                        return(Redirect(response.Checkout.CheckoutPageUrl));
                    }
                    else
                    {
                        return(Redirect("/"));
                    }
                }
            }
            catch (ApiException e)
            {
                return(RedirectToPage("Error", new { error = e.Message }));
            }
        }