"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StripeGateway = void 0;
class StripeGateway {
    secretKey;
    constructor(config) {
        this.secretKey = config?.keySecret || process.env.STRIPE_SECRET_KEY || 'mock_stripe_secret_key';
    }
    async createOrder(order) {
        const sessionOrderId = `st_ord_${Date.now()}`;
        return {
            id: order.id,
            gatewayOrderId: sessionOrderId,
            amount: Number(order.grandTotal),
            currency: 'INR',
            status: 'CREATED',
        };
    }
    async createCheckout(checkout) {
        return {
            checkoutUrl: `https://checkout.stripe.com/pay/${checkout.gatewayOrderId}`,
            gatewayTransactionId: checkout.gatewayOrderId,
        };
    }
    async verifyPayment(payload) {
        const isSuccess = payload.status === 'succeeded' || payload.status === 'success';
        return {
            success: isSuccess,
            status: isSuccess ? 'SUCCESS' : 'FAILED',
            gatewayPaymentId: payload.payment_intent || `pi_${Date.now()}`,
            gatewayTransactionId: payload.id,
            message: 'Stripe checkout verified status',
            rawResponse: payload,
        };
    }
    async capturePayment(paymentId, amount) {
        return {
            success: true,
            gatewayPaymentId: paymentId,
            amount,
            status: 'SUCCESS',
        };
    }
    async refundPayment(transactionId, amount, reason) {
        const refundId = `re_${Date.now()}`;
        return {
            success: true,
            gatewayRefundId: refundId,
            amount,
            status: 'SUCCESS',
        };
    }
    async paymentStatus(transactionId) {
        return {
            status: 'SUCCESS',
            gatewayTransactionId: transactionId,
        };
    }
    async handleCallback(payload) {
        return this.verifyPayment(payload);
    }
    async handleWebhook(payload, signature) {
        // Signature checking logic
        const event = payload.type;
        const session = payload.data?.object;
        let status = 'PENDING';
        if (event === 'checkout.session.completed' || event === 'payment_intent.succeeded') {
            status = 'SUCCESS';
        }
        else if (event === 'payment_intent.payment_failed') {
            status = 'FAILED';
        }
        return {
            event,
            orderId: session?.metadata?.orderId || session?.id,
            paymentId: session?.payment_intent || session?.id,
            status,
        };
    }
    async generateReceipt(paymentId) {
        return { receiptUrl: `https://stripe.com/receipt/${paymentId}` };
    }
    async cancelPayment(paymentId) {
        return { success: true };
    }
}
exports.StripeGateway = StripeGateway;
//# sourceMappingURL=stripe.gateway.js.map