Class: Dodopayments::Resources::Customers

Inherits:
Object
  • Object
show all
Defined in:
lib/dodopayments/resources/customers.rb,
lib/dodopayments/resources/customers/emails.rb,
lib/dodopayments/resources/customers/wallets.rb,
lib/dodopayments/resources/customers/customer_portal.rb,
lib/dodopayments/resources/customers/wallets/ledger_entries.rb,
sig/dodopayments/resources/customers.rbs,
sig/dodopayments/resources/customers/emails.rbs,
sig/dodopayments/resources/customers/wallets.rbs,
sig/dodopayments/resources/customers/customer_portal.rbs,
sig/dodopayments/resources/customers/wallets/ledger_entries.rbs

Defined Under Namespace

Classes: CustomerPortal, Emails, Wallets

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Customers

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Customers.

Parameters:



238
239
240
241
242
243
# File 'lib/dodopayments/resources/customers.rb', line 238

def initialize(client:)
  @client = client
  @customer_portal = Dodopayments::Resources::Customers::CustomerPortal.new(client: client)
  @wallets = Dodopayments::Resources::Customers::Wallets.new(client: client)
  @emails = Dodopayments::Resources::Customers::Emails.new(client: client)
end

Instance Attribute Details

#customer_portalDodopayments::Resources::Customers::CustomerPortal (readonly)



7
8
9
# File 'lib/dodopayments/resources/customers.rb', line 7

def customer_portal
  @customer_portal
end

#emailsDodopayments::Resources::Customers::Emails (readonly)



13
14
15
# File 'lib/dodopayments/resources/customers.rb', line 13

def emails
  @emails
end

#walletsDodopayments::Resources::Customers::Wallets (readonly)



10
11
12
# File 'lib/dodopayments/resources/customers.rb', line 10

def wallets
  @wallets
end

Instance Method Details

#create(email:, name:, metadata: nil, phone_number: nil, request_options: {}) ⇒ Dodopayments::Models::Customer

Parameters:

  • email (String)
  • name (String)
  • metadata (Hash{Symbol=>String, Float, Boolean})

    Additional metadata for the customer

  • phone_number (String, nil)
  • request_options (Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



30
31
32
33
34
35
36
37
38
39
# File 'lib/dodopayments/resources/customers.rb', line 30

def create(params)
  parsed, options = Dodopayments::CustomerCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "customers",
    body: parsed,
    model: Dodopayments::Customer,
    options: options
  )
end

#delete_payment_method(payment_method_id, customer_id:, request_options: {}) ⇒ nil

Parameters:

  • payment_method_id (String)

    Payment Method Id

  • customer_id (String)

    Customer Id

  • request_options (Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/dodopayments/resources/customers.rb', line 130

def delete_payment_method(payment_method_id, params)
  parsed, options = Dodopayments::CustomerDeletePaymentMethodParams.dump_request(params)
  customer_id =
    parsed.delete(:customer_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["customers/%1$s/payment-methods/%2$s", customer_id, payment_method_id],
    model: NilClass,
    options: options
  )
end

#list(created_at_gte: nil, created_at_lte: nil, email: nil, name: nil, page_number: nil, page_size: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::Customer>

Parameters:

  • created_at_gte (Time)

    Filter customers created on or after this timestamp

  • created_at_lte (Time)

    Filter customers created on or before this timestamp

  • email (String)

    Filter by customer email

  • name (String)

    Filter by customer name (partial match, case-insensitive)

  • page_number (Integer)

    Page number default is 0

  • page_size (Integer)

    Page size default is 10 max is 100

  • request_options (Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dodopayments/resources/customers.rb', line 106

def list(params = {})
  parsed, options = Dodopayments::CustomerListParams.dump_request(params)
  query = Dodopayments::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "customers",
    query: query,
    page: Dodopayments::Internal::DefaultPageNumberPagination,
    model: Dodopayments::Customer,
    options: options
  )
end

#list_credit_entitlements(customer_id, request_options: {}) ⇒ Dodopayments::Models::CustomerListCreditEntitlementsResponse

List all credit entitlements for a customer with their current balances

Parameters:

Returns:

See Also:



155
156
157
158
159
160
161
162
# File 'lib/dodopayments/resources/customers.rb', line 155

def list_credit_entitlements(customer_id, params = {})
  @client.request(
    method: :get,
    path: ["customers/%1$s/credit-entitlements", customer_id],
    model: Dodopayments::Models::CustomerListCreditEntitlementsResponse,
    options: params[:request_options]
  )
end

#list_entitlement_grants(customer_id, integration_type: nil, page_number: nil, page_size: nil, status: nil, request_options: {}) ⇒ Dodopayments::Internal::DefaultPageNumberPagination<Dodopayments::Models::Entitlements::EntitlementGrant>

List all of a customer's entitlement grants across every entitlement. One row per grant.

Parameters:

Returns:

See Also:



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/dodopayments/resources/customers.rb', line 184

def list_entitlement_grants(customer_id, params = {})
  parsed, options = Dodopayments::CustomerListEntitlementGrantsParams.dump_request(params)
  query = Dodopayments::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["customers/%1$s/entitlement-grants", customer_id],
    query: query,
    page: Dodopayments::Internal::DefaultPageNumberPagination,
    model: Dodopayments::Entitlements::EntitlementGrant,
    options: options
  )
end

#list_entitlements(customer_id, request_options: {}) ⇒ Dodopayments::Models::CustomerListEntitlementsResponse

List all entitlement grants delivered (or in flight) to a customer.

Parameters:

Returns:

See Also:



208
209
210
211
212
213
214
215
# File 'lib/dodopayments/resources/customers.rb', line 208

def list_entitlements(customer_id, params = {})
  @client.request(
    method: :get,
    path: ["customers/%1$s/entitlements", customer_id],
    model: Dodopayments::Models::CustomerListEntitlementsResponse,
    options: params[:request_options]
  )
end

#retrieve(customer_id, request_options: {}) ⇒ Dodopayments::Models::Customer

Parameters:

Returns:

See Also:



50
51
52
53
54
55
56
57
# File 'lib/dodopayments/resources/customers.rb', line 50

def retrieve(customer_id, params = {})
  @client.request(
    method: :get,
    path: ["customers/%1$s", customer_id],
    model: Dodopayments::Customer,
    options: params[:request_options]
  )
end

#retrieve_payment_methods(customer_id, request_options: {}) ⇒ Dodopayments::Models::CustomerRetrievePaymentMethodsResponse

Parameters:

Returns:

See Also:



226
227
228
229
230
231
232
233
# File 'lib/dodopayments/resources/customers.rb', line 226

def retrieve_payment_methods(customer_id, params = {})
  @client.request(
    method: :get,
    path: ["customers/%1$s/payment-methods", customer_id],
    model: Dodopayments::Models::CustomerRetrievePaymentMethodsResponse,
    options: params[:request_options]
  )
end

#update(customer_id, email: nil, metadata: nil, name: nil, phone_number: nil, request_options: {}) ⇒ Dodopayments::Models::Customer

Parameters:

  • customer_id (String)

    Customer Id

  • email (String, nil)
  • metadata (Hash{Symbol=>String, Float, Boolean}, nil)

    Additional metadata for the customer

  • name (String, nil)
  • phone_number (String, nil)
  • request_options (Dodopayments::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



76
77
78
79
80
81
82
83
84
85
# File 'lib/dodopayments/resources/customers.rb', line 76

def update(customer_id, params = {})
  parsed, options = Dodopayments::CustomerUpdateParams.dump_request(params)
  @client.request(
    method: :patch,
    path: ["customers/%1$s", customer_id],
    body: parsed,
    model: Dodopayments::Customer,
    options: options
  )
end