Class: PurchaseKit::Purchase::Intent
- Inherits:
-
Object
- Object
- PurchaseKit::Purchase::Intent
- Defined in:
- lib/purchasekit/purchase/intent.rb,
lib/purchasekit/purchase/intent/demo.rb,
lib/purchasekit/purchase/intent/remote.rb
Overview
Represents a purchase intent - the record created before a user initiates an in-app purchase.
The intent contains a UUID that gets passed to the store as the appAccountToken (Apple) or obfuscatedAccountId (Google). This allows PurchaseKit to correlate the store’s webhook with your user.
Example:
intent = PurchaseKit::Purchase::Intent.create(
product_id: "prod_XXXXX",
customer_id: current_user.payment_processor.id,
success_path: "/dashboard",
environment: "sandbox"
)
intent.uuid # => Pass to native app for store purchase
intent.product # => Contains store product IDs
Defined Under Namespace
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#success_path ⇒ Object
readonly
Returns the value of attribute success_path.
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Class Method Summary collapse
-
.create(product_id:, customer_id:, success_path: nil, environment: nil) ⇒ Intent
Create a new purchase intent.
Instance Method Summary collapse
-
#initialize(id:, uuid:, product:, success_path: nil) ⇒ Intent
constructor
A new instance of Intent.
-
#xcode_completion_url ⇒ Object
Override in subclasses if needed.
Constructor Details
#initialize(id:, uuid:, product:, success_path: nil) ⇒ Intent
Returns a new instance of Intent.
24 25 26 27 28 29 |
# File 'lib/purchasekit/purchase/intent.rb', line 24 def initialize(id:, uuid:, product:, success_path: nil) @id = id @uuid = uuid @product = product @success_path = success_path end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/purchasekit/purchase/intent.rb', line 22 def id @id end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
22 23 24 |
# File 'lib/purchasekit/purchase/intent.rb', line 22 def product @product end |
#success_path ⇒ Object (readonly)
Returns the value of attribute success_path.
22 23 24 |
# File 'lib/purchasekit/purchase/intent.rb', line 22 def success_path @success_path end |
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
22 23 24 |
# File 'lib/purchasekit/purchase/intent.rb', line 22 def uuid @uuid end |
Class Method Details
.create(product_id:, customer_id:, success_path: nil, environment: nil) ⇒ Intent
Create a new purchase intent.
46 47 48 49 50 51 52 |
# File 'lib/purchasekit/purchase/intent.rb', line 46 def self.create(product_id:, customer_id:, success_path: nil, environment: nil) if PurchaseKit.config.demo_mode? Demo.create(product_id:, customer_id:, success_path:) else Remote.create(product_id:, customer_id:, success_path:, environment:) end end |
Instance Method Details
#xcode_completion_url ⇒ Object
Override in subclasses if needed
32 33 34 |
# File 'lib/purchasekit/purchase/intent.rb', line 32 def xcode_completion_url nil end |