stripe-decline-rate 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/stripe_decline_rate.rb +86 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5295c86633771a8d13162ec911e5c27af786a619
|
4
|
+
data.tar.gz: d2dbf3e3b628831e88dc4baa08292e576530f09c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3f783c097f3ddfde8c050496a3c803cbf2cd453000944ae2e3a7a332c78c4062900297d96f73444965f0e0ee65b48903c5b2231d32bafdf27ff662d30c6aae82
|
7
|
+
data.tar.gz: 2d6a5de601a977a59d0da97ff81423c959786e8757dc3ca9454aca81839721ed138c0c7b375e13e78f1d0f0716126cad4736178fd81e9a8c4677b80b76e8b6d5
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'stripe'
|
2
|
+
require 'date'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
class StripeDeclineRate
|
6
|
+
def initialize(api_key)
|
7
|
+
Stripe.api_key = api_key
|
8
|
+
end
|
9
|
+
|
10
|
+
def latest
|
11
|
+
saturday = starting_saturday
|
12
|
+
sunday = starting_sunday
|
13
|
+
|
14
|
+
10.times do |i|
|
15
|
+
puts "#{sunday} through #{saturday}: #{formatted_decline_ratio(sunday, saturday)}"
|
16
|
+
|
17
|
+
sunday = sunday - 7
|
18
|
+
saturday = saturday - 7
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def starting_saturday
|
23
|
+
(Date.today - Date.today.wday).prev_day
|
24
|
+
end
|
25
|
+
|
26
|
+
def starting_sunday
|
27
|
+
Date.today - Date.today.wday - 7
|
28
|
+
end
|
29
|
+
|
30
|
+
def formatted_decline_ratio(from, to)
|
31
|
+
"#{(decline_ratio(from, to) * 100).round(2)}%"
|
32
|
+
end
|
33
|
+
|
34
|
+
def decline_ratio(from, to)
|
35
|
+
declined_count = declined_charge_fingerprints(from, to).count
|
36
|
+
successful_count = successful_charge_fingerprints(from, to).count
|
37
|
+
declined_count.to_f / (declined_count + successful_count).to_f
|
38
|
+
end
|
39
|
+
|
40
|
+
def successful_charge_fingerprints(from, to)
|
41
|
+
charge_fingerprints(successful_charge_params(from, to))
|
42
|
+
end
|
43
|
+
|
44
|
+
def declined_charge_fingerprints(from, to)
|
45
|
+
charge_fingerprints(decline_charge_params(from, to))
|
46
|
+
end
|
47
|
+
|
48
|
+
def successful_charge_params(from, to)
|
49
|
+
base_params(from, to).merge({
|
50
|
+
type: 'charge.succeeded'
|
51
|
+
})
|
52
|
+
end
|
53
|
+
|
54
|
+
def decline_charge_params(from, to)
|
55
|
+
base_params(from, to).merge({
|
56
|
+
type: 'charge.failed'
|
57
|
+
})
|
58
|
+
end
|
59
|
+
|
60
|
+
def base_params(from, to)
|
61
|
+
{
|
62
|
+
limit: 100,
|
63
|
+
created: {
|
64
|
+
gte: from.to_time.to_i,
|
65
|
+
lt: to.to_time.to_i
|
66
|
+
}
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def charge_fingerprints(params)
|
71
|
+
list = Stripe::Event.all(params)
|
72
|
+
fingerprints = unique_fingerprints(list)
|
73
|
+
while list[:has_more] do
|
74
|
+
last_event_id = list[:data].last[:id]
|
75
|
+
list = Stripe::Event.all(params.merge(starting_after: last_event_id))
|
76
|
+
fingerprints.merge(unique_fingerprints(list))
|
77
|
+
end
|
78
|
+
fingerprints
|
79
|
+
end
|
80
|
+
|
81
|
+
def unique_fingerprints(list)
|
82
|
+
list[:data].map do |event|
|
83
|
+
event[:data][:object][:source][:fingerprint]
|
84
|
+
end.to_set
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stripe-decline-rate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: stripe
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Get visibility into actual ratios of successful charges and failed charge
|
42
|
+
attempts unique to card numbers.
|
43
|
+
email: sean@seancoleman.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/stripe_decline_rate.rb
|
49
|
+
homepage: https://github.com/seanmcoleman/stripe-decline-rate
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.4.5.1
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Easily track Stripe card decline rates.
|
73
|
+
test_files: []
|