Class: MetrifoxSDK::Checkout::Module

Inherits:
BaseModule show all
Defined in:
lib/metrifox_sdk/checkout/module.rb

Instance Attribute Summary

Attributes inherited from BaseModule

#client

Instance Method Summary collapse

Methods inherited from BaseModule

#initialize

Constructor Details

This class inherits a constructor from MetrifoxSDK::BaseModule

Instance Method Details

#card_collection_url(subscription_id: nil, order_id: nil) ⇒ Object

Raises:

  • (StandardError)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/metrifox_sdk/checkout/module.rb', line 29

def card_collection_url(subscription_id: nil, order_id: nil)
  validate_api_key!

  if (subscription_id.nil? || subscription_id.to_s.empty?) && (order_id.nil? || order_id.to_s.empty?)
    raise ArgumentError, "Either subscription_id or order_id is required"
  end

  query_params = {}
  query_params[:subscription_id] = subscription_id if subscription_id && !subscription_id.to_s.empty?
  query_params[:order_id] = order_id if order_id && !order_id.to_s.empty?

  checkout_url = api.generate_card_collection_url(base_url, api_key, query_params)
  raise StandardError, "Card collection URL could not be generated" if checkout_url.nil? || checkout_url.empty?

  checkout_url
end

#url(config) ⇒ Object

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/metrifox_sdk/checkout/module.rb', line 7

def url(config)
  validate_api_key!

  # Handle both hash and struct access patterns
  offering_key = get_value(config, :offering_key)
  billing_interval = get_value(config, :billing_interval)
  customer_key = get_value(config, :customer_key)

  raise ArgumentError, "offering_key is required" if offering_key.nil? || offering_key.empty?

  # Build query parameters
  query_params = { offering_key: offering_key }
  query_params[:billing_interval] = billing_interval if billing_interval && !billing_interval.empty?
  query_params[:customer_key] = customer_key if customer_key && !customer_key.empty?

  # Call API to generate checkout URL
  checkout_url = api.generate_checkout_url(base_url, api_key, query_params)
  raise StandardError, "Checkout URL could not be generated" if checkout_url.nil? || checkout_url.empty?

  checkout_url
end