Files
the_order/packages/payment-gateway/src/stripe.js
defiQUG 2633de4d33 feat(eresidency): Complete eResidency service implementation
- Implement credential revocation endpoint with proper database integration
- Fix database row mapping (snake_case to camelCase) for eResidency applications
- Add missing imports (getRiskAssessmentEngine, VeriffKYCProvider, ComplyAdvantageSanctionsProvider)
- Fix environment variable type checking for Veriff and ComplyAdvantage providers
- Add required 'message' field to notification service calls
- Fix risk assessment type mismatches
- Update audit logging to use 'verified' action type (supported by schema)
- Resolve all TypeScript errors and unused variable warnings
- Add TypeScript ignore comments for placeholder implementations
- Temporarily disable security/detect-non-literal-regexp rule due to ESLint 9 compatibility
- Service now builds successfully with no linter errors

All core functionality implemented:
- Application submission and management
- KYC integration (Veriff placeholder)
- Sanctions screening (ComplyAdvantage placeholder)
- Risk assessment engine
- Credential issuance and revocation
- Reviewer console
- Status endpoints
- Auto-issuance service
2025-11-10 19:43:02 -08:00

70 lines
2.7 KiB
JavaScript

/**
* Stripe payment gateway integration
*/
import Stripe from 'stripe';
import { getEnv } from '@the-order/shared';
export class StripePaymentGateway {
stripe;
constructor() {
const env = getEnv();
const apiKey = env.PAYMENT_GATEWAY_API_KEY;
if (!apiKey) {
throw new Error('PAYMENT_GATEWAY_API_KEY is required');
}
this.stripe = new Stripe(apiKey, {
apiVersion: '2023-10-16',
});
}
async createPaymentIntent(amount, currency, paymentMethod, metadata) {
const paymentIntent = await this.stripe.paymentIntents.create({
amount: Math.round(amount * 100), // Convert to cents
currency: currency.toLowerCase(),
payment_method_types: [paymentMethod === 'credit_card' ? 'card' : paymentMethod],
metadata,
});
return {
id: paymentIntent.id,
amount: paymentIntent.amount / 100,
currency: paymentIntent.currency.toUpperCase(),
status: paymentIntent.status,
client_secret: paymentIntent.client_secret || undefined,
};
}
async confirmPayment(paymentIntentId) {
const paymentIntent = await this.stripe.paymentIntents.retrieve(paymentIntentId);
return {
success: paymentIntent.status === 'succeeded',
transactionId: paymentIntent.id,
status: paymentIntent.status,
gatewayResponse: paymentIntent,
};
}
async processPayment(amount, currency, paymentMethod, metadata) {
const paymentIntent = await this.createPaymentIntent(amount, currency, paymentMethod, metadata);
// For immediate payment, confirm the intent
if (paymentIntent.status === 'requires_payment_method') {
const confirmed = await this.stripe.paymentIntents.confirm(paymentIntent.id);
return {
success: confirmed.status === 'succeeded',
transactionId: confirmed.id,
status: confirmed.status,
gatewayResponse: confirmed,
};
}
return {
success: paymentIntent.status === 'succeeded',
transactionId: paymentIntent.id,
status: paymentIntent.status,
gatewayResponse: paymentIntent,
};
}
async verifyWebhook(payload, signature) {
const env = getEnv();
const webhookSecret = env.PAYMENT_GATEWAY_WEBHOOK_SECRET;
if (!webhookSecret) {
throw new Error('PAYMENT_GATEWAY_WEBHOOK_SECRET is required for webhook verification');
}
return this.stripe.webhooks.constructEvent(payload, signature, webhookSecret);
}
}
//# sourceMappingURL=stripe.js.map