NodeJS with TypeScript types API Client and bindings for the Pomelo Pay Connect API
Using this Client you can interact with your Pomelo Pay Connect API:
- π° Transactions
- πΌ Companies
- π Tokens
- π³ Card Payments (If you are certified as a PCI-DSS merchant)
- Requires NodeJS 8 or higher
- For contributing with development of this client: requires TypeScript 4
The recommended way to install pomelopay-connect-node-ts is through NPM:
To get started, just install the package:
$ npm i pomelopay-connect-node-ts
First get your production
or sandbox
API key from your Dashboard.
If you want to get a production
client:
import Client from 'pomelopay-connect-node-ts'
const client = new Client({appId: <your-app-id>, apiKey: <your-api-key>})
If you want to get a sandbox
client:
import Client from 'pomelopay-connect-node-ts'
const client = new Client({appId: <your-app-id>, apiKey: <your-api-key>, sandbox: true})
If you want to get a cardPayments
client (if you are certified as a PCI-DSS merchant and we've enabled this setting foryou):
import Client from 'pomelopay-connect-node-ts'
// production client
const client = new Client({appId: <your-app-id>, apiKey: <your-api-key>, directCardAuthenticationHost: true})
// sandbox client
const client = new Client({appId: <your-app-id>, apiKey: <your-api-key>, directCardAuthenticationHost: true, sandbox: true})
The following exposed API operations from the Pomelo Pay Connect API are available using the API Client.
See below for more details about each resource.
https://docs.pomelopay.com/docs/connect/12ec79b138bce-get-transaction
const transaction = await client.transactions.get('<transaction-id>')
https://docs.pomelopay.com/docs/connect/7778c88abc14b-create-transaction-v2
The below example includes a lot of optional fields to give an extensive detail on what's possible. As a minimum just currency
and amount
is required.
const transaction = await client.transactions.create({
amount: 1234,
currency: 'USD',
customerReference: `iPhone 13`,
localId: `TX-ID-30483-2023`,
redirectUrl: 'https://www.apple.com/thank-you',
paymentAttemptFailureUrl: 'https://www.apple.com/retry-checkout',
tokenizationDetails: {
tokenize: true,
recurringFrequency: 'AD_HOC',
paymentType: 'UNSCHEDULED'
},
customer: {
name: 'John Doe',
email: 'john.doe@example.com',
billingAddress1: 'Infinite Loop',
billingAddress2: '1',
billingCity: 'Cupertino',
billingPostCode: '95014',
billingCountry: 'US',
billingEmail: 'john.doe@example.com'
}
})
You can then redirect the user to the transaction.url
or transaction.vendorUrl
to complete card payment.
You can also display the QR code image for the users to scan from transaction.qr.url
.
https://docs.pomelopay.com/docs/connect/e0574ed2792c2-get-company
const company = await client.companies.get()
https://docs.pomelopay.com/docs/connect/809153cac2c6a-get-list-of-tokens-for-customer
const tokens = await client.tokens.getList(<customer-id>)
https://docs.pomelopay.com/docs/connect/9d65f123f944e-get-single-token-for-customer
const token = await client.tokens.get(<customer-id>, <token-id>)
For card payment operations your merchant account has to be PCI-DSS certified to be able to send us card PANs and sensitive card data directly.
When using these API's you need to get a directCardAuthenticationHost client that connects to a specific domain at our API that is certified to accept card details.
import Client from 'pomelopay-connect-node-ts'
// production client
const client = new Client({appId: <your-app-id>, apiKey: <your-api-key>, directCardAuthenticationHost: true})
https://docs.pomelopay.com/docs/pomelo-pay-pci-connect/3f679981bd5e2-direct-card-payments
const singlePayment = await client.cardPayments.singlePayment({
cardNumberRaw: "4242424242424242", // this is a test card which can be published with full PAN
cardExpDateRaw: "2312", // YYMM
cardVDRaw: "488",
transactionId: "<transaction-id>",
postalCode: "E15 5AB",
cardHolderName: "John Doe",
customerId: "<customer-id>"
})
This returns a nextAction
URL that you can redirect to for the customer to complete card authentication with their bank.
const customerInitiated = await client.cardPayments.customerInitiatedStoredCredentialsPayment({
token: "<token>", // you can use the list or get token API to get tokens for a customer
customerId: "<ustomer-id>",
transactionId: "<transaction-id>"
})
This returns a nextAction
URL that you can redirect to for the customer to complete card authentication with their bank.
const customerInitiated = await client.cardPayments.merchantInitiatedStoredCredentials({
token: "<token>", // you can use the list or get token API to get tokens for a customer
customerId: "<ustomer-id>",
transactionId: "<transaction-id>"
})
This will immediately charge the card and return an approval auth code if the recurring contract ID is still valid with the cardholder
Thank you for contributing to this client
- Use the same pattern for types and API operations
- Add integration test coverage
- Create an .env file in this project root with the following contents
API_KEY='<sandbox-api-key>'
APP_ID='<sandbox-app-id>'
TX_ID='<sandbox-transaction-od>'
CURRENCY='<sandbox-currency>'
CUSTOMER_ID='<sandbox-customer-id>'
MERCHANT_TOKEN='<sandbox-merchant-recurring-token>'
CUSTOMER_TOKEN='<sandbox-customer-recurring-token>'
- Run npm test:integration and verify all test succeeds
- Open a PR describing the changes
β Sign up as a merchant at https://dashboard.pomelopay.com and start receiving payments in seconds.