znmi
Version:
A simple and easy TypeScript wrapper around NMI's API
1,267 lines (1,263 loc) • 128 kB
JavaScript
import { z } from 'zod';
import ky from 'ky';
import qs from 'qs';
import { XMLParser } from 'fast-xml-parser';
// src/types/transactionSchemas.ts
var TRANSACTION_URL = "https://secure.nmi.com/api/transact.php";
var TransactionTypeSchema = z.enum([
"sale",
"auth",
"credit",
"validate",
"offline",
"complete_partial_payment"
]);
var ProductDataSchema = z.object({
item_product_code: z.string(),
item_description: z.string(),
item_commodity_code: z.string(),
item_unit_of_measure: z.string(),
item_unit_cost: z.number(),
item_quantity: z.number(),
item_total_amount: z.number(),
item_tax_amount: z.number(),
item_tax_rate: z.number(),
item_discount_amount: z.number(),
item_tax_type: z.string(),
item_alternate_tax_id: z.string()
});
var TransactionSchema = z.object({
type: TransactionTypeSchema,
payment_token: z.string().optional(),
transaction_session_id: z.string().length(32).optional(),
googlepay_payment_data: z.string().optional(),
ccnumber: z.string().optional(),
ccexp: z.string().optional(),
cvv: z.string().optional(),
checkname: z.string().optional(),
checkaba: z.string().optional(),
checkaccount: z.string().optional(),
account_holder_type: z.literal("business").or(z.literal("personal")).optional(),
account_type: z.literal("checking").or(z.literal("savings")).optional(),
sec_code: z.literal("PPD").or(z.literal("WEB")).or(z.literal("TEL")).or(z.literal("CCD")).optional(),
amount: z.number().optional(),
surcharge: z.number().default(0).optional(),
convenience_fee: z.number().default(0).optional(),
misc_fee: z.number().default(0).optional(),
misc_fee_name: z.string().default("Miscellaneous Fee").optional(),
tip: z.number().default(0).optional(),
currency: z.string().default("USD").optional(),
payment: z.literal("creditcard").or(z.literal("check")).or(z.literal("cash")).default("creditcard"),
processor_id: z.string().optional(),
authorization_code: z.string().optional(),
dup_seconds: z.number().max(7862400).optional(),
descriptor: z.string().optional(),
descriptor_phone: z.string().optional(),
descriptor_address: z.string().optional(),
descriptor_city: z.string().optional(),
descriptor_state: z.string().optional(),
descriptor_postal: z.string().optional(),
descriptor_country: z.string().optional(),
descriptor_mcc: z.string().optional(),
descriptor_merchant_id: z.string().optional(),
descriptor_url: z.string().optional(),
billing_method: z.literal("recurring").or(z.literal("installment")).optional(),
billing_number: z.number().min(0).max(99).optional(),
billing_total: z.number().optional(),
order_template: z.string().optional(),
order_description: z.string().optional(),
orderid: z.string().optional(),
ipaddress: z.string().optional(),
tax: z.number().default(0).optional(),
shipping: z.number().default(0).optional(),
ponumber: z.string().optional(),
first_name: z.string().optional(),
last_name: z.string().optional(),
company: z.string().optional(),
address1: z.string().optional(),
address2: z.string().optional(),
city: z.string().optional(),
state: z.string().optional(),
zip: z.coerce.string().optional(),
country: z.string().optional(),
phone: z.string().optional(),
fax: z.string().optional(),
email: z.string().optional(),
social_security_number: z.string().optional(),
drivers_license_number: z.string().optional(),
drivers_license_dob: z.string().optional(),
drivers_license_state: z.string().optional(),
shipping_firstname: z.string().optional(),
shipping_lastname: z.string().optional(),
shipping_company: z.string().optional(),
shipping_address1: z.string().optional(),
shipping_address2: z.string().optional(),
shipping_city: z.string().optional(),
shipping_state: z.string().optional(),
shipping_zip: z.coerce.string().optional(),
shipping_country: z.string().optional(),
shipping_email: z.string().optional(),
custom_fields: z.record(z.string(), z.string().or(z.number())).optional(),
customer_receipt: z.boolean().default(false).optional(),
signature_image: z.string().optional(),
cardholder_auth: z.literal("verified").or(z.literal("attempted")).optional(),
cavv: z.string().optional(),
xid: z.string().optional(),
three_ds_version: z.string().optional(),
directory_server_id: z.string().optional(),
source_transaction_id: z.string().optional(),
pinless_debit_override: z.literal("Y").or(z.literal("N")).optional(),
recurring: z.literal("add_subscription").optional(),
plan_id: z.string().optional(),
plan_payments: z.number().default(0).optional(),
plan_amount: z.number().default(0).optional(),
day_frequency: z.number().default(0).optional(),
month_frequency: z.number().min(1).max(24).optional(),
day_of_month: z.number().min(1).max(31).optional(),
start_date: z.string().optional(),
customer_vault: z.literal("add_customer").or(z.literal("update_customer")).optional(),
customer_vault_id: z.string().optional(),
initiated_by: z.literal("customer").or(z.literal("merchant")).optional(),
initial_transaction_id: z.string().optional(),
stored_credential_indicator: z.literal("stored").or(z.literal("used")).optional(),
shipping_postal: z.string().optional(),
ship_from_postal: z.string().optional(),
summary_commodity_code: z.string().optional(),
duty_amount: z.number().default(0).optional(),
discount_amount: z.number().default(0).optional(),
national_tax_amount: z.number().default(0).optional(),
alternate_tax_amount: z.number().default(0).optional(),
alternate_tax_id: z.string().optional(),
vat_tax_amount: z.number().default(0).optional(),
vat_tax_rate: z.number().default(0).optional(),
vat_invoice_reference_number: z.string().optional(),
customer_vat_registration: z.string().optional(),
merchant_vat_registration: z.string().optional(),
order_date: z.string().optional(),
products: z.array(ProductDataSchema).optional(),
payment_facilitator_id: z.string().optional(),
submerchant_id: z.string().optional(),
submerchant_name: z.string().optional(),
submerchant_address: z.string().optional(),
submerchant_city: z.string().optional(),
submerchant_state: z.string().optional(),
submerchant_postal: z.string().optional(),
submerchant_country: z.string().optional(),
submerchant_phone: z.string().optional(),
submerchant_email: z.string().optional(),
partial_payment_id: z.string().optional(),
partial_payments: z.literal("settle_partial").or(z.literal("payment_in_full")).optional()
});
var TransactionRequestSchema = TransactionSchema.transform((data) => {
const products = data.products || [];
const transformedProducts = products.reduce((acc, product, index) => {
const productKeys = Object.keys(product);
const newProduct = productKeys.reduce((productAcc, key) => {
const newKey = `${key}_${index + 1}`;
return {
...productAcc,
[newKey]: product[key]
};
}, {});
return { ...acc, ...newProduct };
}, {});
const customFields = data.custom_fields || {};
const transformedCustomFields = Object.keys(customFields).reduce(
(acc, key, index) => {
const newKey = `merchant_defined_field_${index + 1}`;
return { ...acc, [newKey]: customFields[key] };
},
{}
);
return { ...data, ...transformedProducts, ...transformedCustomFields };
});
var AuthTransactionRequestSchema = TransactionSchema.pick({
// Same fields as ValidateTransactionRequestSchema
type: true,
ccnumber: true,
ccexp: true,
cvv: true,
payment_token: true,
transaction_session_id: true,
googlepay_payment_data: true,
surcharge: true,
convenience_fee: true,
misc_fee: true,
misc_fee_name: true,
tip: true,
currency: true,
processor_id: true,
dup_seconds: true,
descriptor: true,
descriptor_phone: true,
descriptor_address: true,
descriptor_city: true,
descriptor_state: true,
descriptor_postal: true,
descriptor_country: true,
descriptor_mcc: true,
descriptor_merchant_id: true,
descriptor_url: true,
billing_method: true,
billing_number: true,
billing_total: true,
order_template: true,
order_description: true,
orderid: true,
ipaddress: true,
first_name: true,
last_name: true,
company: true,
address1: true,
address2: true,
city: true,
state: true,
zip: true,
country: true,
phone: true,
fax: true,
email: true,
drivers_license_number: true,
drivers_license_dob: true,
drivers_license_state: true,
shipping_firstname: true,
shipping_lastname: true,
shipping_company: true,
shipping_address1: true,
shipping_address2: true,
shipping_city: true,
shipping_state: true,
shipping_zip: true,
shipping_country: true,
shipping_email: true,
custom_fields: true,
customer_receipt: true,
cardholder_auth: true,
cavv: true,
xid: true,
three_ds_version: true,
directory_server_id: true,
source_transaction_id: true,
pinless_debit_override: true,
recurring: true,
plan_id: true,
plan_payments: true,
plan_amount: true,
month_frequency: true,
day_of_month: true,
day_frequency: true,
start_date: true,
customer_vault: true,
customer_vault_id: true,
initiated_by: true,
initial_transaction_id: true,
stored_credential_indicator: true,
shipping: true,
tax: true,
ponumber: true,
shipping_postal: true,
ship_from_postal: true,
summary_commodity_code: true,
duty_amount: true,
discount_amount: true,
national_tax_amount: true,
alternate_tax_amount: true,
alternate_tax_id: true,
vat_tax_amount: true,
vat_tax_rate: true,
vat_invoice_reference_number: true,
customer_vat_registration: true,
merchant_vat_registration: true,
order_date: true,
products: true,
payment_facilitator_id: true,
submerchant_id: true,
submerchant_name: true,
submerchant_address: true,
submerchant_city: true,
submerchant_state: true,
submerchant_postal: true,
submerchant_country: true,
submerchant_phone: true,
submerchant_email: true,
signature_image: true,
// Key difference: amount is required for auth
amount: true
}).extend({
// Override amount to make it required
amount: z.number(),
type: z.literal("auth")
});
var ValidateTransactionRequestSchema = TransactionSchema.pick({
type: true,
ccnumber: true,
ccexp: true,
cvv: true,
payment_token: true,
transaction_session_id: true,
googlepay_payment_data: true,
surcharge: true,
convenience_fee: true,
misc_fee: true,
misc_fee_name: true,
tip: true,
currency: true,
processor_id: true,
dup_seconds: true,
descriptor: true,
descriptor_phone: true,
descriptor_address: true,
descriptor_city: true,
descriptor_state: true,
descriptor_postal: true,
descriptor_country: true,
descriptor_mcc: true,
descriptor_merchant_id: true,
descriptor_url: true,
billing_method: true,
billing_number: true,
billing_total: true,
order_template: true,
order_description: true,
orderid: true,
ipaddress: true,
first_name: true,
last_name: true,
company: true,
address1: true,
address2: true,
city: true,
state: true,
zip: true,
country: true,
phone: true,
fax: true,
email: true,
drivers_license_number: true,
drivers_license_dob: true,
drivers_license_state: true,
shipping_firstname: true,
shipping_lastname: true,
shipping_company: true,
shipping_address1: true,
shipping_address2: true,
shipping_city: true,
shipping_state: true,
shipping_zip: true,
shipping_country: true,
shipping_email: true,
custom_fields: true,
customer_receipt: true,
cardholder_auth: true,
cavv: true,
xid: true,
three_ds_version: true,
directory_server_id: true,
source_transaction_id: true,
pinless_debit_override: true,
recurring: true,
plan_id: true,
plan_payments: true,
plan_amount: true,
month_frequency: true,
day_of_month: true,
day_frequency: true,
start_date: true,
customer_vault: true,
customer_vault_id: true,
initiated_by: true,
initial_transaction_id: true,
stored_credential_indicator: true,
shipping: true,
tax: true,
ponumber: true,
shipping_postal: true,
ship_from_postal: true,
summary_commodity_code: true,
duty_amount: true,
discount_amount: true,
national_tax_amount: true,
alternate_tax_amount: true,
alternate_tax_id: true,
vat_tax_amount: true,
vat_tax_rate: true,
vat_invoice_reference_number: true,
customer_vat_registration: true,
merchant_vat_registration: true,
order_date: true,
products: true,
payment_facilitator_id: true,
submerchant_id: true,
submerchant_name: true,
submerchant_address: true,
submerchant_city: true,
submerchant_state: true,
submerchant_postal: true,
submerchant_country: true,
submerchant_phone: true,
submerchant_email: true,
signature_image: true
}).extend({
type: z.literal("validate")
});
var CaptureTransactionRequestSchema = z.object({
type: z.literal("capture"),
transactionid: z.string(),
amount: z.number(),
tracking_number: z.string().optional(),
shipping_carrier: z.string().optional(),
orderid: z.string().optional(),
signature_image: z.string().optional()
});
var VoidTransactionRequestSchema = z.object({
type: z.literal("void"),
transactionid: z.string(),
void_reason: z.string().optional(),
payment: z.literal("creditcard").or(z.literal("check")).optional()
});
var RefundTransactionSchema = z.object({
type: z.literal("refund"),
transactionid: z.string(),
amount: z.number().optional(),
payment: z.literal("creditcard").or(z.literal("check")).optional()
});
var UpdateTransactionSchema = z.object({
type: z.literal("update"),
transactionid: z.string(),
payment: z.literal("creditcard").or(z.literal("check")).optional(),
tracking_number: z.string().optional(),
shipping: z.number().optional(),
shipping_postal: z.string().optional(),
ship_from_postal: z.string().optional(),
shipping_country: z.string().optional(),
shipping_carrier: z.literal("ups").or(z.literal("fedex")).or(z.literal("dhl")).or(z.literal("usps")).optional(),
shipping_date: z.string().optional(),
order_description: z.string().optional(),
order_date: z.string().optional(),
customer_receipt: z.boolean().default(false).optional(),
signature_image: z.string().optional(),
ponumber: z.string().optional(),
summary_commodity_code: z.string().optional(),
duty_amount: z.number().optional(),
discount_amount: z.number().optional(),
tax: z.number().default(0).optional(),
national_tax_amount: z.number().optional(),
alternate_tax_amount: z.number().optional(),
alternate_tax_id: z.string().optional(),
vat_tax_amount: z.number().optional(),
vat_tax_rate: z.number().optional(),
vat_invoice_reference_number: z.string().optional(),
customer_vat_registration: z.string().optional(),
merchant_vat_registration: z.string().optional(),
custom_fields: z.record(z.string(), z.string().or(z.number())).optional()
});
var UpdateTransactionRequestSchema = UpdateTransactionSchema.transform(
(data) => {
const customFields = data.custom_fields || {};
const transformedCustomFields = Object.keys(customFields).reduce(
(acc, key, index) => {
const newKey = `merchant_defined_field_${index + 1}`;
return { ...acc, [newKey]: customFields[key] };
},
{}
);
return { ...data, ...transformedCustomFields };
}
);
var TransactionResponseSchema = z.object({
response: z.literal("1").or(z.literal("2")).or(z.literal("3")),
responsetext: z.string(),
authcode: z.string().optional(),
transactionid: z.string().optional(),
avsresponse: z.string().optional(),
cvvresponse: z.string().optional(),
orderid: z.string().optional(),
response_code: z.string().optional(),
emv_auth_response_data: z.string().optional(),
customer_vault_id: z.string().optional(),
kount_score: z.string().optional(),
merchant_advice_code: z.string().optional()
});
var parseQueryString = (responseString) => {
return qs.parse(responseString, { ignoreQueryPrefix: true });
};
var PostRequest = async (url, data, options) => {
try {
const security_key = data.security_key;
const formData = qs.stringify(data);
const response = await ky.post(`${url}?security_key=${security_key}`, {
body: formData,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
...options
});
const responseText = await response.text();
const responseData = parseQueryString(responseText);
return {
status: response.status,
data: responseData,
message: "Success"
};
} catch (error) {
console.error("Error in PostRequest", error);
throw error;
}
};
var PostRequestXML = async (url, data, options) => {
try {
const security_key = data.security_key;
const formData = qs.stringify(data);
const response = await ky.post(`${url}?security_key=${security_key}`, {
body: formData,
headers: {
Accept: "application/xml",
"Content-Type": "application/x-www-form-urlencoded"
},
...options
}).text();
return response;
} catch (error) {
console.error("Error in PostRequestXML", error);
return `<?xml version="1.0"?>
<nm_response>
<error_response>Error in PostRequestXML: ${error instanceof Error ? error.message : "Unknown error"}</error_response>
</nm_response>`;
}
};
// src/api/transactionsApi.ts
var TransactionsApi = class {
_securityKey;
constructor(securityKey) {
this._securityKey = securityKey;
}
beforeRequest = (request) => {
return {
...request,
security_key: this._securityKey
};
};
parseResponse = (data) => {
return TransactionResponseSchema.parse(data);
};
createTransaction = async (transactionRequest) => {
const request = this.beforeRequest(transactionRequest);
const response = await PostRequest(TRANSACTION_URL, request);
return this.parseResponse(response.data);
};
captureTransaction = async (captureTransactionRequest) => {
const request = this.beforeRequest(captureTransactionRequest);
const response = await PostRequest(TRANSACTION_URL, request);
return this.parseResponse(response.data);
};
refundTransaction = async (refundTransaction) => {
const request = this.beforeRequest(refundTransaction);
const response = await PostRequest(TRANSACTION_URL, request);
return this.parseResponse(response.data);
};
voidTransaction = async (voidTransactionRequest) => {
const request = this.beforeRequest(voidTransactionRequest);
const response = await PostRequest(TRANSACTION_URL, request);
return this.parseResponse(response.data);
};
updateTransaction = async (updateTransactionRequest) => {
const request = this.beforeRequest(updateTransactionRequest);
const response = await PostRequest(TRANSACTION_URL, request);
return this.parseResponse(response.data);
};
};
// src/functions/transactions.ts
var Transactions = class {
transactionsApi;
_securityKey;
constructor(securityKey) {
this._securityKey = securityKey;
this.transactionsApi = new TransactionsApi(securityKey);
}
// Base transaction methods
async createTransaction(request) {
try {
const result = await this.transactionsApi.createTransaction(request);
return {
status: 200,
data: result,
message: "Transaction created successfully"
};
} catch (error) {
console.log(error);
return {
status: 500,
message: `Error in createTransaction: ${error.message}`
};
}
}
async authorizeTransaction(request) {
return this.createTransaction({
...request,
type: "auth",
payment: "creditcard"
});
}
async validateTransaction(request) {
return this.createTransaction({
...request,
type: "validate",
payment: "creditcard"
});
}
// Transaction type convenience methods
async sale(request) {
return this.createTransaction({
type: "sale",
...request
});
}
async auth(request) {
return this.createTransaction({
type: "auth",
...request
});
}
async validate(request) {
return this.createTransaction({
type: "validate",
...request
});
}
async credit(request) {
return this.createTransaction({
type: "credit",
...request
});
}
async offline(request) {
return this.createTransaction({
type: "offline",
...request
});
}
// Post-transaction operations
async captureTransaction(request) {
try {
const result = await this.transactionsApi.captureTransaction(request);
return {
status: 200,
data: result,
message: "Transaction captured successfully"
};
} catch (error) {
console.log(error);
return {
status: 500,
message: `Error in captureTransaction: ${error.message}`
};
}
}
async refundTransaction(request) {
try {
const result = await this.transactionsApi.refundTransaction(request);
return {
status: 200,
data: result,
message: "Transaction refunded successfully"
};
} catch (error) {
console.log(error);
return {
status: 500,
message: `Error in refundTransaction: ${error.message}`
};
}
}
async voidTransaction(request) {
try {
const result = await this.transactionsApi.voidTransaction(request);
return {
status: 200,
data: result,
message: "Transaction voided successfully"
};
} catch (error) {
console.log(error);
return {
status: 500,
message: `Error in voidTransaction: ${error.message}`
};
}
}
async updateTransaction(request) {
try {
const result = await this.transactionsApi.updateTransaction(request);
return {
status: 200,
data: result,
message: "Transaction updated successfully"
};
} catch (error) {
console.log(error);
return {
status: 500,
message: `Error in updateTransaction: ${error.message}`
};
}
}
};
var CUSTOMER_VAULT_URL = "https://secure.nmi.com/api/transact.php";
var AddUpdateCustomerSchema = z.object({
customer_vault: z.literal("add_customer").or(z.literal("update_customer")).describe(`Add or update a customer in the customer vault`),
customer_vault_id: z.string().or(z.number()).optional().describe(
`The customer vault id of the customer to update, if not set the gateway will generate one randomly.`
),
ccnumber: z.string().optional().describe(`The customer's credit card number`),
billing_id: z.string().optional().describe(
`The billing id of the customer to update, if not set the gateway will create one or the billing id with priority '1' will be updated.`
),
payment_token: z.string().optional().describe(
`The tokenized version of the customer's card or check information. This will be generated by Collect.js and is usable once.`
),
googlepay_payment_data: z.string().optional().describe(
`The tokenized version of the customer's Google Pay payment data created when integrated with Google Pay SDK.`
),
ccexp: z.string().optional().describe(
`The expiration date of the customer's credit card in MMYY format`
),
checkname: z.string().optional().describe(`The name on the customer's checking account`),
checkaba: z.string().optional().describe(`The ABA routing number of the customer's bank`),
checkaccount: z.string().optional().describe(`The customer's checking account number`),
account_holder_type: z.literal("personal").or(z.literal("business")).optional().describe(`The type of account holder. 'personal' or 'business'`),
account_type: z.literal("checking").or(z.literal("savings")).optional().describe(`The type of account. 'checking' or 'savings'`),
sec_code: z.literal("WEB").or(z.literal("TEL")).or(z.literal("CCD")).or(z.literal("PPD")).optional().describe(
`The Standard Entry Class code for the transaction. 'WEB', 'TEL', 'CCD', or 'PPD'`
),
currency: z.string().optional().default("USD").describe(`The currency of the transaction. Defaults to USD`),
payment_type: z.literal("creditcard").or(z.literal("check")).optional().describe(`The type of payment. 'creditcard' or 'check'`),
orderid: z.string().optional().describe(`The order id of the transaction`),
order_description: z.string().optional().describe(`The description of the transaction`),
custom_fields: z.record(z.string()).optional().describe(`Custom fields to be added to the transaction`),
first_name: z.string().optional().describe(`The customer's first name`),
last_name: z.string().optional().describe(`The customer's last name`),
company: z.string().optional().describe(`The customer's company name`),
address1: z.string().optional().describe(`The customer's address`),
address2: z.string().optional().describe(`The customer's address (line 2)`),
city: z.string().optional().describe(`The customer's city`),
state: z.string().optional().describe(`The customer's state`),
zip: z.coerce.string().optional().describe(`The customer's zip code`),
country: z.string().optional().describe(`The customer's country`),
phone: z.string().optional().describe(`The customer's phone number`),
email: z.string().optional().describe(`The customer's email address`),
fax: z.string().optional().describe(`The customer's fax number`),
shipping_id: z.string().optional().describe(
`The shipping entry ID. If none is provided, one will be created or the billing id with priority '1' will be updated.`
),
shipping_firstname: z.string().optional().describe(`The shipping first name`),
shipping_lastname: z.string().optional().describe(`The shipping last name`),
shipping_company: z.string().optional().describe(`The shipping company name`),
shipping_address1: z.string().optional().describe(`The shipping address`),
shipping_address2: z.string().optional().describe(`The shipping address (line 2)`),
shipping_city: z.string().optional().describe(`The shipping city`),
shipping_state: z.string().optional().describe(`The shipping state`),
shipping_zip: z.coerce.string().optional().describe(`The shipping zip code`),
shipping_country: z.string().optional().describe(`The shipping country`),
shipping_phone: z.string().optional().describe(`The shipping phone number`),
shipping_fax: z.string().optional().describe(`The shipping fax number`),
shipping_email: z.string().optional().describe(`The shipping email address`),
source_transaction_id: z.string().optional().describe(`The transaction id of the source transaction`),
acu_enabled: z.literal(true).or(z.literal(false)).optional().describe(
`Is set to true, credit card will be evalutated and sent based upon Automatic Card Updater settings. If set to false, credit card will not be submitted for updates when Automatic Card Updater runs.`
)
});
var AddUpdateCustomerRequestSchema = AddUpdateCustomerSchema.transform(
(data) => {
const customFields = data.custom_fields || {};
const transformedCustomFields = Object.keys(customFields).reduce(
(acc, key, index) => {
const newKey = `merchant_defined_field_${index + 1}`;
return { ...acc, [newKey]: customFields[key] };
},
{}
);
return { ...data, ...transformedCustomFields };
}
);
var CustomerVaultInitiatedTransactionSchema = z.object({
customer_vault_id: z.string().or(z.number()).optional().describe(`The customer vault id of the customer`),
amount: z.number().describe(`The amount of the transaction to be processed`),
currency: z.string().optional().default("USD").describe(`The currency of the transaction. Defaults to USD`),
processor_id: z.string().optional().describe(
`If using Multiple MIDs, route to this processor (processor_id is obtained
under Settings->Transaction Routing in the Control Panel).`
),
descriptor: z.string().optional().describe(
`The descriptor to be used for the transaction. If not set, the default descriptor will be used.`
),
descriptor_phone: z.string().optional().describe(
`The phone number to be used for the transaction descriptor. If not set, the default descriptor phone number will be used.`
),
order_description: z.string().optional().describe(`The description of the transaction`),
orderid: z.string().optional().describe(`The order id of the transaction`),
initiated_by: z.literal("customer").or(z.literal("merchant")).describe(
`Who initiated the transaction. 'customer' or 'merchant'. If not set, the default is 'merchant'`
),
iniital_transaction_id: z.string().optional().describe(`The transaction id of the source transaction`),
stored_credential_indicator: z.literal("stored").or(z.literal("used")).optional().describe(`The indicator of the stored credential.
Values: 'stored' or 'used'
Use 'stored' when processing the initial transaction in which you are storing a customer's payment
details (customer credentials) in the Customer Vault or other third-party payment storage system.
Use 'used' when processing a subsequent or follow-up transaction using the customer payment
details (customer credentials) you have already stored to the Customer Vault or third-party payment
storage method.`)
});
var AuthorizeCustomerByVaultIdRequestSchema = z.object({
type: z.literal("auth").describe(`The type of transaction`),
customer_vault_id: z.string().or(z.number()).describe(`The customer vault id of the customer to authorize`),
amount: z.number().describe(`The amount of the transaction to be processed`),
billing_id: z.string().optional().describe(`The billing id of the customer`)
});
var CreditTransactionByVaultIdRequestSchema = z.object({
type: z.literal("credit").describe(`The type of transaction`),
customer_vault_id: z.string().or(z.number()).describe(`The customer vault id of the customer to credit`),
amount: z.number().describe(`The amount of the transaction to be processed`),
billing_id: z.string().optional().describe(`The billing id of the customer`)
});
var OfflineTransactionByVaultIdRequestSchema = z.object({
type: z.literal("offline").describe(`The type of transaction`),
customer_vault_id: z.string().or(z.number()).describe(
`The customer vault id of the customer to process the transaction`
),
amount: z.number().describe(`The amount of the transaction to be processed`),
billing_id: z.string().optional().describe(`The billing id of the customer`)
});
var SaleByVaultIdRequestSchema = z.object({
type: z.literal("sale").describe(`The type of transaction`),
customer_vault_id: z.string().or(z.number()).describe(
`The customer vault id of the customer to process the transaction`
),
amount: z.number().describe(`The amount of the transaction to be processed`),
billing_id: z.string().optional().describe(`The billing id of the customer, used if multiple exist`)
});
var ValidateCustomerByVaultIdRequestSchema = z.object({
type: z.literal("validate").describe(`Validate a customer vault id in the customer vault`),
customer_vault_id: z.string().or(z.number()).describe(`The customer vault id of the customer to validate`),
billing_id: z.string().optional().describe(`The billing id of the customer to validate`)
});
var DeleteCustomerRecordSchema = z.object({
customer_vault: z.literal("delete_customer").describe(`Delete a customer from the customer vault`),
customer_vault_id: z.string().or(z.number()).describe(`The customer vault id of the customer to delete`)
});
var AddBillingForCustomerRequestSchema = z.object({
customer_vault: z.literal("add_billing").describe(`Add a billing record to the customer vault`),
customer_vault_id: z.string().or(z.number()).optional().describe(`The customer vault id of the customer`),
billing_id: z.string().optional().describe(
`The billing id of the customer to update, if not set the gateway will create one or the billing id with priority '1' will be updated.`
),
ccnumber: z.string().optional().describe(`The customer's credit card number`),
ccexp: z.string().optional().describe(
`The expiration date of the customer's credit card in MMYY format`
),
first_name: z.string().optional().describe(`The customer's first name`),
last_name: z.string().optional().describe(`The customer's last name`),
address1: z.string().optional().describe(`The customer's address`),
address2: z.string().optional().describe(`The customer's address (line 2)`),
city: z.string().optional().describe(`The customer's city`),
state: z.string().optional().describe(`The customer's state`),
zip: z.coerce.string().optional().describe(`The customer's zip code`),
country: z.string().optional().describe(`The customer's country`),
phone: z.string().optional().describe(`The customer's phone number`),
email: z.string().optional().describe(`The customer's email address`),
fax: z.string().optional().describe(`The customer's fax number`),
company: z.string().optional().describe(`The customer's company name`)
});
var UpdateBillingForCustomerRequestSchema = AddBillingForCustomerRequestSchema.extend({
customer_vault: z.literal("update_billing").describe(`Update a billing record in the customer vault`)
});
var DeleteBillingForCustomerRequestSchema = z.object({
customer_vault: z.literal("delete_billing").describe(`Delete a billing record from the customer vault`),
customer_vault_id: z.string().or(z.number()).describe(`The customer vault id of the customer`),
billing_id: z.string().describe(`The billing id of the customer to delete`)
});
var APITransactionResponseSchema = z.object({
response: z.enum(["1", "2", "3"]).describe(`1 is success, 2 is declined, 3 is error`),
responsetext: z.string(),
authcode: z.string(),
transactionid: z.string().optional(),
avsresponse: z.string(),
cvvresponse: z.string(),
orderid: z.string(),
type: z.enum([
"sale",
"auth",
"validate",
"credit",
"offline",
"refund",
"void",
"capture",
"complete_partial_payment"
]),
response_code: z.string(),
partial_payment_id: z.string().optional(),
partial_payment_balance: z.string().optional(),
amount_authorized: z.string().optional()
});
var CustomerVaultResponseSchema = z.object({
response: z.enum(["1", "2", "3"]).describe(`1 is success, 2 is declined, 3 is error`),
responsetext: z.string(),
authcode: z.string(),
transactionid: z.string().optional(),
avsresponse: z.string(),
cvvresponse: z.string(),
orderid: z.string(),
type: z.enum([
"sale",
"auth",
"validate",
"credit",
"offline",
"refund",
"void",
"capture",
"complete_partial_payment",
""
]),
response_code: z.string(),
customer_vault_id: z.string().optional().describe(`Only not included when you delete em.`)
});
var BillingResponseSchema = CustomerVaultResponseSchema;
var InvoiceResponseSchema = z.object({
response: z.enum(["1", "2", "3"]).describe(`1 is success, 2 is declined, 3 is error`),
responsetext: z.string(),
authcode: z.string(),
invoice_id: z.string().optional(),
avsresponse: z.string(),
cvvresponse: z.string(),
orderid: z.string(),
type: z.enum(["add_invoice", "delete_invoice", "update_invoice"]),
response_code: z.string(),
payment_terms: z.string().optional()
});
var RecurringResponseSchema = z.object({
response: z.enum(["1", "2", "3"]).describe(`1 is success, 2 is declined, 3 is error`),
responsetext: z.string(),
recurring_id: z.string().optional(),
avsresponse: z.string(),
cvvresponse: z.string(),
orderid: z.string(),
type: z.enum([
"add_recurring",
"update_recurring",
"delete_recurring",
"get_recurring",
"add_subscription",
""
]),
response_code: z.string(),
subscription_id: z.coerce.number().optional()
});
var ProductResponseSchema = z.object({
response: z.enum(["1", "2", "3"]).describe(`1 is success, 2 is declined, 3 is error`),
responsetext: z.string(),
product_id: z.string(),
product_sku: z.string().optional(),
product_description: z.string().optional(),
product_cost: z.string().optional(),
product_currency: z.string().optional(),
product_commodity_code: z.string().optional(),
product_unit_of_measure: z.string().optional(),
product_tax_amount: z.string().optional(),
product_discount_amount: z.string().optional(),
product_image_name: z.string().optional(),
product_category: z.string().optional(),
response_code: z.string().optional()
});
var QueryCustomerVaultCustomerSchema = z.object({
id: z.string().optional(),
first_name: z.string().optional(),
last_name: z.string().optional(),
address_1: z.coerce.string().optional(),
address_2: z.coerce.string().optional(),
company: z.string().optional(),
city: z.string().optional(),
state: z.string().optional(),
postal_code: z.coerce.string().optional(),
country: z.string().optional(),
email: z.string().optional(),
phone: z.coerce.number().optional(),
fax: z.coerce.number().optional(),
cell_phone: z.coerce.number().optional(),
customertaxid: z.string().optional(),
website: z.string().optional(),
shipping_first_name: z.string().optional(),
shipping_last_name: z.string().optional(),
shipping_address_1: z.coerce.string().optional(),
shipping_address_2: z.coerce.string().optional(),
shipping_company: z.string().optional(),
shipping_city: z.string().optional(),
shipping_state: z.string().optional(),
shipping_postal_code: z.coerce.string().optional(),
shipping_country: z.string().optional(),
shipping_email: z.string().optional(),
shipping_carrier: z.string().optional(),
tracking_number: z.string().optional(),
shipping_date: z.string().optional(),
shipping: z.string().optional(),
cc_number: z.string().regex(/^[0-9xX]+$/).optional(),
cc_hash: z.string().optional(),
cc_exp: z.coerce.number().optional(),
cc_start_date: z.string().optional(),
cc_issue_number: z.string().optional(),
check_account: z.string().optional(),
check_hash: z.string().optional(),
check_aba: z.string().optional(),
check_name: z.string().optional(),
account_holder_type: z.string().optional(),
account_type: z.string().optional(),
sec_code: z.string().optional(),
processor_id: z.string().optional(),
cc_bin: z.coerce.number().optional(),
cc_type: z.string().optional(),
created: z.coerce.number().optional(),
updated: z.coerce.number().optional(),
account_updated: z.coerce.number().optional(),
customer_vault_id: z.string()
});
var QueryCustomerVaultResponseSchema = z.object({
nm_response: z.object({
customer_vault: z.object({
customer: z.union([
z.array(QueryCustomerVaultCustomerSchema),
QueryCustomerVaultCustomerSchema
])
})
})
});
var QueryTestModeResponseSchema = z.object({
nm_response: z.object({
test_mode_enabled: z.boolean()
})
});
var QueryRecurringResponseSchemaBase = z.object({
id: z.string().optional().describe("Unique identifier for the subscription"),
subscription_id: z.coerce.number().describe("Subscription-specific ID"),
plan: z.object({
plan_id: z.string().describe("Plan's specific ID"),
plan_name: z.string().describe("Name of the plan"),
plan_amount: z.coerce.number().describe("Amount associated with the plan"),
plan_payments: z.union([
z.coerce.number(),
z.literal("until_cancelled").or(z.literal("until_canceled"))
]).describe("Number of payments for the plan"),
day_frequency: z.coerce.string().describe("Frequency of the plan in days")
}),
next_charge_date: z.string().describe("Date of next charge for the subscription"),
completed_payments: z.coerce.number().describe("Number of completed payments"),
attempted_payments: z.coerce.number().describe("Number of attempted payments"),
remaining_payments: z.union([
z.literal("until_cancelled").or(z.literal("until_canceled")),
z.coerce.number()
]).describe("Number of remaining payments"),
ponumber: z.string().describe("Purchase Order number"),
orderid: z.string().describe("Order ID"),
order_description: z.string().describe("Description of the order"),
shipping: z.coerce.number().describe("Shipping details"),
tax: z.coerce.number().describe("Tax details"),
first_name: z.string().describe("First name of the customer"),
last_name: z.string().describe("Last name of the customer"),
address_1: z.coerce.string().describe("Address line 1"),
address_2: z.coerce.string().describe("Address line 2"),
company: z.string().describe("Company name"),
city: z.string().describe("City"),
state: z.string().describe("State or region"),
postal_code: z.coerce.number().describe("Postal code"),
country: z.string().describe("Country"),
email: z.string().describe("Email address"),
phone: z.coerce.number().describe("Phone number"),
fax: z.coerce.number().describe("Fax number"),
cell_phone: z.coerce.number().describe("Cell phone number"),
customertaxid: z.string().describe("Customer's tax identification number"),
website: z.string().describe("Website URL"),
cc_number: z.string().regex(/^[0-9xX]+$/).describe("Credit card number"),
cc_hash: z.string().describe("Credit card hash"),
cc_exp: z.coerce.number().describe("Credit card expiration date"),
cc_start_date: z.string().describe("Credit card start date"),
cc_issue_number: z.coerce.number().describe("Credit card issue number"),
cc_bin: z.coerce.number().describe("Credit card BIN number"),
processor_id: z.string().describe("Processor ID")
});
var QueryRecurringResponseSchema = z.object({
nm_response: z.object({
subscription: z.union([
z.array(QueryRecurringResponseSchemaBase),
QueryRecurringResponseSchemaBase
])
})
});
var QueryRecurringPlanSchema = z.object({
id: z.string().optional().describe("Unique identifier for the plan"),
plan_id: z.string().describe("Plan's specific ID"),
plan_name: z.string().describe("Name of the recurring plan"),
plan_amount: z.coerce.number().describe("Amount associated with the plan"),
day_frequency: z.coerce.number().describe("Frequency of the plan in days"),
month_frequency: z.coerce.number().describe("Frequency of the plan in months"),
day_of_month: z.coerce.number().describe("Specific day of the month for the plan"),
plan_payments: z.union([
z.literal("until_cancelled").or(z.literal("until_canceled")),
z.coerce.number()
]).describe("Number of payments for the plan")
});
var QueryRecurringPlansResponseSchema = z.object({
nm_response: z.object({
plan: z.union([
z.array(QueryRecurringPlanSchema),
QueryRecurringPlanSchema
])
})
});
var QueryInvoiceSchema = z.object({
invoice_id: z.string().describe("Unique identifier for the invoice"),
amount: z.string().describe("Total amount of the invoice"),
status: z.string().describe("Status of the invoice"),
currency: z.string().describe("Currency code for the invoice amount"),
order_description: z.string().describe("Description of the order"),
customer_id: z.string().describe("Unique identifier for the customer"),
customer_tax_id: z.string().describe("Tax ID associated with the customer"),
order_id: z.string().describe("Unique identifier for the order"),
po_number: z.string().describe("Purchase order number"),
tax_amount: z.string().describe("Total tax amount for the invoice"),
shipping_amount: z.string().describe("Total shipping amount for the invoice"),
discount_amount: z.string().describe("Total discount amount for the invoice"),
created: z.string().describe("Creation date of the invoice"),
terms: z.string().describe("Payment terms for the invoice"),
payments_applied: z.string().describe("Total payments applied to the invoice"),
billing: z.object({
first_name: z.string().describe("First name for billing contact"),
last_name: z.string().describe("Last name for billing contact"),
address1: z.string().describe("Primary address line for billing"),
address2: z.string().describe("Secondary address line for billing"),
company: z.string().describe("Company name for billing"),
city: z.string().describe("City for billing"),
state: z.string().describe("State for billing"),
postal: z.string().describe("Postal code for billing"),
country: z.string().describe("Country for billing"),
email: z.string().describe("Email address for billing"),
phone: z.string().describe("Phone number for billing"),
fax: z.string().describe("Fax number for billing")
}),
shipping: z.object({
first_name: z.string().describe("First name for shipping contact"),
last_name: z.string().describe("Last name for shipping contact"),
address1: z.string().describe("Primary address line for shipping"),
address2: z.string().describe("Secondary address line for shipping"),
company: z.string().describe("Company name for shipping"),
city: z.string().describe("City for shipping"),
state: z.string().describe("State for shipping"),
postal: z.string().describe("Postal code for shipping"),
country: z.string().describe("Country for shipping"),
email: z.string().describe("Email address for shipping"),
phone: z.string().describe("Phone number for shipping"),
fax: z.string().describe("Fax number for shipping")
})
});
var QueryInvoicingResponseSchema = z.object({
nm_response: z.object({
invoice_report: z.object({
invoice: z.union([z.array(QueryInvoiceSchema), QueryInvoiceSchema])
})
})
});
var GatewayProcessorSchema = z.object({
description: z.string().describe("Description of the gateway processor"),
processor_id: z.string().describe("Unique identifier for the processor"),
platform: z.string().describe("Platform associated with the gateway processor"),
emv_support: z.boolean().describe(
"EMV support status; indicates whether the processor supports EMV transactions"
),
mcc: z.number().describe("Merchant category code")
});
var QueryGatewayProcessorsResponseSchema = z.object({
nm_response: z.object({
gateway_processor: z.array(GatewayProcessorSchema).or(GatewayProcessorSchema)
})
});
var QueryMerchantProcessorSchema = z.object({
id: z.string().describe("Processor's unique identifier"),
type: z.string().describe("Processor's type"),
platform: z.string().describe("Processor's platform"),
tap_to_mobile: z.record(z.unknown()).describe("Details related to tap mobile functionality"),
required_fields: z.string().describe("Fields required by the processor"),
currencies: z.record(z.unknown()).or(z.string().array()).describe("Supported currencies by the processor"),
merchant_category_code: z.number().describe("Merchant category code associated with the processor")
});
var QueryProfileResponseSchema = z.object({
nm_response: z.object({
protected: z.boolean().describe("Indicates whether the response is protected"),
is_gateway: z.boolean().describe("Indicates whether the response is related to a gateway"),
merchant: z.object({
company: z.string().describe("Merchant's company name"),
email: z.string().describe("Merchant's email address"),
phone: z.coerce.number().describe("Merchant's phone number"),
url: z.string().describe("Merchant's website URL"),
address1: z.string().describe("Merchant's primary address line"),
address2: z.string().describe("Merchant's secondary address line"),
city: z.string().describe("Merchant's city"),
state: z.string().describe("Merchant's state"),
zip: z.coerce.number().describe("Merchant's ZIP code"),
country: z.string().describe("Merchant's country"),
timezone: z.string().describe("Merchant's timezone"),
card_schemes: z.string().optional().describe("Supported card schemes by the merchant")
}),
gateway: z.object({
company: z.string().describe("Gateway's company name"),
url: z.string().describe("Gateway's website URL"),
email: z.string().describe("Gateway's email address"),
phone: z.coerce.number().describe("Gateway's phone number"),
primary_color: z.string().describe("Gateway's primary color code"),
complimentary_color_1: z.string().describe("Gateway's first complimentary color code"),
complimentary_color_2: z.string().describe("Gateway's second complimentary color code")
}),
merchant_defined_fields: z.array(z.record(z.unknown())).or(z.string()).describe("Merchant-defined fields"),
merchant_favicon: z.string().describe("Merchant's favicon data"),
processors: z.object({
processor: z.union([
z.array(GatewayProcessorSchema),
GatewayProcessorSchema
])
}).optional(),
account_details: z.object({
account_status: z.string().describe("Status of the merchant's account"),
test_mode_enabled: z.boolean().describe(
"Indicates whether test mode is enabled for the merchant's account"
)
})
})
});
var QueryTransactionResponseSchemaBase = z.object({
transaction_id: z.coerce.number(),
platform_id: z.string().nullable(),
transaction_type: z.string(),
condition: z.string(),
order_id: z.string(),
authorization_code: z.coerce.string(),
ponumber: z.string().nullable(),
order_description: z.string().nullable(),
first_name: z.string(),
last_name: z.string(),
address_1: z.string(),
address_2: z.string().nullable(),
company: z.string().nullable(),
city: z.string(),
state: z.string(),
postal_code: z.coerce.number(),
country: z.string(),
email: z.string(),
phone: z.coerce.number(),
fax: z.string().nullable(),
cell_phone: z.string().nullable(),
customertaxid: z.string().nullable(),
customerid: z.string().nullable(),
website: z.string().nullable(),
shipping_first_name: z.string().nullable(),
shipping_last_name: z.string().nullable(),
shipping_address_1: z.string().nullable(),
shipping_address_2: z.string().nullable(),
shipping_company: z.string().nullable(),
shipping_city: z.string().nullable(),