Checking a Spree Promotion Coupon from an External API

I want to apply a coupon to my spree application, but the coupon needs to be verified from an external API

I searched in the documents as well as in the textbooks, but I did not find anything that could help me.

A requirement is something like this:

  • I sell a product, and I want to give a 10% discount to members of an organization.

  • On the payment page, the user enters their email address, and I want to check that the email from the API is provided by the organization

I mean it right now

1. Promotions

EDIT:

I am currently studying promotion rules and advertising manipulators

+4
source share
1 answer

. app/models/spree/promotion/rules/organisational_user.rb,

module Spree
  class Promotion
    module Rules
      class OrganisationalUser < PromotionRule
        def applicable?(promotable)
          promotable.is_a?(Spree::Order)
        end

        def eligible?(order, options = {})
          # hit external API to verify user existence
        end
      end
    end
  end
end

, spree.rb,

Rails.application.config.after_initialize do
  Rails.application.config.spree.promotions.rules << Spree::Promotion::Rules::OrganisationalUser
end

. . .

+1

Source: https://habr.com/ru/post/1665101/


All Articles