compensated 0.1.0.pre3 → 0.1.0.pre4

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: 223ec3be54d0b75a023875200811eead3fdc7ce5b3435a706e6e6aaa0b832189
4
- data.tar.gz: 1d905b411d77379a8468d7a121aa95fff7a3fbbe57ce70273ad8811628c1b9c1
3
+ metadata.gz: ac2ec14d09df8e16e45e2d6dbbdd0568eea83ad4e19c386f2b2b4a413093c893
4
+ data.tar.gz: a09cbd7eb77b776ab13aa363674554ebbbb59281096bb782ad89469b75d296ce
5
5
  SHA512:
6
- metadata.gz: 3c9b15a18e49698e725712bcf6170ba7e9b5ea2176e63bdb52a400663456540d78e8e75993015805c91d467cf3f72afb3284c115d8ca2fe86c3e00cabee0820c
7
- data.tar.gz: a3eb4e8632d7eda281229524cb6cb595231eea0c7754f2b1a01597b5836dbe2e26f0eb5806d4430b9a37fff6419027329773e866ea8052a5b89706cdf204561b
6
+ metadata.gz: db258bc5034fed17c0e0e0983898c77b8eabc8f81cd049247ee99998abaddb3b6a9cbfde2bbdb548a35621ad493cea26b38d0c9cffb1f1d23409c0df1dd614a7
7
+ data.tar.gz: 0b88d6ff66324262a2b912ad1e9382d4e5184acdf111ece2c353fd801ca7fce9bdd73cb7db52f39d25dd3bb719a6af2fb6df3e1b4154580ebb345059579aed86
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- compensated (0.1.0.pre3)
4
+ compensated (0.1.0.pre4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -20,7 +20,16 @@ module Compensated
20
20
  raw_body: body,
21
21
  raw_event_type: request.data["resource_name"].to_sym,
22
22
  raw_event_id: nil,
23
- payment_processor: :gumroad
23
+ payment_processor: :gumroad,
24
+ amount: {
25
+ paid: request.data["price"].to_i,
26
+ currency: request.data["currency"].upcase,
27
+ },
28
+ customer: {
29
+ id: request.data["purchaser_id"].to_s,
30
+ email: request.data["email"],
31
+ name: request.data["full_name"],
32
+ },
24
33
  }
25
34
  end
26
35
  end
@@ -7,14 +7,61 @@ module Compensated
7
7
  SUPPORTED_EVENTS.include?(request.data[:type])
8
8
  end
9
9
 
10
- def parse(request)
10
+ def normalize(data)
11
+ data = Compensated.json_adapter.parse(data) unless data.respond_to?(:key)
11
12
  {
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],
13
+ raw_body: Compensated.json_adapter.dump(data),
14
+ raw_event_type: data[:type].to_sym,
15
+ raw_event_id: data[:id],
15
16
  payment_processor: :stripe,
17
+ amount: amount(data),
18
+ customer: customer(data),
16
19
  }
17
20
  end
21
+
22
+ def parse(request)
23
+ normalize(request.data)
24
+ end
25
+
26
+ private def customer(data)
27
+ if invoice?(data)
28
+ {
29
+ email: data[:data][:object][:customer_email],
30
+ name: data[:data][:object][:customer_name],
31
+ id: data[:data][:object][:customer],
32
+ }.compact
33
+ else
34
+ {
35
+ id: data[:data][:object][:customer],
36
+ }
37
+ end
38
+ end
39
+
40
+ private def amount(data)
41
+ {
42
+ currency: data[:data][:object][:currency].upcase,
43
+ due: due(data),
44
+ paid: paid(data),
45
+ remaining: remaining(data),
46
+ }.compact
47
+ end
48
+
49
+ private def paid(data)
50
+ return data[:data][:object][:amount_paid] if invoice?(data)
51
+ data[:data][:object][:amount]
52
+ end
53
+
54
+ private def remaining(data)
55
+ data.fetch(:data, {}).fetch(:object, {}).fetch(:amount_remaining, nil)
56
+ end
57
+
58
+ private def due(data)
59
+ data.fetch(:data, {}).fetch(:object, {}).fetch(:amount_due, nil)
60
+ end
61
+
62
+ private def invoice?(data)
63
+ data[:data][:object][:object] == "invoice"
64
+ end
18
65
  end
19
66
  end
20
67
 
@@ -1,3 +1,3 @@
1
1
  module Compensated
2
- VERSION = "0.1.0.pre3"
2
+ VERSION = "0.1.0.pre4"
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.pre3
4
+ version: 0.1.0.pre4
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-13 00:00:00.000000000 Z
11
+ date: 2019-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler