Class: Spree::Api::V2::Tenant::PinCodeGeneratorsController
- Inherits:
-
BaseController
- Object
- ResourceController
- BaseController
- Spree::Api::V2::Tenant::PinCodeGeneratorsController
show all
- Defined in:
- app/controllers/spree/api/v2/tenant/pin_code_generators_controller.rb
Instance Method Summary
collapse
#render_serialized_payload, #require_tenant, #scope
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
|
# File 'app/controllers/spree/api/v2/tenant/pin_code_generators_controller.rb', line 23
def create
context = SpreeCmCommissioner::PinCodeGenerator.call(pin_code_attrs)
if context.success?
render_serialized_payload(201) { serialize_resource(context.pin_code) }
else
render_error_payload(context.message, 400)
end
end
|
#pin_code_attrs ⇒ Object
43
44
45
|
# File 'app/controllers/spree/api/v2/tenant/pin_code_generators_controller.rb', line 43
def pin_code_attrs
params.slice(:phone_number, :email, :type)
end
|
#resource_serializer ⇒ Object
#serialize_resource(resource) ⇒ Object
33
34
35
36
37
|
# File 'app/controllers/spree/api/v2/tenant/pin_code_generators_controller.rb', line 33
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/tenant/pin_code_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.message, 400)
end
|