Struggling to understand why VS2022 is showing an error “; expected” for my CatalogOjbect.Builder. (see image below)
Any help is appreciated.
Struggling to understand why VS2022 is showing an error “; expected” for my CatalogOjbect.Builder. (see image below)
Any help is appreciated.
I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:
Work with Images
Basics of Building Applications
Catalog API
If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.
The error message “; expected” usually indicates that the syntax of your code is incorrect. In your case, it seems like Visual Studio is expecting a semicolon at the end of a statement which is missing.
However, without seeing the actual code it’s hard to provide a specific solution. Please ensure that all your statements are properly terminated with a semicolon. If you’re still facing issues, please share the relevant code snippet for further assistance.
This answer was reviewed by @Bryan-Square.
Would you be able to put the raw text of the code here? It would make it easier to debug vs a screenshot.
@page “/Test”
Test Square
@using Square
@using Square.Apis
@using Square.Authentication
@using Square.Exceptions
@using Square.Models
@using System.Collections.Generic
@inject Microsoft.Extensions.Configuration.IConfiguration Configuration
@inject NavigationManager NavigationManager
@code {
private string? SubPlanId { get; set; } = “MPSSYT6OGBBO2QXTPFHDTTYC”;
private string? SandboxToken { get; set; }
private string? DevMsg { get; set; }
private string? LocationId { get; set; }
private string Uuid { get; set; } = string.Empty;
private SquareClient? client;
protected override async Task OnInitializedAsync()
{
var environment = Configuration["AppSettings:Environment"] == "sandbox" ?
Square.Environment.Sandbox : Square.Environment.Production;
LocationId = Configuration.GetSection("AppSettings:LocationId_SB").Value;
Uuid = NewIdempotencyKey();
SandboxToken = Configuration.GetSection("AppSettings:AccessToken_SB").Value;
var bearerAuthModel = new BearerAuthModel
.Builder(SandboxToken)
.Build();
client = new SquareClient.Builder()
.BearerAuthCredentials(bearerAuthModel)
.Environment(environment)
.Build();
try
{
var recurringPriceMoney = new Money.Builder()
.Amount(1995L)
.Currency("USD")
.Build();
var subscriptionPhase = new SubscriptionPhase.Builder(cadence: "MONTHLY")
.RecurringPriceMoney(recurringPriceMoney)
.Build();
var phases = new List<SubscriptionPhase>();
phases.Add(subscriptionPhase);
var subscriptionPlanData = new CatalogSubscriptionPlan.Builder(name: "One-phase subscription.")
.Phases(phases)
.Build();
var object = new CatalogObject.Builder(type: "SUBSCRIPTION_PLAN", id: "plan")
.SubscriptionPlanData(subscriptionPlanData)
.PresentAtAllLocations(true)
.Build();
var body = new UpsertCatalogObjectRequest.Builder(idempotencyKey: Uuid, object: object)
.Build();
if (client is not null)
{
var result = await client.CatalogApi.UpsertCatalogObjectAsync(body: body);
}
}
catch (ApiException e)
{
DevMsg = e.Message;
}
}
private static string NewIdempotencyKey()
{
return Guid.NewGuid().ToString();
}
}