Square CreatePaymentRequest.Builder not recognizing parameter

103 Views Asked by At

I'm trying to implement square payments, see here.

var client = new SquareClient.Builder()
            .Environment(Square.Environment.Sandbox) // or .Environment(Square.Environment.Production) for production
            .AccessToken(_accessToken)
            .Build();

        var paymentsApi = client.PaymentsApi;

        var money = new Money.Builder()
            .Amount((long)(amount * 100)) // Square API takes amount in cents
            .Currency("USD")
            .Build();

        var paymentRequest = new CreatePaymentRequest.Builder(
                sourceId: cardId,
                idempotencyKey: zero,
                amountMoney: money) //error occurs here. 
            .LocationId(locationId)
            .Build();

but I'm getting the following error:

Severity Code Description Project File Line Suppression State Error CS1739 The best overload for 'Builder' does not have a parameter named 'amountMoney' AURA C:\Users\NICHOLASFLEETWOOD\Documents\Code\DOWNLOADS\AURA-master\Factories\SquarePaymentFactory.cs 177 Active

The model for the CreatePaymentRequest.Builder is below, but the model is long so i didnt include it all.. The link for the docs is here:https://github.com/square/square-dotnet-sdk/blob/master/doc/models/create-payment-request.md

namespace Square.Models
{
public class CreatePaymentRequest
{
    public class Builder
    {
        private string sourceId;

        private string idempotencyKey;

        private Money amountMoney; //this is what im trying to access, i think

        private Money tipMoney;

        private Money appFeeMoney;

        private string delayDuration;

        private string delayAction;

        private bool? autocomplete;

        private string orderId;

        private string customerId;

        private string locationId;

Am I missing something? Im using .net sdk version 32.0.0

edit:

more of the model as i dig down...

public Builder AmountMoney(Money amountMoney)
        {
            this.amountMoney = amountMoney;
            return this;
        }
1

There are 1 best solutions below

0
On

Move your AmountMoney outside of the CreatePaymentRequest.Builder():

var money = new Money.Builder()
    .Amount((long)(amount * 100)) // Square API takes amount in cents
    .Currency("USD")
    .Build();

var paymentRequest = new CreatePaymentRequest.Builder(
    sourceId: cardId,
    idempotencyKey: zero)
        .AmountMoney(money)
        .LocationId(locationId)
        .Build();