Exemple #1
0
 public static CheckoutApi ConfiguredFromOptions(CheckoutApiOptions options)
 {
     return(CheckoutApi.Create(
                secretKey: options.SecretKey,
                publicKey: options.PublicKey,
                uri: options.GatewayUri
                ));
 }
Exemple #2
0
        public SquareService(ICheckoutService checkoutService, IOptions <SquareSecretKey> squareSecretKey, IHostingEnvironment env)
        {
            _checkoutService = checkoutService;
            _env             = env;
            _checkout        = new CheckoutApi();

            Configuration.Default.AccessToken = env.IsProduction() ? squareSecretKey?.Value?.Secret : "sandbox-sq0atb-CiMknPZajSaOmSBVRx6ifQ";
        }
Exemple #3
0
        public void Init()
        {
            instance     = new CheckoutApi();
            testAccounts = new TestAccounts();
            var testAccount = testAccounts["US-Prod-Sandbox"];

            locationId = testAccount.LocationId;
            Configuration.Default.AccessToken = testAccount.AccessToken;
        }
Exemple #4
0
        public static CheckoutApi ConfiguredFromEnvironment()
        {
            var liveMode = false;

            bool.TryParse(Environment.GetEnvironmentVariable("CKO_LIVE_MODE"), out liveMode);
            return(CheckoutApi.Create(
                       secretKey: Environment.GetEnvironmentVariable("CKO_SECRET_KEY"),
                       publicKey: Environment.GetEnvironmentVariable("CKO_PUBLIC_KEY"),
                       useSandbox: !liveMode
                       ));
        }
Exemple #5
0
        public IActionResult OnPost()
        {
            CheckoutApi checkoutApi = new CheckoutApi(configuration: this.configuration);

            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 <CreateOrderRequestLineItem> lineItems = new List <CreateOrderRequestLineItem>()
                {
                    new CreateOrderRequestLineItem(
                        Name: "Test Item A",
                        Quantity: "1",
                        BasePriceMoney: new Money(Amount: 500,
                                                  Currency: Money.CurrencyEnum.USD)
                        ),
                    new CreateOrderRequestLineItem(
                        Name: "Test Item B",
                        Quantity: "3",
                        BasePriceMoney: new Money(Amount: 1000,
                                                  Currency: Money.CurrencyEnum.USD)
                        )
                };

                // create order with the line items
                CreateOrderRequest order = new CreateOrderRequest(
                    LineItems: lineItems
                    );

                // create checkout request with the previously created order
                CreateCheckoutRequest createCheckoutRequest = new CreateCheckoutRequest(
                    IdempotencyKey: Guid.NewGuid().ToString(),
                    Order: order
                    );

                // create checkout response, and redirect to checkout page if successful
                CreateCheckoutResponse response = checkoutApi.CreateCheckout(locationId, createCheckoutRequest);
                return(Redirect(response.Checkout.CheckoutPageUrl));
            }
            catch (Square.Connect.Client.ApiException e)
            {
                return(RedirectToPage("Error", new { error = e.Message }));
            }
        }
Exemple #6
0
        public IActionResult OnPost()
        {
            CheckoutApi checkoutApi = new CheckoutApi();
            int         amount      = (int)float.Parse(Request.Form["amount"]) * 100;

            try
            {
                // create line items for the order
                List <CreateOrderRequestLineItem> lineItems = new List <CreateOrderRequestLineItem>()
                {
                    new CreateOrderRequestLineItem(
                        Name: "Test Payment",
                        Quantity: "1",
                        BasePriceMoney: new Money(Amount: 500,
                                                  Currency: Money.CurrencyEnum.USD)
                        )
                };

                // create order with the line items
                CreateOrderRequest order = new CreateOrderRequest(
                    LineItems: lineItems
                    );

                // create checkout request with the previously created order
                CreateCheckoutRequest body = new CreateCheckoutRequest(
                    IdempotencyKey: Guid.NewGuid().ToString(),
                    Order: order
                    );

                // create checkout response, and redirect to checkout page if successful
                CreateCheckoutResponse response = checkoutApi.CreateCheckout(locationId, body);
                return(Redirect(response.Checkout.CheckoutPageUrl));
            }
            catch (Square.Connect.Client.ApiException e)
            {
                return(RedirectToPage("Error", new { error = e.Message }));
            }
        }
 public static void IntroductionCall()
 {
     const string simpleKey = "109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00";
     var          api       = new CheckoutApi(simpleKey);
 }
Exemple #8
0
 public static void GetCartByReturnTokenCall()
 {
     const string simpleKey = "109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00";
     var          api       = new CheckoutApi(simpleKey);
 }
 public static void GetStateProvincesForCountryCall()
 {
     const string simpleKey = "109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00";
     var          api       = new CheckoutApi(simpleKey);
 }
        public ActionResult ChargeNonce()
        {
            string accessToken = "sandbox-sq0atb-D4TFGj4GmAew2U1yDuxe3Q";

            // Set the location ID
            string locId = "CBASECShk_d_mWkyYVT6bgiV52AgAQ";


            //Create configuration object for apiClient
            Square.Connect.Client.Configuration apiConfiguration = new Square.Connect.Client.Configuration();
            apiConfiguration.AccessToken = accessToken;

            //Create instance of api client
            Square.Connect.Client.ApiClient apiClient = new Square.Connect.Client.ApiClient(apiConfiguration);


            //Create instance of Orders api
            OrdersApi orderApi = new OrdersApi(apiConfiguration);

            //Create instance of Orders api
            CheckoutApi checkoutApi = new CheckoutApi(apiConfiguration);


            //Grab items from session and put them in a list
            List <Item> cartSession = (List <Item>)Session["cart"] != null ? (List <Item>)Session["cart"] : new List <Item>();


            //Create Line Item Request instance
            List <CreateOrderRequestLineItem> lineItems = new List <CreateOrderRequestLineItem>();

            //Create line item for each item stored in the cart session
            foreach (var item in cartSession)
            {
                int lineItemPrice = (int)(item.Product.ProductPrice * 100);

                Money price = new Money(lineItemPrice, Money.CurrencyEnum.USD);
                CreateOrderRequestLineItem lineItem = new CreateOrderRequestLineItem(item.Product.ProductTitle, item.Quantity.ToString(), price);

                lineItems.Add(lineItem);
            }

            string idempotencyKey = Guid.NewGuid().ToString();

            //Create new order request instance with cart items
            CreateOrderRequest orderRequest = new CreateOrderRequest(idempotencyKey, null, lineItems);

            //Get return URL
            //var urlBuilder =
            //new System.UriBuilder(Request.Url.AbsoluteUri)
            //{
            //    Path = Url.Action("PaymentConfirmation", "Products"),
            //    Query = null,
            //};

            //Uri uri = urlBuilder.Uri;
            //string url = urlBuilder.ToString();
            //UNCOMMENT AND CHANGE LAST NULL PARAMETER TO url


            CreateCheckoutRequest checkoutRequest = new CreateCheckoutRequest(idempotencyKey, orderRequest, true, null, null, null);

            try
            {
                var checkoutResponse = checkoutApi.CreateCheckout(locId, checkoutRequest);

                return(Redirect(checkoutResponse.Checkout.CheckoutPageUrl));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #11
0
 public ApiTestFixture()
 {
     Api = new CheckoutApi(new ApiClient(Configuration), Configuration);
 }
Exemple #12
0
 public CheckoutController(IOptions <CheckoutApiOptions> apiOptions, CheckoutApi api, HttpClient client)
 {
     this.apiOptions = apiOptions.Value ?? throw new ArgumentNullException(nameof(apiOptions));
     this.api        = api ?? throw new ArgumentNullException(nameof(api));
     this.client     = client ?? throw new ArgumentNullException(nameof(client));
 }
        private dynamic ExpressCallback(dynamic parameters)
        {
            var mpstatus = this.Request.Query["mpstatus"];
            var checkout_resource_url = this.Request.Query["checkout_resource_url"];
            var oauth_verifier        = this.Request.Query["oauth_verifier"];
            var oauth_token           = this.Request.Query["oauth_token"];
            var pairing_verifier      = this.Request.Query["pairing_verifier"];
            var pairing_token         = this.Request.Query["pairing_token"];

            _setConfigurations();

            AccessTokenResponse accessTokenResponse1 = AccessTokenApi.Create(oauth_token, oauth_verifier);
            string accessToken = accessTokenResponse1.OauthToken;

            AccessTokenResponse accessTokenResponse2 = AccessTokenApi.Create(pairing_token, pairing_verifier);
            string longAccessToken = accessTokenResponse2.OauthToken; // store for future requests


            String checkoutResourceUrl = checkout_resource_url.ToString();
            String checkoutId          = checkoutResourceUrl.IndexOf('?') != -1 ? checkoutResourceUrl.Substring(checkoutResourceUrl.LastIndexOf('/') + 1).Split('?')[0] : checkoutResourceUrl.Substring(checkoutResourceUrl.LastIndexOf('/') + 1);

            Checkout checkout = CheckoutApi.Show(checkoutId, accessToken);

            Card    card                             = checkout.Card;
            Address billingAddress                   = card.BillingAddress;
            Contact contact                          = checkout.Contact;
            AuthenticationOptions authOptions        = checkout.AuthenticationOptions;
            string          preCheckoutTransactionId = checkout.PreCheckoutTransactionId;
            ShippingAddress shippingAddress          = checkout.ShippingAddress;
            string          transactionId            = checkout.TransactionId;
            string          walletId                 = checkout.WalletID;

            /// AQUI DEVE SER CHAMADO O GATEWAY DE PAGAMENTO PARA EXECUTAR O
            /// PAGAMENTO COM OS DADOS RECUPERADOS ACIMA...

            /// UMA VEZ QUE O PAGAMENTO FOI EXECUTADO, CONTINUAR COM O PASSO ABAIXO

            //Create an instance of MerchantTransactions
            MerchantTransactions merchantTransactions = new MerchantTransactions()
                                                        .With_MerchantTransactions(new MerchantTransaction()
                                                                                   .WithTransactionId(transactionId)
                                                                                   .WithPurchaseDate("2017-05-27T12:38:40.479+05:30")
                                                                                   .WithExpressCheckoutIndicator(false)
                                                                                   .WithApprovalCode("sample")
                                                                                   .WithTransactionStatus("Success")
                                                                                   .WithOrderAmount((long)76239)
                                                                                   .WithCurrency("USD")
                                                                                   .WithConsumerKey(Contants.consumerKey));

            //Call the PostbackService with required params
            MerchantTransactions merchantTransactionsResponse = PostbackApi.Create(merchantTransactions);


            /// FIM DO CHECKOUT WITH PAIRING
            ///
            /// INICIO DE UM EXPRESS CHECKOUT

            var model = new
            {
                transactionId   = transactionId,
                longAccessToken = longAccessToken
            };

            return(View["express_execute.htm", model]);

            //return request_token;
        }
Exemple #14
0
 public static void SetupBrowserKeyCall()
 {
     const string simpleKey = "109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00";
     var          api       = new CheckoutApi(simpleKey);
 }
 public static void GetAllowedCountriesCall()
 {
     const string simpleKey = "109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00";
     var          api       = new CheckoutApi(simpleKey);
 }
 public static void RelatedItemsForCartCall()
 {
     const string simpleKey = "109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00";
     var          api       = new CheckoutApi(simpleKey);
 }
 public void Init()
 {
     instance = new CheckoutApi();
 }
 public CheckoutController(CheckoutApi checkoutApi)
 {
     this.checkoutApi = checkoutApi;
 }
Exemple #19
0
 public static void RegisterAffiliateClickCall()
 {
     const string simpleKey = "109ee846ee69f50177018ab12f008a00748a25aa28dbdc0177018ab12f008a00";
     var          api       = new CheckoutApi(simpleKey);
 }