compensated 0.1.0.pre1 → 0.1.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ef6a5718683783e493fdad36e304f857635c301b12c12bd6ac790259bb39756
4
- data.tar.gz: 79de21133b8dc3fc4704b70b98264c6301ab8bb48d113201f0292a4456c8d1be
3
+ metadata.gz: b33e091cd8f3e8e3b36393b3088ab4bb861e99107d2c325432ffa54503df59a9
4
+ data.tar.gz: 9edef7647ce0e9877dd2596a44c027bd8769745086fa390106353ddf014b3ad1
5
5
  SHA512:
6
- metadata.gz: e2180e9ef30642ff344db949945aeed11aebba04a5a9e45659b7b80c450a873c55586eabfbef5cec8ac6afe71975b7aa4866edf348c96bee25dc6cb992f7b18a
7
- data.tar.gz: 5038cb753bc272195f7354fff615c60961ee707f375d5f846a38cf213deac6c2bf082c794c287dcda620a92d06ca68972f6e2bf9cd2d1682996bd92fe38667e7
6
+ metadata.gz: c4f58665f50a4d98011780bebbd8facebfbcbd409ade95c4f042a0dbbaa2b22e7e2af40168038316ffc8d24012fa2c47dea6a83d35b0e8155562cf1cec747aeb
7
+ data.tar.gz: 94886732c8a725f838c8e9b899146057eff3181f762ac7269c75cd9e87736cb2110080f37dd52e33504edb8789020547d52d8b5e9f805e428ffdd415cef417b0
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compensated (0.1.0.pre1)
4
+ compensated (0.1.0.pre2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.3)
10
+ rack (2.0.7)
10
11
  rake (10.5.0)
11
12
  rspec (3.8.0)
12
13
  rspec-core (~> 3.8.0)
@@ -28,6 +29,7 @@ PLATFORMS
28
29
  DEPENDENCIES
29
30
  bundler (~> 2.0)
30
31
  compensated!
32
+ rack
31
33
  rake (~> 10.0)
32
34
  rspec (~> 3.0)
33
35
 
data/compensated.gemspec CHANGED
@@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "bundler", "~> 2.0"
38
38
  spec.add_development_dependency "rake", "~> 10.0"
39
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency "rack"
40
41
  end
@@ -0,0 +1,15 @@
1
+ require "csv"
2
+ module Compensated
3
+ module Gumroad
4
+ class CSVEmitter
5
+ def parse(io)
6
+ CSV.new(io, headers: true).map do |row|
7
+ {payment_processor: :gumroad,
8
+ raw_event_type: :"csv.purchase_entry",
9
+ raw_event_id: row["Purchase ID"],
10
+ raw_body: row.to_s.strip,}
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Compensated
2
+ module Gumroad
3
+ class EventParser
4
+ def parses?(request)
5
+ # Gumroad pings are always form data
6
+ return false unless request.form_data?
7
+ keys = request.data.keys.map(&:to_sym)
8
+ keys.include?(:seller_id) && keys.include?(:product_id) && keys.include?(:product_permalink) && request.data["product_permalink"].include?("gum.co")
9
+ end
10
+
11
+ def parse(request)
12
+ {
13
+ raw_body: request.body,
14
+ raw_event_type: request.data["resource_name"].to_sym,
15
+ raw_event_id: nil,
16
+ payment_processor: :gumroad,
17
+
18
+ }
19
+ end
20
+ end
21
+ Compensated.event_parsers.push(EventParser)
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ require "compensated/gumroad/csv_emitter"
2
+ require "compensated/gumroad/event_parser"
3
+ module Compensated
4
+ module Gumroad
5
+ end
6
+ end
@@ -0,0 +1,31 @@
1
+ require "forwardable"
2
+ module Compensated
3
+ # Decorator for the Rack::Request to provide Compensated specific
4
+ # functionality
5
+ class PaymentProcessorEventRequest
6
+ extend Forwardable
7
+ attr_accessor :request
8
+ # @param request [Rack::Request] A rack-compatible HTTP request triggered
9
+ # by the payment processor
10
+ def initialize(request)
11
+ self.request = request
12
+ end
13
+
14
+ def_delegator :request, :form_data?
15
+ def_delegator :request, :body
16
+
17
+ # @returns Hash
18
+ def data
19
+ return @data unless @data.nil?
20
+ if request.form_data?
21
+ @data = request.params
22
+ elsif !body.nil?
23
+ @data = Compensated.json_adapter.parse(body)
24
+ end
25
+ end
26
+
27
+ def empty?
28
+ body.nil? || body.respond_to?(:empty?) && body.empty?
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,4 @@
1
+ require_relative "payment_processor_event_request"
1
2
  module Compensated
2
3
  # Normalizes events by passing them to an EventParser
3
4
  # Which transforms them into a hash that can be
@@ -7,28 +8,19 @@ module Compensated
7
8
  # @param event_request [Request] A rack-compatible HTTP request triggered
8
9
  # by the payment processor
9
10
  def initialize(event_request)
10
- self.event_request = event_request
11
+ self.event_request = PaymentProcessorEventRequest.new(event_request)
11
12
  end
12
13
 
13
14
  # @return Hash
14
15
  def normalized_event_data
15
- event_parser.parse(event_request_body_data)
16
+ event_parser.parse(event_request)
16
17
  end
17
18
 
18
19
  protected def event_parser
19
20
  return @event_parser unless @event_parser.nil?
20
- @event_parser = Compensated.event_parsers.find { |parser| parser.parses?(event_request_body_data) }
21
- raise NoParserForEventError, event_request_body_data if @event_parser.nil?
21
+ @event_parser = Compensated.event_parsers.find { |parser| parser.parses?(event_request) }
22
+ raise NoParserForEventError, event_request.data if @event_parser.nil?
22
23
  @event_parser
23
24
  end
24
-
25
- protected def event_request_body_data
26
- @event_request_body_data ||= Compensated.json_adapter.parse(event_request_body)
27
- end
28
-
29
- protected def event_request_body
30
- return @event_request_body unless @event_request_body.nil?
31
- @event_request_body = event_request.body
32
- end
33
25
  end
34
26
  end
@@ -2,16 +2,16 @@ module Compensated
2
2
  module Stripe
3
3
  SUPPORTED_EVENTS = %w[charge.succeeded invoice.payment_succeeded]
4
4
  class EventParser
5
- def parses?(input_event)
6
- return false if input_event.nil? || !input_event.respond_to?(:key)
7
- SUPPORTED_EVENTS.include?(input_event[:type])
5
+ def parses?(request)
6
+ return false if request.nil? || request.empty?
7
+ SUPPORTED_EVENTS.include?(request.data[:type])
8
8
  end
9
9
 
10
- def parse(input_event)
10
+ def parse(request)
11
11
  {
12
- raw_body: Compensated.json_adapter.dump(input_event),
13
- raw_event_type: input_event[:type].to_sym,
14
- raw_event_id: input_event[:id],
12
+ raw_body: Compensated.json_adapter.dump(request.data),
13
+ raw_event_type: request.data[:type].to_sym,
14
+ raw_event_id: request.data[:id],
15
15
  payment_processor: :stripe,
16
16
  }
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Compensated
2
- VERSION = "0.1.0.pre1"
2
+ VERSION = "0.1.0.pre2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compensated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre1
4
+ version: 0.1.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-06 00:00:00.000000000 Z
11
+ date: 2019-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Compensated makes handling transactions slightly less of a nightmare.
56
70
  email:
57
71
  - zee@zincma.de
@@ -72,6 +86,10 @@ files:
72
86
  - compensated.gemspec
73
87
  - examples/compensated-rails-5/Gemfile
74
88
  - lib/compensated.rb
89
+ - lib/compensated/gumroad.rb
90
+ - lib/compensated/gumroad/csv_emitter.rb
91
+ - lib/compensated/gumroad/event_parser.rb
92
+ - lib/compensated/payment_processor_event_request.rb
75
93
  - lib/compensated/payment_processor_event_request_handler.rb
76
94
  - lib/compensated/stripe.rb
77
95
  - lib/compensated/stripe/event_parser.rb