Class: SpreeLoyalty::LoyaltyAccountController
- Inherits:
-
Spree::Api::V3::Store::BaseController
- Object
- Spree::Api::V3::Store::BaseController
- SpreeLoyalty::LoyaltyAccountController
- 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
-
#redeem ⇒ Object
POST /api/v3/store/loyalty_account/redeem.
-
#show ⇒ Object
GET /api/v3/store/loyalty_account.
Instance Method Details
#redeem ⇒ Object
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 account = find_or_initialize_account account.save! if account.new_record? store_credit = SpreeLoyalty::Redemption.call(account: account, points: params[:points]) render json: account_json(account.reload).merge( store_credit: { amount: store_credit.amount, currency: store_credit.currency } ) rescue SpreeLoyalty::Redemption::Error => e render json: { error: e. }, status: :unprocessable_entity end |
#show ⇒ Object
GET /api/v3/store/loyalty_account
11 12 13 14 |
# File 'app/controllers/spree_loyalty/loyalty_account_controller.rb', line 11 def show account = find_or_initialize_account render json: account_json(account) end |