Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e54c558
feat(mambu_payments): add datasource with 7 collections
christophebrun-forest May 11, 2026
8bc7cf2
feat(mambu_payments): add incoming_payments, direct_debit_mandates an…
christophebrun-forest May 11, 2026
955f6ee
fix(mambu_payments): align expected_payment schema with Numeral payload
christophebrun-forest May 12, 2026
fe5aed1
feat(mambu_payments): smart actions plugins for account holders, acco…
christophebrun-forest May 18, 2026
8b09be5
feat(mambu_payments): add events and files collections
christophebrun-forest May 18, 2026
8860314
fix(mambu_payments): raise on unsupported filter predicates instead o…
christophebrun-forest May 19, 2026
c76ea88
feat(mambu_payments): add returns collection
christophebrun-forest May 20, 2026
83bab8c
feat(mambu_payments): add claims collection
christophebrun-forest May 20, 2026
269a147
refactor(mambu_payments): make connected_account read-only
christophebrun-forest May 20, 2026
54bc207
refactor(mambu_payments): drop transaction account snapshots in favor…
christophebrun-forest May 20, 2026
174483e
feat(mambu_payments): add reconciliations collection
christophebrun-forest May 21, 2026
ab23351
feat(mambu_payments): add payment_captures collection
christophebrun-forest May 21, 2026
cb4a675
feat(mambu_payments): add payee_verification_requests collection
christophebrun-forest May 21, 2026
628e037
feat(mambu_payments): add account-holder relation plugins
christophebrun-forest May 21, 2026
25d8f65
feat(mambu_payments): add external-account relation plugins
christophebrun-forest May 21, 2026
44ed5d7
feat(mambu_payments): add internal-account relation plugins
christophebrun-forest May 22, 2026
ea57c2a
feat(mambu_payments): add payment-order relation plugins
christophebrun-forest May 22, 2026
63cc59c
feat(mambu_payments): add incoming-payment relation plugins
christophebrun-forest May 22, 2026
a1efb99
chore(mambu_payments): drop freeze on VERSION constant
christophebrun-forest May 26, 2026
f0f56e9
refactor(mambu_payments): fix filters/count/pagination
christophebrun-forest Jun 11, 2026
a25416d
fix(mambu_payments): use Numeral cursor pagination
christophebrun-forest Jun 11, 2026
c223a56
fix(mambu_payments): drop server-side count (unsupported)
christophebrun-forest Jun 11, 2026
637d001
refactor(mambu_payments): dedup link plugins, cut complexity
christophebrun-forest Jun 12, 2026
cc99174
ci(mambu_payments): wire datasource into CI and release
christophebrun-forest Jun 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- forest_admin_datasource_rpc
- forest_admin_datasource_zendesk
- forest_admin_datasource_snowflake
- forest_admin_datasource_mambu_payments

steps:
- name: Checkout
Expand Down Expand Up @@ -74,6 +75,7 @@ jobs:
- forest_admin_datasource_rpc
- forest_admin_datasource_zendesk
- forest_admin_datasource_snowflake
- forest_admin_datasource_mambu_payments
services:
mongodb:
image: mongo:latest
Expand Down Expand Up @@ -141,7 +143,7 @@ jobs:
with:
verbose: true
oidc: true
files: ${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_agent/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_active_record/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_customizer/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_toolkit/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_mongoid/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_rpc_agent/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_rpc/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_zendesk/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_snowflake/coverage.json
files: ${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_agent/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_active_record/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_customizer/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_toolkit/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_mongoid/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_rpc_agent/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_rpc/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_zendesk/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_snowflake/coverage.json,${{ github.workspace }}/reports/${{ matrix.ruby-version }}-forest_admin_datasource_mambu_payments/coverage.json

deploy:
name: Release package
Expand Down
7 changes: 5 additions & 2 deletions .releaserc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module.exports = {
'sed -i \'s/VERSION = ".*"/VERSION = "${nextRelease.version}"/g\' packages/forest_admin_rpc_agent/lib/forest_admin_rpc_agent/version.rb; '+
'sed -i \'s/VERSION = ".*"/VERSION = "${nextRelease.version}"/g\' packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/version.rb; '+
'sed -i \'s/VERSION = ".*"/VERSION = "${nextRelease.version}"/g\' packages/forest_admin_datasource_zendesk/lib/forest_admin_datasource_zendesk/version.rb; '+
'sed -i \'s/VERSION = ".*"/VERSION = "${nextRelease.version}"/g\' packages/forest_admin_datasource_snowflake/lib/forest_admin_datasource_snowflake/version.rb; ',
'sed -i \'s/VERSION = ".*"/VERSION = "${nextRelease.version}"/g\' packages/forest_admin_datasource_snowflake/lib/forest_admin_datasource_snowflake/version.rb; '+
'sed -i \'s/VERSION = ".*"/VERSION = "${nextRelease.version}"/g\' packages/forest_admin_datasource_mambu_payments/lib/forest_admin_datasource_mambu_payments/version.rb; ',
successCmd:
'( cd packages/forest_admin_agent && gem build && gem push forest_admin_agent-*.gem );' +
'( cd packages/forest_admin_datasource_active_record && gem build && gem push forest_admin_datasource_active_record-*.gem );' +
Expand All @@ -41,7 +42,8 @@ module.exports = {
'( cd packages/forest_admin_rpc_agent && gem build && gem push forest_admin_rpc_agent-*.gem );' +
'( cd packages/forest_admin_datasource_rpc && gem build && gem push forest_admin_datasource_rpc-*.gem );' +
'( cd packages/forest_admin_datasource_zendesk && gem build && gem push forest_admin_datasource_zendesk-*.gem );' +
'( cd packages/forest_admin_datasource_snowflake && gem build && gem push forest_admin_datasource_snowflake-*.gem );' ,
'( cd packages/forest_admin_datasource_snowflake && gem build && gem push forest_admin_datasource_snowflake-*.gem );' +
'( cd packages/forest_admin_datasource_mambu_payments && gem build && gem push forest_admin_datasource_mambu_payments-*.gem );' ,
},
],
[
Expand All @@ -62,6 +64,7 @@ module.exports = {
'packages/forest_admin_datasource_rpc/lib/forest_admin_datasource_rpc/version.rb',
'packages/forest_admin_datasource_zendesk/lib/forest_admin_datasource_zendesk/version.rb',
'packages/forest_admin_datasource_snowflake/lib/forest_admin_datasource_snowflake/version.rb',
'packages/forest_admin_datasource_mambu_payments/lib/forest_admin_datasource_mambu_payments/version.rb',
'package.json'
],
},
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Style/MutableConstant:
- 'packages/forest_admin_datasource_active_record/lib/forest_admin_datasource_active_record/version.rb'
- 'packages/forest_admin_datasource_zendesk/lib/forest_admin_datasource_zendesk/version.rb'
- 'packages/forest_admin_datasource_snowflake/lib/forest_admin_datasource_snowflake/version.rb'
- 'packages/forest_admin_datasource_mambu_payments/lib/forest_admin_datasource_mambu_payments/version.rb'

# Offense count: 38
# This cop supports safe autocorrection (--autocorrect).
Expand Down Expand Up @@ -211,6 +212,7 @@ Style/StringLiterals:
- 'packages/forest_admin_datasource_active_record/spec/spec_helper.rb'
- 'packages/forest_admin_datasource_zendesk/lib/forest_admin_datasource_zendesk/version.rb'
- 'packages/forest_admin_datasource_snowflake/lib/forest_admin_datasource_snowflake/version.rb'
- 'packages/forest_admin_datasource_mambu_payments/lib/forest_admin_datasource_mambu_payments/version.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Expand Down Expand Up @@ -282,6 +284,7 @@ Metrics/ModuleLength:
- 'packages/forest_admin_datasource_mongoid/spec/**/*'
- 'packages/forest_admin_datasource_customizer/spec/**/*'
- 'packages/forest_admin_datasource_zendesk/spec/**/*'
- 'packages/forest_admin_datasource_mambu_payments/spec/**/*'
- 'packages/forest_admin_rails/spec/**/*'
- 'packages/forest_admin_rpc_agent/spec/**/*'
- 'packages/forest_admin_datasource_mongoid/lib/forest_admin_datasource_mongoid/utils/helpers.rb'
Expand Down
3 changes: 3 additions & 0 deletions packages/forest_admin_datasource_mambu_payments/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
16 changes: 16 additions & 0 deletions packages/forest_admin_datasource_mambu_payments/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
source 'https://rubygems.org'

gemspec

gem 'forest_admin_datasource_customizer'
gem 'forest_admin_datasource_toolkit'
gem 'rake', '~> 13.0'
gem 'rubocop', '1.86.1'
gem 'rubocop-performance', '1.26.1'
gem 'rubocop-rspec', '3.9.0'

group :development, :test do
gem 'rspec', '~> 3.0'
gem 'simplecov', '~> 0.22', require: false
gem 'webmock', '~> 3.0'
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 17 lines of identical code in 2 locations (mass = 76) [qlty:identical-code]

19 changes: 19 additions & 0 deletions packages/forest_admin_datasource_mambu_payments/Gemfile-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in forest_admin_datasource_mambu_payments.gemspec
gemspec

gem 'rake', '~> 13.0'
gem 'rubocop', '1.86.1'
gem 'rubocop-performance', '1.26.1'
gem 'rubocop-rspec', '3.9.0'

group :development, :test do
gem 'forest_admin_datasource_customizer', path: '../forest_admin_datasource_customizer'
gem 'forest_admin_datasource_toolkit', path: '../forest_admin_datasource_toolkit'
gem 'rspec', '~> 3.0'
gem 'simplecov', '~> 0.22', require: false
gem 'simplecov-html', '~> 0.12.3'
gem 'simplecov_json_formatter', '~> 0.1.4'
gem 'webmock', '~> 3.0'
end
6 changes: 6 additions & 0 deletions packages/forest_admin_datasource_mambu_payments/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: :spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)

require_relative 'lib/forest_admin_datasource_mambu_payments/version'

Gem::Specification.new do |spec|
spec.name = 'forest_admin_datasource_mambu_payments'
spec.version = ForestAdminDatasourceMambuPayments::VERSION
spec.authors = ['Forest Admin']
spec.email = ['contact@forestadmin.com']
spec.homepage = 'https://www.forestadmin.com'
spec.summary = 'Mambu Payments (Numeral) datasource for Forest Admin Ruby agent.'
spec.description = 'Surface Mambu Payments connected accounts, payment orders, ' \
'transactions and balances as Forest Admin collections.'
spec.license = 'GPL-3.0'
spec.required_ruby_version = '>= 3.0.0'

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/ForestAdmin/agent-ruby'
spec.metadata['changelog_uri'] = 'https://github.com/ForestAdmin/agent-ruby/blob/main/CHANGELOG.md'
spec.metadata['rubygems_mfa_required'] = 'true'

spec.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
(File.expand_path(f) == __FILE__) ||
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
end
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_dependency 'activesupport', '>= 6.1'
spec.add_dependency 'faraday', '~> 2.0'
spec.add_dependency 'faraday-retry', '~> 2.0'
spec.add_dependency 'zeitwerk', '~> 2.3'
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require_relative 'forest_admin_datasource_mambu_payments/version'
require 'logger'
require 'zeitwerk'
require 'faraday'
require 'faraday/retry'
require 'forest_admin_datasource_toolkit'

loader = Zeitwerk::Loader.for_gem
loader.setup

module ForestAdminDatasourceMambuPayments
class Error < StandardError; end
class ConfigurationError < Error; end
class UnsupportedOperatorError < Error; end

# Raised when a Numeral API call fails. Carries the HTTP status and the
# (parsed) response body so callers — smart actions in particular — can
# surface the API's own validation message instead of a generic string.
class APIError < Error
attr_reader :status, :body

def initialize(message, status: nil, body: nil)
super(message)
@status = status
@body = body
end
end

class << self
attr_writer :logger

def logger
@logger ||= default_logger
end

private

def default_logger
return Rails.logger if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger

Logger.new($stderr).tap { |l| l.progname = 'forest_admin_datasource_mambu_payments' }
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
module ForestAdminDatasourceMambuPayments
# rubocop:disable Metrics/ClassLength
class Client
include Reads
include Writes

MAX_PER_PAGE = 100

def initialize(configuration)
@configuration = configuration
end

private

def list_resource(path, params = {})
must_succeed("list(#{path})") do
body = connection.get(path, normalize_params(params)).body
extract_records(body, path)
end
end

def get_resource(path, id)
extract_record(connection.get("#{path}/#{id}").body)
rescue Faraday::ResourceNotFound
nil
rescue Faraday::Error => e
raise api_error("get(#{path}/#{id})", e)
rescue StandardError => e
raise APIError, "Mambu Payments API call failed: get(#{path}/#{id}): #{e.class}: #{e.message}"
end

def post_resource(path, attributes)
must_succeed("create(#{path})") do
extract_record(connection.post(path, attributes).body)
end
end

def patch_resource(path, id, attributes)
must_succeed("update(#{path}/#{id})") do
extract_record(connection.patch("#{path}/#{id}", attributes).body)
end
end

# POST .../:id/:action — Numeral exposes side-effect endpoints (approve,
# cancel, verify) as sub-paths returning the updated resource.
def post_action_resource(path, id, action, attributes = {})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function with many parameters (count = 4): post_action_resource [qlty:function-parameters]

must_succeed("#{action}(#{path}/#{id})") do
extract_record(connection.post("#{path}/#{id}/#{action}", attributes).body)
end
end

# Numeral list responses are typically wrapped (e.g. { "data": [...] } or
# { "connected_accounts": [...] }) but we accept a raw array too. Falls back
# to the first array-valued field so we don't silently coerce a wrapper hash
# into an array of [key, value] pairs.
def extract_records(body, path)
return body if body.is_a?(Array)
return [] unless body.is_a?(Hash)

wrapped = body['data'] || body[path] || body['records'] || body['items']
wrapped.is_a?(Array) ? wrapped : fallback_records(body, path)
end

# Last resort when the wrapper key is unknown: return the first array-valued
# field, logging that we guessed so an unexpected envelope is visible.
def fallback_records(body, path)
fallback = body.values.find { |v| v.is_a?(Array) }
return [] unless fallback

ForestAdminDatasourceMambuPayments.logger.warn(
"[forest_admin_datasource_mambu_payments] list(#{path}) used wrapper-key fallback; " \
"body keys=#{body.keys.inspect}"
)
fallback
end

def extract_record(body)
return nil if body.nil?
return body['data'] if body.is_a?(Hash) && body['data'].is_a?(Hash)

body
end

def delete_resource(path, id)
must_succeed("delete(#{path}/#{id})") do
connection.delete("#{path}/#{id}")
true
end
end

def normalize_params(params)
params.compact.transform_values { |v| v.is_a?(Array) ? v.join(',') : v }
end

def must_succeed(operation)
yield
rescue Faraday::Error => e
raise api_error(operation, e)
rescue StandardError => e
raise APIError, "Mambu Payments API call failed: #{operation}: #{e.class}: #{e.message}"
end

# Builds an APIError that preserves the HTTP status and the API's own error
# body. Numeral returns structured validation errors (e.g. on a 422), which
# smart actions surface to the operator instead of a generic failure string.
def api_error(operation, error)
response = error.respond_to?(:response) ? error.response : nil
status = response.is_a?(Hash) ? response[:status] : nil
body = response.is_a?(Hash) ? response[:body] : nil
detail = error_detail(status, body) || "#{error.class}: #{error.message}"
APIError.new("Mambu Payments API call failed: #{operation}: #{detail}", status: status, body: parse_body(body))
end

def error_detail(status, body)
return nil unless status

["HTTP #{status}", error_message(parse_body(body))].compact.join(' ').strip
end

# Pulls the human-readable message out of the common Numeral error shapes
# ({ "error": { "message": ... } }, { "errors": [...] }, { "message": ... }).
def error_message(parsed)
return parsed.to_s[0, 500] unless parsed.is_a?(Hash)

message = parsed.dig('error', 'message') || parsed['message'] || parsed['detail'] || join_errors(parsed['errors'])
(message.to_s.empty? ? parsed.to_json : message)[0, 500]
Comment thread
qltysh[bot] marked this conversation as resolved.
end

def join_errors(errors)
Array(errors).filter_map { |e| e.is_a?(Hash) ? (e['message'] || e['detail']) : e }.join('; ')
end

def parse_body(body)
return body unless body.is_a?(String) && !body.empty?

JSON.parse(body)
rescue JSON::ParserError
body
end

def best_effort(operation, default:)
yield
rescue StandardError => e
ForestAdminDatasourceMambuPayments.logger.warn(
"[forest_admin_datasource_mambu_payments] #{operation} failed; degrading: #{e.class}: #{e.message}"
)
default
end

def connection
@connection ||= Faraday.new(url: @configuration.url) do |f|
f.request :json
f.request :retry, max: 3, interval: 0.2, backoff_factor: 2,
retry_statuses: [429, 502, 503, 504]
f.response :json
f.response :raise_error
f.headers['x-api-key'] = @configuration.api_key
f.headers['Accept'] = 'application/json'
f.headers['User-Agent'] = "forest_admin_datasource_mambu_payments/#{VERSION}"
f.options.open_timeout = @configuration.open_timeout
f.options.timeout = @configuration.timeout
end
end
end
# rubocop:enable Metrics/ClassLength
end
Loading
Loading