Module: ChargebeeRails::Customer

Defined in:
lib/chargebee_rails/customer.rb

Instance Method Summary collapse

Instance Method Details

#as_chargebee_customerObject

Retrieve the chargebee customer of the subscription owner - i.e subscription owner as chargebee customer

  • Returns :

    • the chargebee customer

  • Raises :

    • ChargeBee::InvalidRequestError -> If subscription owner is invalid



70
71
72
# File 'lib/chargebee_rails/customer.rb', line 70

def as_chargebee_customer
  ChargeBee::Customer.retrieve(chargebee_id).customer
end

#invoicesObject

List all invoices for the subscription owner (customer).

  • Returns :

    • the list of invoices for the customer in chargebee

  • Raises :

    • ChargeBee::InvalidRequestError -> If customer is invalid



80
81
82
# File 'lib/chargebee_rails/customer.rb', line 80

def invoices
  ChargeBee::Invoice.invoices_for_customer(chargebee_id).map(&:invoice)
end

#subscribe(options = {}) ⇒ Object

Subscribe customer to a new subscription in chargebee.

  • Args :

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

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

  • Returns :

    • the subscription

  • Raises :

    • ChargeBee::InvalidRequestError -> If subscription options is invalid



14
15
16
# File 'lib/chargebee_rails/customer.rb', line 14

def subscribe(options={})
  SubscriptionBuilder.new(self, options).create
end

#subscribe_via_hosted_page(hosted_page) ⇒ Object

Subscribe customer to a new subscription in chargebee via chargebee’s hosted page.

  • Args :

    • hosted_page -> the hosted_page returned by chargebee

The subscription for the customer is created from the hosted_page returned by chargebee. This hosted_page object contains the details about the subscription in chargebee for the customer. For more on hosted_page apidocs.chargebee.com/docs/api/hosted_pages?lang=ruby#checkout_new_subscription

  • Returns :

    • the subscription

  • Raises :

    • ChargeBee::InvalidRequestError -> If hosted_page is invalid



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

def subscribe_via_hosted_page(hosted_page)
  HostedPageSubscriptionManager.new(self, hosted_page).create
end

#update_subscription(options = {}) ⇒ Object

Update the customer’s subscription

  • Args :

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

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

  • Returns :

    • the updated subscription

  • Raises :

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



59
60
61
# File 'lib/chargebee_rails/customer.rb', line 59

def update_subscription(options={})
  SubscriptionBuilder.new(self, options).update
end

#update_subscription_via_hosted_page(hosted_page) ⇒ Object

Subscribe customer to a new subscription in chargebee via chargebee’s hosted page.

  • Args :

    • hosted_page -> the hosted_page returned by chargebee

The subscription for the customer is updated from the hosted_page returned by chargebee. This hosted_page object contains the details about the updated subscription in chargebee for the customer.

  • Returns :

    • the subscription

  • Raises :

    • ChargeBee::InvalidRequestError -> If hosted_page is invalid



45
46
47
# File 'lib/chargebee_rails/customer.rb', line 45

def update_subscription_via_hosted_page(hosted_page)
  HostedPageSubscriptionManager.new(self, hosted_page).update
end