Class: Cryptopay::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptopay/api/subscriptions.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Subscriptions

Returns a new instance of Subscriptions.



8
9
10
# File 'lib/cryptopay/api/subscriptions.rb', line 8

def initialize(connection)
  @connection = connection
end

Instance Method Details

#cancel(subscription_id, _opts = {}) ⇒ SubscriptionResult

Cancel a subscription

Parameters:

  • subscription_id (String)

    Subscription ID

  • opts (Hash)

    the optional parameters

Returns:



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cryptopay/api/subscriptions.rb', line 16

def cancel(subscription_id, _opts = {})
  path = '/api/subscriptions/{subscription_id}/cancel'
  path = path.sub('{subscription_id}', CGI.escape(subscription_id.to_s))

  req = Request.new(
    method: :post,
    path: path
  )

  connection.call(req, return_type: SubscriptionResult)
end

#create(subscription_params, _opts = {}) ⇒ SubscriptionResult

Create a subscription

Parameters:

Returns:



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cryptopay/api/subscriptions.rb', line 32

def create(subscription_params, _opts = {})
  path = '/api/subscriptions'

  req = Request.new(
    method: :post,
    path: path,
    body_params: subscription_params
  )

  connection.call(req, return_type: SubscriptionResult)
end

#list(opts = {}) ⇒ SubscriptionListResult

List subscriptions

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :starting_after (String)

    Pagination parameter. ID to start after

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cryptopay/api/subscriptions.rb', line 48

def list(opts = {})
  path = '/api/subscriptions'

  query_params = {}
  query_params[:starting_after] = opts[:starting_after] unless opts[:starting_after].nil?

  req = Request.new(
    method: :get,
    path: path,
    query_params: query_params
  )

  connection.call(req, return_type: SubscriptionListResult)
end

#retrieve(subscription_id, _opts = {}) ⇒ SubscriptionResult

Retrieve a subscription

Parameters:

  • subscription_id (String)

    Subscription ID

  • opts (Hash)

    the optional parameters

Returns:



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cryptopay/api/subscriptions.rb', line 67

def retrieve(subscription_id, _opts = {})
  path = '/api/subscriptions/{subscription_id}'
  path = path.sub('{subscription_id}', CGI.escape(subscription_id.to_s))

  req = Request.new(
    method: :get,
    path: path
  )

  connection.call(req, return_type: SubscriptionResult)
end

#retrieve_by_custom_id(custom_id, _opts = {}) ⇒ SubscriptionResult

Retrieve a subscription by custom_id

Parameters:

  • custom_id (String)
  • opts (Hash)

    the optional parameters

Returns:



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/cryptopay/api/subscriptions.rb', line 83

def retrieve_by_custom_id(custom_id, _opts = {})
  path = '/api/subscriptions/custom_id/{custom_id}'
  path = path.sub('{custom_id}', CGI.escape(custom_id.to_s))

  req = Request.new(
    method: :get,
    path: path
  )

  connection.call(req, return_type: SubscriptionResult)
end