Class: Pago::V2026_04::Services::Customers
- Defined in:
- lib/pago/v2026_04/services/customers.rb,
sig/pago/v2026_04/generated.rbs
Defined Under Namespace
Classes: Members
Instance Attribute Summary
Attributes inherited from Service
Instance Method Summary collapse
-
#create(body: {}) ⇒ Object
Create a customer.
-
#delete(id, anonymize: false) ⇒ nil
Delete a customer.
-
#delete_external(external_id, anonymize: false) ⇒ nil
Delete a customer by external ID.
-
#export(organization_id: nil) ⇒ String
Export customers as a CSV file.
-
#get(id) ⇒ Object
Get a customer by ID.
-
#get_external(external_id) ⇒ Object
Get a customer by external ID.
-
#get_state(id) ⇒ Object
Get a customer state by ID.
-
#get_state_external(external_id) ⇒ Object
Get a customer state by external ID.
-
#list(organization_id: nil, email: nil, query: nil, active: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil) ⇒ Models::ListResourceCustomer
List customers.
-
#list_each(organization_id: nil, email: nil, query: nil, active: nil, limit: 10, sorting: ["-created_at"], metadata: nil) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of
list, fetching pages on demand. -
#list_payment_methods(id, page: 1, limit: 10) ⇒ Models::ListResourcePaymentMethod
Get saved payment methods of a customer.
-
#list_payment_methods_each(id, limit: 10) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of
list_payment_methods, fetching pages on demand. -
#list_payment_methods_external(external_id, page: 1, limit: 10) ⇒ Models::ListResourcePaymentMethod
Get saved payment methods of a customer by external ID.
-
#list_payment_methods_external_each(external_id, limit: 10) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of
list_payment_methods_external, fetching pages on demand. - #members ⇒ Members
-
#update(id, body: {}) ⇒ Object
Update a customer.
-
#update_external(external_id, body: {}) ⇒ Object
Update a customer by external ID.
Methods inherited from Service
Constructor Details
This class inherits a constructor from Pago::Service
Instance Method Details
#create(body: {}) ⇒ Object
Create a customer.
Scopes: customers:write
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/pago/v2026_04/services/customers.rb', line 56 def create(body: {}) data = client.request( http_method: "POST", path: "/v1/customers/", path_params: {}, query: {}, body: body, response_type: :json, errors: { 422 => Errors::HTTPValidationError } ) Unions::Customer.from_json(data) end |
#delete(id, anonymize: false) ⇒ nil
Delete a customer.
This action cannot be undone and will immediately:
- Cancel any active subscriptions for the customer
- Revoke all their benefits
- Clear any
external_id
Use it only in the context of deleting a user within your own service. Otherwise, use more granular API endpoints to cancel a specific subscription or revoke certain benefits.
Note: The customers information will nonetheless be retained for historic orders and subscriptions.
Set anonymize=true to also anonymize PII for GDPR compliance.
Scopes: customers:write
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/pago/v2026_04/services/customers.rb', line 133 def delete(id, anonymize: false) client.request( http_method: "DELETE", path: "/v1/customers/{id}", path_params: { "id" => id }, query: { "anonymize" => anonymize }, response_type: :none, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) end |
#delete_external(external_id, anonymize: false) ⇒ nil
Delete a customer by external ID.
Immediately cancels any active subscriptions and revokes any active benefits.
Set anonymize=true to also anonymize PII for GDPR compliance.
Scopes: customers:write
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/pago/v2026_04/services/customers.rb', line 202 def delete_external(external_id, anonymize: false) client.request( http_method: "DELETE", path: "/v1/customers/external/{external_id}", path_params: { "external_id" => external_id }, query: { "anonymize" => anonymize }, response_type: :none, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) end |
#export(organization_id: nil) ⇒ String
Export customers as a CSV file.
Scopes: customers:read customers:write
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pago/v2026_04/services/customers.rb', line 77 def export(organization_id: nil) client.request( http_method: "GET", path: "/v1/customers/export", path_params: {}, query: { "organization_id" => organization_id }, response_type: :text, errors: { 422 => Errors::HTTPValidationError } ) end |
#get(id) ⇒ Object
Get a customer by ID.
Scopes: customers:read customers:write
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pago/v2026_04/services/customers.rb', line 97 def get(id) data = client.request( http_method: "GET", path: "/v1/customers/{id}", path_params: { "id" => id }, query: {}, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::Customer.from_json(data) end |
#get_external(external_id) ⇒ Object
Get a customer by external ID.
Scopes: customers:read customers:write
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/pago/v2026_04/services/customers.rb', line 176 def get_external(external_id) data = client.request( http_method: "GET", path: "/v1/customers/external/{external_id}", path_params: { "external_id" => external_id }, query: {}, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::Customer.from_json(data) end |
#get_state(id) ⇒ Object
Get a customer state by ID.
The customer state includes information about the customer's active subscriptions and benefits.
It's the ideal endpoint to use when you need to get a full overview of a customer's status.
Scopes: customers:read customers:write
251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/pago/v2026_04/services/customers.rb', line 251 def get_state(id) data = client.request( http_method: "GET", path: "/v1/customers/{id}/state", path_params: { "id" => id }, query: {}, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::CustomerState.from_json(data) end |
#get_state_external(external_id) ⇒ Object
Get a customer state by external ID.
The customer state includes information about the customer's active subscriptions and benefits.
It's the ideal endpoint to use when you need to get a full overview of a customer's status.
Scopes: customers:read customers:write
278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/pago/v2026_04/services/customers.rb', line 278 def get_state_external(external_id) data = client.request( http_method: "GET", path: "/v1/customers/external/{external_id}/state", path_params: { "external_id" => external_id }, query: {}, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::CustomerState.from_json(data) end |
#list(organization_id: nil, email: nil, query: nil, active: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil) ⇒ Models::ListResourceCustomer
List customers.
Scopes: customers:read customers:write
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pago/v2026_04/services/customers.rb', line 25 def list(organization_id: nil, email: nil, query: nil, active: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil) data = client.request( http_method: "GET", path: "/v1/customers/", path_params: {}, query: { "organization_id" => organization_id, "email" => email, "query" => query, "active" => active, "page" => page, "limit" => limit, "sorting" => sorting, "metadata" => }, response_type: :json, errors: { 422 => Errors::HTTPValidationError } ) Models::ListResourceCustomer.from_json(data) end |
#list_each(organization_id: nil, email: nil, query: nil, active: nil, limit: 10, sorting: ["-created_at"], metadata: nil) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of list, fetching pages on demand.
41 42 43 44 45 46 |
# File 'lib/pago/v2026_04/services/customers.rb', line 41 def list_each(organization_id: nil, email: nil, query: nil, active: nil, limit: 10, sorting: ["-created_at"], metadata: nil, &block) paginator = ::Pago::Paginator.new do |page_number| list(organization_id: organization_id, email: email, query: query, active: active, page: page_number, limit: limit, sorting: sorting, metadata: ) end block ? paginator.each(&block) : paginator end |
#list_payment_methods(id, page: 1, limit: 10) ⇒ Models::ListResourcePaymentMethod
Get saved payment methods of a customer.
Scopes: customers:read customers:write
301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/pago/v2026_04/services/customers.rb', line 301 def list_payment_methods(id, page: 1, limit: 10) data = client.request( http_method: "GET", path: "/v1/customers/{id}/payment-methods", path_params: { "id" => id }, query: { "page" => page, "limit" => limit }, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Models::ListResourcePaymentMethod.from_json(data) end |
#list_payment_methods_each(id, limit: 10) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of list_payment_methods, fetching pages on demand.
317 318 319 320 321 322 |
# File 'lib/pago/v2026_04/services/customers.rb', line 317 def list_payment_methods_each(id, limit: 10, &block) paginator = ::Pago::Paginator.new do |page_number| list_payment_methods(id, page: page_number, limit: limit) end block ? paginator.each(&block) : paginator end |
#list_payment_methods_external(external_id, page: 1, limit: 10) ⇒ Models::ListResourcePaymentMethod
Get saved payment methods of a customer by external ID.
Scopes: customers:read customers:write
335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/pago/v2026_04/services/customers.rb', line 335 def list_payment_methods_external(external_id, page: 1, limit: 10) data = client.request( http_method: "GET", path: "/v1/customers/external/{external_id}/payment-methods", path_params: { "external_id" => external_id }, query: { "page" => page, "limit" => limit }, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Models::ListResourcePaymentMethod.from_json(data) end |
#list_payment_methods_external_each(external_id, limit: 10) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of list_payment_methods_external, fetching pages on demand.
351 352 353 354 355 356 |
# File 'lib/pago/v2026_04/services/customers.rb', line 351 def list_payment_methods_external_each(external_id, limit: 10, &block) paginator = ::Pago::Paginator.new do |page_number| list_payment_methods_external(external_id, page: page_number, limit: limit) end block ? paginator.each(&block) : paginator end |
#members ⇒ Members
8 |
# File 'lib/pago/v2026_04/services/customers.rb', line 8 def members = @members ||= Members.new(client) |
#update(id, body: {}) ⇒ Object
Update a customer.
Scopes: customers:write
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/pago/v2026_04/services/customers.rb', line 154 def update(id, body: {}) data = client.request( http_method: "PATCH", path: "/v1/customers/{id}", path_params: { "id" => id }, query: {}, body: body, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::Customer.from_json(data) end |
#update_external(external_id, body: {}) ⇒ Object
Update a customer by external ID.
Scopes: customers:write
223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/pago/v2026_04/services/customers.rb', line 223 def update_external(external_id, body: {}) data = client.request( http_method: "PATCH", path: "/v1/customers/external/{external_id}", path_params: { "external_id" => external_id }, query: {}, body: body, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::Customer.from_json(data) end |