Verification of Payment Status for Payment Links

I’ve successfully created a payment link, and my next step is to verify whether the customer has made the payment or not. Here is the code snippet I used to create the payment link:

csharp

var priceMoney = new Money.Builder()
    .Amount(priceAmount)
    .Currency(currencyCode)
    .Build();

var quickPay = new QuickPay.Builder(
    name: quickPayName,
    priceMoney: priceMoney,
    locationId: locationID)
    .Build();

var acceptedPaymentMethods = new AcceptedPaymentMethods.Builder()
    .ApplePay(true)
    .GooglePay(true)
    .CashAppPay(true)
    .AfterpayClearpay(false)
    .Build();

var checkoutOptions = new CheckoutOptions.Builder()
    .AllowTipping(false)
    .MerchantSupportEmail(merchantSupportEmail)
    .AskForShippingAddress(false)
    .AcceptedPaymentMethods(acceptedPaymentMethods)
    .EnableCoupon(false)
    .EnableLoyalty(false)
    .Build();

var buyerAddress = new Address.Builder()
    .Country(buyerCountry)
    .FirstName(buyerFirstName)
    .LastName(buyerLastName)
    .Build();

var prePopulatedData = new PrePopulatedData.Builder()
    .BuyerEmail(buyerEmail)
    .BuyerAddress(buyerAddress)
    .Build();

var body = new CreatePaymentLinkRequest.Builder()
    .Description("Test payment link")
    .QuickPay(quickPay)
    .CheckoutOptions(checkoutOptions)
    .PrePopulatedData(prePopulatedData)
    .PaymentNote("Payment ...HHH")
    .Build();

try
{
    var result = await client.CheckoutApi.CreatePaymentLinkAsync(body: body);

    Console.WriteLine("Short Payment Link (URL): " + result.PaymentLink.Url);
    Console.WriteLine("Long Payment Link (longURL): " + result.PaymentLink.LongUrl);
    Console.WriteLine("PaymentLink.ID: " + result.PaymentLink.Id);

    // Return the PaymentLink ID for further processing
    return result.PaymentLink.Id;
}
catch (ApiException e)
{
    Console.WriteLine("Failed to create the payment link");
    Console.WriteLine($"Response Code: {e.ResponseCode}");
    Console.WriteLine($"Exception: {e.Message}");
}

Now, I want to create another method in C# that will verify based on result.PaymentLink.Id whether the customer has paid or not.
How can I verify in C# whether the customer has paid using this link or not?
If direct verification is not possible, what alternatives can I use to check the payment status?

when I open the URL to pay . i have this page


after the Checkout Completed , the order State still equale to OPEN . why ?
It should be equale to COMPLETED1.

:wave: 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:

Additional Documentation

Verify a Buyer
Verify the Payment
Checkout 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.

Are you listening to webhook events? If so you can look for a payment.created and payment.updated events that contain the order_id that was created when then link was created. :slightly_smiling_face:

Hello,

this is my methode that I use to see the state of the order:

csharp

Copier le code

static async Task CheckPaymentStatusAsync(string paymentLinkId)
{
    if (string.IsNullOrEmpty(paymentLinkId))
    {
        Console.WriteLine("Invalid payment link ID.");
        return;
    }

    try
    {
        var result = await client.CheckoutApi.RetrievePaymentLinkAsync(paymentLinkId);
        var paymentLink = result.PaymentLink;
        var orderResult = await client.OrdersApi.RetrieveOrderAsync(paymentLink.OrderId);
        var orderState = orderResult.Order.State;
        Console.WriteLine($"Order state for {paymentLink.OrderId}: {orderState}");
    }
    catch (ApiException e)
    {
        Console.WriteLine("Failed to make the request");
        Console.WriteLine($"Response Code: {e.ResponseCode}");
        Console.WriteLine($"Exception: {e.Message}");
    }
}

When I run this method every 10 seconds to check the order state, I notice that initially, it is set to DRAFT, and then it changes to OPEN when I open the link. After making the payment, the order state should change to COMPLETED, but that is not happening for me. Why?

With payment links it won’t automatically change the order to COMPLETED. The order will remain in an open state unless you call the Orders API to UpdateOrder to a COMPLETED state. :slightly_smiling_face: