ruby_native 0.21.1 → 0.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 214a6d7b02be3c7c90c308071419aae2ea57f13257450199eab2eab0ef9f7e6b
4
- data.tar.gz: c2791d0963affa9ad1fa1bd3774ebef1ffa102605814c4085180adfb354d9218
3
+ metadata.gz: 75acfc035b871e5a9119b4eb519cbe88ee50e5ec70d7ec4c06cc7788d4a5fbe1
4
+ data.tar.gz: b3faa7112b75471d344d13930109b721520f0dcf0a97d8e2d514bfcb147fbd92
5
5
  SHA512:
6
- metadata.gz: 4b94380d87da65e5f8ac6b8a0cabf310c692325a3394ad8ac581ac8d86eadd95828d28fded7157e93a11ad57df580d7695c71e5edf672c2faff83f63e418cc22
7
- data.tar.gz: 974292315e6f1d86746295a56a71f1dfef557d78d7db371112f3060577c6ae96a189c72188262559c2cde8198d0f672f104a5e81389b736c65a96ebdcecdb75f
6
+ metadata.gz: 185ee05736b75bc3e0625fc498511cf744fc7c0f28a6284d3d83d3d19a4983782a95911386003f57d2ce8ef9bdb6800919adb53a03371b1ee279c9406c2e3b8f
7
+ data.tar.gz: 3c9bd57c913a361a4796cfc2f7f0b0bd137a1dc0ecbc1f4128ea32ac0129895b14751be09c81953759feef7f7367bde7c41f9c3f150e50b754508ccd5e33a33c
@@ -15,7 +15,7 @@ module RubyNative
15
15
  intent.update!(status: :completed, environment: transaction["environment"]&.downcase)
16
16
 
17
17
  event = Event.new(
18
- type: "subscription.created",
18
+ type: one_time_product?(transaction["type"]) ? "purchase.created" : "subscription.created",
19
19
  status: "active",
20
20
  owner_token: intent.customer_id,
21
21
  product_id: transaction["productId"],
@@ -54,7 +54,7 @@ module RubyNative
54
54
  intent.update!(intent_attributes(transaction))
55
55
 
56
56
  event = Event.new(
57
- type: "subscription.created",
57
+ type: one_time_product?(transaction["type"]) ? "purchase.created" : "subscription.created",
58
58
  status: "active",
59
59
  owner_token: intent.customer_id,
60
60
  product_id: transaction["productId"],
@@ -16,6 +16,7 @@ module RubyNative
16
16
  :purchase_date,
17
17
  :expires_date,
18
18
  :offer_type,
19
+ :product_type,
19
20
  :environment
20
21
  )
21
22
 
@@ -38,6 +39,7 @@ module RubyNative
38
39
  purchase_date: parse_timestamp(transaction_info["purchaseDate"]),
39
40
  expires_date: parse_timestamp(transaction_info["expiresDate"]),
40
41
  offer_type: transaction_info["offerType"],
42
+ product_type: transaction_info["type"],
41
43
  environment: payload["data"]["environment"]&.downcase
42
44
  )
43
45
  end
@@ -58,6 +60,11 @@ module RubyNative
58
60
  raise VerificationError, "signedDate is out of range"
59
61
  end
60
62
 
63
+ # Apple's `type` on a transaction. Anything but an auto-renewing subscription is a one-time purchase.
64
+ def one_time_product?(product_type)
65
+ product_type.present? && product_type != "Auto-Renewable Subscription"
66
+ end
67
+
61
68
  def parse_timestamp(milliseconds)
62
69
  return nil if milliseconds.nil?
63
70
  Time.at(milliseconds / 1000.0).utc
@@ -31,7 +31,15 @@ module RubyNative
31
31
  end
32
32
 
33
33
  def created?
34
- type == "subscription.created"
34
+ type == "subscription.created" || type == "purchase.created"
35
+ end
36
+
37
+ def one_time?
38
+ type.start_with?("purchase.")
39
+ end
40
+
41
+ def refunded?
42
+ type == "purchase.refunded"
35
43
  end
36
44
 
37
45
  def canceled?
@@ -1,6 +1,8 @@
1
1
  module RubyNative
2
2
  module IAP
3
3
  module Normalizable
4
+ include Decodable
5
+
4
6
  TYPE_MAPPING = {
5
7
  "SUBSCRIBED" => "subscription.created",
6
8
  "DID_RENEW" => "subscription.updated",
@@ -18,16 +20,28 @@ module RubyNative
18
20
  "REFUND" => "subscription.expired"
19
21
  }.freeze
20
22
 
23
+ ONE_TIME_TYPE_MAPPING = {
24
+ "ONE_TIME_CHARGE" => "purchase.created",
25
+ "REFUND" => "purchase.refunded"
26
+ }.freeze
27
+
21
28
  STATUS_MAPPING = {
22
29
  "subscription.created" => "active",
23
30
  "subscription.updated" => "active",
24
31
  "subscription.canceled" => "active",
25
- "subscription.expired" => "expired"
32
+ "subscription.expired" => "expired",
33
+ "purchase.created" => "active",
34
+ "purchase.updated" => "active",
35
+ "purchase.refunded" => "expired"
26
36
  }.freeze
27
37
 
28
38
  private
29
39
 
30
40
  def normalized_type(notification)
41
+ if one_time_product?(notification.product_type)
42
+ return ONE_TIME_TYPE_MAPPING[notification.notification_type] || "purchase.updated"
43
+ end
44
+
31
45
  mapping = TYPE_MAPPING[notification.notification_type]
32
46
 
33
47
  if mapping.is_a?(Hash)
@@ -1,3 +1,3 @@
1
1
  module RubyNative
2
- VERSION = "0.21.1"
2
+ VERSION = "0.21.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.1
4
+ version: 0.21.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Masilotti