Class: PurchaseKit::Purchase::Intent

Inherits:
Object
  • Object
show all
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

Direct Known Subclasses

Demo, Remote

Defined Under Namespace

Classes: Demo, Remote

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/purchasekit/purchase/intent.rb', line 22

def id
  @id
end

#productObject (readonly)

Returns the value of attribute product.



22
23
24
# File 'lib/purchasekit/purchase/intent.rb', line 22

def product
  @product
end

#success_pathObject (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

#uuidObject (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.

Parameters:

  • product_id (String)

    The PurchaseKit product ID

  • customer_id (Integer, String)

    Your customer/user ID (will be included in webhooks)

  • success_path (String) (defaults to: nil)

    Where to redirect after successful purchase

  • environment (String) (defaults to: nil)

    “sandbox” or “production”

Returns:

Raises:



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_urlObject

Override in subclasses if needed



32
33
34
# File 'lib/purchasekit/purchase/intent.rb', line 32

def xcode_completion_url
  nil
end