Class: ZaiPayment::Resources::BatchTransaction
- Inherits:
-
Object
- Object
- ZaiPayment::Resources::BatchTransaction
- Defined in:
- lib/zai_payment/resources/batch_transaction.rb
Overview
These endpoints are only available in the prelive environment
BatchTransaction resource for managing Zai batch transactions (Prelive only)
Constant Summary collapse
- TRANSACTION_TYPES =
Valid transaction types
%w[payment refund disbursement fee deposit withdrawal].freeze
- TRANSACTION_TYPE_METHODS =
Valid transaction type methods
%w[credit_card npp bpay wallet_account_transfer wire_transfer misc].freeze
- DIRECTIONS =
Valid directions
%w[debit credit].freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#export_transactions ⇒ Response
Export batch transactions (Prelive only).
-
#initialize(client: nil, config: nil) ⇒ BatchTransaction
constructor
A new instance of BatchTransaction.
-
#list(**options) ⇒ Response
List batch transactions.
-
#process_to_bank_processing(batch_id, exported_ids:) ⇒ Response
Move transactions to bank_processing state (Prelive only).
-
#process_to_successful(batch_id, exported_ids:) ⇒ Response
Move transactions to successful state (Prelive only).
-
#show(id) ⇒ Response
Show a batch transaction.
-
#update_transaction_states(batch_id, exported_ids:, state:) ⇒ Response
Update batch transaction states (Prelive only).
Constructor Details
#initialize(client: nil, config: nil) ⇒ BatchTransaction
Returns a new instance of BatchTransaction.
20 21 22 23 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 20 def initialize(client: nil, config: nil) @client = client || Client.new(base_endpoint: :core_base) @config = config || ZaiPayment.config end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 9 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 9 def config @config end |
Instance Method Details
#export_transactions ⇒ Response
Export batch transactions (Prelive only)
Calls the GET /batch_transactions/export_transactions API which moves all pending batch_transactions into batched state. As a result, this API will return all the batch_transactions that have moved from pending to batched. Please store the id in order to progress it in Pre-live.
109 110 111 112 113 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 109 def export_transactions ensure_prelive_environment! client.get('/batch_transactions/export_transactions') end |
#list(**options) ⇒ Response
List batch transactions
Retrieve an ordered and paginated list of existing batch transactions. The list can be filtered by account, batch ID, item, and transaction type.
59 60 61 62 63 64 65 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 59 def list(**) () params = build_list_params() client.get('/batch_transactions', params: params) end |
#process_to_bank_processing(batch_id, exported_ids:) ⇒ Response
Move transactions to bank_processing state (Prelive only)
Convenience method that calls update_transaction_states with state 12700. This simulates the step where transactions are moved to bank_processing state.
192 193 194 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 192 def process_to_bank_processing(batch_id, exported_ids:) update_transaction_states(batch_id, exported_ids: exported_ids, state: 12_700) end |
#process_to_successful(batch_id, exported_ids:) ⇒ Response
Move transactions to successful state (Prelive only)
Convenience method that calls update_transaction_states with state 12000. This simulates the final step where transactions are marked as successful and triggers the batch_transactions webhook.
216 217 218 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 216 def process_to_successful(batch_id, exported_ids:) update_transaction_states(batch_id, exported_ids: exported_ids, state: 12_000) end |
#show(id) ⇒ Response
Show a batch transaction
Get a batch transaction using its ID (UUID or numeric ID).
86 87 88 89 90 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 86 def show(id) validate_id!(id, 'id') client.get("/batch_transactions/#{id}") end |
#update_transaction_states(batch_id, exported_ids:, state:) ⇒ Response
Update batch transaction states (Prelive only)
Calls the PATCH /batches/:id/transaction_states API which moves one or more batch_transactions into a specific state. You will need to pass in the batch_id from the export_transactions response.
State codes:
- 12700: bank_processing state
- 12000: successful state (final state, triggers webhook)
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/zai_payment/resources/batch_transaction.rb', line 159 def update_transaction_states(batch_id, exported_ids:, state:) ensure_prelive_environment! validate_id!(batch_id, 'batch_id') validate_exported_ids!(exported_ids) validate_state!(state) body = { exported_ids: exported_ids, state: state } client.patch("/batches/#{batch_id}/transaction_states", body: body) end |