0.0
A long-lived project that still receives updates
A Ruby gem for integrating with Zai payment platform APIs.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 0.3.0
~> 3.3
~> 2.0
 Project Readme

Zai Payment Ruby Library

GitHub License Code of Conduct Gem Version GitHub release Gem CI Endpoint Badge GitHub top language Documentation Contributing

A lightweight and extensible Ruby client for the Zai (AssemblyPay) API โ€” starting with secure OAuth2 authentication, and ready for Payments, Virtual Accounts, Webhooks, and more.


โœจ Features

  • ๐Ÿ” OAuth2 Authentication - Client Credentials flow with automatic token management
  • ๐Ÿง  Smart Token Caching - Auto-refresh before expiration, thread-safe storage
  • ๐Ÿ‘ฅ User Management - Create and manage payin (buyers) & payout (sellers) users
  • ๐Ÿ“ฆ Item Management - Full CRUD for transactions/payments between buyers and sellers
  • ๐Ÿฆ Bank Account Management - Complete CRUD + validation for AU/UK bank accounts
  • ๐Ÿ’ณ BPay Account Management - Manage BPay accounts for Australian bill payments
  • ๐Ÿ’ผ Wallet Account Management - Show wallet accounts, check balances, and pay bills via BPay
  • ๐Ÿฆ Virtual Accounts - Complete virtual account management with PayTo and BPay support
  • ๐Ÿ’ณ PayID Management - Create and manage PayIDs for Australian NPP payments
  • ๐ŸŽซ Token Auth - Generate secure tokens for bank and card account data collection
  • ๐Ÿช Webhooks - Full CRUD + secure signature verification (HMAC SHA256)
  • ๐Ÿงช Batch Transactions - Prelive-only endpoints for testing batch transaction flows
  • โš™๏ธ Environment-Aware - Seamless Pre-live / Production switching
  • ๐Ÿงฑ Modular & Extensible - Clean resource-based architecture
  • ๐Ÿงฐ Zero Heavy Dependencies - Lightweight, fast, and reliable
  • ๐Ÿ“ฆ Production Ready - 97%+ test coverage, RuboCop compliant

๐Ÿงญ Installation

Add this line to your Gemfile:

gem 'zai_payment'

Then install

bundle install

โš™๏ธ Configuration

# config/initializers/zai_payment.rb
ZaiPayment.configure do |c|
  c.environment   = Rails.env.production? ? :production : :prelive
  c.client_id     = ENV.fetch("ZAI_CLIENT_ID")
  c.client_secret = ENV.fetch("ZAI_CLIENT_SECRET")
  c.scope         = ENV.fetch("ZAI_OAUTH_SCOPE")
  
  # Optional: Configure timeout settings (defaults shown)
  c.timeout       = 30  # General request timeout in seconds
  c.open_timeout  = 10  # Connection open timeout in seconds
  c.read_timeout  = 30  # Read timeout in seconds
end

๐Ÿš€ Quick Start

Authentication

Get an OAuth2 token with automatic caching and refresh:

# Simple one-liner (recommended)
token = ZaiPayment.token

# Or with full control (advanced)
config = ZaiPayment::Config.new
config.environment = :prelive
config.client_id = 'your_client_id'
config.client_secret = 'your_client_secret'
config.scope = 'your_scope'

token_provider = ZaiPayment::Auth::TokenProvider.new(config: config)
token = token_provider.bearer_token

The gem handles OAuth2 Client Credentials flow automatically - tokens are cached and refreshed before expiration.

๐Ÿ“– Complete Authentication Guide - Two approaches, examples, and best practices

Users

Manage payin (buyer) and payout (seller/merchant) users.

๐Ÿ“š Documentation:

Items

Manage transactions/payments between buyers and sellers.

๐Ÿ“š Documentation:

Bank Accounts

Manage bank accounts for Australian and UK users, with routing number validation.

๐Ÿ“š Documentation:

BPay Accounts

Manage BPay accounts for Australian bill payments.

๐Ÿ“š Documentation:

Wallet Accounts

Manage wallet accounts, check balances, and pay bills via BPay.

๐Ÿ“š Documentation:

Quick Example:

wallet_accounts = ZaiPayment::Resources::WalletAccount.new

# Check wallet balance
response = wallet_accounts.show('wallet_account_id')
balance = response.data['balance']  # in cents
puts "Balance: $#{balance / 100.0}"

# Pay a bill from wallet to BPay account
payment_response = wallet_accounts.pay_bill(
  'wallet_account_id',
  account_id: 'bpay_account_id',
  amount: 17300,  # $173.00 in cents
  reference_id: 'bill_nov_2024'
)

if payment_response.success?
  disbursement = payment_response.data
  puts "Payment successful: #{disbursement['id']}"
  puts "State: #{disbursement['state']}"
end

Virtual Accounts

Manage virtual accounts with support for AKA names and Confirmation of Payee (CoP) lookups.

๐Ÿ“š Documentation:

PayID

Register and manage PayIDs (EMAIL type) for Australian NPP (New Payments Platform) payments.

๐Ÿ“š Documentation:

Token Auth

Generate secure tokens for collecting bank and card account information.

๐Ÿ“š Documentation:

Webhooks

Manage webhook endpoints with secure signature verification.

๐Ÿ“š Documentation:

Batch Transactions (Prelive Only)

Simulate batch transaction processing for testing in the prelive environment.

๐Ÿ“š Documentation:

Quick Example:

# Export pending transactions to batched state
export_response = ZaiPayment.batch_transactions.export_transactions
batch_id = export_response.data.first['batch_id']
transaction_ids = export_response.data.map { |t| t['id'] }

# Move to bank_processing state
ZaiPayment.batch_transactions.process_to_bank_processing(
  batch_id,
  exported_ids: transaction_ids
)

# Complete processing (triggers webhooks)
ZaiPayment.batch_transactions.process_to_successful(
  batch_id,
  exported_ids: transaction_ids
)

Error Handling

The gem provides specific error classes for different scenarios:

begin
  response = ZaiPayment.webhooks.create(
    url: 'https://example.com/webhook',
    object_type: 'transactions'
  )
rescue ZaiPayment::Errors::ValidationError => e
  # Handle validation errors (400, 422)
  puts "Validation error: #{e.message}"
rescue ZaiPayment::Errors::UnauthorizedError => e
  # Handle authentication errors (401)
  puts "Authentication failed: #{e.message}"
rescue ZaiPayment::Errors::NotFoundError => e
  # Handle not found errors (404)
  puts "Resource not found: #{e.message}"
rescue ZaiPayment::Errors::ApiError => e
  # Handle other API errors
  puts "API error: #{e.message}"
end

๐Ÿงฉ Roadmap

Area Description Status
โœ… Authentication OAuth2 Client Credentials flow Done
โœ… Webhooks CRUD for webhook endpoints Done
โœ… Users Manage PayIn / PayOut users Done
โœ… Items Transactions/payments (CRUD) Done
โœ… Bank Accounts AU/UK bank accounts + validation Done
โœ… BPay Accounts Manage BPay accounts Done
โœ… Wallet Accounts Show, check balance, pay bills Done
โœ… Token Auth Generate bank/card tokens Done
โœ… Batch Transactions (Prelive) Simulate batch processing flows Done
โœ… Payments Single and recurring payments Done
โœ… Virtual Accounts Manage virtual accounts & PayTo Done
โœ… PayID Create and manage PayIDs Done

๐Ÿงช Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Running Tests

bundle exec rspec

Code Quality

This project uses RuboCop for linting. Run it with:

bundle exec rubocop

Interactive Console

For development and testing, use the interactive console:

bin/console

This will load the gem and all its dependencies, allowing you to experiment with the API in a REPL environment.

๐Ÿงพ Versioning

This gem follows Semantic Versioning.

See changelog.md for release history.

๐Ÿค Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Sentia/zai-payment. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

๐Ÿชช License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the ZaiPayment project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

๐Ÿ“š Documentation

Getting Started

Examples & Patterns

Technical Guides

Security

External Resources