Square Card Payment c# example (sqRazorSample) CARD_DECLINED_VERIFICATION_REQUIRED

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

Name Value Type
[0] {Error : (this.Category = PAYMENT_METHOD_ERROR, this.Code = CARD_DECLINED_VERIFICATION_REQUIRED, this.Detail = Authorization error: ‘CARD_DECLINED_VERIFICATION_REQUIRED’, this.Field = null)} Square.Models.Error

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).

: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

Download, Configure, and Run the Client Sample
Card Payments
Strong Customer Authentication

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:

This guide provides step-by-step instructions on how to modify your payment flow to verify a buyer’s identity using additional secure authentication.

This answer was reviewed by @Bryan-Square.

thanks for your reply.

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,

Was the verification_token generated with the same location_id and the same application? Also was the API Explorer pointing to production or sandbox? :slightly_smiling_face:

Hi Bryan,

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’,
};

and the testing card details
4800 0000 0000 0004

token: cnon:CA4SEA1qZWrKoLg8ufJ9pZSpOIoYASgC
verificationToken: verf:CA4SECMqwjBBcVbRt6ELMfvokLkgACgB

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)”

found the following error details from the command window regarding the payment failure I came across

Do you have the src set to https://sandbox.web.squarecdn.com/v1/square.js? :slightly_smiling_face:

Yes. I do have

in the header of the testing example page “card-payment.html”.

I also changed currencyCode to “GBP” in “const verificationDetails”. I used a testing UK card “5248 4800 0021 0026”

I cannot find any error details in the Api log.

BTW, once I got the following Square 3d verification form, what kind of OTP code should I put in?

I changed the “currency” to “GBP” in the server.js file from “web_payment_QuickStart”; the “CurrencyCode” to “GBP” in card-payment.html ;

When I debugged in the web browser, the verification token was generated and passed to the fetch(“/payment”).

However, I got the following error from console window regarding CARD_DECLINED_VERIFICATION_REQUIRED

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.

Is there something else I missed?? many thanks,

When the model pops up are you using the test value 123456? :slightly_smiling_face:

Bingo :smiley: Yes. I did put some other random numbers.

BTW, another quick question,

regarding the cshar_payment example under “connect-examples\v2”
\SquarePaymentExamples\connect-examples\v2\csharp_payment

Whether c# Square package has the similar verifyBuyer()method under

SquareClient.client.PaymentApi?

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. :slightly_smiling_face: