I am trying to see the payment form that a user would, but for some reason it’s as shown in the second image. However, I am able to submit payments and view payments in the dev sand box.
Source Code
[HttpPost]
public async Task<IActionResult> Checkout(CheckOutViewModel model)
{
string locationId = "LB1Y7J1A86DAQ";
RetrieveLocationResponse locationResponse = await
_squareClient.LocationsApi.RetrieveLocationAsync(locationId);
string currency = locationResponse.Location.Currency;
Money coffeeMugMoney = new Money.Builder()
.Amount(500L)
.Currency(currency)
.Build();
OrderLineItem lineItem = new OrderLineItem.Builder(model.CoffeeMug.ToString())
.Name("Coffee Mug")
.BasePriceMoney(coffeeMugMoney)
.Build();
List<OrderLineItem> lineItems = [lineItem];
Order order = new Order.Builder(locationId)
.LineItems(lineItems)
.Build();
CheckoutOptions options = new CheckoutOptions.Builder()
.AskForShippingAddress(false)
.AllowTipping(false)
.EnableCoupon(false)
.EnableLoyalty(false)
.RedirectUrl("https://localhost:44356/Home/Confirmation")
.Build();
CreatePaymentLinkRequest paymentLinkRequest = new CreatePaymentLinkRequest.Builder()
.Order(order)
.IdempotencyKey (Guid.NewGuid().ToString())
.CheckoutOptions(options)
.Build();
try
{
CreatePaymentLinkResponse response = await _squareClient.CheckoutApi.CreatePaymentLinkAsync(paymentLinkRequest);
string orderId = response.PaymentLink.OrderId;
CookieOptions cookieOptions = new();
cookieOptions.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Append(nameof(orderId), orderId, cookieOptions);
Thread.Sleep(100);
return Redirect(response.PaymentLink.Url);
}
catch (Exception)
{
return BadRequest(new { Status = "Bad" });
}
//return Ok(new { Status = "Diego was here", NumOfCoffeeMug = model.CoffeeMug });
}