Class: ZaiPayment::Resources::PayId

Inherits:
Object
  • Object
show all
Defined in:
lib/zai_payment/resources/pay_id.rb

Overview

PayID resource for managing Zai PayID registrations

Constant Summary collapse

CREATE_FIELD_MAPPING =

Map of attribute keys to API field names for create

{
  pay_id: :pay_id,
  type: :type,
  details: :details
}.freeze
VALID_TYPES =

Valid PayID types

%w[EMAIL].freeze
VALID_STATUSES =

Valid PayID statuses for update

%w[deregistered].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil) ⇒ PayId

Returns a new instance of PayId.



24
25
26
# File 'lib/zai_payment/resources/pay_id.rb', line 24

def initialize(client: nil)
  @client = client || Client.new(base_endpoint: :va_base)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/zai_payment/resources/pay_id.rb', line 9

def client
  @client
end

Instance Method Details

#create(virtual_account_id, **attributes) ⇒ Response

Register a PayID for a given Virtual Account

Examples:

Register an EMAIL PayID

pay_ids = ZaiPayment::Resources::PayId.new
response = pay_ids.create(
  '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
  pay_id: '[email protected]',
  type: 'EMAIL',
  details: {
    pay_id_name: 'J Smith',
    owner_legal_name: 'Mr John Smith'
  }
)
response.data # => {"id" => "46deb476-c1a6-41eb-8eb7-26a695bbe5bc", ...}

Parameters:

  • virtual_account_id (String)

    the virtual account ID

  • attributes (Hash)

    PayID attributes

  • details (Hash)

    a customizable set of options

Options Hash (**attributes):

  • :pay_id (String) — default: Required

    The PayID being registered (max 256 chars)

  • :type (String) — default: Required

    The type of PayID ('EMAIL')

  • :details (Hash) — default: Required

    Additional details

Returns:

  • (Response)

    the API response containing PayID details

See Also:



53
54
55
56
57
58
59
# File 'lib/zai_payment/resources/pay_id.rb', line 53

def create(, **attributes)
  validate_id!(, 'virtual_account_id')
  validate_create_attributes!(attributes)

  body = build_create_body(attributes)
  client.post("/virtual_accounts/#{virtual_account_id}/pay_ids", body: body)
end

#show(pay_id_id) ⇒ Response

Show a specific PayID

Examples:

Get PayID details

pay_ids = ZaiPayment::Resources::PayId.new
response = pay_ids.show('46deb476-c1a6-41eb-8eb7-26a695bbe5bc')
response.data # => {"id" => "46deb476-c1a6-41eb-8eb7-26a695bbe5bc", ...}

Parameters:

  • pay_id_id (String)

    the PayID ID

Returns:

  • (Response)

    the API response containing PayID details

See Also:



72
73
74
75
# File 'lib/zai_payment/resources/pay_id.rb', line 72

def show(pay_id_id)
  validate_id!(pay_id_id, 'pay_id_id')
  client.get("/pay_ids/#{pay_id_id}")
end

#update_status(pay_id_id, status) ⇒ Response

Update Status for a PayID

Update the status of a PayID. Currently, this endpoint only supports deregistering PayIDs by setting the status to 'deregistered'. This is an asynchronous operation that returns a 202 Accepted response.

Examples:

Deregister a PayID

pay_ids = ZaiPayment::Resources::PayId.new
response = pay_ids.update_status(
  '46deb476-c1a6-41eb-8eb7-26a695bbe5bc',
  'deregistered'
)
response.data # => {"id" => "46deb476-c1a6-41eb-8eb7-26a695bbe5bc", "message" => "...", ...}

Parameters:

  • pay_id_id (String)

    the PayID ID

  • status (String)

    the new status (must be 'deregistered')

Returns:

  • (Response)

    the API response containing the operation status

See Also:



96
97
98
99
100
101
102
# File 'lib/zai_payment/resources/pay_id.rb', line 96

def update_status(pay_id_id, status)
  validate_id!(pay_id_id, 'pay_id_id')
  validate_status!(status)

  body = { status: status }
  client.patch("/pay_ids/#{pay_id_id}/status", body: body)
end