async public Task <IActionResult> OnPost() { 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 = NewIdempotencyKey(); // Get the currency for the location RetrieveLocationResponse locationResponse = await client.LocationsApi.RetrieveLocationAsync(locationId : locationId); string currency = locationResponse.Location.Currency; // 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(currency) .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 Sample Csharp App") .Build(); try { CreatePaymentResponse response = PaymentsApi.CreatePayment(createPaymentRequest); ResultMessage = "Payment complete! " + response.Payment.Note; } catch (ApiException e) { ResultMessage = e.Message; } return(Page()); }
async public Task <IActionResult> OnPost() { ICheckoutApi checkoutApi = client.CheckoutApi; try { // Get the currency for the location RetrieveLocationResponse locationResponse = await client.LocationsApi.RetrieveLocationAsync(locationId : locationId); string currency = locationResponse.Location.Currency; // 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(currency) .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(currency) .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 })); } }