x

Struggling to integrate my ASP.Net ecommere with API

I'm just not getting the Square Connect process apparently, and I'm struggling to find any relevant resources despite days of trying to solve this.

 

I'm using ASP.net (VB.net specifically, though C# examples are fine too) I've gotten the HTML form to pass the credit card info, retrieve the card nonce, send it to the Charge function, and receive a response. It appears to be valid JSON.

 

My first seemingly stupid question is...how do I know if the credit card was approved? It doesn't throw an error, but only says "Status: Captured" and things like that. What is the variable I should care about when determining if this transaction was a success? Maybe I'm thinking too "Old School" here, but I assumed I would receive a variable that says "Success" or something, and I would go on about my completion of the order, or be able to easily display an error as to why it wasn't a success.

 

Also, I have found parsing the JSON in VB.net or Javascript to be a difficult task. How would I grab a single variable from the JSON and display its value? Sorry to ask such a broad question, but I have tried and tried without success. I've tried the NewtonSoft .net plugin, and tried using JQuery json deserializer (which isn't ideal for me).

 

*****Update**************

I basically cheated my way through it, and just performed some SQL DB updates if the transaction came back as a success (If response.Errors Is Nothing Then), and I didn't do the DB updates if it had an error..  I'm still dealing with the error handling and displaying the status to the customer etc, again, I may be old school in my approaches, but I would have expected this all to be much more intuitive.  Not to mention having some working examples and demos that are provided by Square, not just the community.  I'm not going to spend 50 hours becoming an expert in this API just to do some simple tasks with it.  I've spent 10 hours on it already.

 

I'm not happy with the way this API works, but then I'm not happy with the way any other Payment Processor API works either, and I've been programming them for 15 years.  I had hoped Square was going to have a solution that is easier to work with, but alas unless I'm going to drop big hours on something so simple, I'm just going to move on and use my hacked code. 

Tags (1)
3,827 Views
Message 1 of 3
Report
2 REPLIES 2
Alumni

Hello! 

 

I'm sorry you are having a hard time, we do spend quite a bit of time trying to design and impelement our API in ways that make it easy for everyone to use. I don't personally work in ASP.net, but I'll try to answer as best  as I can. 

 

If your request resulted in any errors, you'll get a body of your response JSON labeled "errors". For example, if you were using an improper access token to make a charge request, you might get a response like 

 

{
  "errors": [
    {
      "category": "AUTHENTICATION_ERROR",
      "code": "UNAUTHORIZED",
      "detail": "This request could not be authorized."
    }
  ]
}

 

 

 

If your response does not include an error field, your request went through correctly, I'm sorry that we don't explicitly state that in a dedicated field. See this page for more info: https://docs.connect.squareup.com/api/connect/v2/#handlingerrors

 

It is actually very easy to parse JSON with javascript, (once you know the right functions!). For example, if I wanted to pull out the details of the above error message, my javascript code might look like this:

 

 

var rawError = {
  "errors": [
    {
      "category": "AUTHENTICATION_ERROR",
      "code": "UNAUTHORIZED",
      "detail": "This request could not be authorized."
    }
  ]
}

var parsedDetail = rawError.errors[0].detail;

If for some reason you have converted your error to a string (frequently the problem when you move from front end to back end systems), you can juse the JSON.parse() to convert it back to native JSON. 

 

We have a complete (but basic) example of the payment form and making the charger here: https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/csharp_payment, have you taken a look at it? 

 

 

3,788 Views
Message 2 of 3
Report

Thanks for the reply. I'm not trying to be hard on Square here, but I just feel like there is an information gap. I have looked around and not seen much about parsing the JSON, and since it is structured with different levels I found it tougher to traverse. It wasn't a section in the API documentation I read I don't think.

 

I also never saw anything saying that if no error is returned then it is successful. I'm not saying it isn't there, but that seems pretty important. I feel like this API could be so much simpler, or at least have better demos and code examples. I only state these couple of things as a heads up in the hopes that it will lead to more documentation..

 

There is no reason this couldn't be turned into something that only takes a few hours to implement in a custom site...I'm sure that to you guys working there it is easy and clear, but to me I found the documentation to be lacking in a few ways. (Sorry I'm jaded after years and years of dealing with your competitors products and finding similar issues.)

 

However, overall I'm liking it and looking forward to using your service. It looks great on my website and is simple to use now that it is mostly implemented. Thanks again.

3,781 Views
Message 3 of 3
Report