Class: ZaiPayment::Resources::User
- Inherits:
-
Object
- Object
- ZaiPayment::Resources::User
- Defined in:
- lib/zai_payment/resources/user.rb
Overview
User resource for managing Zai users (payin and payout)
Constant Summary collapse
- USER_TYPE_PAYIN =
User types
'payin'- USER_TYPE_PAYOUT =
'payout'- VALID_USER_TYPES =
Valid user types
[USER_TYPE_PAYIN, USER_TYPE_PAYOUT].freeze
- FIELD_MAPPING =
Map of attribute keys to API field names
{ id: :id, email: :email, first_name: :first_name, last_name: :last_name, mobile: :mobile, phone: :phone, address_line1: :address_line1, address_line2: :address_line2, city: :city, state: :state, zip: :zip, country: :country, dob: :dob, government_number: :government_number, drivers_license_number: :drivers_license_number, drivers_license_state: :drivers_license_state, logo_url: :logo_url, color_1: :color_1, color_2: :color_2, custom_descriptor: :custom_descriptor, authorized_signer_title: :authorized_signer_title, user_type: :user_type, device_id: :device_id, ip_address: :ip_address }.freeze
- COMPANY_FIELD_MAPPING =
Map of company attribute keys to API field names
{ name: :name, legal_name: :legal_name, tax_number: :tax_number, business_email: :business_email, charge_tax: :charge_tax, address_line1: :address_line1, address_line2: :address_line2, city: :city, state: :state, zip: :zip, country: :country, phone: :phone }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#bank_account(user_id) ⇒ Response
Show the user's bank account.
-
#bpay_accounts(user_id) ⇒ Response
List BPay accounts associated with the user.
-
#card_account(user_id) ⇒ Response
Show the user's card account.
-
#create(**attributes) ⇒ Response
Create a new user (payin or payout).
-
#initialize(client: nil) ⇒ User
constructor
A new instance of User.
-
#items(user_id, limit: 10, offset: 0) ⇒ Response
List items associated with the user.
-
#list(limit: 10, offset: 0, search: nil) ⇒ Response
List all users.
-
#set_disbursement_account(user_id, account_id) ⇒ Response
Set the user's disbursement account.
-
#show(user_id) ⇒ Response
Get a specific user by ID.
-
#update(user_id, **attributes) ⇒ Response
Update an existing user.
-
#verify(user_id) ⇒ Response
Verify user (Prelive Only) Sets a user's verification state to approved on pre-live environment.
-
#wallet_account(user_id) ⇒ Response
Show the user's wallet account.
Constructor Details
#initialize(client: nil) ⇒ User
Returns a new instance of User.
63 64 65 |
# File 'lib/zai_payment/resources/user.rb', line 63 def initialize(client: nil) @client = client || Client.new end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/zai_payment/resources/user.rb', line 10 def client @client end |
Instance Method Details
#bank_account(user_id) ⇒ Response
Show the user's bank account
350 351 352 353 |
# File 'lib/zai_payment/resources/user.rb', line 350 def bank_account(user_id) validate_id!(user_id, 'user_id') client.get("/users/#{user_id}/bank_accounts") end |
#bpay_accounts(user_id) ⇒ Response
List BPay accounts associated with the user
401 402 403 404 |
# File 'lib/zai_payment/resources/user.rb', line 401 def bpay_accounts(user_id) validate_id!(user_id, 'user_id') client.get("/users/#{user_id}/bpay_accounts") end |
#card_account(user_id) ⇒ Response
Show the user's card account
385 386 387 388 |
# File 'lib/zai_payment/resources/user.rb', line 385 def card_account(user_id) validate_id!(user_id, 'user_id') client.get("/users/#{user_id}/card_accounts") end |
#create(**attributes) ⇒ Response
Create a new user (payin or payout)
218 219 220 221 222 223 |
# File 'lib/zai_payment/resources/user.rb', line 218 def create(**attributes) validate_create_attributes!(attributes) body = build_user_body(attributes) client.post('/users', body: body) end |
#items(user_id, limit: 10, offset: 0) ⇒ Response
List items associated with the user
310 311 312 313 314 315 316 317 318 |
# File 'lib/zai_payment/resources/user.rb', line 310 def items(user_id, limit: 10, offset: 0) validate_id!(user_id, 'user_id') params = { limit: limit, offset: offset } client.get("/users/#{user_id}/items", params: params) end |
#list(limit: 10, offset: 0, search: nil) ⇒ Response
List all users
83 84 85 86 87 88 89 90 91 |
# File 'lib/zai_payment/resources/user.rb', line 83 def list(limit: 10, offset: 0, search: nil) params = { limit: limit, offset: offset } params[:search] = search if search client.get('/users', params: params) end |
#set_disbursement_account(user_id, account_id) ⇒ Response
Set the user's disbursement account
331 332 333 334 335 336 337 |
# File 'lib/zai_payment/resources/user.rb', line 331 def set_disbursement_account(user_id, account_id) validate_id!(user_id, 'user_id') validate_id!(account_id, 'account_id') body = { account_id: account_id } client.patch("/users/#{user_id}/disbursement_account", body: body) end |
#show(user_id) ⇒ Response
Get a specific user by ID
104 105 106 107 |
# File 'lib/zai_payment/resources/user.rb', line 104 def show(user_id) validate_id!(user_id, 'user_id') client.get("/users/#{user_id}") end |
#update(user_id, **attributes) ⇒ Response
Update an existing user
259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/zai_payment/resources/user.rb', line 259 def update(user_id, **attributes) validate_id!(user_id, 'user_id') body = build_user_body(attributes) validate_email!(attributes[:email]) if attributes[:email] validate_dob!(attributes[:dob]) if attributes[:dob] raise Errors::ValidationError, 'At least one attribute must be provided for update' if body.empty? client.patch("/users/#{user_id}", body: body) end |
#verify(user_id) ⇒ Response
This endpoint only works in the pre-live environment. The user verification workflow holds for all users in production.
Verify user (Prelive Only) Sets a user's verification state to approved on pre-live environment
369 370 371 372 |
# File 'lib/zai_payment/resources/user.rb', line 369 def verify(user_id) validate_id!(user_id, 'user_id') client.patch("/users/#{user_id}/identity_verified") end |
#wallet_account(user_id) ⇒ Response
Show the user's wallet account
289 290 291 292 |
# File 'lib/zai_payment/resources/user.rb', line 289 def wallet_account(user_id) validate_id!(user_id, 'user_id') client.get("/users/#{user_id}/wallet_accounts") end |