Square Up has updated their SDK for payment processing and made a change that will obsolete the method we were using to take customer payments. We've updated our payment processing code to make use of the CheckoutApi CreatePaymentLinkAsync method. The Square Up SDK documentation for this does not include the client local variable definition so to help those who may want to use the same payment processing method we've included a code snippet from our Buy controller.
We hope this helps with your development efforts. Thanks for reading our post!
if (tempProduct.SalePrice.HasValue) { var client = new Square.SquareClient.Builder() .Environment(Square.Environment.Production) .AccessToken(ConfigurationManager.AppSettings["squareUpAPIKey"]) .Build(); var priceMoney = new Square.Models.Money.Builder() .Amount((long?)(tempProduct.SalePrice * 100.0M)) .Currency("USD") .Build(); var quickPay = new QuickPay.Builder( name: tempProduct.FileName + " Activation Key", priceMoney: priceMoney, locationId: ConfigurationManager.AppSettings["HSS_squareUpLocationID"]) .Build(); var prePopulatedData = new PrePopulatedData.Builder() .BuyerEmail(currentEmail) .BuyerPhoneNumber("+1" + tblPRESSCustomer.PhoneNumber) .Build(); var checkoutOptions = new CheckoutOptions.Builder() .RedirectUrl(@"https://horvathsoftware.com/tblPRESSCustomerTransactionData/Success?activationKey=" + keyWeFound + @"&EmailAddress=" + currentEmail + @"&FileName=" + tempProduct.FileName + @"&customerID=" + customerID.ToString() + @"&transactionAmount=" + ((decimal)tempProduct.SalePrice).ToString()) .Build(); var body = new CreatePaymentLinkRequest.Builder() .IdempotencyKey(NewIdempotencyKey()) .QuickPay(quickPay) .PrePopulatedData(prePopulatedData) .CheckoutOptions(checkoutOptions) .Build(); try { var resultLink = await client.CheckoutApi.CreatePaymentLinkAsync(body: body); int waitTime=3000; HSS_DB_Settings.DBAppSettings.GetSettingInt32("waitToRedirectPayment", out waitTime); System.Threading.Thread.Sleep(waitTime); return Redirect(resultLink.PaymentLink.Url); } catch (ApiException e) { Console.WriteLine("Failed to make the request"); Console.WriteLine($"Response Code: {e.ResponseCode}"); Console.WriteLine($"Exception: {e.Message}"); goto returnView; } }