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.
-
#google_base_plan_id ⇒ Object
The Google Play base plan ID (e.g., “annual”, “monthly”).
-
#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
120 121 122 |
# File 'lib/purchasekit/events.rb', line 120 def current_period_end parse_time(payload[:current_period_end]) end |
#current_period_start ⇒ Object
When the current billing period started
115 116 117 |
# File 'lib/purchasekit/events.rb', line 115 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)
125 126 127 |
# File 'lib/purchasekit/events.rb', line 125 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 |
#google_base_plan_id ⇒ Object
The Google Play base plan ID (e.g., “annual”, “monthly”). Only present when the purchase used Google’s umbrella subscription with multiple base plans. Nil for Apple and for flat Google products.
100 101 102 |
# File 'lib/purchasekit/events.rb', line 100 def google_base_plan_id payload[:google_base_plan_id] end |
#status ⇒ Object
Current status: “active”, “canceled”, “expired”, etc.
110 111 112 |
# File 'lib/purchasekit/events.rb', line 110 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
105 106 107 |
# File 'lib/purchasekit/events.rb', line 105 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.
136 137 138 |
# File 'lib/purchasekit/events.rb', line 136 def success_path payload[:success_path] end |
#trial_ends_at ⇒ Object
When the trial period ends (nil if no trial)
130 131 132 |
# File 'lib/purchasekit/events.rb', line 130 def trial_ends_at parse_time(payload[:trial_ends_at]) end |