nua_pay 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cbd1c6154d8f174c934ce0239dbc051059b4c3cc043ea2bf3e9e7adb993a1536
4
+ data.tar.gz: 851805a8c0f0e213f88df56b2aedb81735da7a6c321c6f714e482fd5882e787c
5
+ SHA512:
6
+ metadata.gz: 149f76930cec668eec7ff1629f7fc1511be3dd541e1765dd4d4b99798d9a8c25e7c0ce58b1605975283fe029f2fdabc854e4dba506cafb5b43c104c4902aa72b
7
+ data.tar.gz: 7f013fa53fd103e847eea2e4e7a999d48ec0ce67ddb29bb51011adb01a2fab9ac96d11eb38115a1010b505391a430abf5b4a42a1fff2169c00680cf2c5770685
@@ -0,0 +1,43 @@
1
+ # NuaPay
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nua_pay`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nua_pay'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nua_pay
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nua_pay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the NuaPay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nua_pay/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ require "nua_pay/"
2
+
3
+ module NuaPay
4
+ end
@@ -0,0 +1,13 @@
1
+ class NuaPay::Account < NuaPay
2
+
3
+ def validate_iban( iban )
4
+ url = build_url( NUAPAY_API["IBAN"] + NUAPAY_API["VALIDATE"] )
5
+ get_response( url , {request_type: :post}, {iban: iban} )
6
+ end
7
+
8
+ def list(page_num=1, size=10)
9
+ url = build_url( NUAPAY_API["ACCOUNTS"] + NUAPAY_API["LIST"] )
10
+ get_response( url , {request_type: :post}, {page: {pageNumber: page_num, pageSize: size}} )
11
+ end
12
+
13
+ end
@@ -0,0 +1,49 @@
1
+ module NuaPay
2
+ class Base
3
+ def get_response(url, additional_options={}, params={})
4
+ resource = RestClient::Request.new({
5
+ method: additional_options[:request_type] || :get,
6
+ url: url,
7
+ user: ENV['NUAPAY_API_KEY'],
8
+ payload: (params.to_json if params.compact.present?),
9
+ headers: { content_type: 'application/json'}
10
+ })
11
+
12
+ begin
13
+ response = resource.execute
14
+ response && JSON.parse( response )["data"]
15
+ rescue => e
16
+ puts JSON.parse( e.response )
17
+ raise e
18
+ end
19
+
20
+ end
21
+
22
+ protected
23
+ def build_url( url="" )
24
+ ENV['NUAPAY_BASE_URL'] + url
25
+ end
26
+
27
+ def mandate_base_url
28
+ base_url + NUAPAY_API['MANDATES']
29
+ end
30
+
31
+ def mandate_url( id )
32
+ build_url( mandate_base_url + id )
33
+ end
34
+
35
+ def validate_mandate_params(data)
36
+ data = data.with_indifferent_access.compact
37
+ data.fetch(:debtorAccount).fetch(:iban) && data.fetch(:creditorAccount).fetch(:iban) && data.fetch(:debtor).fetch(:name)
38
+ end
39
+
40
+ def base_url
41
+ NUAPAY_API['SCHEMES'] + ENV['NUAPAY_IDENTIFIER']
42
+ end
43
+
44
+ def cancellation( reason )
45
+ {"operationReason": reason }
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,68 @@
1
+ # Direct Debit payments allows to pull payments from the borrower's accounts,
2
+ # once the borrower has signed an authorisation via signed mandates.
3
+ class NuaPay::DirectDebitInfo < NuaPay
4
+
5
+ # data = {"requestedCollectionDate": "2019-06-08", "paymentAmount": 5000.01, "settlementDateShift": true }
6
+
7
+ def create( mandate_id, data={} )
8
+ validate_direct_debit_post_params( data )
9
+
10
+ url = mandate_url( mandate_id ) + NUAPAY_API['DIRECT_DEBITS']
11
+ get_response( url , {request_type: :post}, data )
12
+ end
13
+
14
+ def create_mandate_with_direct_debit(data={})
15
+ validate_direct_debit_with_mandate_post_params( data )
16
+ url = build_url( base_url + NUAPAY_API['DIRECT_DEBITS'] )
17
+ get_response( url , {request_type: :post}, data )
18
+ end
19
+
20
+ def get(mandate_id, id )
21
+ url = mandate_url( mandate_id ) + NUAPAY_API['DIRECT_DEBITS'] + id
22
+ get_response( url )
23
+ end
24
+
25
+ def list
26
+ url = build_url( NUAPAY_API['DIRECT_DEBITS_LIST'] )
27
+ get_response( url )
28
+ end
29
+
30
+ def fetch_by_mandate( mandate_id )
31
+ url = mandate_url( mandate_id ) + NUAPAY_API['DIRECT_DEBITS']
32
+ get_response( url )
33
+ end
34
+
35
+ def fetch_by_scheme
36
+ url = build_url( base_url + NUAPAY_API['DIRECT_DEBITS'] )
37
+ get_response( url )
38
+ end
39
+
40
+ def revoke( mandate_id, id, reason="" )
41
+ url = mandate_url( mandate_id ) + NUAPAY_API['DIRECT_DEBITS'] + id + NUAPAY_API['REVOKE']
42
+ get_response( url , {request_type: :post}, cancellation( reason ) )
43
+ end
44
+
45
+ def revoke_all( mandate_id, reason="" )
46
+ url = mandate_url( mandate_id ) + NUAPAY_API['REVOKE_ALL_DIRECT_DEBITS']
47
+ get_response( url , {request_type: :post}, cancellation( reason ) )
48
+ end
49
+
50
+ def represent( mandate_id, id )
51
+ url = mandate_url( mandate_id ) + NUAPAY_API['DIRECT_DEBITS'] + id + NUAPAY_API['REPRESENT']
52
+ get_response( url , {request_type: :post} )
53
+ end
54
+
55
+ private
56
+ # requestedCollectionDate should be two days prior to the current date
57
+ def validate_direct_debit_post_params( data )
58
+ _data = data.with_indifferent_access.compact
59
+ _data.fetch(:requestedCollectionDate) && _data.fetch(:paymentAmount)
60
+ end
61
+
62
+ def validate_direct_debit_with_mandate_post_params( data )
63
+ mandate = data.fetch(:mandate)
64
+ validate_direct_debit_post_params( data ) && validate_mandate_params( mandate )
65
+ end
66
+ end
67
+
68
+ # data = {"requestedCollectionDate": (Date.today + 2.days).strftime, "paymentAmount": 5000.01, "settlementDateShift": true, "mandate": {"debtor": {"name": "Debtor Name"}, "debtorAccount": {"iban": "GB94SELN00999976543215"}, "creditorAccount": {"iban": "GB95SELN00999960724146"} } }
@@ -0,0 +1,32 @@
1
+ class NuaPay::MandateInfo < NuaPay
2
+
3
+ def get( id )
4
+ get_response( mandate_url( id ) )
5
+ end
6
+
7
+ def update( id, data={} )
8
+ get_response( mandate_url( id ) , {request_type: :put }, data )
9
+ end
10
+
11
+ def create( data={} )
12
+ validate_mandate_params( data )
13
+ get_response( build_url( mandate_base_url ), {request_type: :post}, data )
14
+ end
15
+
16
+ def list
17
+ get_response( build_url( mandate_base_url ) )
18
+ end
19
+
20
+ def activate( id )
21
+ activation_url = mandate_url( id ) + NUAPAY_API['ACTIVATE']
22
+ get_response( activation_url , {request_type: :post }, {"signatureDate": Date.today.strftime } )
23
+ end
24
+
25
+ def cancel( id, reason="" )
26
+ deactivation_url = mandate_url( id ) + NUAPAY_API['CANCEL']
27
+ get_response( deactivation_url , {request_type: :post }, cancellation( reason ) )
28
+ end
29
+
30
+ end
31
+
32
+ # data = { "debtor": { "name": "Nitanshu Rehani"}, "debtorAccount": { "iban": "GB95SELN00999960724146", "bic": "SELNGB21" }, "creditorAccount": { "iban": "GB95SELN00999960724146", "bic": "SELNGB21" } }.with_indifferent_access
@@ -0,0 +1,15 @@
1
+ MANDATES: '/mandates/'
2
+ SCHEMES: 'schemes/'
3
+ ACTIVATE: '/activate'
4
+ CANCEL: '/cancel'
5
+ DIRECT_DEBITS: '/directdebits/'
6
+ DIRECT_DEBITS_LIST: 'directdebits/'
7
+ REVOKE: '/revoke'
8
+ REVOKE_ALL_DIRECT_DEBITS: '/revokealldirectdebits'
9
+ REPRESENT: '/represent'
10
+ PAYMENT_SCHEDULES: '/paymentschedules/'
11
+ PAYMENT_SCHEDULES_LIST: 'paymentschedules/'
12
+ IBAN: 'iban/'
13
+ VALIDATE: 'validate/'
14
+ ACCOUNTS: 'accounts/'
15
+ LIST: 'list/'
@@ -0,0 +1 @@
1
+ NUAPAY_API = YAML.load_file("nua_pay/nua_pay_api_urls.yml")
@@ -0,0 +1,48 @@
1
+ class NuaPay::PaymentSchedule < NuaPay
2
+
3
+ # data = { "paymentFrequency":"DAILY", "paymentType":"FIXED_LENGTH", "startDate":(Date.today + 5.days).strftime, "numberOfPayments":2, "paymentAmount":9.90, "firstPaymentAmount":1.10, "lastPaymentAmount":9.90, "remittanceInformation":"remittanceInformation", "twoPaymentsSamePeriod":true, "settlementDateShift": true }.with_indifferent_access
4
+ def create( mandate_id, data={} )
5
+ validate_post_params( data )
6
+ url = mandate_url( mandate_id ) + NUAPAY_API['PAYMENT_SCHEDULES']
7
+ get_response( url , {request_type: :post}, data )
8
+ end
9
+
10
+ # data = { "paymentFrequency":"DAILY", "paymentType":"FIXED_LENGTH", "startDate":(Date.today + 5.days).strftime, "numberOfPayments":2, "paymentAmount":9.90, "firstPaymentAmount":1.10, "lastPaymentAmount":9.90, "remittanceInformation":"remittanceInformation", "twoPaymentsSamePeriod":true, "settlementDateShift": true, "mandate": {"debtor": {"name": "Debtor Name"}, "debtorAccount": {"iban": "GB94SELN00999976543215"}, "creditorAccount": {"iban": "GB95SELN00999960724146"} } }
11
+
12
+ def create_mandate_with_payment_schedule
13
+ validate_payment_schedule_with_mandate_post_params( data )
14
+ url = build_url( base_url + NUAPAY_API['PAYMENT_SCHEDULES'] )
15
+ get_response( url , {request_type: :post}, data )
16
+ end
17
+
18
+ def list
19
+ url = build_url( NUAPAY_API['PAYMENT_SCHEDULES_LIST'] )
20
+ get_response( url )
21
+ end
22
+
23
+ def fetch_by_scheme
24
+ url = build_url( base_url + NUAPAY_API['PAYMENT_SCHEDULES'] )
25
+ get_response( url )
26
+ end
27
+
28
+ def fetch_by_mandate( mandate_id )
29
+ url = mandate_url( mandate_id ) + NUAPAY_API['PAYMENT_SCHEDULES']
30
+ get_response( url )
31
+ end
32
+
33
+ def cancel( mandate_id, id, reason="" )
34
+ url = mandate_url( mandate_id ) + NUAPAY_API['PAYMENT_SCHEDULES'] + id + NUAPAY_API['CANCEL']
35
+ get_response( url , {request_type: :post}, cancellation( reason ) )
36
+ end
37
+
38
+ private
39
+ def validate_post_params( data )
40
+ data.fetch(:paymentFrequency) && data.fetch(:paymentType) && data.fetch(:startDate) && data.fetch(:numberOfPayments) && data.fetch(:paymentAmount)
41
+ end
42
+
43
+ def validate_payment_schedule_with_mandate_post_params( data )
44
+ mandate = data.fetch(:mandate)
45
+ validate_post_params( data ) && validate_mandate_params( mandate )
46
+ end
47
+
48
+ end
@@ -0,0 +1,17 @@
1
+ class NuaPay::Scheme < NuaPay
2
+
3
+ def get_schemes
4
+ get_response( build_url( NUAPAY_API['SCHEMES'] ) )
5
+ end
6
+
7
+ # Don't remove this method as it can be used in the future for fetching
8
+ # scheme identifier from the schemes api
9
+ def get_scheme_identifer
10
+ data = get_schemes.select{|scheme| scheme["creditorSchemeId"] == ENV['NUA_PAY_CREDIT_SCHEME_ID'] }
11
+ if data.blank?
12
+ raise "Credit Scheme ID missing in the schemes"
13
+ else
14
+ data.first["id"]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module NuaPay
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nua_pay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nitanshu Rehani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: 'This gem contains class for scheme, mandate, direct debit, payment schedules and account
56
+ info '
57
+ email:
58
+ - nitanshu.nik@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - README.md
64
+ - Rakefile
65
+ - lib/nua_pay.rb
66
+ - lib/nua_pay/account.rb
67
+ - lib/nua_pay/base.rb
68
+ - lib/nua_pay/direct_debit_info.rb
69
+ - lib/nua_pay/mandate_info.rb
70
+ - lib/nua_pay/nua_pay_api_urls.yml.rb
71
+ - lib/nua_pay/nuapay_api_url.rb
72
+ - lib/nua_pay/payment_schedule.rb
73
+ - lib/nua_pay/scheme.rb
74
+ - lib/nua_pay/version.rb
75
+ homepage: https://flender.ie/
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.0.1
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: This gem hold the methods for the nua pay api's
98
+ test_files: []