api_banking 0.1.19 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a722356b292718216b23a3fdf2a8ee4b3eb1f86
4
- data.tar.gz: e97adc292ce7e9cabf7b894a9de648af81371cbd
3
+ metadata.gz: a06b5e133aa97502d4236c4d0c48cae4c6d36af2
4
+ data.tar.gz: 9e448a1e2c4ebfc86d321964ad061d05c271f133
5
5
  SHA512:
6
- metadata.gz: 7a3c15ba8d4e5eb4bc9a7bc3cd217bf97fb6c0650538dd621e718afefefc174350984e0b838841dffb6a60055ddcf61e480840f1a20e9d27ffe757f8f30df01a
7
- data.tar.gz: 62b7f4392b0448fd7a18065759727898e9abde0db8d62b73e0c5e4cd49e33c094bd89d4cc443c256bd13aa5662555688b1cf20fb37d7ebc642a8d5f8b3be565b
6
+ metadata.gz: 0418763bdace7c77ba5931366565a768b6ca7ddebb0f0b9ea40ed011e6e1a2f8f8fbdc7b8e8d4db5153c4ad11464743aa6e28c207d098a5ac0fd7835f297751f
7
+ data.tar.gz: a88d50caed784c8ca9fbac5e530771fb2c94383ec087eccfb865f422c58054361a92381f347f538a4d1855a8bf74b86351f0c512999c0b26c86a620c9877337e
data/api_banking.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "typhoeus", "~> 1.1.0"
28
28
  spec.add_dependency "nokogiri", "~> 1.6.8"
29
+ spec.add_dependency "money", "6.7.1"
29
30
  end
data/lib/api_banking.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "nokogiri"
2
2
  require "typhoeus"
3
+ require "money"
3
4
  require "api_banking/version"
4
5
  require_relative "api_banking/config"
5
6
  require_relative "api_banking/environment/rbl/env"
@@ -24,6 +25,7 @@ require_relative "api_banking/soap/aadhaarVerificationService"
24
25
 
25
26
  require_relative "api_banking/json/json_client"
26
27
  require_relative "api_banking/json/singlePayment"
28
+ require_relative "api_banking/json/accountStatement"
27
29
 
28
30
  module ApiBanking
29
31
 
@@ -1,11 +1,14 @@
1
1
  module ApiBanking
2
2
  module Environment
3
3
  module RBL
4
- UAT = Struct.new(:user, :password, :client_id, :client_secret, :ssl_client_cert, :ssl_client_key, :ssl_ca_file, :url) do
4
+ UAT = Struct.new(:user, :password, :client_id, :client_secret, :ssl_client_cert, :ssl_client_key, :ssl_ca_file, :endpoints) do
5
5
  def initialize(*)
6
6
  super
7
7
  self.ssl_ca_file ||= File.expand_path('./uat.pem', File.dirname(__FILE__))
8
- self.url ||= 'https://apideveloper.rblbank.com'
8
+ self.endpoints = {
9
+ SinglePayment: 'https://apideveloper.rblbank.com/test/sb/rbl/v1/payments/corp/payment',
10
+ AccountStatement: 'https://apideveloper.rblbank.com/test/sb/rbl/v1/cas/statement'
11
+ }
9
12
  end
10
13
  end
11
14
  end
@@ -0,0 +1,104 @@
1
+ module ApiBanking
2
+ class AccountStatement < JsonClient
3
+
4
+ SERVICE_VERSION = 1
5
+
6
+ attr_accessor :request, :result
7
+
8
+ ReqHeader = Struct.new(:tranID, :corpID, :approverID)
9
+ ReqBody = Struct.new(:accountNo, :transactionType, :fromDate, :toDate)
10
+ Request = Struct.new(:header, :body)
11
+
12
+ Transactions = Struct.new(:transactionDateTime, :transactionType, :amount, :narrative, :referenceNo, :balance)
13
+ Result = Struct.new(:transactions)
14
+
15
+ class << self
16
+ attr_accessor :configuration
17
+ end
18
+
19
+ def self.configure
20
+ self.configuration ||= Configuration.new
21
+ yield(configuration)
22
+ end
23
+
24
+ class Configuration
25
+ attr_accessor :environment, :proxy, :timeout
26
+ end
27
+
28
+ def self.get_statement(env, request, callbacks = nil)
29
+ dataHash = {}
30
+ dataHash[:Acc_Stmt_DtRng_Req] = {}
31
+ dataHash[:Acc_Stmt_DtRng_Req][:Header] = {}
32
+ dataHash[:Acc_Stmt_DtRng_Req][:Body] = {}
33
+
34
+ dataHash[:Acc_Stmt_DtRng_Req][:Header][:TranID] = request.header.tranID
35
+ dataHash[:Acc_Stmt_DtRng_Req][:Header][:Corp_ID] = request.header.corpID
36
+ # the tags Maker_ID and Checker_ID have been removed since Schema Validation Error is returned when these are sent in the request.
37
+ dataHash[:Acc_Stmt_DtRng_Req][:Header][:Approver_ID] = request.header.approverID
38
+
39
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Acc_No] = request.body.accountNo
40
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Tran_Type] = request.body.transactionType
41
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:From_Dt] = request.body.fromDate
42
+
43
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details] = {}
44
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details][:Last_Balance] = {}
45
+
46
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details][:Last_Balance][:Amount_Value] = ''
47
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details][:Last_Balance][:Currency_Code] = ''
48
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details][:Last_Pstd_Date] = ''
49
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details][:Last_Txn_Date] = ''
50
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details][:Last_Txn_Id] = ''
51
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:Pagination_Details][:Last_Txn_SrlNo] = ''
52
+
53
+ dataHash[:Acc_Stmt_DtRng_Req][:Body][:To_Dt] = request.body.toDate
54
+
55
+ reply = do_remote_call(env, dataHash, callbacks)
56
+
57
+ parse_reply(:getStatement, reply)
58
+ end
59
+
60
+ private
61
+
62
+ def self.parse_reply(operationName, reply)
63
+ if reply.kind_of?Fault
64
+ return reply
65
+ else
66
+ case operationName
67
+ when :getStatement
68
+ sortedTxnArray = Array.new
69
+ txnArray = reply['Acc_Stmt_DtRng_Res']['Body']['transactionDetails'].sort_by { |e| DateTime.parse(e['pstdDate'])}
70
+ txnArray.each do |txn|
71
+ txnAmt = parsed_money(
72
+ txn['transactionSummary']['txnAmt']['amountValue'],
73
+ txn['transactionSummary']['txnAmt']['currencyCode']
74
+ )
75
+ txnBalance = parsed_money(
76
+ txn['txnBalance']['amountValue'],
77
+ txn['txnBalance']['currencyCode']
78
+ )
79
+
80
+ sortedTxnArray << AccountStatement::Transactions.new(
81
+ parsed_datetime(txn['pstdDate']),
82
+ txn['transactionSummary']['txnType'],
83
+ txnAmt,
84
+ txn['transactionSummary']['txnDesc'],
85
+ txn['txnId'],
86
+ txnBalance
87
+ )
88
+ end
89
+ return AccountStatement::Result.new(
90
+ sortedTxnArray
91
+ )
92
+ end
93
+ end
94
+ end
95
+
96
+ def self.parsed_money(amount, currency)
97
+ Money.new(amount, currency)
98
+ end
99
+
100
+ def self.parsed_datetime(datetime)
101
+ DateTime.parse(datetime)
102
+ end
103
+ end
104
+ end
@@ -3,26 +3,25 @@ module ApiBanking
3
3
 
4
4
  class JsonClient
5
5
 
6
- def self.do_remote_call(dataHash, callbacks = nil)
6
+ def self.do_remote_call(env, dataHash, callbacks = nil)
7
7
  options = {}
8
8
  options[:method] = :post
9
9
 
10
10
  add_signature(dataHash)
11
11
  options[:body] = JSON.generate(dataHash)
12
12
 
13
- options[:headers] = {'Content-Type' => "application/json; charset=utf-8"}
13
+ options[:headers] = {'Content-Type' => "application/json; charset=utf-8", 'User-Agent' => "Quantiguous; API Banking, Ruby Gem #{ApiBanking::VERSION}"}
14
14
 
15
- options[:proxy] = self.configuration.proxy
16
- options[:timeout] = self.configuration.timeout
15
+ set_options_for_environment(env, options)
16
+ set_params_for_environment(env, options)
17
17
 
18
- set_options_for_environment(options)
19
- set_params_for_environment(options)
20
-
21
- request = Typhoeus::Request.new(self.configuration.environment.url + uri, options)
18
+ request = Typhoeus::Request.new(env.endpoints[self.name.split('::').last.to_sym], options)
22
19
 
23
20
  callbacks.before_send.call(request) if (callbacks && callbacks.before_send.respond_to?(:call))
24
21
  response = request.run
25
22
  callbacks.on_complete.call(request.response) if (callbacks && callbacks.on_complete.respond_to?(:call))
23
+
24
+ Thread.current[:last_response] = response
26
25
 
27
26
  parse_response(response)
28
27
  end
@@ -31,34 +30,37 @@ module ApiBanking
31
30
  private
32
31
 
33
32
  def self.add_signature(dataHash)
34
- dataHash[:Single_Payment_Corp_Req][:Signature] = {}
35
- dataHash[:Single_Payment_Corp_Req][:Signature][:Signature] = 'Signature'
33
+ dataHash.first[1][:Signature] = {}
34
+ dataHash.first[1][:Signature][:Signature] = 'Signature'
36
35
  end
37
-
38
- def self.set_params_for_environment(options)
36
+
37
+ def self.set_params_for_environment(env, options)
39
38
  params = {}
40
- params[:client_id] = self.configuration.environment.client_id
41
- params[:client_secret] = self.configuration.environment.client_secret
39
+ params[:client_id] = env.client_id
40
+ params[:client_secret] = env.client_secret
42
41
  options[:params] = params
43
42
  end
44
43
 
45
- def self.set_options_for_environment(options)
46
- if self.configuration.environment.kind_of?ApiBanking::Environment::RBL::UAT
47
- options[:userpwd] = "#{self.configuration.environment.user}:#{self.configuration.environment.password}"
48
- options[:cainfo] = self.configuration.environment.ssl_ca_file
49
- options[:sslkey] = self.configuration.environment.ssl_client_key
50
- options[:sslcert] = self.configuration.environment.ssl_client_cert
44
+ def self.set_options_for_environment(env, options)
45
+ if env.kind_of?ApiBanking::Environment::RBL::UAT
46
+ options[:userpwd] = "#{env.user}:#{env.password}"
47
+ options[:cainfo] = env.ssl_ca_file
48
+ options[:sslkey] = env.ssl_client_key
49
+ options[:sslcert] = env.ssl_client_cert
51
50
  options[:ssl_verifypeer] = true
52
51
  end
53
52
  puts "#{options}"
53
+ puts env
54
54
  end
55
55
 
56
56
  def self.parse_response(response)
57
+ p response.response_body
58
+
57
59
  if response.success?
58
- if response.headers['Content-Type'] =~ /json/ then
60
+ if response.headers['Content-Type'] =~ /json/
59
61
  j = JSON::parse(response.response_body)
60
- if j[:Status] = 'FAILED' then
61
- return Fault.new(j[:Status], j.first[1]['Header']['Error_Cde'], j.first[1]['Header']['Error_Desc'])
62
+ if j.first[1]['Header']['Status'] == 'FAILED'
63
+ return Fault.new(j.first[1]['Header']['Status'], j.first[1]['Header']['Error_Cde'], j.first[1]['Header']['Error_Desc'])
62
64
  end
63
65
  return j
64
66
  end
@@ -68,7 +70,7 @@ module ApiBanking
68
70
  return Fault.new(response.code, "", response.return_message)
69
71
  else
70
72
  # http status indicating error
71
- if response.headers['Content-Type'] =~ /xml/ then
73
+ if response.headers['Content-Type'] =~ /xml/
72
74
  reply = Nokogiri::XML(response.response_body)
73
75
 
74
76
  # service failures return a fault
@@ -77,7 +79,7 @@ module ApiBanking
77
79
  end
78
80
 
79
81
  # datapower failures return an xml
80
- unless reply.at_xpath('//errorResponse').nil? then
82
+ unless reply.at_xpath('//errorResponse').nil?
81
83
  return parse_dp_reply(reply)
82
84
  end
83
85
 
@@ -98,6 +100,5 @@ module ApiBanking
98
100
  reasonText = content_at(reply.at_xpath('//soapenv12:Fault/soapenv12:Reason/soapenv12:Text', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope'))
99
101
  return Fault.new(code, subcode, reasonText)
100
102
  end
101
-
102
103
  end
103
104
  end
@@ -25,7 +25,7 @@ module ApiBanking
25
25
  attr_accessor :environment, :proxy, :timeout
26
26
  end
27
27
 
28
- def self.transfer(request, callbacks = nil)
28
+ def self.transfer(env, request, callbacks = nil)
29
29
  dataHash = {}
30
30
  dataHash[:Single_Payment_Corp_Req] = {}
31
31
  dataHash[:Single_Payment_Corp_Req][:Header] = {}
@@ -40,10 +40,10 @@ module ApiBanking
40
40
  dataHash[:Single_Payment_Corp_Req][:Body][:Amount] = request.amount
41
41
  dataHash[:Single_Payment_Corp_Req][:Body][:Debit_Acct_No] = request.remitter.accountNo
42
42
  dataHash[:Single_Payment_Corp_Req][:Body][:Debit_Acct_Name] = request.remitter.accountName
43
- dataHash[:Single_Payment_Corp_Req][:Body][:Debit_IFSC] = request.remitter.accountIFSC
44
- dataHash[:Single_Payment_Corp_Req][:Body][:Debit_Mobile] = request.remitter.mobileNo
45
- dataHash[:Single_Payment_Corp_Req][:Body][:Debit_TrnParticulars] = request.remitter.tranParticulars
46
- dataHash[:Single_Payment_Corp_Req][:Body][:Debit_PartTrnRmks] = request.remitter.partTranRemarks
43
+ dataHash[:Single_Payment_Corp_Req][:Body][:Debit_IFSC] = request.remitter.accountIFSC unless request.remitter.accountIFSC.nil?
44
+ dataHash[:Single_Payment_Corp_Req][:Body][:Debit_Mobile] = request.remitter.mobileNo unless request.remitter.mobileNo.nil?
45
+ dataHash[:Single_Payment_Corp_Req][:Body][:Debit_TrnParticulars] = request.remitter.tranParticulars unless request.remitter.tranParticulars.nil?
46
+ dataHash[:Single_Payment_Corp_Req][:Body][:Debit_PartTrnRmks] = request.remitter.partTranRemarks unless request.remitter.partTranRemarks.nil?
47
47
 
48
48
  dataHash[:Single_Payment_Corp_Req][:Body][:Ben_IFSC] = request.beneficiary.accountIFSC
49
49
  dataHash[:Single_Payment_Corp_Req][:Body][:Ben_Acct_No] = request.beneficiary.accountNo
@@ -62,7 +62,7 @@ module ApiBanking
62
62
  dataHash[:Single_Payment_Corp_Req][:Body][:RptCode] = request.rptCode
63
63
 
64
64
 
65
- reply = do_remote_call(dataHash, callbacks)
65
+ reply = do_remote_call(env, dataHash, callbacks)
66
66
 
67
67
  parse_reply(:transferResponse, reply)
68
68
  end
@@ -70,14 +70,6 @@ module ApiBanking
70
70
 
71
71
  private
72
72
 
73
- def self.uri()
74
- if self.configuration.environment.kind_of?ApiBanking::Environment::RBL::UAT
75
- return '/test/sb/rbl/v1/payments/corp/payment'
76
- else
77
- return '/sb/rbl/v1/payments/corp/payment'
78
- end
79
- end
80
-
81
73
  def self.parse_reply(operationName, reply)
82
74
  if reply.kind_of?Fault
83
75
  return reply
@@ -1,3 +1,3 @@
1
1
  module ApiBanking
2
- VERSION = "0.1.19"
2
+ VERSION = "0.1.20"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_banking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.19
4
+ version: 0.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - akil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-17 00:00:00.000000000 Z
11
+ date: 2017-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.6.8
111
+ - !ruby/object:Gem::Dependency
112
+ name: money
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 6.7.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 6.7.1
111
125
  description:
112
126
  email:
113
127
  - hello@quantiguous.com
@@ -132,6 +146,7 @@ files:
132
146
  - lib/api_banking/environment/rbl/uat.pem
133
147
  - lib/api_banking/environment/ybl/env.rb
134
148
  - lib/api_banking/environment/ybl/prd.pem
149
+ - lib/api_banking/json/accountStatement.rb
135
150
  - lib/api_banking/json/json_client.rb
136
151
  - lib/api_banking/json/singlePayment.rb
137
152
  - lib/api_banking/soap/aadhaarVerificationService.rb