In Person Payments - JavaScript SDK

Modified on Wed, 12 Apr 2023 at 08:23 PM

ACME Payments JavaScript SDK

The ACME Payments Card Present JavaScript SDK easily enables secure, PCI Compliant transactions into your checkout flows. Enable online, in-store, and omnichannel transactions in any customer present context in a few lines of code within your Webapp or POS today.

ACME Seller account required for API key access — get started today at sales@acmepayments.com.

Installation

NOTE: If you're migrating some of your merchants over from our previous library @acmeticketing/payment-sdk you should review our migration steps.

ES Module

  • Intended for use with modern bundlers like webpack.
  • This is the recommended approach and will provide the best developer experience.
npm install @acmeticketing/payments

UMD

UMD builds can be used directly in the browser via a <script> tag. Manually add the index.umd.js script tag to the <head> of your site.

<!-- Somewhere in your site's <head> -->
<script src="https://unpkg.com/@acmeticketing/payments@1.0.0/index.umd.js" async></script>

Usage (ES Module)

All of the examples also apply to the UMD version but instead of importing our library as an ES Module it will be available under the global ACME object.

const acmePayments = window.ACME.ACMEPayments.create({
  mid: 'your_mid', // Use your provided merchant identification number (MID)
  publishableKey: 'your_publishable_key', // Use your provided publishable
});

Activate a terminal

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

try {
  const response = await acmePayments.activateTerminal({
    activationCode: 'activation_code_from_terminal',
    description: 'description_of_the_terminal',
    terminalId: 'unique_id_for_this_terminal',
  });
} catch (error) {
  // handle error
}

Make a sale

This example assumes you have already gone through the terminal activation process.

The process goes like this:

  1. Choose one of your terminal IDs

    You can look for it by retrieving a list of your terminals if you don't know the exact terminal ID.

  2. Authorize the payment amount with the terminal you picked

  3. Use the generated transactionId to capture the payment

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

async function capturePayment(terminalId: string, amount: string, externalId?: string) {
  try {
    const paymentAuthorizationResponse = await acmePayments.authorizePayment({
      terminalId,
      amount,
    });

    return acmePayments.capturePayment({
      transactionId: paymentAuthorizationResponse.transactionId,
      externalId,
    });
  } catch (error) {
    // handle error
  }
}

Find a terminal by serial number

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

async function findTerminalBySerialNumber(serialNumber: string) {
  const response = await acmePayments.fetchTerminals();
  const terminal = response.list.find((terminal) => terminal.serialNumber === serialNumber);

  if (terminal == null) {
    throw new Error(`Could not find terminal with serial number: ${serialNumber}`);
  }

  return terminal;
}

Delete a terminal

This example assumes you have already gone through the terminal activation process.

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

try {
  await acmePayments.deleteTerminal({
    terminalId: 'unique_id_for_this_terminal',
  });
} catch (error) {
  // handle error
}

Migrating from previous versions

We’ve migrated our terminals infrastructure. New terminal lifecycle calls are documented here: https://developers.acmepayments.com/support/solutions/articles/33000279925-payments-terminals

You will find some methods have changed if you were previously using our previous @acmeticketing/payment-sdk package:

From @acmeticketing/payment-sdkTo @acmeticketing/payments
async ACMEPayments.init()ACMEPayments.create()
async ACMEPayments.activateTerminal(props) The pairing process only has to be done once.
async ACMEPayments.deleteTerminal(props)
ACMEPayments.createTerminal(props)Not available by this SDK version. Instead, you may pass a terminalId in most methods.
ACMETerminal.getConnectionStatus()Not available in this SDK version.
ACMETerminal.getConnectedReader()Not available in this SDK version.
ACMETerminal.getPaymentStatus()Not available in this SDK version.
async ACMETerminal.discoverReaders()async ACMEPayments.fetchTerminals(props?)
async ACMETerminal.connectReader(readerOrId)Not available this SDK version. You pass a terminalId in most methods instead.
async ACMETerminal.disconnectReader()You may delete a terminal but you're not required to disconnect from it.
async ACMETerminal.sale(params)You need to call async ACMEPayments.authorizePayment(props) followed by async ACMEPayments.capturePayment(props)
async ACMETerminal.cancelSale()Not available in this SDK version.
async ACMETerminal.refund(params)At present, this SDK version does not support refunds, please use our PCI compliant tokenized method. Referenced here: https://developers.acmepayments.com/support/solutions/articles/33000262275-payments-refund
async ACMETerminal.getTransactionById(transactionId)At present, this SDK version does not support transactions. Please use our Transactions API referenced here: https://developers.acmepayments.com/support/solutions/articles/33000268600-payments-transactions
async ACMETerminal.getTransactionsByExternalId(externalId)At present, this SDK version does not support transactions. Please use our Transactions API referenced here: https://developers.acmepayments.com/support/solutions/articles/33000268600-payments-transactions

Classes

/ ACMEPayments

Class: ACMEPayments

Table of contents

Methods

  • create
  • activateTerminal
  • fetchTerminals
  • deleteTerminal
  • authorizePayment
  • capturePayment

Methods

create

Static create(props): ACMEPayments

Example

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});
Parameters
NameType
propsOmit<PaymentsProps, "baseUrl">
Returns

ACMEPayments


activateTerminal

activateTerminal(«destructured»): Promise<ActivateTerminalResponse>

Example

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

try {
  const response = await acmePayments.activateTerminal({
    activationCode: 'activation_code_from_terminal',
    description: 'description_of_the_terminal',
    terminalId: 'unique_id_for_this_terminal',
  });
} catch (error) {
  // handle error
}
Parameters
NameType
«destructured»ActivateTerminalDto
Returns

Promise<ActivateTerminalResponse>


fetchTerminals

fetchTerminals(«destructured»?): Promise<FetchTerminalsResponse>

Example

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

try {
  const response = await acmePayments.fetchTerminals({
    page: 1,
    pageSize: 100,
    sortDirection: 'asc',
  });
} catch (error) {
  // handle error
}
Parameters
NameType
«destructured»Partial<PaginationParams>
Returns

Promise<FetchTerminalsResponse>


deleteTerminal

deleteTerminal(«destructured»): Promise<DeleteTerminalResponse>

Example

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

try {
  await acmePayments.deleteTerminal({
    terminalId: 'unique_id_for_this_terminal',
  });
} catch (error) {
  // handle error
}
Parameters
NameType
«destructured»DeleteTerminalDto
Returns

Promise<DeleteTerminalResponse>


authorizePayment

authorizePayment(«destructured»): Promise<AuthorizePaymentResponse>

Example

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

try {
  const response = await acmePayments.authorizePayment({
    terminalId: 'unique_id_for_this_terminal',
    amount: '10.00',
  });
} catch (error) {
  // handle error
}
Parameters
NameType
«destructured»AuthorizePaymentDto
Returns

Promise<AuthorizePaymentResponse>


capturePayment

capturePayment(«destructured»): Promise<CapturePaymentResponse>

Example

import { ACMEPayments } from '@acmeticketing/payments';

const acmePayments = ACMEPayments.create({
  mid: 'your_mid',
  publishableKey: 'your_publishable_key',
});

try {
  const response = await acmePayments.capturePayment({
    transactionId: 'your_transaction_id',
    externalId: 'optional_external_id',
  });
} catch (error) {
  // handle error
}
Parameters
NameType
«destructured»CapturePaymentDto
Returns

Promise<CapturePaymentResponse>

Interfaces

ActivateTerminalDto

Properties

PropertyTypeDefaultDescription
terminalIdstringrequiredTerminal ID for this terminal (must be unique)
activationCodestringrequiredActivation code displayed on the terminal
descriptionstringundefinedA description of the terminal

ActivateTerminalResponse

Properties

PropertyTypeDefaultDescription
status"success" | "failure"required-

AuthorizePaymentDto

Properties

PropertyTypeDefaultDescription
terminalIdstringrequiredThe terminal id that we will be prompting the customer to insert their card into.
amountstringrequiredThe amount that we would like to authorize.

AuthorizePaymentResponse

Properties

PropertyTypeDefaultDescription
transactionIdstringrequiredExample

'205828417'
transactionDateTimestringrequiredExample

'2023-01-26T17:05:29.0000000+00:00'
totalAmountnumberrequiredExample

0.5
tipAmountnumberrequiredExample

0.0
terminalIdstringrequiredExample

'SDKTestTerminal'
cardLogostringrequiredExample

'Mastercard'
cardHolderNamestringrequiredExample

'Test Card 1'
entryModestringrequiredExample

'ContactIcc'
pinVerifiedbooleanrequiredExample

false
accountNumberstringrequiredExample

'************0681'
expirationMonthstringrequiredExample

'12'
expirationYearstringrequiredExample

'22'
_hasErrorsbooleanrequiredExample

false
emvObjectrequired-

_processorObjectrequired-

_errors[]required-
approvedAmountstringrequired-
statusCodestringrequired-

CapturePaymentDto

Properties

PropertyTypeDefaultDescription
transactionIdstringrequired-
externalIdstringundefined-

CapturePaymentResponse

Properties

PropertyTypeDefaultDescription
expressResponseCodenumberrequiredExample

0
expressResponseMessagestringrequiredExample

'Approved'
hostResponseCodenumberrequiredExample

0
hostResponseMessagenullrequiredExample

null
cvvResponseMessagenullrequiredExample

null
avsResponseMessagenullrequiredExample

null
cvvResponseCodenullrequiredExample

null
avsResponseCodenullrequiredExample

null
transactionStatusCodestringrequiredExample

'1'
approvalNumberstringrequiredExample

'001004'
acquirerDatastringrequiredExample

'148941
transactionIDstringrequiredExample

'207149117'
externalIdstringundefined-
cardLogostringrequiredExample

'Discover'
lastFourDigitsstringrequiredExample

'0059'
transactionAmountnullrequiredExample

null
networkTransactionIDnullrequiredExample

null
expirationMonthstringrequiredExample

'12'
expirationYearstringrequiredExample

'22'
referenceNumberstringrequiredExample

'31'
tokenIDnullrequiredExample

null
tokenProvidernullrequiredExample

null
transactionAmountCurrencyObjectrequired-

DeleteTerminalDto

Properties

PropertyTypeDefaultDescription
terminalIdstringrequired-

ErrorResponse<T>

Type parameters

Name
T

Properties

PropertyTypeDefaultDescription
errorTrequired-

PaginatedList<T>

Type parameters

Name
T

Properties

PropertyTypeDefaultDescription
listT[]required-
paginationPaginationrequired-

Pagination

Properties

PropertyTypeDefaultDescription
hasMorebooleanrequired-
pagenumberrequired-
pageSizenumberrequired-
sortDirectionSortDirectionrequired-
sortFieldstringrequired-

PaginationParams

Properties

PropertyTypeDefaultDescription
pagenumberrequiredDefault

1
pageSizenumberrequiredDefault

100
sortDirectionSortDirectionrequiredDefault

'asc'

PaymentTerminal

Properties

PropertyTypeDefaultDescription
idstringrequiredThe unique ID of the terminal
terminalIdstringrequiredHuman readable id of this terminal i.e. "Front Desk".
Must be unique for this tenant
descriptionstringundefinedA description of the terminal
modelNumberstringrequiredA string value from TriPoS
serialNumberstringrequiredA string value from TriPoS

PaymentsProps

Properties

PropertyTypeDefaultDescription
publishableKeystringrequiredThis is used by the ISV
midstringrequiredThis is an identifier for the business

Type aliases

(README.md) / Exports

ACMEPayments

Table of contents

Classes

  • ACMEPayments

Interfaces

  • ActivateTerminalDto
  • ActivateTerminalResponse
  • AuthorizePaymentDto
  • AuthorizePaymentResponse
  • CapturePaymentDto
  • CapturePaymentResponse
  • DeleteTerminalDto
  • ErrorResponse
  • PaginatedList
  • Pagination
  • PaginationParams
  • PaymentTerminal
  • PaymentsProps

Type Aliases

  • DeleteTerminalResponse
  • FetchTerminalsDto
  • FetchTerminalsResponse
  • SortDirection

Type Aliases

DeleteTerminalResponse

Ƭ DeleteTerminalResponse: Record<string, never>


FetchTerminalsDto

Ƭ FetchTerminalsDto: PaginationParams


FetchTerminalsResponse

Ƭ FetchTerminalsResponse: PaginatedList<PaymentTerminal>


SortDirection

Ƭ SortDirection: "asc" | "desc"

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article