Quantcast
Channel: Square Developer Forums - Latest topics
Viewing all articles
Browse latest Browse all 1325

Help initializing the Square clint via C# to send and receive data about the sale

$
0
0

how do i create an instance of the square client to process this payment? using System;
using System.Threading.Tasks;
using Square;
using Square.Apis;
using Square.Exceptions;
using Square.Models;
using System.Windows.Forms;

namespace PracticeEnviornment
{
public static class Payment
{
private static SquareClient _client;

    public static async Task<bool> ConstructedClient()
    {
        return _client != null;
    }

    public static async Task CreateClient(string accesstoken)
    {
        _client = new SquareClient.Builder()
            .Environment(Square.Environment.Production).AccessToken(accesstoken)
            .Build();
    }

    private static async Task QuickPayment()
    {
        var priceMoney = new Money.Builder()

.Amount(12500L)
.Currency(“USD”)
.Build();

        var quickPay = new QuickPay.Builder(
            name: "Auto Detailing",
            priceMoney: priceMoney,
            locationId: "{LOCATION_ID}")
          .Build();

        var body = new CreatePaymentLinkRequest.Builder()
          .IdempotencyKey("{UNIQUE_KEY}")
          .QuickPay(quickPay)
          .Build();

        try
        {
            var result = await _client.CheckoutApi.CreatePaymentLinkAsync(body: body);
        }
        catch (ApiException e)
        {
            Console.WriteLine("Failed to make the request");
            Console.WriteLine($"Response Code: {e.ResponseCode}");
            Console.WriteLine($"Exception: {e.Message}");
        }
    }
}

}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1325

Trending Articles