I want to apply a coupon to my spree application but the coupon should be verified from an external API
I searched through the docs as well as tutorials but I haven't found anything which can help me
The requirement is something like this:
I am selling a product and I want to give a discount of 10% to members of some organization.
On payment page, the user will enter his email address and I want to verify that email from API provided by organization
I am referring this right now
1 . Promotions
EDIT:
I am currently looking into Promotion rules and Promotion Handlers
Registering a New Rule
Promotion Handler - Coupon
You can create a new user rule.
In 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
Register this rule,
In spree.rb
,
Rails.application.config.after_initialize do
Rails.application.config.spree.promotions.rules << Spree::Promotion::Rules::OrganisationalUser
end
Then add requisite view files and translation for this rule. And that should be it. Now you can use that rule in conjunction with any other rule and action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With