Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Layout/EmptyLinesAroundBlockBody:

Style/MissingRespondToMissing:
Enabled: false
Style/MethodMissingSuper:
Lint/MissingSuper:
Enabled: false
Style/NumericPredicate:
Enabled: false
Expand All @@ -34,7 +34,7 @@ Documentation:
Enabled: false

AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.7
Exclude:
- bin/**/*
- vendor/**/*
Expand Down
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby 3.2.2
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cache: bundler
language: ruby
rvm:
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- 3.2
script:
- bundle exec rspec spec
- bundle exec rubocop
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'http://rubygems.org'

# Specify your gem's dependencies in FatZebra.gemspec
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'rspec/core/rake_task'
Expand Down
6 changes: 5 additions & 1 deletion fat_zebra.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand All @@ -16,10 +18,12 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
s.require_paths = %w[lib]

s.required_ruby_version = '>= 2.7'

s.add_development_dependency 'byebug'
s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 3.6'
s.add_development_dependency 'rubocop', '~> 0.58.1'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'vcr', '~> 3.0'
s.add_development_dependency 'webmock', '~> 3.0'
end
7 changes: 7 additions & 0 deletions lib/fat_zebra.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(__dir__) unless $LOAD_PATH.include?(__dir__)

# Libraries
require 'securerandom'
require 'json'
Expand Down Expand Up @@ -38,6 +42,9 @@
require 'fat_zebra/web_hook'
require 'fat_zebra/batch'

# Utilities/Mastercard
require 'fat_zebra/utilities/mastercard/click_to_pay/registration'

# Paypal API Resources
require 'fat_zebra/paypal/billing_agreement'
require 'fat_zebra/paypal/order'
Expand Down
11 changes: 7 additions & 4 deletions lib/fat_zebra/api_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Helper
Expand Down Expand Up @@ -40,20 +42,21 @@ def build_endpoint_url(base_url, path, params = nil, options = {})
port = port.to_i if port

url_params = Util.compact(
host: host,
path: path,
port: port,
host: host,
path: path,
port: port,
query: params
)

return URI::HTTPS.build(url_params) if options[:http_secure]

URI::HTTP.build(url_params)
end

def default_headers
{
headers: {
accept: 'application/json',
accept: 'application/json',
content_type: 'application/json'
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/api_operation/delete.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
class APIOperation
##
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/api_operation/find.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
class APIOperation
##
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/api_operation/save.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
class APIOperation
##
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/api_operation/search.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
class APIOperation
##
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/api_operation/void.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
class APIOperation
##
Expand Down
18 changes: 11 additions & 7 deletions lib/fat_zebra/api_resource.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \API \Resource
Expand Down Expand Up @@ -30,16 +32,17 @@ def request(method, path, payload = {}, options = {})
uri = build_endpoint_url(configurations.gateway, path, url_params, http_secure: configurations.http_secure)

request_options = Util.compact(
method: method,
url: uri.to_s,
method: method,
url: uri.to_s,
payload: payload,
proxy: configurations.proxy,
proxy: configurations.proxy,
use_ssl: configurations.http_secure
).merge(authentication).merge(default_headers).merge(configurations.global_options).merge(options)

Request.execute(request_options).body
rescue FatZebra::RequestError => error
return error.http_body if error.http_status == 422
rescue FatZebra::RequestError => e
return e.http_body if e.http_status == 422

raise
end
# rubocop:enable Metrics/AbcSize
Expand All @@ -48,16 +51,17 @@ def request(method, path, payload = {}, options = {})

def ssl_options
return {} unless configurations.http_secure

{
ca_file: File.expand_path(File.dirname(__FILE__) + '/../../vendor/cacert.pem'),
ca_file: File.expand_path("#{File.dirname(__FILE__)}/../../vendor/cacert.pem"),
verify_mode: OpenSSL::SSL::VERIFY_PEER
}
end

def authentication
{
basic_auth: {
user: configurations.username,
user: configurations.username,
password: configurations.token
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/authenticate.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Authenticate
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/bank_account.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Bank \Account
Expand Down
7 changes: 5 additions & 2 deletions lib/fat_zebra/batch.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Batch
Expand Down Expand Up @@ -51,8 +53,9 @@ def create(params, options = {})
# @return [String] formated as CSV
def result(params = {}, options = {})
request(:get, "#{resource_path}/#{id}/result.csv", params, options)
rescue FatZebra::RequestError => error
return error.http_body if error.http_status == 422
rescue FatZebra::RequestError => e
return e.http_body if e.http_status == 422

raise
end

Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/card.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Card
Expand Down
4 changes: 3 additions & 1 deletion lib/fat_zebra/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Config
Expand All @@ -7,7 +9,7 @@ class Config

GATEWAY_URLS = {
production: 'gateway.fatzebra.com.au',
sandbox: 'gateway.sandbox.fatzebra.com.au'
sandbox: 'gateway.sandbox.fatzebra.com.au'
}.freeze

##
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/customer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Customer
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/direct_credit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Direct \Credit
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/direct_debit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Direct \Debit
Expand Down
7 changes: 3 additions & 4 deletions lib/fat_zebra/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra

##
Expand All @@ -16,10 +18,7 @@ class UnknownRequestMethod < StandardError; end
# Request to API Error
class RequestError < StandardError

attr_reader :http_body
attr_reader :http_status
attr_reader :http_status_type
attr_reader :http_message
attr_reader :http_body, :http_status, :http_status_type, :http_message

def initialize(response, message: nil)
@http_status = response.code.to_i
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/fat_zebra_object.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Object
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/information.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Information
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/object_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == Object \Helper
Expand Down
2 changes: 2 additions & 0 deletions lib/fat_zebra/payment_plan.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Payment \Plan
Expand Down
4 changes: 3 additions & 1 deletion lib/fat_zebra/paypal/authorization.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Paypal::Authorization
Expand All @@ -16,7 +18,7 @@ class Authorization < APIResource

class << self
def base_path
super + '/paypal/'
"#{super}/paypal/"
end

##
Expand Down
4 changes: 3 additions & 1 deletion lib/fat_zebra/paypal/billing_agreement.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Paypal::BillingAgreement
Expand All @@ -21,7 +23,7 @@ class BillingAgreement < APIResource

class << self
def base_path
super + '/paypal/'
"#{super}/paypal/"
end

##
Expand Down
4 changes: 3 additions & 1 deletion lib/fat_zebra/paypal/capture.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Paypal::Capture
Expand All @@ -15,7 +17,7 @@ class Capture < APIResource

class << self
def base_path
super + '/paypal/'
"#{super}/paypal/"
end

##
Expand Down
4 changes: 3 additions & 1 deletion lib/fat_zebra/paypal/order.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Paypal::Order
Expand All @@ -14,7 +16,7 @@ class Order < APIResource

class << self
def base_path
super + '/paypal/'
"#{super}/paypal/"
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/fat_zebra/paypal/refund.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module FatZebra
##
# == FatZebra \Paypal::Refund
Expand All @@ -14,7 +16,7 @@ class Refund < APIResource

class << self
def base_path
super + '/paypal/'
"#{super}/paypal/"
end
end
end
Expand Down
Loading