Discussions

Ask a Question
Back to all

Paying open invoices with check.

Hello,

I am in the process of writing an application that finds open invoices and pays them with a check. I am not sure what the direct way to do this would be, but I did find the endpoint called "InvoicePayment" which I thought would be appropriate.

Currently, I have filled out the empty json object to the best of my ability and this is what I currently have:

const config = {
    baseUrl: `${window.location.protocol}//${window.location.host}`,
    partyId: JSON.parse(document.getElementById("__ClientContext").value).selectedPartyId,
    requestVerificationToken: document.getElementById("__RequestVerificationToken").value,
};

const options = {
  method: 'POST',
  headers: {
    accept: 'application/json', 
    'content-type': 'application/json',
    'RequestVerificationToken': config.requestVerificationToken
  },
  body: JSON.stringify({
    $type: 'Asi.Soa.Commerce.DataContracts.InvoicePaymentData, Asi.Contracts',
    InvoiceId: '234363',
    InvoiceKey: 'ba3cdd4a-961f-47c7-b867-1ed103436109',
    InvoiceNumber: '221464',
    Payment: {
      $type: 'Asi.Soa.Commerce.DataContracts.RemittanceData, Asi.Contracts',
      Amount: {
        $type: 'Asi.Soa.Core.DataContracts.MonetaryAmountData, Asi.Contracts',
        Amount: 45.51,
        Currency: {
          $type: 'Asi.Soa.Core.DataContracts.CurrencyData, Asi.Contracts',
          CurrencyCode: 'USD',
          DecimalPositions: 2
        },
        IsAmountDefined: false
      },
      ContactId: '33691',
      GatewayAccountKey: null,
      Id: '8137',
      Intent: null,
      InternalRecurringInstructionId: null,
      InvoiceNumber: 221464,
      IsMoto: false,
      Nickname: null,
      PaymentMethod: {
        $type: 'Asi.Soa.Commerce.DataContracts.PaymentMethodData, Asi.Contracts',
        CustomerId: null,
        Description: null,
        IsReadOnly: false,
        Metadata: null,
        OriginalPaymentToken: null,
        PaymentTokenExpirationDate: null
      },
      ProcessOn: null,
      Status: {
        $type: 'Asi.Soa.Commerce.DataContracts.RemittanceStatusData, Asi.Contracts',
        AuthorizationCode: null,
        GatewayTransactionIdentifier: null,
        Msg: null,
        StatusCode: 'AwaitingProcessing'
      },
      StatusUpdatedOn: null,
      ThreeDS: {
        $type: 'DataVault.Contracts.ThreeDSPayloadData, Asi.Contracts',
        CAVV: null,
        DSTransactionId: null,
        ECIFlag: null,
        Enrolled: null,
        IsMerchantInitiated: false,
        IsRecurring: false,
        PAResStatus: null,
        SignatureVerification: null,
        ThreeDSVersion: null,
        XID: null
      },
      TransactionDate: null
    }
  })
};

fetch(`${config.baseUrl}/api/InvoicePayment`, options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));

This however is returning this error:

{
    "$type": "Asi.Soa.Core.DataContracts.ValidationResultsData, Asi.Contracts",
    "Errors": {
        "$type": "Asi.Soa.Core.DataContracts.ValidationResultDataCollection, Asi.Contracts",
        "$values": [
            {
                "$type": "Asi.Soa.Core.DataContracts.ValidationResultData, Asi.Contracts",
                "Message": "Payment method must be CreditCard, DirectDebit or Service."
            }
        ]
    },
    "Warnings": {
        "$type": "Asi.Soa.Core.DataContracts.ValidationResultDataCollection, Asi.Contracts",
        "$values": []
    }
}

I am trying to have this paid by check so I am not sure how I would go about this; I also do not know where you would put the payment object in the JSON.

Best,

Andrew Tang

Contact us
Copyright © Advanced Solutions International, All rights reserved.