Skip to content

Instantly share code, notes, and snippets.

@uptownhr

uptownhr/error Secret

Last active August 29, 2015 14:19
Show Gist options
  • Save uptownhr/96e79631622d4f378b5b to your computer and use it in GitHub Desktop.
Save uptownhr/96e79631622d4f378b5b to your computer and use it in GitHub Desktop.
/api/v1 Trans::Throttle total processing restrictions declines after processing restriction being hit
Failure/Error: get "/api/v1", data
NoMethodError:
undefined method `where' for nil:NilClass
# ./lib/trans/throttle.rb:75:in `do_total_processing_restrictions'
# ./lib/trans/throttle.rb:64:in `block in run'
# ./lib/trans/throttle.rb:44:in `each'
# ./lib/trans/throttle.rb:44:in `each_with_index'
# ./lib/trans/throttle.rb:44:in `run'
# ./lib/trans/throttle.rb:8:in `initialize'
# ./lib/trans/api.rb:46:in `new'
# ./lib/trans/api.rb:46:in `run'
# ./app/controllers/api.rb:8:in `block (2 levels) in <top (required)>'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/application/routing.rb:504:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/application/routing.rb:504:in `block in route'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/ext/http_router.rb:33:in `[]'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/ext/http_router.rb:33:in `block (3 levels) in process_destination_path'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/ext/http_router.rb:33:in `block (2 levels) in process_destination_path'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/ext/http_router.rb:33:in `catch'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/ext/http_router.rb:33:in `block in process_destination_path'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/ext/http_router.rb:8:in `instance_eval'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/ext/http_router.rb:8:in `process_destination_path'
# (eval):142:in `block in call'
# (eval):131:in `catch'
# (eval):131:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.1/lib/http_router.rb:288:in `raw_call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/http_router-0.11.1/lib/http_router.rb:142:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/application/routing.rb:931:in `route!'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/application/routing.rb:915:in `block in dispatch!'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/application/routing.rb:913:in `dispatch!'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:186:in `call!'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:164:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/omniauth-1.2.2/lib/omniauth/builder.rb:59:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-1.6.0/lib/rack/head.rb:13:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-1.6.0/lib/rack/methodoverride.rb:22:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-1.6.0/lib/rack/session/abstract/id.rb:225:in `context'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-1.6.0/lib/rack/session/abstract/id.rb:220:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/router.rb:84:in `block in call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/router.rb:75:in `each'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/padrino-core-0.12.4/lib/padrino-core/router.rb:75:in `call'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
# ./spec/app/controllers/api_spec.rb:267:in `do_purchase'
# ./spec/app/controllers/api_spec.rb:248:in `block (5 levels) in <top (required)>'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.0/lib/active_support/core_ext/range/each.rb:7:in `each'
# /Users/uptown/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.0/lib/active_support/core_ext/range/each.rb:7:in `each_with_time_with_zone'
# ./spec/app/controllers/api_spec.rb:243:in `block (4 levels) in <top (required)>'
class Transaction < Sequel::Model
plugin :timestamps
many_to_many :batches
end
module Trans
class Throttle
attr_reader :errors
def initialize(transaction = nil)
@errors = []
if !transaction.nil?
run(transaction)
end
end
# adds to errors
def has_error (name, error)
@errors.push({:name => name, :error => error})
end
# get list of all the fraud throttles
def get_throttles
throttles = [
{name: 'total_processing_restrictions', label: 'Total Processing Restrictions (including declines)'},
{name: 'processing_restrictions', label: 'Processing restrictions'},
{name: 'refund_restrictions', label: 'Refund restrictions'},
{name: 'charges_per_card', label: 'Charges per card restrictions'},
{name: 'min_max_price', label: 'Min Max Price'},
{name: 'ip_velocity', label: 'IP Velocity'},
{name: 'card_velocity', label: 'Card Velocity'},
{name: 'bin_overuse', label: 'Bin Overuse'},
{name: 'cards_per_email', label: 'Cards per email'}
]
return throttles
end
# run throttle from mid's throttle_data
def run(transaction)
@transaction = transaction
@throttles = get_throttles
@mid_id = @transaction.params[:mid_id]
@currency = @transaction.params[:currency]
@mid_throttles = @transaction.data[:throttle_data]
# loop through all fraud throttles and then run those where the mid have activated them
if !@throttles.nil?
@throttles.each_with_index do |obj|
name = obj[:name]
#map to arrays
throttle_arr = @mid_throttles.map {|t| t[1] }
#select matching currencies
throttle = throttle_arr.find do |t|
if t.keys.empty?
false
else
t[t.keys[0]]["currency"] == @currency && t.keys[0].to_s == name
end
end
#run throttle rule
if throttle
rule = throttle.keys[0]
data = throttle[rule]
self.send("do_#{rule}", data)
end
end
end
end
# fraud throttle methods
def do_total_processing_restrictions data
if ['auth','purchase'].include?(@transaction.params[:type])
threshold = data["num"].to_i
if threshold
value = ::Transaction.where(:mid_id => @mid_id).where(:type => ['purchase', 'authorization']).count
if value > threshold
has_error('total_processing_restrictions(count)', "value: #{value}, threshold: #{threshold}")
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment