diff --git a/app/helpers/registration_helper.rb b/app/helpers/registration_helper.rb index 5880f23..89fe59a 100644 --- a/app/helpers/registration_helper.rb +++ b/app/helpers/registration_helper.rb @@ -32,8 +32,7 @@ module RegistrationHelper steps -= [:hosting] end - steps -= [:payment] unless registration.conference.paypal_email_address.present? && registration.conference.paypal_username.present? && registration.conference.paypal_password.present? && registration.conference.paypal_signature.present? - steps -= [:payment, :workshops] if registration.is_attending == 'n' + steps -= [:payment, :workshops] if registration.is_attending == 'n' steps.each do |step| # disable the step if we've already found an incomplete step diff --git a/app/views/registration_steps/_payment_type.html.haml b/app/views/registration_steps/_payment_type.html.haml index fe2d7b1..f974d92 100644 --- a/app/views/registration_steps/_payment_type.html.haml +++ b/app/views/registration_steps/_payment_type.html.haml @@ -4,7 +4,13 @@ = save_registration_step do .vertical-registration-step-options .options + - paypal_configured = @this_conference.paypal_email_address.present? && @this_conference.paypal_username.present? && @this_conference.paypal_password.present? && @this_conference.paypal_signature.present? - @payment_methods.each do |option| - - class_name = [:unstyled] - - class_name << :selected if @payment_method.present? && @payment_method.to_sym == option - = button "payment_#{option}".to_sym, value: option, class: class_name + - if !paypal_configured && option.to_sym == :paypal + - class_name = [:unstyled] + - class_name << :selected if @payment_method.present? && @payment_method.to_sym == option + = button "payment_paypal_fallback".to_sym, value: option, class: class_name + - elsif option.to_sym != :paypal || paypal_configured + - class_name = [:unstyled] + - class_name << :selected if @payment_method.present? && @payment_method.to_sym == option + = button "payment_#{option}".to_sym, value: option, class: class_name diff --git a/config/initializers/paypal_fallback.rb b/config/initializers/paypal_fallback.rb new file mode 100644 index 0000000..86388b2 --- /dev/null +++ b/config/initializers/paypal_fallback.rb @@ -0,0 +1,47 @@ +# Monkey-patch for bikecollectives_core gem to gracefully handle missing PayPal credentials +# This allows the payment flow to work without PayPal configured +if defined?(RegistrationControllerHelper) + module PayPalFallback + def paypal_configured?(conference) + conference.paypal_email_address.present? && + valid_paypal_credential?(conference.paypal_username) && + valid_paypal_credential?(conference.paypal_password) && + valid_paypal_credential?(conference.paypal_signature) + end + def valid_paypal_credential?(value) + value.present? && value.strip.present? + end + def payment_type_step_update(registration, params) + conference = registration.conference + payment_type = params[:value].try(:to_sym) + if !paypal_configured?(conference) && payment_type == :paypal + registration.data ||= {} + registration.data['payment_method'] = 'paypal' + registration.save! + return { status: :complete } + end + super + end + def payment_form_step_update(registration, params) + conference = registration.conference + username = conference.paypal_username + password = conference.paypal_password + signature = conference.paypal_signature + unless valid_paypal_credential?(username) && valid_paypal_credential?(password) && valid_paypal_credential?(signature) + Rails.logger.warn "[PayPalFallback] Missing or invalid PayPal credentials for conference #{conference.id}. Username: #{username.present?}, Password: #{password.present?}, Signature: #{signature.present?}" + value = (params[:value] || params[:custom_value] || 0).to_f + currency = conference.default_currency + registration.data ||= {} + registration.data['payment_amount'] = value + registration.payment_info = { + amount: value, + currency: currency + }.to_yaml + registration.save! + return { status: :complete } + end + super + end + end + RegistrationControllerHelper.prepend(PayPalFallback) +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 3facd0c..064e761 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2441,6 +2441,7 @@ en: cancel_registration: Cancel my registration organization_none: None of the above payment_paypal: I can pay now online + payment_paypal_fallback: I can pay via host provided link payment_on_arrival: I can pledge to pay on arrival payment_none: Not now food_meat: I eat meat and dairy diff --git a/config/locales/es.yml b/config/locales/es.yml index e5b0ecc..a606f78 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -2011,6 +2011,7 @@ es: payment_none: Por ahora no payment_on_arrival: Puedo comprometerme a pagar a mi llegada payment_paypal: Puedo pagar ahora con Paypal + payment_paypal_fallback: Puedo pagar mediante un enlace proporcionado por el anfitrión reopen_registration: Re-abrir mi registro review: Revisar 'yes': Sí diff --git a/config/locales/fr.yml b/config/locales/fr.yml index fedcb8f..ff0d6b0 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1850,6 +1850,7 @@ fr: 'no': Non maybe: Peut-être payment_paypal: Je peux payer à l'instant avec Paypal + payment_paypal_fallback: Je peux payer via un lien fourni par l'hôte food_vegan: Je suis végétalien food_vegetarian: Je suis végétarien food_meat: Je mange de la viande et des produits laitiers