Class: BunnyApp::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny_app/subscription.rb

Class Method Summary collapse

Class Method Details

.cancel(subscription_id:) ⇒ Object

Raises:



153
154
155
156
157
158
159
160
161
162
# File 'lib/bunny_app/subscription.rb', line 153

def self.cancel(subscription_id:)
  variables = {
    ids: [subscription_id]
  }

  res = Client.new.query(@subscription_cancel_mutation, variables)
  raise ResponseError, res['data']['subscriptionCancel']['errors'].join(',') if res['data']['subscriptionCancel']['errors']

  true
end

.create(price_list_code:, options: {}) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity

Raises:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/bunny_app/subscription.rb', line 81

def self.create(price_list_code:, options: {})
  variables = {
    attributes: {
      priceListCode: price_list_code,
      trial: options[:trial] || false,
      evergreen: options[:evergreen] || false
    }
  }

  if options[:account_id]
    variables[:attributes][:accountId] = options[:account_id]
  else
    variables[:attributes][:account] = {
      name: options[:account_name]&.to_s,
      billingContact: {
        firstName: options[:first_name]&.to_s,
        lastName: options[:last_name]&.to_s,
        email: options[:email]&.to_s
      }
    }
  end

  if options[:tenant_code]
    variables[:attributes][:tenant] = {
      code: options[:tenant_code]&.to_s,
      name: options[:tenant_name]&.to_s
    }
  end

  res = Client.new.query(@subscription_create_mutation, variables)
  raise ResponseError, res['data']['subscriptionCreate']['errors'].join(',') if res['data']['subscriptionCreate']['errors']

  res['data']['subscriptionCreate']['subscription']
end

.quantity_update(subscription_id:, quantities:, options: {}) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/bunny_app/subscription.rb', line 116

def self.quantity_update(subscription_id:, quantities:, options: {})
  variables = {
    subscriptionId: subscription_id,
    quantities:,
    invoiceImmediately: options[:invoice_immediately] || false,
    startDate: options[:start_date],
    name: options[:name],
    allowQuantityLimitsOverride: options[:allow_quantity_limits_override] || false
  }

  res = Client.new.query(@subscription_quantity_update_mutation, variables)
  if res['data']['subscriptionQuantityUpdate']['errors']
    raise ResponseError,
          res['data']['subscriptionQuantityUpdate']['errors'].join(',')
  end

  res['data']['subscriptionQuantityUpdate']['quote']
end

.trial_convert(subscription_id:, price_list_id: nil, price_list_code: nil, payment_id: nil) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/bunny_app/subscription.rb', line 135

def self.trial_convert(subscription_id:, price_list_id: nil, price_list_code: nil, payment_id: nil)
  variables = {
    subscriptionId: subscription_id
  }

  variables[:paymentId] = payment_id if payment_id
  variables[:priceListId] = price_list_id if price_list_id
  variables[:priceListCode] = price_list_code if price_list_code

  res = Client.new.query(@subscription_trial_convert_mutation, variables)
  if res['data']['subscriptionTrialConvert']['errors']
    raise ResponseError,
          res['data']['subscriptionTrialConvert']['errors'].join(',')
  end

  res['data']['subscriptionTrialConvert']
end