class Workarea::Sezzle::Gateway
Attributes
options[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 7 def initialize(options = {}) requires!(options, :api_public_key, :api_private_key) @options = options end
Public Instance Methods
create_session(attrs = {})
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 12 def create_session(attrs = {}) response = connection.post do |req| req.url 'v2/session' req.body = attrs.to_json end Sezzle::Response.new(response) end
delete_checkout(id)
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 45 def delete_checkout(id) response = connection.delete do |req| req.url "v2/order/#{id}/checkout" end Sezzle::Response.new(response) end
get_order(id, attrs = {})
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 38 def get_order(id, attrs = {}) response = connection.get do |req| req.url "v2/order/#{id}" end Sezzle::Response.new(response) end
refund(id, attrs)
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 30 def refund(id, attrs) response = connection.post do |req| req.url "v2/order/#{id}/refund" req.body = attrs.to_json end Sezzle::Response.new(response) end
Private Instance Methods
api_headers()
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 75 def api_headers { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => "Bearer #{token}" } end
connection()
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 54 def connection request_timeouts = { timeout: Workarea.config.sezzle[:api_timeout], open_timeout: Workarea.config.sezzle[:open_timeout] } Faraday.new(url: rest_endpoint, headers: api_headers, request: timeout_options) end
requires!(hash, *params)
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 90 def requires!(hash, *params) params.each do |param| if param.is_a?(Array) raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first) valid_options = param[1..-1] raise ArgumentError.new("Parameter: #{param.first} must be one of #{valid_options.to_sentence(words_connector: 'or')}") unless valid_options.include?(hash[param.first]) else raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param) end end end
rest_endpoint()
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 63 def rest_endpoint if test? 'https://sandbox.gateway.sezzle.com' else 'https://gateway.sezzle.com' end end
test?()
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 71 def test? (options.has_key?(:test) ? options[:test] : false) end
timeout_options()
click to toggle source
# File lib/workarea/sezzle/gateway.rb, line 83 def timeout_options { timeout: Workarea.config.sezzle[:api_timeout], open_timeout: Workarea.config.sezzle[:open_timeout] } end