feat: Prepare to use Stripe a checkout component

This commit is contained in:
kbe
2025-08-30 14:57:33 +02:00
parent 055640b73e
commit 476438c5c4
9 changed files with 294 additions and 42 deletions

View File

@@ -6,4 +6,7 @@ module ApplicationHelper
# Include flash message helpers
include FlashMessagesHelper
# Include Stripe helper
include StripeHelper
end

View File

@@ -0,0 +1,32 @@
module StripeHelper
# Check if Stripe is properly configured
def stripe_configured?
Rails.application.config.stripe[:secret_key].present?
end
# Initialize Stripe with the configured API key
def initialize_stripe
return false unless stripe_configured?
Stripe.api_key = Rails.application.config.stripe[:secret_key]
true
rescue => e
Rails.logger.error "Failed to initialize Stripe: #{e.message}"
false
end
# Safely call Stripe methods with error handling
def safe_stripe_call(&block)
return nil unless stripe_configured?
# Initialize Stripe if not already done
initialize_stripe unless Stripe.api_key.present?
begin
yield if block_given?
rescue Stripe::StripeError => e
Rails.logger.error "Stripe Error: #{e.message}"
nil
end
end
end