Hi there, I am new to Square payment development. I am using “\SquarePaymentExamples\connect-examples\v2\csharp_payment” example to set up the initial testing program locally. I used my SandBox application ID, AccessToken, and also the test payment card
“Visa 4800 0000 0000 0004 111 No Challenge N/A” as shown in your website.
In “ProcessPayment.cshtml.cs”, if I didn’t hard-code " token = “cnon:card-nonce-ok”;, and used the Token generated based on that test card.
var request = JObject.Parse(await new StreamReader(Request.Body).ReadToEndAsync());
var token = (String)request[“token”];
I kept having the error “HTTP Response Not OK”
CARD_DECLINED_VERIFICATION_REQUIRED
In the other post, it mentioned about the “issuer requires additional verification through Strong Customer Authentication (SCA).”.
Is there any existing example of running SCA checking based on the testing card (listed on your website).
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:
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.
Yes, Square provides support for Strong Customer Authentication (SCA) through the use of 3D Secure (3DS). This is a standard protocol that can be used to satisfy the requirements of SCA.
In your case, you can use the verifyBuyer() function in the Web Payments SDK to start the 3DS flow. This function should be invoked only when the buyer is present and has initiated the transaction.
For more detailed information on how to implement SCA in your application, you can refer to the following guides:
I downloaded the “square_web_payment_quickstart” repository to my local. I found the “Card-payment.html” example under the “public/examples” folder.
The “Card-payment.html” contains the bit of codes calling the payments.verifyBuyer( ).
I copied the code and run in my local web application. by stepping into the code, I managed to get the copy of generated verification code “verf:CA4SEIXp9oAVN68N0CZdYMa-2q0gACgC”
When I put all those details AccessToken, LocationID, verification code into the API explorer for a quick test, the c# version code as the following
var tipMoney = new Money.Builder()
.Amount(100L)
.Currency(“GBP”)
.Build();
var body = new CreatePaymentRequest.Builder(sourceId: “cnon:CA4SELvbpDLqdGGYIA9SH48F1FAYASgC”, idempotencyKey: “dd92e167-588d-4f3f-9d99-1e00fc24c632”)
.TipMoney(tipMoney)
.LocationId(“LNDNRCGDR85T5”)
.VerificationToken(“verf:CA4SEIXp9oAVN68N0CZdYMa-2q0gACgC”)
.AcceptPartialAuthorization(false)
.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}”);
}
I got the error 401 with the message as the following.
{
"errors": [
{
"category": "AUTHENTICATION_ERROR",
"code": "UNAUTHORIZED",
"detail": "This request could not be authorized."
}
]
}
Do you know which part might have went wrong? many thanks,
followed the “ReadMe” doc from “Square_web_payment_quickStart”, I’ve installed node.js locally, and run the npm run dev to launch the local server on http://localhost:3000;
In the card-payment.html example, I replaced the application id and location id with my sandbox ones
const appId = ‘sandbox-sq0idb-vr69KK3nLdIrMdNrvJS3Ng’;
const locationId = ‘LNDNRCGDR85T5’;
I used the buyer details as listed in the example:-
const verificationDetails = {
amount: ‘1.00’,
billingContact: {
givenName: ‘John’,
familyName: ‘Doe’,
email: ‘[email protected]’,
phone: ‘3214563987’,
addressLines: [‘123 Main Street’, ‘Apartment 1’],
city: ‘London’,
state: ‘LND’,
countryCode: ‘GB’,
},
currencyCode: ‘GBP’,
intent: ‘CHARGE’,
};
When I stepped into the code, it seems the error was thrown at the line of
await fetch(‘/payment’, method: ‘post’, headers: { ‘content-type’: ‘application/json’, })
the details of error as the following:- Response error code: 401.
“Error: Response status code was not ok: 401.
at new ApiError (C:\Projects\Square_Web_Payment_QuickStart\node_modules\square\dist\cjs\errors\apiError.js:18:24)
at C:\Projects\Square_Web_Payment_QuickStart\node_modules@apimatic\core\lib\http\requestBuilder.js:352:23
at DefaultRequestBuilder. (C:\Projects\Square_Web_Payment_QuickStart\node_modules@apimatic\core\lib\http\requestBuilder.js:186:50)
at step (C:\Projects\Square_Web_Payment_QuickStart\node_modules\tslib\tslib.js:196:27)
at Object.next (C:\Projects\Square_Web_Payment_QuickStart\node_modules\tslib\tslib.js:177:57)
at fulfilled (C:\Projects\Square_Web_Payment_QuickStart\node_modules\tslib\tslib.js:167:62)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)”
I added the " console.log(payment.verificationToken);" in the server.js file after assigning the verificationToken to the payment request object.
// VerificationDetails is part of Secure Card Authentication.
// This part of the payload is highly recommended (and required for some countries)
// for 'unauthenticated' payment methods like Cards.
if (payload.verificationToken) {
payment.verificationToken = payload.verificationToken;
}
console.log(payment.verificationToken);
As shown from the following screen-shot, the verificationToken was generated and passed to square.js api, but it sill got the card_declined_verification_required.
With the Web Payments SDK verifyBuyer() is a JavaScript method only for the Web Payments SDK. It’s not included in the the .Net SDK.
Also you may want to instead consider using our charge and store a card on file with SCA. This will eliminate the verifyBuyer call. Also it’s the future of 3DS. We will be deprecating verifyBuyer once this goes to GA.