From 3adce60158d29d60a72c653adafb3e64ef1dfecd Mon Sep 17 00:00:00 2001 From: Felipe Rodrigues Date: Mon, 8 Jun 2026 21:09:08 -0300 Subject: [PATCH] [ING-240] feat(wallets): add grants_target_top_up to recurring transaction rules --- .../customers/wallets/whitelist_params.rb | 1 + .../api/resources/customers/wallets_spec.rb | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/lib/lago/api/resources/customers/wallets/whitelist_params.rb b/lib/lago/api/resources/customers/wallets/whitelist_params.rb index 4f8c3ca6..ba28c532 100644 --- a/lib/lago/api/resources/customers/wallets/whitelist_params.rb +++ b/lib/lago/api/resources/customers/wallets/whitelist_params.rb @@ -70,6 +70,7 @@ def recurring_rules_params(rules) :transaction_metadata, :transaction_name, :ignore_paid_top_up_limits, + :grants_target_top_up, ) payment_method = payment_method_params(r[:payment_method]) diff --git a/spec/lago/api/resources/customers/wallets_spec.rb b/spec/lago/api/resources/customers/wallets_spec.rb index 825cb713..bcf739a4 100644 --- a/spec/lago/api/resources/customers/wallets_spec.rb +++ b/spec/lago/api/resources/customers/wallets_spec.rb @@ -164,6 +164,40 @@ end end + context 'when grants_target_top_up is provided in a target recurring rule' do + let(:params_with_grants) do + params.deep_merge( + recurring_transaction_rules: [ + factory_wallet.recurring_transaction_rules.first.merge( + method: 'target', + target_ongoing_balance: '200', + grants_target_top_up: true, + ), + ], + ) + end + let(:body_with_grants) do + body['wallet']['recurring_transaction_rules'].first.merge!( + 'method' => 'target', + 'target_ongoing_balance' => '200', + 'grants_target_top_up' => true, + ) + body + end + + before do + stub_request(:post, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets") + .with(body: body_with_grants) + .to_return(body: response, status: 200) + end + + it 'forwards grants_target_top_up in the request' do + wallet = resource.create(customer_id, params_with_grants) + + expect(wallet.lago_id).to eq('this-is-lago-id') + end + end + context 'when wallet failed to create' do before do stub_request(:post, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets") @@ -225,6 +259,40 @@ end end + context 'when grants_target_top_up is provided in a target recurring rule' do + let(:params_with_grants) do + params.deep_merge( + recurring_transaction_rules: [ + factory_wallet.recurring_transaction_rules.first.merge( + method: 'target', + target_ongoing_balance: '200', + grants_target_top_up: true, + ), + ], + ) + end + let(:body_with_grants) do + body['wallet']['recurring_transaction_rules'].first.merge!( + 'method' => 'target', + 'target_ongoing_balance' => '200', + 'grants_target_top_up' => true, + ) + body + end + + before do + stub_request(:put, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets/#{code}") + .with(body: body_with_grants) + .to_return(body: response, status: 200) + end + + it 'forwards grants_target_top_up in the request' do + wallet = resource.update(customer_id, code, params_with_grants) + + expect(wallet.lago_id).to eq('this-is-lago-id') + end + end + context 'when wallet failed to update' do before do stub_request(:put, "https://api.getlago.com/api/v1/customers/#{customer_id}/wallets/#{code}")