Implement PayPal fallback for registration payment process and update localization for fallback option (changes button). TODO still need to get fallback working properly in regards to the payment buttons.

This commit is contained in:
Jonathan Rosenbaum 2026-01-31 19:05:30 +00:00
parent 1ce328511a
commit f8b504827c
6 changed files with 60 additions and 5 deletions

View File

@ -32,7 +32,6 @@ 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.each do |step|

View File

@ -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|
- 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

View File

@ -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

View File

@ -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

View File

@ -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':

View File

@ -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