Class: PurchaseKit::Events::Event
- Inherits:
-
Object
- Object
- PurchaseKit::Events::Event
- Defined in:
- lib/purchasekit/events.rb
Overview
Represents a subscription event from Apple or Google.
Events are normalized by the PurchaseKit SaaS before being sent to your application, so you get a consistent interface regardless of which store the purchase came from.
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#current_period_end ⇒ Object
When the current billing period ends.
-
#current_period_start ⇒ Object
When the current billing period started.
-
#customer_id ⇒ Object
The customer ID you passed when creating the purchase intent.
-
#ends_at ⇒ Object
When the subscription will end (for canceled subscriptions).
-
#event_id ⇒ Object
Unique identifier for this event.
-
#initialize(type:, payload:) ⇒ Event
constructor
A new instance of Event.
-
#status ⇒ Object
Current status: “active”, “canceled”, “expired”, etc.
-
#store ⇒ Object
Which store the purchase came from: “apple” or “google”.
-
#store_product_id ⇒ Object
The store-specific product ID (e.g., “com.example.pro.annual”).
-
#subscription_id ⇒ Object
The unique subscription ID from the store.
-
#subscription_name ⇒ Object
The subscription name you configured in PurchaseKit.
-
#success_path ⇒ Object
The success path you passed when creating the purchase intent.
-
#trial_ends_at ⇒ Object
When the trial period ends (nil if no trial).
Constructor Details
#initialize(type:, payload:) ⇒ Event
Returns a new instance of Event.
63 64 65 66 |
# File 'lib/purchasekit/events.rb', line 63 def initialize(type:, payload:) @type = type.to_sym @payload = payload.is_a?(Hash) ? payload.with_indifferent_access : payload end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
61 62 63 |
# File 'lib/purchasekit/events.rb', line 61 def payload @payload end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
61 62 63 |
# File 'lib/purchasekit/events.rb', line 61 def type @type end |
Instance Method Details
#current_period_end ⇒ Object
When the current billing period ends
113 114 115 |
# File 'lib/purchasekit/events.rb', line 113 def current_period_end parse_time(payload[:current_period_end]) end |
#current_period_start ⇒ Object
When the current billing period started
108 109 110 |
# File 'lib/purchasekit/events.rb', line 108 def current_period_start parse_time(payload[:current_period_start]) end |
#customer_id ⇒ Object
The customer ID you passed when creating the purchase intent. Use this to look up the user in your database.
76 77 78 |
# File 'lib/purchasekit/events.rb', line 76 def customer_id payload[:customer_id] end |
#ends_at ⇒ Object
When the subscription will end (for canceled subscriptions)
118 119 120 |
# File 'lib/purchasekit/events.rb', line 118 def ends_at parse_time(payload[:ends_at]) end |
#event_id ⇒ Object
Unique identifier for this event. Use for idempotency checks. Store processed event_ids to prevent duplicate processing.
70 71 72 |
# File 'lib/purchasekit/events.rb', line 70 def event_id payload[:event_id] end |
#status ⇒ Object
Current status: “active”, “canceled”, “expired”, etc.
103 104 105 |
# File 'lib/purchasekit/events.rb', line 103 def status payload[:status] end |
#store ⇒ Object
Which store the purchase came from: “apple” or “google”
88 89 90 |
# File 'lib/purchasekit/events.rb', line 88 def store payload[:store] end |
#store_product_id ⇒ Object
The store-specific product ID (e.g., “com.example.pro.annual”)
93 94 95 |
# File 'lib/purchasekit/events.rb', line 93 def store_product_id payload[:store_product_id] end |
#subscription_id ⇒ Object
The unique subscription ID from the store. Apple: originalTransactionId Google: purchaseToken
83 84 85 |
# File 'lib/purchasekit/events.rb', line 83 def subscription_id payload[:subscription_id] end |
#subscription_name ⇒ Object
The subscription name you configured in PurchaseKit
98 99 100 |
# File 'lib/purchasekit/events.rb', line 98 def subscription_name payload[:subscription_name] end |
#success_path ⇒ Object
The success path you passed when creating the purchase intent. Use this for redirecting after purchase completion.
129 130 131 |
# File 'lib/purchasekit/events.rb', line 129 def success_path payload[:success_path] end |
#trial_ends_at ⇒ Object
When the trial period ends (nil if no trial)
123 124 125 |
# File 'lib/purchasekit/events.rb', line 123 def trial_ends_at parse_time(payload[:trial_ends_at]) end |