Class: PurchaseKit::Product
- Inherits:
-
Object
- Object
- PurchaseKit::Product
- Defined in:
- lib/purchasekit/product.rb,
lib/purchasekit/product/demo.rb,
lib/purchasekit/product/remote.rb
Overview
Represents a product configured in the PurchaseKit dashboard.
Products contain the store-specific product IDs for Apple and Google. Display text (name, description, price) should be fetched from the stores at runtime or defined in your views for i18n support.
Example:
product = PurchaseKit::Product.find("prod_XXXXX")
product.apple_product_id # => "com.example.pro.annual"
product.google_product_id # => "pro_annual"
Defined Under Namespace
Instance Attribute Summary collapse
-
#apple_product_id ⇒ Object
readonly
Returns the value of attribute apple_product_id.
-
#google_base_plan_id ⇒ Object
readonly
Returns the value of attribute google_base_plan_id.
-
#google_product_id ⇒ Object
readonly
Returns the value of attribute google_product_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
-
.find(id) ⇒ Product
Find a product by ID.
Instance Method Summary collapse
-
#initialize(id:, apple_product_id: nil, google_product_id: nil, google_base_plan_id: nil) ⇒ Product
constructor
A new instance of Product.
-
#store_product_id(platform:) ⇒ String
Get the store-specific product ID for a platform.
Constructor Details
#initialize(id:, apple_product_id: nil, google_product_id: nil, google_base_plan_id: nil) ⇒ Product
Returns a new instance of Product.
16 17 18 19 20 21 |
# File 'lib/purchasekit/product.rb', line 16 def initialize(id:, apple_product_id: nil, google_product_id: nil, google_base_plan_id: nil) @id = id @apple_product_id = apple_product_id @google_product_id = google_product_id @google_base_plan_id = google_base_plan_id end |
Instance Attribute Details
#apple_product_id ⇒ Object (readonly)
Returns the value of attribute apple_product_id.
14 15 16 |
# File 'lib/purchasekit/product.rb', line 14 def apple_product_id @apple_product_id end |
#google_base_plan_id ⇒ Object (readonly)
Returns the value of attribute google_base_plan_id.
14 15 16 |
# File 'lib/purchasekit/product.rb', line 14 def google_base_plan_id @google_base_plan_id end |
#google_product_id ⇒ Object (readonly)
Returns the value of attribute google_product_id.
14 15 16 |
# File 'lib/purchasekit/product.rb', line 14 def google_product_id @google_product_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/purchasekit/product.rb', line 14 def id @id end |
Class Method Details
.find(id) ⇒ Product
Find a product by ID.
In demo mode, reads from configured demo_products. In production, fetches from the PurchaseKit API.
45 46 47 48 49 50 51 |
# File 'lib/purchasekit/product.rb', line 45 def self.find(id) if PurchaseKit.config.demo_mode? Demo.find(id) else Remote.find(id) end end |
Instance Method Details
#store_product_id(platform:) ⇒ String
Get the store-specific product ID for a platform.
28 29 30 31 32 33 34 |
# File 'lib/purchasekit/product.rb', line 28 def store_product_id(platform:) case platform when :apple then apple_product_id when :google then google_product_id else raise ArgumentError, "Unknown platform: #{platform}" end end |