Class: SpreeLoyalty::LoyaltyAccountController

Inherits:
Spree::Api::V3::Store::BaseController
  • Object
show all
Defined in:
app/controllers/spree_loyalty/loyalty_account_controller.rb

Overview

Small custom Store API surface (mirrors Spree::Api::V3::Store::WishlistsController's own require_authentication!/current_user shape — a loyalty account is a user-scoped resource the same way a wishlist is). The storefront never touches SpreeLoyalty::Account/Transaction directly, only through these two actions.

Instance Method Summary collapse

Instance Method Details

#redeemObject

POST /api/v3/store/loyalty_account/redeem



17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/spree_loyalty/loyalty_account_controller.rb', line 17

def redeem
   = 
  .save! if .new_record?

  store_credit = SpreeLoyalty::Redemption.call(account: , points: params[:points])
  render json: (.reload).merge(
    store_credit: { amount: store_credit.amount, currency: store_credit.currency }
  )
rescue SpreeLoyalty::Redemption::Error => e
  render json: { error: e.message }, status: :unprocessable_entity
end

#showObject

GET /api/v3/store/loyalty_account



11
12
13
14
# File 'app/controllers/spree_loyalty/loyalty_account_controller.rb', line 11

def show
   = 
  render json: ()
end