@smartbase-js/raiaccept-api-client
v0.9.4
Published
TypeScript SDK for RaiAccept payment gateway API
Readme
RaiAccept TypeScript SDK
TypeScript/JavaScript SDK for RaiAccept payment gateway API.
Installation
npm install @smartbase-js/raiaccept-api-clientUsage
import { RaiAcceptService } from '@smartbase-js/raiaccept-api-client';
// Create service instance
const service = new RaiAcceptService();
// Authenticate with your credentials
const authResult = await service.retrieveAccessTokenWithCredentials(
'your-username', // Replace with your actual username
'your-password', // Replace with your actual password
cert, // Client certificate for mTLS
key // Client private key for mTLS
);
const accessToken = authResult?.accessToken;
const response = await service.createOrderEntry(accessToken, orderRequest);Create Payment
import { RaiAcceptService, HttpClient } from '@smartbase-js/raiaccept-api-client';
// Initialize HTTP client (optional, for logging)
const httpClient = new HttpClient({
logger: console, // Optional: for debugging
});
// Initialize the unified SDK client
const service = new RaiAcceptService(httpClient);
// Authenticate
const authResult = await service.retrieveAccessTokenWithCredentials(
'your-username',
'your-password',
cert, // Client certificate for mTLS
key // Client private key for mTLS
);
const accessToken = authResult?.accessToken;
// Create an order and payment session (two-step process)
const orderRequest = {
invoice: {
amount: 100.00,
currency: 'EUR',
description: 'Test payment',
merchantOrderReference: 'ORDER-123',
items: [
{
description: 'Product 1',
numberOfItems: 1,
price: 100.00
}
]
},
urls: {
successUrl: 'https://example.com/success',
failUrl: 'https://example.com/fail',
cancelUrl: 'https://example.com/cancel',
notificationUrl: 'https://example.com/webhook'
},
consumer: {
email: '[email protected]',
firstName: 'John',
lastName: 'Doe',
phone: '+1234567890'
},
paymentMethodPreference: 'CARD',
linkId: 'unique-link-id'
};
// Step 1: Create order entry
const orderResponse = await service.createOrderEntry(accessToken, orderRequest);
const orderIdentification = orderResponse.object.getOrderIdentification();
console.log('Order created:', orderIdentification);
// Step 2: Create payment session for the order
const paymentSessionResponse = await service.createPaymentSession(
accessToken,
orderRequest,
orderIdentification
);
const paymentRedirectURL = paymentSessionResponse.object?.paymentRedirectURL;
console.log('Payment session created. Redirect customer to:', paymentRedirectURL);API Reference
Initialization
import { RaiAcceptService, HttpClient } from '@smartbase-js/raiaccept-api-client';
// With HTTP client (recommended for logging)
const httpClient = new HttpClient({ logger: console });
const client = new RaiAcceptService(httpClient);
// Without HTTP client (uses default)
const client = new RaiAcceptService();Authentication
const authResult = await client.retrieveAccessTokenWithCredentials(
username,
password,
cert, // Client certificate for mTLS
key // Client private key for mTLS
);
const accessToken = authResult?.accessToken;
// Also available: authResult.refreshToken, authResult.accessTokenExpiresIn, authResult.refreshTokenExpiresInOrder Operations
client.createOrderEntry(accessToken, orderRequest)- Create a new orderclient.createPaymentSession(accessToken, sessionRequest, externalOrderId)- Create payment sessionclient.getOrderDetails(accessToken, orderId)- Get order detailsclient.getOrderTransactions(accessToken, orderId)- Get order transactions
Transaction Operations
client.getTransactionDetails(accessToken, orderId, transactionId)- Get transaction detailsclient.refund(accessToken, orderId, transactionId, refundRequest)- Process a refund
Utility Functions
RaiAcceptService.transliterate(string)- Transliterate non-Latin charactersRaiAcceptService.transliterateAndLimitLength(string, limit)- Transliterate and limit lengthRaiAcceptService.cleanPhoneNumber(phoneNumber)- Clean phone number formatRaiAcceptService.getCountryIso3(countryCode)- Convert 2-letter to 3-letter country code
TypeScript Support
This SDK is written in TypeScript and includes full type definitions. All types are exported and available for use in your TypeScript projects.
Testing
Run the test suite:
# Run unit tests (mocked)
npm run unit-tests
# Run integration tests (real API calls!)
npm run integration-testsFor more details, see TEST_SETUP.md and tests/README.md.
License
OSL-3.0
