Skip to content

solidusio-contrib/solidus_virtual_gift_card

Repository files navigation

Solidus - Virtual Gift Card

CircleCI

A virtual gift card implementation for Solidus.

  • Allows setup of virtual gift card products that get unique codes upon purchase.
  • The virtual gift card codes can be used to add store credit to a user's account.

Installation

In your Gemfile:

gem "solidus_virtual_gift_card"

Bundle your dependencies and run the installation generator:

bundle install
bundle exec rails g solidus_virtual_gift_card:install

Use Gift Card during Checkout

  1. Visit /admin/payment_methods and add the Gift Card payment method. It should not be available to Users or Admins.
  2. During checkout, you can call the API POST /api/orders/:order_id/gift_card_codes(.:format) to add gift card codes to the order.
  3. At the finalization step, the gift cards listed on the order will be used as payment.

Add expire job

If you want to change the configuration, you can add the following to an initializer:

SolidusVirtualGiftCard::Config.tap do |config|

Amount of time after which the authorized transaction should be voided

config.authorize_timeout = 1.month

config.schedule_job_class = 'SolidusVirtualGiftCard::VoidExpiredAuthorizedEventsJob' end

The last step in the installation process is to configure the SolidusVirtualGiftCard::VoidExpiredAuthorizedEventsJob background job to run regularly. There are different ways to do this depending on the environment your application is running in: Heroku Scheduler, cron etc.

Authorization

For discrete authorization, two permission sets have been added to allow for granular display in the admin.

Spree::PermissionSets::VirtualGiftCardDisplay and Spree::PermissionSets::VirtualGiftCardManagement have been added and can be registered via RoleConfiguration

Testing

First bundle your dependencies, then run rake. rake will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using rake test_app.

bundle
bundle exec rake

When testing your application's integration with this extension you may use its factories. Simply add this require statement to your spec_helper:

require "solidus_virtual_gift_card/factories"