dscf-banking 0.1.2 → 0.1.12

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.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +0 -0
  3. data/README.md +0 -0
  4. data/Rakefile +0 -0
  5. data/app/controllers/dscf/banking/accounts_controller.rb +0 -0
  6. data/app/controllers/dscf/banking/application_controller.rb +0 -0
  7. data/app/controllers/dscf/banking/applications_controller.rb +0 -0
  8. data/app/controllers/dscf/banking/interest_configurations_controller.rb +0 -0
  9. data/app/controllers/dscf/banking/interest_rate_tiers_controller.rb +0 -0
  10. data/app/controllers/dscf/banking/interest_rate_types_controller.rb +0 -0
  11. data/app/controllers/dscf/banking/product_approvals_controller.rb +0 -0
  12. data/app/controllers/dscf/banking/product_categories_controller.rb +0 -0
  13. data/app/controllers/dscf/banking/virtual_account_products_controller.rb +0 -0
  14. data/app/jobs/dscf/banking/application_job.rb +0 -0
  15. data/app/mailers/dscf/banking/application_mailer.rb +0 -0
  16. data/app/models/concerns/dscf/banking/auditable.rb +0 -0
  17. data/app/models/dscf/banking/account.rb +2 -24
  18. data/app/models/dscf/banking/application.rb +0 -0
  19. data/app/models/dscf/banking/application_record.rb +0 -0
  20. data/app/models/dscf/banking/interest_configuration.rb +0 -0
  21. data/app/models/dscf/banking/interest_rate_tier.rb +0 -0
  22. data/app/models/dscf/banking/interest_rate_type.rb +0 -0
  23. data/app/models/dscf/banking/product_approval.rb +0 -0
  24. data/app/models/dscf/banking/product_audit_log.rb +0 -0
  25. data/app/models/dscf/banking/product_category.rb +0 -0
  26. data/app/models/dscf/banking/virtual_account_product.rb +0 -0
  27. data/app/serializers/dscf/banking/account_serializer.rb +0 -0
  28. data/app/serializers/dscf/banking/application_serializer.rb +0 -0
  29. data/app/serializers/dscf/banking/interest_configuration_serializer.rb +0 -0
  30. data/app/serializers/dscf/banking/interest_rate_tier_serializer.rb +0 -0
  31. data/app/serializers/dscf/banking/interest_rate_type_serializer.rb +0 -0
  32. data/app/serializers/dscf/banking/product_approval_serializer.rb +0 -0
  33. data/app/serializers/dscf/banking/product_category_serializer.rb +0 -0
  34. data/app/serializers/dscf/banking/virtual_account_product_serializer.rb +0 -0
  35. data/app/services/dscf/banking/account_creation_service.rb +0 -0
  36. data/config/routes.rb +0 -14
  37. data/db/migrate/20250830211002_create_dscf_banking_product_categories.rb +0 -0
  38. data/db/migrate/20250830211027_create_dscf_banking_interest_rate_types.rb +0 -0
  39. data/db/migrate/20250831063605_add_code_and_remove_fields_from_interest_rate_types.rb +0 -0
  40. data/db/migrate/20250831064917_create_dscf_banking_virtual_account_products.rb +0 -0
  41. data/db/migrate/20250831072627_create_dscf_banking_interest_configurations.rb +0 -0
  42. data/db/migrate/20250831080745_create_dscf_banking_interest_rate_tiers.rb +0 -0
  43. data/db/migrate/20250831082356_create_dscf_banking_product_approvals.rb +0 -0
  44. data/db/migrate/20250831083907_create_dscf_banking_product_audit_logs.rb +0 -0
  45. data/db/migrate/20250831084706_allow_null_virtual_account_product_id_in_product_audit_logs.rb +0 -0
  46. data/db/migrate/20250912193134_create_dscf_banking_applications.rb +0 -0
  47. data/db/migrate/20250912203527_create_dscf_banking_accounts.rb +0 -0
  48. data/lib/dscf/banking/engine.rb +0 -0
  49. data/lib/dscf/banking/version.rb +1 -1
  50. data/lib/dscf/banking.rb +0 -0
  51. data/lib/tasks/dscf/banking_tasks.rake +0 -0
  52. data/spec/factories/dscf/banking/accounts.rb +0 -28
  53. data/spec/factories/dscf/banking/applications.rb +5 -6
  54. data/spec/factories/dscf/banking/interest_configurations.rb +0 -0
  55. data/spec/factories/dscf/banking/interest_rate_tiers.rb +0 -0
  56. data/spec/factories/dscf/banking/interest_rate_types.rb +0 -0
  57. data/spec/factories/dscf/banking/product_approvals.rb +0 -0
  58. data/spec/factories/dscf/banking/product_audit_logs.rb +0 -0
  59. data/spec/factories/dscf/banking/product_categories.rb +0 -0
  60. data/spec/factories/dscf/banking/virtual_account_products.rb +0 -0
  61. metadata +2 -19
  62. data/app/controllers/dscf/banking/transaction_types_controller.rb +0 -27
  63. data/app/controllers/dscf/banking/transactions_controller.rb +0 -275
  64. data/app/models/dscf/banking/transaction.rb +0 -68
  65. data/app/models/dscf/banking/transaction_type.rb +0 -20
  66. data/app/serializers/dscf/banking/transaction_serializer.rb +0 -19
  67. data/app/serializers/dscf/banking/transaction_type_serializer.rb +0 -9
  68. data/app/services/dscf/banking/base_transaction_service.rb +0 -99
  69. data/app/services/dscf/banking/deposit_service.rb +0 -97
  70. data/app/services/dscf/banking/transfer_service.rb +0 -78
  71. data/app/services/dscf/banking/withdrawal_service.rb +0 -100
  72. data/db/migrate/20250919084147_add_account_type_to_accounts.rb +0 -6
  73. data/db/migrate/20250919084927_make_account_associations_optional.rb +0 -6
  74. data/db/migrate/20250919182831_create_dscf_banking_transaction_types.rb +0 -14
  75. data/db/migrate/20250919184220_create_dscf_banking_transactions.rb +0 -21
  76. data/db/seeds.rb +0 -125
  77. data/spec/factories/dscf/banking/transaction_types.rb +0 -56
  78. data/spec/factories/dscf/banking/transactions.rb +0 -52
@@ -1,100 +0,0 @@
1
- module Dscf::Banking
2
- class WithdrawalService < BaseTransactionService
3
- attr_reader :transaction
4
-
5
- def initialize(account:, amount:, description:, transaction_type_code: "WITHDRAWAL")
6
- super()
7
- @account = account
8
- @amount = amount.to_f
9
- @description = description
10
- @transaction_type_code = transaction_type_code
11
- @transaction = nil
12
- end
13
-
14
- def execute
15
- return self unless validate_withdrawal
16
-
17
- ActiveRecord::Base.transaction do
18
- create_withdrawal_transaction
19
- return self unless success?
20
-
21
- process_withdrawal
22
- return self unless success?
23
- end
24
-
25
- self
26
- end
27
-
28
- private
29
-
30
- def validate_withdrawal
31
- # Validate account
32
- return false unless validate_account_active(@account, "Source account")
33
-
34
- # Validate amount
35
- if @amount <= 0
36
- add_error("Withdrawal amount must be greater than zero")
37
- return false
38
- end
39
-
40
- # Validate sufficient funds
41
- return false unless validate_sufficient_funds(@account, @amount)
42
-
43
- true
44
- end
45
-
46
- def create_withdrawal_transaction
47
- transaction_type = find_or_create_transaction_type(@transaction_type_code)
48
- return unless transaction_type
49
-
50
- # For withdrawals, we need a system account as the credit account
51
- # This represents the external destination
52
- system_account = find_or_create_system_account
53
-
54
- @transaction = create_transaction(
55
- account: @account, # Primary account for the transaction
56
- transaction_type: transaction_type,
57
- debit_account: @account, # Customer account being debited
58
- credit_account: system_account, # External destination
59
- amount: @amount,
60
- currency: @account.currency,
61
- description: @description,
62
- status: :pending
63
- )
64
- end
65
-
66
- def process_withdrawal
67
- @transaction.update(status: :processing)
68
-
69
- # Update account balance (decrease for withdrawal)
70
- new_balance = @account.current_balance - @amount
71
- new_available = @account.available_balance - @amount
72
-
73
- if @account.update(current_balance: new_balance, available_balance: new_available)
74
- @transaction.update(status: :completed)
75
- true
76
- else
77
- @account.errors.full_messages.each { |msg| add_error(msg) }
78
- @transaction.update(status: :failed)
79
- false
80
- end
81
- end
82
-
83
- def find_or_create_system_account
84
- # Find or create a system account for external withdrawals
85
- system_account = Dscf::Banking::Account.system_accounts
86
- .where(currency: @account.currency)
87
- .where("name LIKE ?", "%Withdrawal%")
88
- .first
89
-
90
- unless system_account
91
- # In a real system, this would be pre-created during setup
92
- # For now, we'll assume it exists or create a placeholder
93
- add_error("System withdrawal account not found for currency #{@account.currency}")
94
- return nil
95
- end
96
-
97
- system_account
98
- end
99
- end
100
- end
@@ -1,6 +0,0 @@
1
- class AddAccountTypeToAccounts < ActiveRecord::Migration[8.0]
2
- def change
3
- add_column :dscf_banking_accounts, :system_account, :boolean, default: false, null: false
4
- add_index :dscf_banking_accounts, :system_account
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- class MakeAccountAssociationsOptional < ActiveRecord::Migration[8.0]
2
- def change
3
- change_column_null :dscf_banking_accounts, :virtual_account_product_id, true
4
- change_column_null :dscf_banking_accounts, :application_id, true
5
- end
6
- end
@@ -1,14 +0,0 @@
1
- class CreateDscfBankingTransactionTypes < ActiveRecord::Migration[8.0]
2
- def change
3
- create_table :dscf_banking_transaction_types do |t|
4
- t.string :code, null: false, limit: 20
5
- t.string :name, null: false, limit: 100
6
- t.text :description
7
-
8
- t.timestamps
9
- end
10
-
11
- add_index :dscf_banking_transaction_types, :code, unique: true
12
- add_index :dscf_banking_transaction_types, :name, unique: true
13
- end
14
- end
@@ -1,21 +0,0 @@
1
- class CreateDscfBankingTransactions < ActiveRecord::Migration[8.0]
2
- def change
3
- create_table :dscf_banking_transactions do |t|
4
- t.references :account, null: false, foreign_key: { to_table: :dscf_banking_accounts }
5
- t.references :transaction_type, null: false, foreign_key: { to_table: :dscf_banking_transaction_types }
6
- t.decimal :amount, precision: 20, scale: 4, null: false
7
- t.string :currency, null: false, default: "ETB"
8
- t.string :reference_number, null: false
9
- t.text :description
10
- t.integer :status, default: 0, null: false
11
- t.references :debit_account, null: false, foreign_key: { to_table: :dscf_banking_accounts }
12
- t.references :credit_account, null: false, foreign_key: { to_table: :dscf_banking_accounts }
13
-
14
- t.timestamps
15
- end
16
-
17
- add_index :dscf_banking_transactions, :status
18
- add_index :dscf_banking_transactions, :reference_number, unique: true
19
- add_index :dscf_banking_transactions, [ :account_id, :created_at ]
20
- end
21
- end
data/db/seeds.rb DELETED
@@ -1,125 +0,0 @@
1
- # db/seeds.rb
2
-
3
- # DEBUG: Confirm seed file execution and model availability
4
- puts "Seed file started"
5
- puts "Dscf::Core::User loaded? => #{defined?(Dscf::Core::User)}"
6
- puts "Dscf::Core::Role loaded? => #{defined?(Dscf::Core::Role)}"
7
-
8
- # DSCF Banking Engine Seed Data
9
- # This file seeds the database with sample data for all models in the correct dependency order
10
-
11
- puts "Starting DSCF Banking Engine seed data..."
12
-
13
-
14
- # 1. Seed roles (if model exists)
15
- puts "Seeding roles..."
16
- if defined?(Dscf::Core::Role)
17
- user_role = Dscf::Core::Role.find_or_create_by(code: 'user') do |role|
18
- role.name = 'User'
19
- end
20
- officer_role = Dscf::Core::Role.find_or_create_by(code: 'virtual_account_officer') do |role|
21
- role.name = 'Virtual Account Officer'
22
- end
23
- manager_role = Dscf::Core::Role.find_or_create_by(code: 'virtual_account_manager') do |role|
24
- role.name = 'Virtual Account Manager'
25
- end
26
- kyc_officer_role = Dscf::Core::Role.find_or_create_by(code: 'kyc_officer') do |role|
27
- role.name = 'KYC Officer'
28
- end
29
- branch_manager_role = Dscf::Core::Role.find_or_create_by(code: 'branch_manager') do |role|
30
- role.name = 'Branch Manager'
31
- end
32
- puts "✓ Roles created/found"
33
- else
34
- puts "Warning: Dscf::Core::Role model not found. Skipping role seeding."
35
- end
36
- # 2. Seed users with roles (if model exists)
37
- puts "Seeding users..."
38
- if defined?(Dscf::Core::User)
39
- user1 = Dscf::Core::User.find_or_create_by(email: "user@banking.com") do |u|
40
- u.phone = "+251911123456"
41
- u.password = "SecurePassword123!"
42
- u.verified_at = Time.current
43
- u.temp_password = false
44
- end
45
- user1.roles << user_role if defined?(user_role)
46
- puts "Created user: #{user1.email} (user@banking.com)"
47
-
48
- user2 = Dscf::Core::User.find_or_create_by(email: "virtual_account_officer@banking.com") do |u|
49
- u.phone = "+251922123456"
50
- u.password = "SecurePassword123!"
51
- u.verified_at = Time.current
52
- u.temp_password = false
53
- end
54
- user2.roles << officer_role if defined?(officer_role)
55
- puts "Created user: #{user2.email} (virtual_account_officer@banking.com)"
56
-
57
- user3 = Dscf::Core::User.find_or_create_by(email: "virtual_account_manager@banking.com") do |u|
58
- u.phone = "+251933123456"
59
- u.password = "SecurePassword123!"
60
- u.verified_at = Time.current
61
- u.temp_password = false
62
- end
63
- user3.roles << manager_role if defined?(manager_role)
64
- puts "Created user: #{user3.email} (virtual_account_manager@banking.com)"
65
-
66
- user4 = Dscf::Core::User.find_or_create_by(email: "user_virtual_account_officer@banking.com") do |u|
67
- u.phone = "+251944123456"
68
- u.password = "SecurePassword123!"
69
- u.verified_at = Time.current
70
- u.temp_password = false
71
- end
72
- user4.roles << user_role if defined?(user_role)
73
- user4.roles << officer_role if defined?(officer_role)
74
- puts "Created user: #{user4.email} (user_virtual_account_officer@banking.com)"
75
-
76
- user5 = Dscf::Core::User.find_or_create_by(email: "virtual_account_manager2@banking.com") do |u|
77
- u.phone = "+251955123456"
78
- u.password = "SecurePassword123!"
79
- u.verified_at = Time.current
80
- u.temp_password = false
81
- end
82
- user5.roles << manager_role if defined?(manager_role)
83
- puts "Created user: #{user5.email} (virtual_account_manager2@banking.com)"
84
-
85
- user6 = Dscf::Core::User.find_or_create_by(email: "kyc_officer@banking.com") do |u|
86
- u.phone = "+251966123456"
87
- u.password = "SecurePassword123!"
88
- u.verified_at = Time.current
89
- u.temp_password = false
90
- end
91
- user6.roles << kyc_officer_role if defined?(kyc_officer_role)
92
- puts "Created user: #{user6.email} (kyc_officer@banking.com)"
93
-
94
- user7 = Dscf::Core::User.find_or_create_by(email: "branch_manager@banking.com") do |u|
95
- u.phone = "+251977123456"
96
- u.password = "SecurePassword123!"
97
- u.verified_at = Time.current
98
- u.temp_password = false
99
- end
100
- user7.roles << branch_manager_role if defined?(branch_manager_role)
101
- puts "Created user: #{user7.email} (branch_manager@banking.com)"
102
- else
103
- puts "Warning: Dscf::Core::User model not found. Skipping user seeding."
104
- end# 3. Seed transaction types (engine model)
105
- puts "Seeding transaction types..."
106
- if defined?(Dscf::Banking::TransactionType)
107
- transaction_types = [
108
- { name: "Deposit", code: "DEP" },
109
- { name: "Withdrawal", code: "WDL" },
110
- { name: "Transfer", code: "TRF" },
111
- { name: "Interest Credit", code: "INTC" },
112
- { name: "Fee Debit", code: "FEED" }
113
- ]
114
-
115
- transaction_types.each do |attrs|
116
- Dscf::Banking::TransactionType.find_or_create_by(code: attrs[:code]) do |tt|
117
- tt.name = attrs[:name]
118
- end
119
- end
120
- puts "✓ Transaction types created/found"
121
- else
122
- puts "Warning: Dscf::Banking::TransactionType not found. Skipping transaction type seeding."
123
- end
124
-
125
- puts "DSCF Banking Engine seed data completed successfully!"
@@ -1,56 +0,0 @@
1
- FactoryBot.define do
2
- factory :dscf_banking_transaction_type, class: "Dscf::Banking::TransactionType" do
3
- sequence(:code) { |n| "TXN_TYPE_#{n}" }
4
- sequence(:name) { |n| "Transaction Type #{n}" }
5
- description { "Test transaction type description" }
6
-
7
- trait :deposit do
8
- code { "DEPOSIT" }
9
- name { "Deposit" }
10
- description { "Customer deposit from external source" }
11
- end
12
-
13
- trait :withdrawal do
14
- code { "WITHDRAWAL" }
15
- name { "Withdrawal" }
16
- description { "Customer withdrawal to external destination" }
17
- end
18
-
19
- trait :transfer do
20
- code { "TRANSFER" }
21
- name { "Transfer" }
22
- description { "Transfer between customer accounts" }
23
- end
24
-
25
- trait :interest_credit do
26
- code { "INTEREST_CREDIT" }
27
- name { "Interest Credit" }
28
- description { "Interest payment to customer account" }
29
- end
30
-
31
- trait :interest_expense do
32
- code { "INTEREST_EXPENSE" }
33
- name { "Interest Expense" }
34
- description { "Interest expense booking" }
35
- end
36
-
37
- trait :tax_withholding do
38
- code { "TAX_WITHHOLDING" }
39
- name { "Tax Withholding" }
40
- description { "Tax withholding on interest payments" }
41
- end
42
-
43
- trait :settlement do
44
- code { "SETTLEMENT" }
45
- name { "Settlement" }
46
- description { "Settlement transaction with core banking system" }
47
- end
48
- end
49
-
50
- # Alias for shared spec compatibility
51
- factory :transaction_type, class: "Dscf::Banking::TransactionType" do
52
- sequence(:code) { |n| "TXN_TYPE_#{n}" }
53
- sequence(:name) { |n| "Transaction Type #{n}" }
54
- description { "Test transaction type description" }
55
- end
56
- end
@@ -1,52 +0,0 @@
1
- FactoryBot.define do
2
- factory :dscf_banking_transaction, class: "Dscf::Banking::Transaction" do
3
- association :account, factory: :dscf_banking_account
4
- association :transaction_type, factory: [ :dscf_banking_transaction_type, :deposit ]
5
- association :debit_account, factory: :dscf_banking_account
6
- association :credit_account, factory: :dscf_banking_account
7
-
8
- amount { 1000.00 }
9
- currency { "ETB" }
10
- description { "Test transaction" }
11
- status { :pending }
12
-
13
- trait :deposit do
14
- association :transaction_type, factory: [ :dscf_banking_transaction_type, :deposit ]
15
-
16
- after(:build) do |transaction|
17
- transaction.credit_account = transaction.account
18
- transaction.debit_account = create(:dscf_banking_account, :settlement_account, currency: transaction.currency)
19
- end
20
- end
21
-
22
- trait :withdrawal do
23
- association :transaction_type, factory: [ :dscf_banking_transaction_type, :withdrawal ]
24
-
25
- after(:build) do |transaction|
26
- transaction.debit_account = transaction.account
27
- transaction.credit_account = create(:dscf_banking_account, :settlement_account, currency: transaction.currency)
28
- end
29
- end
30
-
31
- trait :completed do
32
- status { :completed }
33
- end
34
-
35
- trait :failed do
36
- status { :failed }
37
- end
38
- end
39
-
40
- # Alias for shared spec compatibility
41
- factory :transaction, class: "Dscf::Banking::Transaction" do
42
- association :account, factory: :dscf_banking_account
43
- association :transaction_type, factory: [ :dscf_banking_transaction_type, :deposit ]
44
- association :debit_account, factory: :dscf_banking_account
45
- association :credit_account, factory: :dscf_banking_account
46
-
47
- amount { 1000.00 }
48
- currency { "ETB" }
49
- description { "Test transaction" }
50
- status { :pending }
51
- end
52
- end