Class: Spree::Api::V2::Storefront::PinCodeOtpGeneratorsController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Spree::Api::V2::Storefront::PinCodeOtpGeneratorsController
- Defined in:
- app/controllers/spree/api/v2/storefront/pin_code_otp_generators_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
:phone_number, :email, :type, :recaptcha_token, :recaptcha_action, :recaptcah_site_key.
- #otp_attrs ⇒ Object
- #resource_serializer ⇒ Object
- #serialize_resource(resource) ⇒ Object
- #validate_recaptcha ⇒ Object
Instance Method Details
#create ⇒ Object
:phone_number, :email, :type, :recaptcha_token, :recaptcha_action, :recaptcah_site_key
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/spree/api/v2/storefront/pin_code_otp_generators_controller.rb', line 23 def create = otp_attrs [:type] = 'SpreeCmCommissioner::PinCodeOtp' context = SpreeCmCommissioner::PinCodeGenerator.call() if context.success? render_serialized_payload(201) { serialize_resource(context.pin_code) } else render_error_payload(context., 400) end end |
#otp_attrs ⇒ Object
46 47 48 |
# File 'app/controllers/spree/api/v2/storefront/pin_code_otp_generators_controller.rb', line 46 def otp_attrs params.slice(:phone_number, :email) end |
#resource_serializer ⇒ Object
42 43 44 |
# File 'app/controllers/spree/api/v2/storefront/pin_code_otp_generators_controller.rb', line 42 def resource_serializer SpreeCmCommissioner::V2::Storefront::PinCodeSerializer end |
#serialize_resource(resource) ⇒ Object
36 37 38 39 40 |
# File 'app/controllers/spree/api/v2/storefront/pin_code_otp_generators_controller.rb', line 36 def serialize_resource(resource) resource_serializer.new( resource ).serializable_hash end |
#validate_recaptcha ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/spree/api/v2/storefront/pin_code_otp_generators_controller.rb', line 8 def validate_recaptcha return unless ENV['RECAPTCHA_TOKEN_VALIDATOR_ENABLE'] == 'yes' context = SpreeCmCommissioner::RecaptchaTokenValidator.call( token: params[:recaptcha_token], action: params[:recaptcha_action], site_key: params[:recaptcah_site_key] ) return if context.success? render_error_payload(context., 400) end |