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:



86
87
88
89
90
91
92
93
94
95
# File 'lib/bunny_app/subscription.rb', line 86

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:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bunny_app/subscription.rb', line 51

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