How to make a payment gateway from square.com in my c# mvc project RRS feed

  • Question

  • User229488726 posted

    I want to add payment gateway from square.com in my c# mvc project. I already tried lots of things from google but unable to find proper solution.

    Here is my controller code I already tried

    public ActionResult Squre()
    _transactionApi = new TransactionApi();

    var client = new RestSharp.RestClient();
    var request = new RestSharp.RestRequest("https://connect.squareup.com/v1/me/payments", RestSharp.Method.GET);
    request.RequestFormat = RestSharp.DataFormat.Json;
    request.AddHeader("Authorization", "Bearer sq0atp-zHuWWPD4ds9J6YoVlEoYZg");
    var Response = client.Execute(request);

    HttpWebResponse response = null;
    string responseMessage = null;
    response = (HttpWebResponse)request.GetResponse();

    if (response.StatusCode == HttpStatusCode.OK)
    using (Stream stream = response.GetResponseStream())
    using (StreamReader reader = new StreamReader(stream))
    responseMessage = reader.ReadToEnd();

    return View();

    namespaces i have used mentioned below here

    using System.Runtime.Serialization.Json;
    using Square.Connect.Api;
    using Square.Connect.Model

    I want to make a payment gateway from square in my site. i need full tutorial for this can anyone help me please. What should i do??
    Which things i have to modified in my code. Can anyone modify my code please or please give me the proper code

    Saturday, October 22, 2016 2:07 PM

All replies

  • User229488726 posted

    thank you for your reply . but sorry i can't understood the solution from this links,can you describe me in details please.

    Saturday, October 22, 2016 2:30 PM
  • User409696431 posted

    The links provide the details, including the code sample.   If you are working in C#, follow the instructions on https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/csharp_payment and look at the downloaded files.  (You can find the download link on https://github.com/square/connect-api-examples, and you would only use the files in the folder corresponding to the example you are following, in csharp_payment)

    Saturday, October 22, 2016 10:09 PM
  • User-341979711 posted

    Hi Kathy

    I am trying to use the latest v2 and the sample code that references Money.ToCurrencyEnum doesn't seem to exist anymore. Do you know how to get around this?

    Money amount = NewMoney(100, "USD");

    public static Money NewMoney(int amount, string currency)
    return new Money(amount, Money.ToCurrencyEnum(currency));

    Sunday, April 30, 2017 2:22 PM
  • User-1392299251 posted

    the example lacks an important element. here is the comment as it exists in the example

    // Monetary amounts are specified in the smallest unit of the applicable currency.
    // This amount is in cents. It's also hard-coded for $1.00,
    // which isn't very useful.

    I have to agree it isn't very useful and it's Square's own example..???

    I have submitted 2 support request with them and have received no reply...

    the question, for me, is how do I replace the hardcoded 100 with the total charge value form the form? in MVC5 C#

    the code is in ProcessPament.cshtml.cs in the example.

    Money amount = new Money(100, Money.CurrencyEnum.USD);

    ANY help would be greatly appreciated TIA

    Yours in frustration


    Saturday, July 6, 2019 11:45 PM
  • User-474980206 posted

    did you even look at the source code?

    The the important data is collected in the sample javascript routine onGetCardNonce(). the nonce value is all that's passed to the mvc action, the square javascript calls square server and passes all the the information collected from your supplied onGetCardNonce(). presumably your UI would have a form field to identity the whats purchased, the unit count, the server should calc the amount, as if it was a post back value the user could hack it. if you must post back the amount, it should be encrypted.

    the security feature of square, is that the credit card info does not go to your site, only the nonce (transaction identifier is sent to your site). your site uses this and the amount to do a charge. 

    Monday, July 8, 2019 1:02 AM