You’re on the right track by looking at the Payments API. I think the part that you’re missing is that the source_id
is where you would insert a Card Nonce (this is the one-time use token to refer to a customer’s card details).
Using API Explorer, you could see that an example would look like this:
var amountMoney = new Money.Builder()
.Amount(100L)
.Currency("USD")
.Build();
var body = new CreatePaymentRequest.Builder(
sourceId: "cnon:card-nonce-ok",
idempotencyKey: "89831522-606e-49e1-aafb-17deaeb37795",
amountMoney: amountMoney)
.Build();
try
{
var result = await client.PaymentsApi.CreatePaymentAsync(body: body);
}
catch (ApiException e)
{
Console.WriteLine("Failed to make the request");
Console.WriteLine($"Response Code: {e.ResponseCode}");
Console.WriteLine($"Exception: {e.Message}");
}
The cnon:card-nonce-ok
is a test value to use in Sandbox, that is intended to stand in place of an actual nonce that you would normally get from your front-end.
You’ll want to work through the Payment Form guide to get your front-end setup to accept credit card payments (assuming you’re building a web app).
You can also find examples in the GitHub docs for the DotNet (C#) SDK to see how to build your requests.
At a very basic level, the flow should follow:
Front-end (either mobile or web) to securely capture card details => Post nonce/token to backend for process => Make call to Square APIs to process nonce/token
For the final step, you can see in our docs the various ways you can process a payment.