public async Task <IActionResult> ProcessPaymentAsync(string nonce) { try { Square.Environment environment = appSettings.Environment == "sandbox" ? Square.Environment.Sandbox : Square.Environment.Production; // Build base client SquareClient client = new SquareClient.Builder() .Environment(environment) .AccessToken(this.appSettings.AccessToken) .Build(); IPaymentsApi PaymentsApi = client.PaymentsApi; CreatePaymentRequest request_body = new CreatePaymentRequest(nonce, this.NewIdempotencyKey(), new Money(100, "USD")); CreatePaymentResponse responce = await PaymentsApi.CreatePaymentAsync(request_body); if (responce?.Payment?.Status == "COMPLETED") { //this.UpdateCart(new CartModel()); return(this.Ok()); } else { return(this.BadRequest($"STATUS: {responce?.Payment?.Status}")); } } catch (Exception ex) { return(this.BadRequest($"PaymentError: { ex.Message }")); } }
public SquareHelper(SquareLocationModel location) { _env = location.ApplicationId.StartsWith("sandbox") ? Square.Environment.Sandbox : Square.Environment.Production; _accessToken = location.AccessToken; LocationId = location.LocationId; Client = new SquareClient.Builder() .Environment(_env) .AccessToken(_accessToken) .Build(); }
public ProcessPaymentModel(Microsoft.Extensions.Configuration.IConfiguration configuration) { // Get environment Square.Environment environment = configuration["AppSettings:Environment"] == "sandbox" ? Square.Environment.Sandbox : Square.Environment.Production; // Build base client client = new SquareClient.Builder() .Environment(environment) .AccessToken(configuration["AppSettings:AccessToken"]) .Build(); }
public _Default() { // Get environment Square.Environment environment = ConfigurationManager.AppSettings["Environment"] == "sandbox" ? Square.Environment.Sandbox : Square.Environment.Production; // Build base client client = new SquareClient.Builder() .Environment(environment) .AccessToken(ConfigurationManager.AppSettings["AccessToken"]) .Build(); }
public IActionResult Paid() { Square.Environment environment = this.appSettings.Environment == "sandbox" ? Square.Environment.Sandbox : Square.Environment.Production; // Build base client SquareClient client = new SquareClient.Builder() .Environment(environment) .AccessToken(this.appSettings.AccessToken) .Build(); string nonce = Request.Form["nonce"]; IPaymentsApi PaymentsApi = client.PaymentsApi; // Every payment you process with the SDK must have a unique idempotency key. // If you're unsure whether a particular payment succeeded, you can reattempt // it with the same idempotency key without worrying about double charging // the buyer. string uuid = this.NewIdempotencyKey(); // Monetary amounts are specified in the smallest unit of the applicable currency. // This amount is in cents. It's also hard-coded for $1.00, // which isn't very useful. Money amount = new Money.Builder() .Amount(500L) .Currency("USD") .Build(); // To learn more about splitting payments with additional recipients, // see the Payments API documentation on our [developer site] // (https://developer.squareup.com/docs/payments-api/overview). CreatePaymentRequest createPaymentRequest = new CreatePaymentRequest.Builder(nonce, uuid, amount) .Note("From Square Visit Cart App") .Build(); try { CreatePaymentResponse response = PaymentsApi.CreatePayment(createPaymentRequest); PaymentResultModel model = new PaymentResultModel { ResultMessage = "Payment complete! " + response.Payment.Note }; return(View(model)); } catch (ApiException ex) { return(View("PaymentError", new ErrorViewModel { Message = ex.Message })); } }
public CheckoutSquare() { // Get environment Square.Environment environment = WebConfigurationManager.AppSettings["SQUARE_Environment"] == "sandbox" ? Square.Environment.Sandbox : Square.Environment.Production; // Build base client client = new SquareClient.Builder() .Environment(environment) .AccessToken(WebConfigurationManager.AppSettings["SQUARE_AccessToken"]) .Build(); locationId = WebConfigurationManager.AppSettings["SQUARE_LocationId"]; }
public PaymentController(Microsoft.Extensions.Configuration.IConfiguration configuration) { iConfig = configuration; // Get environment Square.Environment environment = configuration["AppSettings:Environment"] == "sandbox" ? Square.Environment.Sandbox : Square.Environment.Production; // Build base client client = new SquareClient.Builder() .Environment(environment) .AccessToken(configuration["AppSettings:AccessToken"]) .Build(); //locationId = configuration["AppSettings:LocationId"]; }
public CheckoutModel(Microsoft.Extensions.Configuration.IConfiguration configuration, DropShipModels.MyContext context) { dbContext = context; // Get environment Square.Environment environment = configuration["AppSettings:Environment"] == "sandbox" ? Square.Environment.Sandbox : Square.Environment.Production; // Build base client client = new SquareClient.Builder() .Environment(environment) .AccessToken(configuration["AppSettings:AccessToken"]) .Build(); locationId = configuration["AppSettings:LocationId"]; }