zai_payment 2.8.1 → 2.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a1b779cc3a64f6f5d53beabacc7eccbf06bc380c0b58f86f989673a5924b6aa
4
- data.tar.gz: 5654753fffd844b167c4c10343b34a5d7f6a969ad68c058141647ee20319ea57
3
+ metadata.gz: b3f20fe256ab69c787f421db039fac49e817c855ca7aa07441380fb1d03ab2ca
4
+ data.tar.gz: 995f5e6a67dbc86b4ebadd2918c96dd63ba0effe5c8991826fd35e89bfdd6c0c
5
5
  SHA512:
6
- metadata.gz: c433a00fd122c1bf91a7e112438f1df59dd7b35a4554effeadd380f93cf8bcbb0b6593e87e44727c71994c4327792cf1552320a5d71a3d7a87fc6fff90732796
7
- data.tar.gz: dd2d61c6ca97cf1d02f272b985e3cf568592acfe02912b3f877462dde9d89fb812a904d4cc5c5792806f10731ece2a12f2a594f2a3ba802c4f951a9f193dc81f
6
+ metadata.gz: e7152d67c815e5698d8f61aa4f28fa9957190b7ba97a3dac7fee73248698d04cf1d44acfca6988cd301fcf6e3094420f1b90d135e643af4b5150e8cde796c799
7
+ data.tar.gz: 811ec3899505dc68601c9432f7c4356f4e5fc3d44703bd156b5ce55daeb5ec90ceede45d9fc1084fa09ec7f5c281856635d9d3f1b1064338094dddf4e93d2e63
@@ -15,6 +15,16 @@ module ZaiPayment
15
15
  reference_id: :reference_id
16
16
  }.freeze
17
17
 
18
+ # Map of attribute keys to API field names for withdraw
19
+ WITHDRAW_FIELD_MAPPING = {
20
+ account_id: :account_id,
21
+ amount: :amount,
22
+ custom_descriptor: :custom_descriptor,
23
+ reference_id: :reference_id,
24
+ end_to_end_id: :end_to_end_id,
25
+ ifti_information: :ifti_information
26
+ }.freeze
27
+
18
28
  def initialize(client: nil)
19
29
  @client = client || Client.new
20
30
  end
@@ -118,6 +128,58 @@ module ZaiPayment
118
128
  client.post("/wallet_accounts/#{wallet_account_id}/bill_payment", body: body)
119
129
  end
120
130
 
131
+ # Withdraw funds from a Wallet Account to a specified disbursement account
132
+ #
133
+ # @param wallet_account_id [String] the wallet account ID
134
+ # @param attributes [Hash] withdrawal attributes
135
+ # @option attributes [String] :account_id (Required) Account ID to withdraw to
136
+ # @option attributes [Integer] :amount (Required) Amount in cents to withdraw
137
+ # @option attributes [String] :custom_descriptor Custom descriptor for the withdrawal
138
+ # (max 200 chars for NPP, 18 for DE batch)
139
+ # @option attributes [String] :reference_id Unique reference information (cannot contain '.' character)
140
+ # @option attributes [String] :end_to_end_id Unique identifier for NPP IFTI payout tracking (mandatory for IFTI)
141
+ # @option attributess [Hash] :ifti_information IFTI payer information hash (required for IFTI payouts)
142
+ # @return [Response] the API response containing disbursement details
143
+ #
144
+ # @example Basic withdrawal
145
+ # wallet_accounts = ZaiPayment::Resources::WalletAccount.new
146
+ # response = wallet_accounts.withdraw(
147
+ # 'wallet_account_id',
148
+ # account_id: 'bank_account_id',
149
+ # amount: 10000
150
+ # )
151
+ #
152
+ # @example Withdrawal with custom descriptor and reference
153
+ # response = wallet_accounts.withdraw(
154
+ # 'wallet_account_id',
155
+ # account_id: 'bank_account_id',
156
+ # amount: 10000,
157
+ # custom_descriptor: 'Invoice #12345 Payment',
158
+ # reference_id: 'ref-12345'
159
+ # )
160
+ #
161
+ # @example NPP IFTI withdrawal
162
+ # response = wallet_accounts.withdraw(
163
+ # 'wallet_account_id',
164
+ # account_id: 'bank_account_id',
165
+ # amount: 10000,
166
+ # end_to_end_id: 'E2E-UNIQUE-ID-123',
167
+ # ifti_information: {
168
+ # payer_name: 'John Doe',
169
+ # payer_address: '123 Main St, Sydney NSW 2000',
170
+ # payer_country: 'AUS'
171
+ # }
172
+ # )
173
+ #
174
+ # @see https://developer.hellozai.com/reference
175
+ def withdraw(wallet_account_id, **attributes)
176
+ validate_id!(wallet_account_id, 'wallet_account_id')
177
+ validate_withdraw_attributes!(attributes)
178
+
179
+ body = build_withdraw_body(attributes)
180
+ client.post("/wallet_accounts/#{wallet_account_id}/withdraw", body: body)
181
+ end
182
+
121
183
  private
122
184
 
123
185
  def validate_id!(value, field_name)
@@ -159,6 +221,40 @@ module ZaiPayment
159
221
  raise Errors::ValidationError, "reference_id cannot contain single quote (') character"
160
222
  end
161
223
 
224
+ def validate_withdraw_attributes!(attributes)
225
+ validate_required_withdraw_attributes!(attributes)
226
+ validate_amount!(attributes[:amount]) if attributes[:amount]
227
+ validate_withdraw_reference_id!(attributes[:reference_id]) if attributes[:reference_id]
228
+ validate_custom_descriptor!(attributes[:custom_descriptor]) if attributes[:custom_descriptor]
229
+ end
230
+
231
+ def validate_required_withdraw_attributes!(attributes)
232
+ required_fields = %i[account_id amount]
233
+
234
+ missing_fields = required_fields.select do |field|
235
+ attributes[field].nil? || (attributes[field].respond_to?(:to_s) && attributes[field].to_s.strip.empty?)
236
+ end
237
+
238
+ return if missing_fields.empty?
239
+
240
+ raise Errors::ValidationError,
241
+ "Missing required fields: #{missing_fields.join(', ')}"
242
+ end
243
+
244
+ def validate_withdraw_reference_id!(reference_id)
245
+ # Reference ID cannot contain '.' character
246
+ return unless reference_id.to_s.include?('.')
247
+
248
+ raise Errors::ValidationError, "reference_id cannot contain '.' character"
249
+ end
250
+
251
+ def validate_custom_descriptor!(custom_descriptor)
252
+ # Basic validation - max 200 characters for NPP (API will enforce specific limits)
253
+ return if custom_descriptor.to_s.length <= 200
254
+
255
+ raise Errors::ValidationError, 'custom_descriptor must be 200 characters or less'
256
+ end
257
+
162
258
  def build_pay_bill_body(attributes)
163
259
  body = {}
164
260
 
@@ -171,6 +267,19 @@ module ZaiPayment
171
267
 
172
268
  body
173
269
  end
270
+
271
+ def build_withdraw_body(attributes)
272
+ body = {}
273
+
274
+ attributes.each do |key, value|
275
+ next if value.nil? || (value.respond_to?(:empty?) && value.empty?)
276
+
277
+ api_field = WITHDRAW_FIELD_MAPPING[key]
278
+ body[api_field] = value if api_field
279
+ end
280
+
281
+ body
282
+ end
174
283
  end
175
284
  end
176
285
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ZaiPayment
4
- VERSION = '2.8.1'
4
+ VERSION = '2.8.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zai_payment
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.1
4
+ version: 2.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eddy Jaga
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-11-07 00:00:00.000000000 Z
11
+ date: 2025-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.5.22
148
+ rubygems_version: 3.5.11
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Ruby gem for Zai payment integration