class StraightServer::GatewayOnConfig
Uses a config file to load attributes and a special _last_keychain_id file to store last_keychain_id
Attributes
This affects whether it is possible to create a new order with the gateway. If it's set to false, then it won't be possible to create a new order, but it will keep checking on the existing ones.
A url to which the gateway will send an HTTP request with the status of the order data (in JSON) when the status of the order is changed. The response should always be 200, otherwise the gateway will awesome something went wrong and will keep trying to send requests to this url according to a specific shedule.
If set to false, doesn't require an unique id of the order along with the signed md5 hash of that id + secret to be passed into the create_order
method.
This will be assigned the number that is the order in which this gateway follows in the config file.
This is used to generate the next address to accept payments
This is the key that allows users (those, who use the gateway, online stores, for instance) to connect and create orders. It is not used directly, but is mixed with all the params being sent and a MD5 hash is calculted. Then the gateway checks whether the MD5 hash is correct.
This is used to generate the next address to accept payments
Public Class Methods
# File lib/straight-server/gateway.rb, line 516 def self.find_by_hashed_id(s) self.find_by_id(s) end
This method is a replacement for the Sequel's model one used in DB version of the gateway and it finds gateways using the index of @@gateways Array.
# File lib/straight-server/gateway.rb, line 572 def self.find_by_id(id) @@gateways[id.to_i-1] end
# File lib/straight-server/gateway.rb, line 520 def initialize initialize_callbacks initialize_exchange_rate_adapters initialize_blockchain_adapters initialize_status_check_schedule initialize_network end
Public Instance Methods
# File lib/straight-server/gateway.rb, line 566 def address_provider Kernel.const_get("Straight::AddressProvider::#{address_provider_type}").new(self) end
# File lib/straight-server/gateway.rb, line 562 def address_provider_type @address_provider ? @address_provider.to_sym : :Bip32 end
# File lib/straight-server/gateway.rb, line 557 def build_keychain_path filename = self.test_mode ? "/#{name}_test_last_keychain_id" : "/#{name}_last_keychain_id" StraightServer::Initializer::ConfigDir.path + filename end
Loads last_keychain_id
from a file in the .straight dir. If the file doesn't exist, we create it. Later, whenever an attribute is updated, we save it to the file.
# File lib/straight-server/gateway.rb, line 542 def load_last_keychain_id! @last_keychain_id_file ||= build_keychain_path if File.exists?(@last_keychain_id_file) self.last_keychain_id = File.read(@last_keychain_id_file).to_i else self.last_keychain_id = 0 save end end
Because this is a config based gateway, we only save last_keychain_id
and nothing more.
# File lib/straight-server/gateway.rb, line 535 def save save_last_keychain_id! end
# File lib/straight-server/gateway.rb, line 552 def save_last_keychain_id! @last_keychain_id_file ||= build_keychain_path File.open(@last_keychain_id_file, 'w') {|f| f.write(last_keychain_id) } end
# File lib/straight-server/gateway.rb, line 528 def validate_config raise NoPubkey if pubkey_missing? raise NoTestPubkey if test_pubkey_missing? end