feat: integrate Stripe payment with bugfixes and active timeout cancellation
- Add Stripe payment provider with Checkout Session flow - Payment provider abstraction layer (EasyPay + Stripe unified interface) - Stripe webhook with proper raw body handling and signature verification - Frontend: Stripe button with URL validation, anti-duplicate click, noopener - Active timeout cancellation: query platform before expiring, recover paid orders - Singleton Stripe client, idempotency keys, Math.round for amounts - Handle async_payment events, return null for unknown webhook events - Set Checkout Session expires_at aligned with order timeout - Add cancelPayment to provider interface (Stripe: sessions.expire, EasyPay: no-op) - Enable stripe in frontend payment type list
This commit is contained in:
29
src/lib/payment/registry.ts
Normal file
29
src/lib/payment/registry.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { PaymentProvider, PaymentType } from './types';
|
||||
|
||||
export class PaymentProviderRegistry {
|
||||
private providers = new Map<PaymentType, PaymentProvider>();
|
||||
|
||||
register(provider: PaymentProvider): void {
|
||||
for (const type of provider.supportedTypes) {
|
||||
this.providers.set(type, provider);
|
||||
}
|
||||
}
|
||||
|
||||
getProvider(type: PaymentType): PaymentProvider {
|
||||
const provider = this.providers.get(type);
|
||||
if (!provider) {
|
||||
throw new Error(`No payment provider registered for type: ${type}`);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
hasProvider(type: PaymentType): boolean {
|
||||
return this.providers.has(type);
|
||||
}
|
||||
|
||||
getSupportedTypes(): PaymentType[] {
|
||||
return Array.from(this.providers.keys());
|
||||
}
|
||||
}
|
||||
|
||||
export const paymentRegistry = new PaymentProviderRegistry();
|
||||
Reference in New Issue
Block a user