Class: Spree::Api::V3::Admin::PaymentMethodsController

Inherits:
ResourceController show all
Includes:
SubclassedResource
Defined in:
app/controllers/spree/api/v3/admin/payment_methods_controller.rb

Constant Summary

Constants included from ScopedAuthorization

ScopedAuthorization::READ_ACTIONS

Constants inherited from BaseController

BaseController::RATE_LIMIT_RESPONSE

Constants included from Idempotent

Idempotent::IDEMPOTENCY_HEADER, Idempotent::IDEMPOTENCY_TTL, Idempotent::MAX_KEY_LENGTH, Idempotent::MUTATING_METHODS

Constants included from ErrorHandler

ErrorHandler::ERROR_CODES

Constants included from JwtAuthentication

JwtAuthentication::JWT_AUDIENCE_ADMIN, JwtAuthentication::JWT_AUDIENCE_STORE, JwtAuthentication::JWT_ISSUER, JwtAuthentication::USER_TYPE_ADMIN, JwtAuthentication::USER_TYPE_CUSTOMER

Instance Method Summary collapse

Methods included from SubclassedResource

#create, #update

Methods inherited from ResourceController

#create, #destroy, #index, #show, #update

Methods included from Spree::Api::V3::ApiKeyAuthentication

#authenticate_api_key!, #authenticate_secret_key!

Methods included from JwtAuthentication

#authenticate_user, #require_authentication!

Instance Method Details

#typesObject

Lists available payment provider subclasses for the create form. Returns: { data: [{ type, label, description, preference_schema }] }. The preference_schema array describes the provider-specific configuration fields, so admin UIs can render a generic preferences form without hard-coding per-provider knowledge. Filters out subclasses already installed in the current store —mirrors the legacy admin’s “available_payment_methods” helper, so admins don’t see (and accidentally double-install) the same provider twice.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/spree/api/v3/admin/payment_methods_controller.rb', line 22

def types
  authorize! :create, model_class

  # Query via direct join rather than `current_store.payment_methods`
  # — the has_many-through association can cache stale results when
  # `current_store` was loaded earlier in the request (e.g. by the
  # auth layer).
  installed_class_names = Spree::PaymentMethod
                            .joins(:store_payment_methods)
                            .where(spree_payment_methods_stores: { store_id: current_store.id })
                            .pluck(:type)
  installed_shorthands = installed_class_names.filter_map do |name|
    name.safe_constantize&.api_type
  end
  available = model_class.subclasses_with_preference_schema.reject do |entry|
    installed_shorthands.include?(entry[:type])
  end

  render json: { data: available }
end