Class: Stripe::CustomerService

Inherits:
StripeService show all
Defined in:
lib/stripe/services/customer_service.rb

Defined Under Namespace

Classes: CreateParams, DeleteDiscountParams, DeleteParams, ListParams, RetrieveParams, SearchParams, UpdateParams

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from StripeService

#request, #request_stream

Constructor Details

#initialize(requestor) ⇒ CustomerService

Returns a new instance of CustomerService.



8
9
10
11
12
13
14
15
16
17
# File 'lib/stripe/services/customer_service.rb', line 8

def initialize(requestor)
  super
  @cash_balance = Stripe::CustomerCashBalanceService.new(@requestor)
  @balance_transactions = Stripe::CustomerBalanceTransactionService.new(@requestor)
  @cash_balance_transactions = Stripe::CustomerCashBalanceTransactionService.new(@requestor)
  @payment_sources = Stripe::CustomerPaymentSourceService.new(@requestor)
  @tax_ids = Stripe::CustomerTaxIdService.new(@requestor)
  @payment_methods = Stripe::CustomerPaymentMethodService.new(@requestor)
  @funding_instructions = Stripe::CustomerFundingInstructionsService.new(@requestor)
end

Instance Attribute Details

#balance_transactionsObject (readonly)

Returns the value of attribute balance_transactions.



6
7
8
# File 'lib/stripe/services/customer_service.rb', line 6

def balance_transactions
  @balance_transactions
end

#cash_balanceObject (readonly)

Returns the value of attribute cash_balance.



6
7
8
# File 'lib/stripe/services/customer_service.rb', line 6

def cash_balance
  @cash_balance
end

#cash_balance_transactionsObject (readonly)

Returns the value of attribute cash_balance_transactions.



6
7
8
# File 'lib/stripe/services/customer_service.rb', line 6

def cash_balance_transactions
  @cash_balance_transactions
end

#funding_instructionsObject (readonly)

Returns the value of attribute funding_instructions.



6
7
8
# File 'lib/stripe/services/customer_service.rb', line 6

def funding_instructions
  @funding_instructions
end

#payment_methodsObject (readonly)

Returns the value of attribute payment_methods.



6
7
8
# File 'lib/stripe/services/customer_service.rb', line 6

def payment_methods
  @payment_methods
end

#payment_sourcesObject (readonly)

Returns the value of attribute payment_sources.



6
7
8
# File 'lib/stripe/services/customer_service.rb', line 6

def payment_sources
  @payment_sources
end

#tax_idsObject (readonly)

Returns the value of attribute tax_ids.



6
7
8
# File 'lib/stripe/services/customer_service.rb', line 6

def tax_ids
  @tax_ids
end

Instance Method Details

#create(params = {}, opts = {}) ⇒ Object

Creates a new customer object.



595
596
597
# File 'lib/stripe/services/customer_service.rb', line 595

def create(params = {}, opts = {})
  request(method: :post, path: "/v1/customers", params: params, opts: opts, base_address: :api)
end

#delete(customer, params = {}, opts = {}) ⇒ Object

Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.



600
601
602
603
604
605
606
607
608
# File 'lib/stripe/services/customer_service.rb', line 600

def delete(customer, params = {}, opts = {})
  request(
    method: :delete,
    path: format("/v1/customers/%<customer>s", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

#delete_discount(customer, params = {}, opts = {}) ⇒ Object

Removes the currently applied discount on a customer.



611
612
613
614
615
616
617
618
619
# File 'lib/stripe/services/customer_service.rb', line 611

def delete_discount(customer, params = {}, opts = {})
  request(
    method: :delete,
    path: format("/v1/customers/%<customer>s/discount", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

#list(params = {}, opts = {}) ⇒ Object

Returns a list of your customers. The customers are returned sorted by creation date, with the most recent customers appearing first.



622
623
624
# File 'lib/stripe/services/customer_service.rb', line 622

def list(params = {}, opts = {})
  request(method: :get, path: "/v1/customers", params: params, opts: opts, base_address: :api)
end

#retrieve(customer, params = {}, opts = {}) ⇒ Object

Retrieves a Customer object.



627
628
629
630
631
632
633
634
635
# File 'lib/stripe/services/customer_service.rb', line 627

def retrieve(customer, params = {}, opts = {})
  request(
    method: :get,
    path: format("/v1/customers/%<customer>s", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end

#search(params = {}, opts = {}) ⇒ Object

Search for customers you’ve previously created using Stripe’s [Search Query Language](docs.stripe.com/docs/search#search-query-language). Don’t use search in read-after-write flows where strict consistency is necessary. Under normal operating conditions, data is searchable in less than a minute. Occasionally, propagation of new or updated data can be up to an hour behind during outages. Search functionality is not available to merchants in India.



641
642
643
644
645
646
647
648
649
# File 'lib/stripe/services/customer_service.rb', line 641

def search(params = {}, opts = {})
  request(
    method: :get,
    path: "/v1/customers/search",
    params: params,
    opts: opts,
    base_address: :api
  )
end

#update(customer, params = {}, opts = {}) ⇒ Object

Updates the specified customer by setting the values of the parameters passed. Any parameters not provided will be left unchanged. For example, if you pass the source parameter, that becomes the customer’s active source (e.g., a card) to be used for all charges in the future. When you update a customer to a new valid card source by passing the source parameter: for each of the customer’s current subscriptions, if the subscription bills automatically and is in the past_due state, then the latest open invoice for the subscription with automatic collection enabled will be retried. This retry will not count as an automatic retry, and will not affect the next regularly scheduled payment for the invoice. Changing the default_source for a customer will not trigger this behavior.

This request accepts mostly the same arguments as the customer creation call.



654
655
656
657
658
659
660
661
662
# File 'lib/stripe/services/customer_service.rb', line 654

def update(customer, params = {}, opts = {})
  request(
    method: :post,
    path: format("/v1/customers/%<customer>s", { customer: CGI.escape(customer) }),
    params: params,
    opts: opts,
    base_address: :api
  )
end