compensated 0.1.0.pre6 → 0.1.0.pre7

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: afddd0b43b5b41b3bde8326b00521228076301d3757bfe249fec121e66a9b2a1
4
- data.tar.gz: 89a8d978d3fc779ef30db11f860e9e77297f79cff12befb32c4aa4eacec876c0
3
+ metadata.gz: 8c19dff720370589fb90015944b4b0ff8520b047f280c7968c91d083216d46e2
4
+ data.tar.gz: 93390c30dfb4a274be691396e18870132e1a6783cd03f8f443ce6fa344fb5244
5
5
  SHA512:
6
- metadata.gz: c4bb960beeec13c0bd8a5fb14fba79e316e4fe1df76abf8aa8004aac44e8088ea5758bf1898950d0e2b4a73f433bad9771e4707bc4cd0606196cf6bf59164386
7
- data.tar.gz: 5cb5af381c061c589336eedaf9b3273ae7ccc606e1f67e4726b4cd43d3a807b1fb1b5f9676a4887ac565513508588ed831e47cde16c6a4439d5c6c5d697144f5
6
+ metadata.gz: 459cbd3cfd663b13fa2864c6b68614fd89407664859f94f0684cc816314cb150f070302038942c71f302d11c55fc3197552ebb690627e800b3b9da730b07070e
7
+ data.tar.gz: 8d7d650d1715e8567245358a4b624889e719f7ed98ec4a62cbde3d902c5d9d4784322cd7f89a610e09d9c0b512a9dc292a0b2f150ea24336ea581d939250527a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compensated (0.1.0.pre6)
4
+ compensated (0.1.0.pre7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/compensated.gemspec CHANGED
@@ -3,14 +3,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "compensated/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "compensated"
7
- spec.version = Compensated::VERSION
8
- spec.authors = ["Zee"]
9
- spec.email = ["zee@zincma.de"]
6
+ spec.name = "compensated"
7
+ spec.version = Compensated::VERSION
8
+ spec.authors = ["Zee"]
9
+ spec.email = ["zee@zincma.de"]
10
10
 
11
- spec.summary = "Provide value (In Ruby!). Get paid."
12
- spec.description = "Compensated makes handling transactions slightly less of a nightmare."
13
- spec.homepage = "https://github.com/zinc-technology/compensated"
11
+ spec.summary = "Provide value (In Ruby!). Get paid."
12
+ spec.description = "Compensated makes handling transactions slightly less of a nightmare."
13
+ spec.homepage = "https://github.com/zinc-technology/compensated"
14
14
 
15
15
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
16
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
31
31
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin|examples)/}) }
32
32
  end
33
- spec.bindir = "exe"
34
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
36
 
37
37
  spec.add_development_dependency "bundler", "~> 2.0"
@@ -0,0 +1,42 @@
1
+ require "compensated/event_parser"
2
+ module Compensated
3
+ module AppleIap
4
+ class EventParser < Compensated::EventParser
5
+ SUPPORTED_TYPES = ["INTERACTIVE_RENEWAL", "DID_CHANGE_RENEWAL_STATUS"]
6
+ def parses?(request)
7
+ return false unless request.data
8
+ request.data[:notification_type] &&
9
+ SUPPORTED_TYPES.include?(request.data[:notification_type])
10
+ end
11
+
12
+ def normalize(data)
13
+ data = Compensated.json_adapter.parse(data) unless data.respond_to?(:key)
14
+ {
15
+ raw_body: Compensated.json_adapter.dump(data),
16
+ raw_event_type: data[:notification_type].to_sym,
17
+ raw_event_id: receipt_data(data)[:transaction_id],
18
+ payment_processor: :apple_iap,
19
+ customer: customer(data),
20
+ products: products(data),
21
+ }.compact
22
+ end
23
+
24
+ def receipt_data(data)
25
+ data[:latest_expired_receipt_info] || data[:latest_receipt_info]
26
+ end
27
+
28
+ def products(data)
29
+ [
30
+ {sku: receipt_data(data)[:product_id]},
31
+ ]
32
+ end
33
+
34
+ def customer(data)
35
+ {
36
+ id: receipt_data(data)[:original_transaction_id],
37
+ }
38
+ end
39
+ end
40
+ end
41
+ event_parsers.push(AppleIap::EventParser.new)
42
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "apple_iap/event_parser"
2
+
3
+ module Compensated
4
+ module AppleIap
5
+ class Error < Compensated::Error; end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module Compensated
2
+ class EventParser
3
+ def parse(request)
4
+ normalize(request.data)
5
+ end
6
+
7
+ def parses?(request)
8
+ raise NotImplementedError("Implement in Child")
9
+ end
10
+
11
+ def normalize(data)
12
+ raise NotImplementedError("Implement in Child")
13
+ end
14
+ end
15
+ end
@@ -4,6 +4,7 @@ module Compensated
4
4
  # functionality
5
5
  class PaymentProcessorEventRequest
6
6
  extend Forwardable
7
+
7
8
  attr_accessor :request
8
9
  # @param request [Rack::Request] A rack-compatible HTTP request triggered
9
10
  # by the payment processor
@@ -16,7 +17,7 @@ module Compensated
16
17
 
17
18
  # @returns Hash
18
19
  def data
19
- return @data unless @data.nil?
20
+ return @data if defined?(@data) && !@data.nil?
20
21
  if request.form_data?
21
22
  @data = request.params
22
23
  elsif !body.nil?
@@ -1,7 +1,8 @@
1
+ require "compensated/event_parser"
1
2
  module Compensated
2
3
  module Stripe
3
4
  SUPPORTED_EVENTS = %w[charge.succeeded invoice.payment_succeeded]
4
- class EventParser
5
+ class EventParser < Compensated::EventParser
5
6
  def parses?(request)
6
7
  return false if request.nil? || request.empty?
7
8
  SUPPORTED_EVENTS.include?(request.data[:type])
@@ -19,10 +20,6 @@ module Compensated
19
20
  }
20
21
  end
21
22
 
22
- def parse(request)
23
- normalize(request.data)
24
- end
25
-
26
23
  private def customer(data)
27
24
  if invoice?(data)
28
25
  {
@@ -1,3 +1,3 @@
1
1
  module Compensated
2
- VERSION = "0.1.0.pre6"
2
+ VERSION = "0.1.0.pre7"
3
3
  end
data/lib/compensated.rb CHANGED
@@ -29,7 +29,7 @@ module Compensated
29
29
  # In cases where the default JSON parser is unacceptable, configure
30
30
  # the json engine using `Compensated.json_engine = <Your preferred JSON parser>`
31
31
  def self.json_engine
32
- require "json" unless @json_engine
32
+ require "json" unless defined?(@json_engine)
33
33
  @json_engine ||= JSON
34
34
  end
35
35
 
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.pre6
4
+ version: 0.1.0.pre7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-02 00:00:00.000000000 Z
11
+ date: 2019-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,6 +81,9 @@ files:
81
81
  - Rakefile
82
82
  - compensated.gemspec
83
83
  - lib/compensated.rb
84
+ - lib/compensated/apple_iap.rb
85
+ - lib/compensated/apple_iap/event_parser.rb
86
+ - lib/compensated/event_parser.rb
84
87
  - lib/compensated/gumroad.rb
85
88
  - lib/compensated/gumroad/csv_emitter.rb
86
89
  - lib/compensated/gumroad/event_parser.rb