Module: ChargebeeRails

Defined in:
lib/chargebee_rails/engine.rb,
lib/chargebee_rails.rb,
lib/chargebee_rails/errors.rb,
lib/chargebee_rails/version.rb,
lib/chargebee_rails/customer.rb,
lib/chargebee_rails/sync_plans.rb,
lib/chargebee_rails/subscription.rb,
lib/chargebee_rails/configuration.rb,
lib/chargebee_rails/metered_billing.rb,
lib/chargebee_rails/webhook_handler.rb,
lib/chargebee_rails/subscription_builder.rb,
lib/generators/chargebee_rails/install_generator.rb,
app/controllers/chargebee_rails/webhooks_controller.rb,
lib/chargebee_rails/hosted_page_subscription_manager.rb

Overview

Defined Under Namespace

Modules: Customer, Subscription, WebhookHandler Classes: Configuration, Error, EventEngine, HostedPageSubscriptionManager, InstallGenerator, MeteredBilling, PlanError, SubscriptionBuilder, SyncPlans, UnauthorizedError, WebhooksController

Constant Summary collapse

VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.add_customer_contacts(customer, options = {}) ⇒ Object

Add contacts to a chargebee customer, the subscription owner and the contact details hash is given as options.

  • Args :

    • customer -> the subscription owner

    • options -> the options hash allowed for adding contacts to customer in chargebee

For more details on the options hash, refer the input parameters for apidocs.chargebee.com/docs/api/customers?lang=ruby#add_contacts_to_a_customer

  • Returns :

    • the updated chargebee customer

  • Raises :

    • ChargeBee::InvalidRequestError -> If customer or options is invalid



67
68
69
# File 'lib/chargebee_rails.rb', line 67

def self.add_customer_contacts(customer, options={})
  ChargeBee::Customer.add_contact(customer.chargebee_id, options).customer
end

.configurationObject



4
5
6
# File 'lib/chargebee_rails/configuration.rb', line 4

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



15
16
17
18
# File 'lib/chargebee_rails/configuration.rb', line 15

def self.configure
  yield configuration
  setup
end

.setupObject



8
9
10
11
12
13
# File 'lib/chargebee_rails/configuration.rb', line 8

def self.setup
  ::ChargeBee.configure(
    site: configuration.chargebee_site, 
    api_key: configuration.chargebee_api_key
  )
end

.update_billing_info(customer, options = {}) ⇒ Object

Update the billing information of the chargebee customer. The changes in the billing details are also reflected in the subscription owner’s chargebee_customer_data

  • Args :

    • customer -> the subscription owner

    • options -> the options hash allowed for updating customer billing info in chargebee

For more details on the options hash, refer the input parameters for apidocs.chargebee.com/docs/api/customers?lang=ruby#update_billing_info_for_a_customer

  • Returns :

    • the updated subscription owner

  • Raises :

    • ChargeBee::InvalidRequestError -> If customer or options is invalid



49
50
51
52
53
# File 'lib/chargebee_rails.rb', line 49

def self.update_billing_info(customer, options={})
  chargebee_customer = ChargeBee::Customer.update_billing_info(customer.chargebee_id, options).customer
  customer.update(chargebee_id: chargebee_customer.id, chargebee_data: chargebee_customer_data(chargebee_customer))
  customer
end

.update_customer(customer, options = {}) ⇒ Object

This method is used to update the chargebee customer and also reflects the changes to the subscription owner in the application.

  • Args :

    • customer -> the subscription owner

    • options -> the options hash allowed for customer update in chargebee

For more details on the options hash, refer the input parameters for apidocs.chargebee.com/docs/api/customers?lang=ruby#update_a_customer

  • Returns :

    • the updated subscription owner

  • Raises :

    • ChargeBee::InvalidRequestError -> If customer or options is invalid



30
31
32
33
34
# File 'lib/chargebee_rails.rb', line 30

def self.update_customer(customer, options={})
  chargebee_customer = ChargeBee::Customer.update(customer.chargebee_id, options).customer
  customer.update(chargebee_id: chargebee_customer.id, chargebee_data: chargebee_customer_data(chargebee_customer))
  customer
end

.update_customer_contacts(customer, options = {}) ⇒ Object

Update the contacts for a chargebee customer - the chargebee contact id must be passed in the options to update the existing contact for the subscription owner

  • Args :

    • customer -> the subscription owner

    • options -> the options hash allowed for updating customer contacts in chargebee

For more details on the options hash, refer the input parameters for apidocs.chargebee.com/docs/api/customers?lang=ruby#update_contacts_for_a_customer

  • Returns :

    • the updated chargebee customer

  • Raises :

    • ChargeBee::InvalidRequestError -> If customer or options is invalid



84
85
86
# File 'lib/chargebee_rails.rb', line 84

def self.update_customer_contacts(customer, options={})
  ChargeBee::Customer.update_contact(customer.chargebee_id, options).customer
end