4

I am working on Square Payment gateway integration in ASp.Net. I want to request card_nonce using information stored in database. Can I directly request for card_nonce without using SqPaymentForm?

I tried to send request using Restsharp request but getting error in response. Below is my code and response from Square Up.

RequestCode:

RestSharp.RestClient ClientNonce = new RestSharp.RestClient("https://connect.squareup.com");
RestSharp.RestRequest RequestNonce = new RestSharp.RestRequest("v2/card_nonce", RestSharp.Method.POST);
RequestNonce.RequestFormat = RestSharp.DataFormat.Json;
RequestNonce.AddHeader("Accept", "application/json");

string jsonBodyNone = "{\"client_id\":\""+sandboxId+"\",\"card_data\":{\"billing_postal_code\":\"73001\",\"cvv\":\"564\",\"exp_month\":\"1\",\"exp_year\":\"2021\",\"number\":\"4532759734545858\"},\"website_url\":\"http://localhost:24584/\"}";

RequestNonce.AddParameter("application/json", jsonBodyNone, RestSharp.ParameterType.RequestBody);

RestSharp.IRestResponse responseNonce = ClientNonce.Execute(RequestNonce);
System.Net.HttpStatusCode getresponseNonce = responseNonce.StatusCode;

ResponseFromSquare: {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"BAD_REQUEST","detail":"Your request could not be processed"}]}

Bhavini
  • 43
  • 3

1 Answers1

3

Square has designed the API such that merchant sites do not store, process or transmit cardholder data. As a result,it is not possible to generate a card nonce without using SqPaymentForm.

Ben Hartard
  • 114
  • 2
  • https://devhub.io/repos/square-connect-csharp-sdk ;; there seems to be something about a token built through their customerAPI that would allow you to process without a nonce (or by giving you a nonce through that api instead of through the JS&Form. Might be what OP was hoping for. If I get anywhere with it I'll post it as an answer. – Spacemonkey Apr 11 '19 at 17:09