module Straight::OrderModule

This module should be included into your own class to extend it with Order functionality. For example, if you have a ActiveRecord model called Order, you can include OrderModule into it and you'll now be able to do everything to check order's status, but you'll also get AR Database storage funcionality, its validations etc.

The right way to implement this would be to do it the other way: inherit from Straight::Order, then include ActiveRecord, but at this point ActiveRecord doesn't work this way. Furthermore, some other libraries, like Sequel, also require you to inherit from them. Thus, the module.

When this module is included, it doesn't actually include all the methods, some are prepended (see Ruby docs on prepend). It is important specifically for getters and setters and as a general rule only getters and setters are prepended.

If you don't want to bother yourself with modules, please use Straight::Order class and simply create new instances of it. However, if you are contributing to the library, all new funcionality should go to either Straight::OrderModule::Includable or Straight::OrderModule::Prependable (most likely the former).

Constants

STATUSES

Worth noting that statuses above 1 are immutable. That is, an order status cannot be changed if it is more than 1. It makes sense because if an order is paid (5) or expired (2), nothing else should be able to change the status back. Similarly, if an order is overpaid (4) or underpaid (5), it requires admin supervision and possibly a new order to be created.

Attributes

old_status[R]

Public Class Methods

included(base) click to toggle source

Only add getters and setters for those properties in the extended class that don't already have them. This is very useful with ActiveRecord for example where we don't want to override AR getters and setters that set attribtues.

# File lib/straight/order.rb, line 23
def self.included(base)
  base.class_eval do
    [:amount, :amount_paid, :address, :gateway, :keychain_id, :status, :tid, :title, :callback_url, :test_mode].each do |field|
      attr_reader field unless base.method_defined?(field)
      attr_writer field unless base.method_defined?("#{field}=")
    end
    prepend Prependable
    include Includable
  end
end