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
# File 'app/controllers/spree/api/v3/admin/payment_methods_controller.rb', line 22

def types
  authorize! :create, model_class

  installed_class_names = current_store.payment_methods.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