hws-payment_operations_demo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/generators/hws/payment_operations_demo/install_generator.rb +24 -0
- data/lib/generators/hws/payment_operations_demo/templates/migration.rb.erb +18 -0
- data/lib/hws/payment_operations_demo/exceptions/exceptions.rb +5 -0
- data/lib/hws/payment_operations_demo/models/instrument_resource_store.rb +5 -0
- data/lib/hws/payment_operations_demo/railtie.rb +44 -0
- data/lib/hws/payment_operations_demo/transactional_value_store.rb +111 -0
- data/lib/hws/payment_operations_demo/users.rb +23 -0
- data/lib/hws/payment_operations_demo/virtual_account.rb +148 -0
- data/lib/hws/payment_operations_demo.rb +26 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 952490c1deacfcf1e911da3b8faa3bf0ef2096b0febdb84c01b474510bc7a243
|
4
|
+
data.tar.gz: 0a212ec4c22de31886edb1b9203ebbc9b101032d5bbf98d485279899824ae9a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e9a19a051e179fff14c26a57569b6fadad4acc56af55358450c6ee3f19d56ff6deeae72e54fec2bb8f44cbf254d8c470b56e2fb626a19c06b756b610768ea02
|
7
|
+
data.tar.gz: f722be13c05c6097a0509f7d8ee67a5e2952f7a72e95d3635caecf53e5c21548b90e284dbc26565e79439a756df10463302fd587a3b5becff959d9927d690a76
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: single_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Style/ClassAndModuleChildren:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: compact
|
16
|
+
|
17
|
+
Style/RedundantSelf:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Karthick
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Hws::PaymentOperationsDemo
|
2
|
+
|
3
|
+
This is a demo orchestration using Hypto's primitives and connector libraries. This orchestration at the moment supports the below functionalities.
|
4
|
+
|
5
|
+
**Virtual Accounts**:
|
6
|
+
- Create a Virtual account
|
7
|
+
- Activate / Deactivate a virtual account
|
8
|
+
- Track balance of a virtual account.
|
9
|
+
- Track Incoming credits into virtual accounts via webhook.
|
10
|
+
|
11
|
+
**Payouts**:
|
12
|
+
- Transfer funds to a beneficiary using NEFT, IMPS, RTGS or UPI.
|
13
|
+
- Refresh status of a transaction.
|
14
|
+
- Update transaction status based on webhooks
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'hws-payment_operations_demo'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle install
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install hws-payment_operations_demo
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hwslabs/hws-payment_operations_demo.
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'hws/payment_operations_demo'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
|
5
|
+
class Hws::PaymentOperationsDemo::InstallGenerator < Rails::Generators::Base # :nodoc:
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path('templates', __dir__)
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
ActiveRecord::Generators::Base.next_migration_number(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def install_dependencies
|
15
|
+
generate 'hws:resources:install'
|
16
|
+
generate 'hws:stores:install'
|
17
|
+
generate 'hws:transactions:install'
|
18
|
+
generate 'hws:instruments:install'
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_migrations
|
22
|
+
migration_template 'migration.rb.erb', 'db/migrate/create_hws_instrument_resource_store_table.rb'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
2
|
+
def self.up
|
3
|
+
create_table :instruments_resources_stores do |t|
|
4
|
+
t.belongs_to :store, type: :uuid, foreign_key: true
|
5
|
+
t.belongs_to :instrument, type: :uuid, foreign_key: true
|
6
|
+
t.belongs_to :resource, type: :uuid, foreign_key: true
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :instruments_resources_stores, %I[store_id instrument_id], name: 's_i_index'
|
12
|
+
add_index :instruments_resources_stores, %I[instrument_id store_id], name: 'i_s_index'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :instruments_resources_stores
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PaymentOperationsDemoRailtie < Rails::Railtie # :nodoc:
|
4
|
+
initializer 'PaymentOperationsDemo.connector_initialization' do # rubocop:disable Metrics/BlockLength
|
5
|
+
Hws::Connectors.configure do |config| # rubocop:disable Metrics/BlockLength
|
6
|
+
config.webhooks = {
|
7
|
+
'payouts' => {
|
8
|
+
'callback' => lambda do |_entity, response|
|
9
|
+
Rails.logger.debug response.inspect
|
10
|
+
|
11
|
+
begin
|
12
|
+
Hws::PaymentOperationsDemo::VirtualAccount.record_txn_status_change(
|
13
|
+
response.reference_number, response.status, response.bank_ref_num
|
14
|
+
)
|
15
|
+
rescue StandardError => e
|
16
|
+
Rails.logger.info e.backtrace
|
17
|
+
raise e
|
18
|
+
end
|
19
|
+
end
|
20
|
+
},
|
21
|
+
'virtual_accounts' => {
|
22
|
+
'notify' => lambda do |_entity, response|
|
23
|
+
Rails.logger.debug response.inspect
|
24
|
+
begin
|
25
|
+
Hws::PaymentOperationsDemo::VirtualAccount.funds_received_webhook(
|
26
|
+
va_num: response.beneficiary.account_number,
|
27
|
+
amount: response.amount,
|
28
|
+
payment_type: response.payment_type,
|
29
|
+
txn_time: response.credit_time,
|
30
|
+
status: 'COMPLETED',
|
31
|
+
bank_ref_id: response.bank_ref_num,
|
32
|
+
beneficiary: response.beneficiary,
|
33
|
+
remitter: response.remitter
|
34
|
+
)
|
35
|
+
rescue StandardError => e
|
36
|
+
Rails.logger.info e.backtrace
|
37
|
+
raise e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
}
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hws
|
4
|
+
module PaymentOperationsDemo
|
5
|
+
class TransactionalValueStore # :nodoc:
|
6
|
+
attr_accessor :store_id, :transaction_group_id
|
7
|
+
|
8
|
+
def store
|
9
|
+
@store ||= Hws::Stores.get_store(@store_id)
|
10
|
+
@store
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(store_id:, transaction_group_id:)
|
14
|
+
@store_id = store_id
|
15
|
+
@transaction_group_id = transaction_group_id
|
16
|
+
end
|
17
|
+
|
18
|
+
def deposit(amount:, tags:, txn_time: Time.now)
|
19
|
+
entry = ActiveRecord::Base.transaction do
|
20
|
+
Hws::Stores.increment(@store_id, amount)
|
21
|
+
tags.key?(:immutable_tags) ? tags[:immutable_tags][:store_id] = store_id : tags[:immutable_tags] = { store_id: store_id }
|
22
|
+
Hws::Transactions.add_entry(@transaction_group_id, amount, txn_time, tags)
|
23
|
+
end
|
24
|
+
|
25
|
+
entry.id
|
26
|
+
end
|
27
|
+
|
28
|
+
def withdraw(amount:, tags:, txn_time: Time.now)
|
29
|
+
self.deposit(amount: amount * -1, tags: tags, txn_time: txn_time)
|
30
|
+
end
|
31
|
+
|
32
|
+
def balance
|
33
|
+
store = Hws::Stores.get_store(@store_id)
|
34
|
+
store[:data]
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_txn_status(entry_id, status, tags = {})
|
38
|
+
entry = Hws::Transactions.get_entry(entry_id)
|
39
|
+
|
40
|
+
return if status == entry['status']
|
41
|
+
|
42
|
+
entry = ActiveRecord::Base.transaction do
|
43
|
+
Hws::Transactions.update_entry(@transaction_group_id, entry_id, { status: status }.merge(tags))
|
44
|
+
Hws::Stores.increment(@store_id, (entry[:value] * -1)) if entry['status'] != 'FAILED' && status == 'FAILED'
|
45
|
+
|
46
|
+
Hws::Transactions.get_entry(entry_id)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class << self
|
51
|
+
def load(store_id)
|
52
|
+
store = Hws::Stores.get_store(store_id)
|
53
|
+
tg_id = store[:tags]['ledger_id']
|
54
|
+
TransactionalValueStore.new(store_id: store_id, transaction_group_id: tg_id)
|
55
|
+
end
|
56
|
+
|
57
|
+
def create(name:, description: nil, store_tags: {}, txn_tags: [])
|
58
|
+
ActiveRecord::Base.transaction do
|
59
|
+
store_id = Hws::Stores.create_store(
|
60
|
+
{
|
61
|
+
name: name, description: description, data: 0,
|
62
|
+
schema: { type: :number, multipleOf: 0.01 }.with_indifferent_access, tags: store_tags
|
63
|
+
}
|
64
|
+
)
|
65
|
+
|
66
|
+
transaction_group = Hws::Transactions.create_group(
|
67
|
+
"store_ledger_#{store_id}", "value_store_#{description}", %I[status bank_ref_id].concat(txn_tags),
|
68
|
+
%I[store_id instrument_id beneficiary remitter txn_time note pymt_type]
|
69
|
+
)
|
70
|
+
|
71
|
+
Hws::Stores.update_store(store_id: store_id, tags: { ledger_id: transaction_group.id })
|
72
|
+
|
73
|
+
TransactionalValueStore.new(store_id: store_id, transaction_group_id: transaction_group.id)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def update_txn_status(entry_id, status, tags = {})
|
78
|
+
entry = Hws::Transactions.get_entry(entry_id)
|
79
|
+
|
80
|
+
return if status == entry['status']
|
81
|
+
|
82
|
+
entry = ActiveRecord::Base.transaction do
|
83
|
+
Hws::Transactions.update_entry(entry[:transaction_group_id], entry_id, { status: status }.merge(tags))
|
84
|
+
if status == 'FAILED'
|
85
|
+
store_id = get_immutable_tags_from_entry(entry).try(:[], 'store_id')
|
86
|
+
raise 'couldnot find store corresponding to txn entry' if store_id.nil?
|
87
|
+
|
88
|
+
Hws::Stores.increment(store_id, (entry[:value] * -1))
|
89
|
+
end
|
90
|
+
|
91
|
+
Hws::Transactions.get_entry(entry_id)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_instrument_for_entry(entry_id)
|
96
|
+
entry = Hws::Transactions.get_entry(entry_id)
|
97
|
+
instrument_id = get_immutable_tags_from_entry(entry).try(:[], 'instrument_id')
|
98
|
+
return if instrument_id.nil?
|
99
|
+
|
100
|
+
Hws::Instruments::Models::Instrument.find_by(id: instrument_id)
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def get_immutable_tags_from_entry(entry)
|
106
|
+
entry.try(:[], :tags).try(:[], :immutable_tags)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hws
|
4
|
+
module PaymentOperationsDemo
|
5
|
+
class Users # :nodoc:
|
6
|
+
def create(name, description, tags)
|
7
|
+
Hws::Stores.create_owner(name: name, description: description, tags: tags)
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch(owner_id)
|
11
|
+
Hws::Stores.get_owner(owner_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def update(owner_id, name: nil, description: nil, tags: {})
|
15
|
+
Hws::Stores.update_owner(owner_id, name, description, tags)
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(owner_id)
|
19
|
+
Hws::Stores.delete(owner_id)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hws::PaymentOperationsDemo # :nodoc:
|
4
|
+
class VirtualAccount # :nodoc:
|
5
|
+
attr_accessor :store, :instrument
|
6
|
+
|
7
|
+
HYPTO_VA_CONNECTOR_ID = 'Hws::Connectors::Hypto::VirtualAccount'
|
8
|
+
HYPTO_PAYOUT_CONNECTOR_ID = 'Hws::Connectors::Hypto::Payout'
|
9
|
+
|
10
|
+
def as_json
|
11
|
+
{
|
12
|
+
name: @store.store[:name],
|
13
|
+
description: @store.store[:description],
|
14
|
+
va_info: {
|
15
|
+
id: self.instrument.value['id'],
|
16
|
+
account_number: self.instrument.value['va_num'],
|
17
|
+
account_ifsc: self.instrument.value['account_ifsc']
|
18
|
+
}
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
# Hws::PaymentOperationsDemo::VirtualAccount.create(name: 'name')
|
23
|
+
def self.create(name:, description: nil)
|
24
|
+
va_instr_config = Hws::Instruments::Models::InstrumentConfig.find_by(connector_id: HYPTO_VA_CONNECTOR_ID)
|
25
|
+
if va_instr_config.nil?
|
26
|
+
Rails.logger.error "cannot find instrument_config for connector_id #{HYPTO_VA_CONNECTOR_ID}"
|
27
|
+
raise Hws::PaymentOperationsDemo::Exceptions::EntityNotFoundError, "InstrumentConfig [#{HYPTO_VA_CONNECTOR_ID}] not found"
|
28
|
+
end
|
29
|
+
instrument, store = ActiveRecord::Base.transaction do
|
30
|
+
instrument = va_instr_config.create_instrument
|
31
|
+
Rails.logger.info "Instrument [#{instrument.id}] created"
|
32
|
+
|
33
|
+
store = TransactionalValueStore.create(name: name, description: description)
|
34
|
+
Rails.logger.info "Store [#{store.store_id}] created"
|
35
|
+
|
36
|
+
Hws::PaymentOperationsDemo::Models::InstrumentResourceStore.create(
|
37
|
+
store_id: store.store_id, instrument_id: instrument.id
|
38
|
+
)
|
39
|
+
Rails.logger.info 'InstrumentResourceStore entry created'
|
40
|
+
|
41
|
+
[instrument, store]
|
42
|
+
end
|
43
|
+
|
44
|
+
VirtualAccount.new(instrument, store)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Hws::PaymentOperationsDemo::VirtualAccount.of('HYPTOUAT70809083139849')
|
48
|
+
def self.of(va_num)
|
49
|
+
instrument = Hws::Instruments::Models::Instrument.find_by(external_identifier: va_num)
|
50
|
+
raise Hws::PaymentOperationsDemo::Exceptions::EntityNotFoundError, 'Instrument not found' if instrument.nil?
|
51
|
+
|
52
|
+
store = TransactionalValueStore.load(
|
53
|
+
Hws::PaymentOperationsDemo::Models::InstrumentResourceStore
|
54
|
+
.find_by(instrument_id: instrument.id).store_id
|
55
|
+
)
|
56
|
+
|
57
|
+
VirtualAccount.new(instrument, store)
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(instrument, store)
|
61
|
+
@instrument = instrument
|
62
|
+
@store = store
|
63
|
+
end
|
64
|
+
|
65
|
+
def payout_instrument
|
66
|
+
return @payout_instrument if @payout_instrument.present?
|
67
|
+
|
68
|
+
Rails.logger.warn 'Payout instrument not configured. Trying to auto configure...'
|
69
|
+
# @payout_instrument ||= instrument
|
70
|
+
payout_i_c = Hws::Instruments::Models::InstrumentConfig.where(connector_id: HYPTO_PAYOUT_CONNECTOR_ID, connector_credentials: @instrument.instrument_config.connector_credentials).first
|
71
|
+
if payout_i_c.nil?
|
72
|
+
Rails.logger.error 'Cannot find a matching instrument config. Unable to auto configure'
|
73
|
+
raise 'Cannot find a matching instrument config. Unable to auto configure'
|
74
|
+
end
|
75
|
+
payout_instruments = payout_i_c.instruments
|
76
|
+
@payout_instrument = if payout_instruments.empty?
|
77
|
+
Rails.logger.warn 'No payout instrument found. Creating one'
|
78
|
+
payout_i_c.create_instrument
|
79
|
+
else
|
80
|
+
payout_instruments.first
|
81
|
+
end
|
82
|
+
|
83
|
+
@payout_instrument
|
84
|
+
end
|
85
|
+
|
86
|
+
def activate
|
87
|
+
@instrument.execute(action: __method__, options: { va_num: @instrument.external_identifier })
|
88
|
+
end
|
89
|
+
|
90
|
+
def deactivate
|
91
|
+
@instrument.execute(action: __method__, options: { va_num: @instrument.external_identifier })
|
92
|
+
end
|
93
|
+
|
94
|
+
# fetch_balance
|
95
|
+
def balance
|
96
|
+
@store.balance
|
97
|
+
end
|
98
|
+
|
99
|
+
# send_funds
|
100
|
+
def transfer_funds(amount:, payment_type:, beneficiary:)
|
101
|
+
instrument = self.payout_instrument
|
102
|
+
|
103
|
+
entry_id = self.store.withdraw(
|
104
|
+
amount: amount,
|
105
|
+
tags: {
|
106
|
+
mutable_tags: { status: 'PENDING' },
|
107
|
+
immutable_tags: { pymt_type: payment_type, beneficiary: beneficiary, instrument_id: instrument.id }
|
108
|
+
}
|
109
|
+
)
|
110
|
+
begin
|
111
|
+
payload = { amount: amount, reference_number: entry_id, payment_type: payment_type, beneficiary: beneficiary }.with_indifferent_access
|
112
|
+
if payment_type == 'UPI' && beneficiary.key?('upi_id')
|
113
|
+
payout_instrument.execute(action: :send_to_upi_id, options: payload)
|
114
|
+
else # NEFT, IMPS, RTGS or UPI to bank account number
|
115
|
+
payout_instrument.execute(action: :send_to_bank_account, options: payload)
|
116
|
+
end
|
117
|
+
rescue StandardError => e
|
118
|
+
Rails.logger.error e
|
119
|
+
self.store.update_txn_status(entry_id, 'FAILED') if entry_id.present?
|
120
|
+
raise e
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.funds_received_webhook(va_num:, amount:, payment_type:, txn_time: Time.now, status:, bank_ref_id:, beneficiary:, remitter:)
|
125
|
+
virtual_account = self.of(va_num)
|
126
|
+
virtual_account.store.deposit(
|
127
|
+
amount: amount,
|
128
|
+
tags: {
|
129
|
+
mutable_tags: { status: status, bank_ref_id: bank_ref_id },
|
130
|
+
immutable_tags: { pymt_type: payment_type, txn_time: txn_time, beneficiary: beneficiary, remitter: remitter }
|
131
|
+
}
|
132
|
+
)
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.record_txn_status_change(reference_number, status, bank_ref_num)
|
136
|
+
TransactionalValueStore.update_txn_status(reference_number, status, { bank_ref_id: bank_ref_num })
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.fetch_transaction_status(reference_number)
|
140
|
+
instrument = TransactionalValueStore.get_instrument_for_entry(reference_number)
|
141
|
+
return if instrument.nil?
|
142
|
+
|
143
|
+
resp = instrument.execute(action: :status, options: { reference_number: reference_number })
|
144
|
+
Rails.logger.info "Fetch_transaction_status: response - #{resp}"
|
145
|
+
TransactionalValueStore.update_txn_status(reference_number, resp.status, { bank_ref_id: resp.bank_ref_num })
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hws-resources'
|
4
|
+
require 'hws-transactions'
|
5
|
+
require 'hws-stores'
|
6
|
+
require 'hws-instruments'
|
7
|
+
|
8
|
+
module Hws
|
9
|
+
# Main demo app module
|
10
|
+
module PaymentOperationsDemo
|
11
|
+
require 'hws/payment_operations_demo/transactional_value_store'
|
12
|
+
require 'hws/payment_operations_demo/virtual_account'
|
13
|
+
|
14
|
+
# ActiveRecord Models for the demo
|
15
|
+
module Models
|
16
|
+
require 'hws/payment_operations_demo/models/instrument_resource_store'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Exceptions for the demo
|
20
|
+
module Exceptions
|
21
|
+
require 'hws/payment_operations_demo/exceptions/exceptions'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'hws/payment_operations_demo/railtie' if defined?(Rails::Railtie)
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hws-payment_operations_demo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hypto Engineering Team
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hws-instruments
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hws-resources
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hws-stores
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hws-transactions
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.1'
|
69
|
+
description: Demo payments operation gem
|
70
|
+
email:
|
71
|
+
- engineering@hypto.in
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".rspec"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- CHANGELOG.md
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/generators/hws/payment_operations_demo/install_generator.rb
|
86
|
+
- lib/generators/hws/payment_operations_demo/templates/migration.rb.erb
|
87
|
+
- lib/hws/payment_operations_demo.rb
|
88
|
+
- lib/hws/payment_operations_demo/exceptions/exceptions.rb
|
89
|
+
- lib/hws/payment_operations_demo/models/instrument_resource_store.rb
|
90
|
+
- lib/hws/payment_operations_demo/railtie.rb
|
91
|
+
- lib/hws/payment_operations_demo/transactional_value_store.rb
|
92
|
+
- lib/hws/payment_operations_demo/users.rb
|
93
|
+
- lib/hws/payment_operations_demo/virtual_account.rb
|
94
|
+
homepage: https://github.com/hwslabs/hws-payment_operations_demo
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
homepage_uri: https://github.com/hwslabs/hws-payment_operations_demo
|
99
|
+
source_code_uri: https://github.com/hwslabs/hws-payment_operations_demo
|
100
|
+
changelog_uri: https://github.com/hwslabs/hws-payment_operations_demo/blob/main/CHANGELOG.md
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.5.0
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.0.3
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Demo payments operation gem
|
120
|
+
test_files: []
|