shora-ai-payment-sdk
Version:
The first open-source payment SDK designed specifically for AI agents and chatbots - ACP Compatible
88 lines (87 loc) • 3.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PaymentService = void 0;
const retry_logic_1 = require("./retry-logic");
const error_handling_1 = require("./error-handling");
class PaymentService {
constructor(client) {
this.client = client;
this.circuitBreaker = new retry_logic_1.CircuitBreaker();
}
async createPaymentSession(request, options) {
return (0, retry_logic_1.withRetry)(async () => this.circuitBreaker.execute(async () => {
const headers = {};
if (options?.idempotencyKey)
headers['Idempotency-Key'] = options.idempotencyKey;
const response = await this.client.post('/v2/payments/sessions', request, { headers });
return response.data;
}));
}
async processPayment(sessionId, paymentMethod, cardToken) {
return (0, retry_logic_1.withRetry)(async () => this.circuitBreaker.execute(async () => {
const response = await this.client.post('/v2/payments/process', { sessionId, paymentMethod, cardToken });
return response.data;
}));
}
async createACPCheckout(request) {
try {
const response = await this.client.post('/v2/acp/checkout', request);
return response.data;
}
catch (error) {
throw (0, error_handling_1.parseError)(error);
}
}
async healthCheck() {
try {
const response = await this.client.get('/v2/test/health');
return response.data;
}
catch (error) {
throw (0, error_handling_1.parseError)(error);
}
}
async createCheckoutIntent(request, options) {
return (0, retry_logic_1.withRetry)(async () => this.circuitBreaker.execute(async () => {
const headers = {};
if (options?.idempotencyKey)
headers['Idempotency-Key'] = options.idempotencyKey;
const response = await this.client.post('/v1/acp/checkout-intent', request, { headers });
return response.data;
}));
}
async confirmCheckout(request, options) {
return (0, retry_logic_1.withRetry)(async () => this.circuitBreaker.execute(async () => {
const headers = {};
if (options?.idempotencyKey)
headers['Idempotency-Key'] = options.idempotencyKey;
const response = await this.client.post('/v1/acp/checkout-confirm', request, { headers });
return response.data;
}));
}
async getPaymentSession(sessionId) {
return (0, retry_logic_1.withRetry)(async () => this.circuitBreaker.execute(async () => {
const response = await this.client.get(`/v2/payments/sessions/${sessionId}`);
return response.data;
}));
}
async getReceipt(receiptId) {
try {
const response = await this.client.get(`/v1/acp/receipts/${receiptId}`);
return response.data;
}
catch (error) {
throw (0, error_handling_1.parseError)(error);
}
}
async getSupportedMethods() {
try {
const response = await this.client.get('/v1/acp/supported-methods');
return response.data;
}
catch (error) {
throw (0, error_handling_1.parseError)(error);
}
}
}
exports.PaymentService = PaymentService;