npm install @smartbase-js/raiaccept-api-clientimport { RaiAcceptService, HttpClient } from '@smartbase-js/raiaccept-api-client';
// Initialize client
const httpClient = new HttpClient();
const service = new RaiAcceptService(httpClient, cert, key);
// Authenticate
const authResult = await service.retrieveAccessTokenWithCredentials(
'username',
'password'
);
const accessToken = authResult?.accessToken;
// Step 1: Create order entry
const orderResponse = await service.createOrderEntry(accessToken, orderRequest);
const orderIdentification = orderResponse.object.getOrderIdentification();
// Step 2: Create payment session for the order
const paymentSessionResponse = await service.createPaymentSession(
accessToken,
orderRequest,
orderIdentification
);
const paymentRedirectURL = paymentSessionResponse.object?.paymentRedirectURL;Main API client for interacting with RaiAccept services.
const apiClient = new RaiAcceptAPIApi(httpClient, cert, key);Parameters:
httpClient(HttpClient): HTTP client instance for making requestscert(string | Buffer): Client certificate for mTLSkey(string | Buffer): Client private key for mTLS
Authenticate with username and password.
Parameters:
username(string): Usernamepassword(string): Password
Returns: Promise<ApiResponse<AuthApiLoginOutput>> - Authentication response with access token, refresh token, and expiration times
Example:
const response = await apiClient.token('username', 'password');
const authResult = response.object;
const accessToken = authResult?.accessToken;
const refreshToken = authResult?.refreshToken;
const accessTokenExpiresIn = authResult?.accessTokenExpiresIn;
const refreshTokenExpiresIn = authResult?.refreshTokenExpiresIn;Logout with refresh token. Uses AUTH_URL; cert and key not required.
Parameters:
token(string): Refresh token to logout
Returns: Promise<boolean> - True if logout successful (HTTP 200), false otherwise
Example:
const success = await apiClient.tokenLogout(refreshToken);Create a new order entry.
Parameters:
accessToken(string): Bearer token for authenticationcreateOrderRequest(Object): Order request object
Returns: Promise<Object> - Order creation response
Example:
const orderRequest = {
invoice: {
amount: 100.00,
currency: 'EUR',
description: 'Payment description',
merchantOrderReference: 'ORDER-123',
items: [...]
},
urls: {
successUrl: 'https://example.com/success',
failUrl: 'https://example.com/fail',
cancelUrl: 'https://example.com/cancel'
},
consumer: { ... },
paymentMethodPreference: 'CARD',
linkId: 'unique-link-id'
};
// Step 1: Create order entry
const orderResponse = await apiClient.createOrderEntry(accessToken, orderRequest);
const orderIdentification = orderResponse.object.getOrderIdentification();
// Step 2: Create payment session for the order (see createPaymentSession method below)Create payment session for an existing order. Note: This must be called after createOrderEntry to complete the payment flow.
Parameters:
accessToken(string): Bearer tokenpaymentSessionRequest(Object): Payment session configurationexternalOrderId(string): External order identifier
Returns: Promise<Object> - Payment session response with checkout URL
Example:
// After creating an order entry (see createOrderEntry example above)
const paymentSessionResponse = await apiClient.createPaymentSession(
accessToken,
orderRequest, // Use the same request object from createOrderEntry
orderIdentification // The order ID from createOrderEntry response
);
const paymentRedirectURL = paymentSessionResponse.object?.paymentRedirectURL;
const sessionId = paymentSessionResponse.object?.sessionId;
console.log('Redirect customer to:', paymentRedirectURL);Retrieve details for a specific order.
Parameters:
accessToken(string): Bearer tokenorderId(string): Order identifier
Returns: Promise<Object> - Order details
Example:
const response = await apiClient.getOrderDetails(accessToken, 'order-123');
const status = response.object.getStatus();Get all transactions for an order.
Parameters:
accessToken(string): Bearer tokenorderId(string): Order identifier
Returns: Promise<Object> - List of transactions
Example:
const response = await apiClient.getOrderTransactions(accessToken, 'order-123');
const transactions = response.object.transactions;Get details for a specific transaction.
Parameters:
accessToken(string): Bearer tokenorderId(string): Order identifiertransactionId(string): Transaction identifier
Returns: Promise<Object> - Transaction details
Process a refund for a transaction.
Parameters:
accessToken(string): Bearer tokenorderId(string): Order identifiertransactionId(string): Transaction identifierrefundRequest(Object): Refund details
Returns: Promise<Object> - Refund response
Example:
const refundRequest = {
amount: 50.00,
currency: 'EUR'
};
const response = await apiClient.refund(
accessToken,
'order-123',
'txn-456',
refundRequest
);Returns array of statuses indicating successful payment: ['PAID', 'SUCCESS']
Returns array of statuses indicating failed payment: ['FAILED']
Returns array of statuses indicating cancelled payment: ['CANCELED', 'ABANDONED']
Returns array of all rejected statuses: ['FAILED', 'CANCELED', 'ABANDONED']
Transliterate non-Latin characters to Latin equivalents.
Example:
const result = RaiAcceptService.transliterate('Γεια σου');
// Result: "Geia sou"Transliterate and limit string length.
Example:
const result = RaiAcceptService.transliterateAndLimitLength('Very long text...', 50);Clean and format phone number.
Example:
const cleaned = RaiAcceptService.cleanPhoneNumber('+1 (234) 567-8900');
// Result: "+12345678900"Convert 2-letter country code to 3-letter ISO code.
Example:
const iso3 = RaiAcceptService.getCountryIso3('US');
// Result: "USA"All models support fromObject(data) static method for deserialization.
{
addressStreet1: string,
addressStreet2: string,
addressStreet3: string,
city: string,
country: string,
firstName: string,
lastName: string,
postalCode: string,
state: string
}{
email: string,
firstName: string,
ipAddress: string,
lastName: string,
mobilePhone: string,
phone: string,
workPhone: string
}{
amount: number,
currency: string,
description: string,
items: InvoiceItem[],
merchantOrderReference: string // must be unique for merchant
}{
description: string,
numberOfItems: number,
price: number
}{
successUrl: string,
failUrl: string,
cancelUrl: string,
notificationUrl: string|null
}{
transactionId: string,
transactionAmount: number,
transactionCurrency: string,
isProduction: boolean,
transactionType: string, // 'PURCHASE' or 'REFUND'
paymentMethod: string,
status: string,
statusCode: string,
statusMessage: string,
createdOn: string,
updatedOn: string
}Utility class for serialization and deserialization.
sanitizeForSerialization(data)- Prepare data for API transmissiontoPathValue(value)- URL-encode value for path parameterstoString(value)- Convert value to stringdeserialize(data, modelClass)- Deserialize JSON to model instance
Thrown when API requests fail.
Properties:
message(string): Error messagestatusCode(number): HTTP status codeheaders(Object): Response headersbody(string): Response bodyresponseObject(Object): Parsed response object
Example:
try {
// Step 1: Create order entry
const orderResponse = await apiClient.createOrderEntry(accessToken, orderRequest);
const orderIdentification = orderResponse.object.getOrderIdentification();
// Step 2: Create payment session
const paymentSessionResponse = await apiClient.createPaymentSession(
accessToken,
orderRequest,
orderIdentification
);
} catch (error) {
if (error instanceof ApiException) {
console.error('API Error:', error.statusCode, error.message);
console.error('Response:', error.body);
}
}Thrown when required parameters are missing or invalid.
Example:
try {
const response = await apiClient.getOrderDetails(null, 'order-123');
} catch (error) {
if (error instanceof InvalidArgumentException) {
console.error('Invalid argument:', error.message);
}
}RaiAcceptAPIApi.ACCEPTED_LANGUAGES
// ['en', 'de', 'fr', 'cs', 'sk', 'sr', 'al', 'ro', 'pl', 'hr']See examples/basic-usage.js for a complete working example.