Class: ZaiPayment::Resources::TokenAuth

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

Overview

TokenAuth resource for generating tokens for bank or card accounts

Constant Summary collapse

TOKEN_TYPE_BANK =

Token types

'bank'
TOKEN_TYPE_CARD =
'card'
VALID_TOKEN_TYPES =

Valid token types

[TOKEN_TYPE_BANK, TOKEN_TYPE_CARD].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil) ⇒ TokenAuth

Returns a new instance of TokenAuth.



18
19
20
# File 'lib/zai_payment/resources/token_auth.rb', line 18

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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#generate(user_id:, token_type: TOKEN_TYPE_BANK) ⇒ Response

Generate a token for bank or card account

Create a token, either for a bank or a card account, that can be used with the PromisePay.js package to securely send Assembly credit card details.

Examples:

Generate a bank token

token_auth = ZaiPayment::Resources::TokenAuth.new
response = token_auth.generate(
  user_id: "seller-68611249",
  token_type: "bank"
)
response.data # => {"token_auth" => {"token" => "...", "user_id" => "...", ...}}

Generate a card token

token_auth = ZaiPayment::Resources::TokenAuth.new
response = token_auth.generate(
  user_id: "buyer-12345",
  token_type: "card"
)

Parameters:

  • user_id (String)

    (Required) Buyer or Seller ID (already created)

  • token_type (String) (defaults to: TOKEN_TYPE_BANK)

    Token type ID, use 'bank' or 'card' (default: 'bank')

Returns:

  • (Response)

    the API response containing generated token

See Also:



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/zai_payment/resources/token_auth.rb', line 47

def generate(user_id:, token_type: TOKEN_TYPE_BANK)
  validate_user_id!(user_id)
  validate_token_type!(token_type)

  body = {
    token_type: token_type,
    user_id: user_id
  }

  client.post('/token_auths', body: body)
end