api_banking 0.1.17 → 0.1.18

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: 28d48b1427a405f18aa8d460e82493e760adcda3
4
- data.tar.gz: da3b60964984655ecb762e1eb23467a1ade38f23
3
+ metadata.gz: 95fbde3e678ea25f667e53e871591f9c87f3833f
4
+ data.tar.gz: 505c9388ea41db462554fb4272e7f9ca22cd04db
5
5
  SHA512:
6
- metadata.gz: dd7a9786a77bcea6b7f59302d86e6ce4238ab3a48272fe28082e415804f0ca803df0942e2915ad1d226d0c0830eec74153a0ee0e9708e039355a0065dbaa7495
7
- data.tar.gz: 55c56f2f1f224e7af8ace02258a2abf43fc0416e6671b4e63f26fcad553800127385d53d4abbd130aa38d25dbae8b6210985bb5387680ae1b0811775c28a9f28
6
+ metadata.gz: eabe44622b207ae992686c8fdaeab71ebdca06bd3bdfc25e919d971cf8b58c639ad89bf24d29f770eae44bdcffc17b032e9eec4cfcd480f9da13a86431e98ee5
7
+ data.tar.gz: 698270c990b1d4e8e0f9f6fe841ca406a088b25b135dad4946faf4e8f7a87bdaae2badeba3f462dcf2078953317ff4ca3fd3952a47d5fcdc3af8339903290965
data/lib/api_banking.rb CHANGED
@@ -7,6 +7,7 @@ require_relative "api_banking/environment/ybl/env"
7
7
  require_relative "api_banking/environment/qg/env"
8
8
 
9
9
  require_relative "api_banking/soap/fault"
10
+ require_relative "api_banking/soap/callbacks"
10
11
  require_relative "api_banking/soap/soap_client"
11
12
  require_relative "api_banking/soap/fundsTransferByCustomerService"
12
13
  require_relative "api_banking/soap/fundsTransferByCustomerService2"
@@ -1,44 +1,47 @@
1
1
  require 'json'
2
2
  module ApiBanking
3
-
4
- class JsonClient
5
-
6
- def self.do_remote_call(dataHash)
3
+
4
+ class JsonClient
5
+
6
+ def self.do_remote_call(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
13
  options[:headers] = {'Content-Type' => "application/json; charset=utf-8"}
14
-
14
+
15
15
  options[:proxy] = self.configuration.proxy
16
16
  options[:timeout] = self.configuration.timeout
17
-
17
+
18
18
  set_options_for_environment(options)
19
19
  set_params_for_environment(options)
20
20
 
21
21
  request = Typhoeus::Request.new(self.configuration.environment.url + uri, options)
22
+
23
+ callbacks.before_send.call(request) if (callbacks && callbacks.before_send.respond_to?(:call))
22
24
  response = request.run
23
-
25
+ callbacks.on_complete.call(request.response) if (callbacks && callbacks.on_complete.respond_to?(:call))
26
+
24
27
  parse_response(response)
25
28
  end
26
-
27
29
 
28
- private
29
-
30
+
31
+ private
32
+
30
33
  def self.add_signature(dataHash)
31
- dataHash[:Single_Payment_Corp_Req][:Signature] = {}
34
+ dataHash[:Single_Payment_Corp_Req][:Signature] = {}
32
35
  dataHash[:Single_Payment_Corp_Req][:Signature][:Signature] = 'Signature'
33
36
  end
34
-
37
+
35
38
  def self.set_params_for_environment(options)
36
39
  params = {}
37
40
  params[:client_id] = self.configuration.environment.client_id
38
41
  params[:client_secret] = self.configuration.environment.client_secret
39
42
  options[:params] = params
40
43
  end
41
-
44
+
42
45
  def self.set_options_for_environment(options)
43
46
  if self.configuration.environment.kind_of?ApiBanking::Environment::RBL::UAT
44
47
  options[:userpwd] = "#{self.configuration.environment.user}:#{self.configuration.environment.password}"
@@ -49,7 +52,7 @@ module ApiBanking
49
52
  end
50
53
  puts "#{options}"
51
54
  end
52
-
55
+
53
56
  def self.parse_response(response)
54
57
  if response.success?
55
58
  if response.headers['Content-Type'] =~ /json/ then
@@ -61,13 +64,13 @@ module ApiBanking
61
64
  end
62
65
  elsif response.timed_out?
63
66
  return Fault.new("502", "", "#{response.return_message}")
64
- elsif response.code == 0
67
+ elsif response.code == 0
65
68
  return Fault.new(response.code, "", response.return_message)
66
69
  else
67
70
  # http status indicating error
68
71
  if response.headers['Content-Type'] =~ /xml/ then
69
72
  reply = Nokogiri::XML(response.response_body)
70
-
73
+
71
74
  # service failures return a fault
72
75
  unless reply.at_xpath('//soapenv12:Fault', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope').nil? then
73
76
  return parse_fault(reply)
@@ -77,18 +80,18 @@ module ApiBanking
77
80
  unless reply.at_xpath('//errorResponse').nil? then
78
81
  return parse_dp_reply(reply)
79
82
  end
80
-
83
+
81
84
  end
82
85
  return Fault.new("#{response.code.to_s}", "", response.status_message)
83
86
  end
84
87
  end
85
-
88
+
86
89
  def self.parse_dp_reply(reply)
87
90
  code = content_at(reply.at_xpath('/errorResponse/httpCode'))
88
91
  reasonText = content_at(reply.at_xpath('/errorResponse/moreInformation'))
89
92
  return Fault.new(code, "", reasonText)
90
93
  end
91
-
94
+
92
95
  def self.parse_fault(reply)
93
96
  code = content_at(reply.at_xpath('//soapenv12:Fault/soapenv12:Code/soapenv12:Subcode/soapenv12:Value', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope'))
94
97
  subcode = content_at(reply.at_xpath('//soapenv12:Fault/soapenv12:Code/soapenv12:Subcode/soapenv12:Subcode/soapenv12:Value', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope'))
@@ -1,8 +1,8 @@
1
1
  module ApiBanking
2
2
  class SinglePayment < JsonClient
3
-
3
+
4
4
  SERVICE_VERSION = 1
5
-
5
+
6
6
  attr_accessor :request, :result
7
7
 
8
8
  #transfer
@@ -11,32 +11,32 @@ module ApiBanking
11
11
  Request = Struct.new(:uniqueRequestNo, :corpID, :makerID, :checkerID, :approverID, :remitter, :beneficiary, :amount, :issueBranchCode, :modeOfPay, :remarks, :rptCode)
12
12
 
13
13
  Result = Struct.new(:status, :errorCode, :errorDescription)
14
-
14
+
15
15
  class << self
16
16
  attr_accessor :configuration
17
17
  end
18
-
18
+
19
19
  def self.configure
20
20
  self.configuration ||= Configuration.new
21
21
  yield(configuration)
22
22
  end
23
-
23
+
24
24
  class Configuration
25
25
  attr_accessor :environment, :proxy, :timeout
26
26
  end
27
-
28
- def self.transfer(request)
27
+
28
+ def self.transfer(request, callbacks = nil)
29
29
  dataHash = {}
30
30
  dataHash[:Single_Payment_Corp_Req] = {}
31
31
  dataHash[:Single_Payment_Corp_Req][:Header] = {}
32
32
  dataHash[:Single_Payment_Corp_Req][:Body] = {}
33
-
33
+
34
34
  dataHash[:Single_Payment_Corp_Req][:Header][:TranID] = request.uniqueRequestNo
35
35
  dataHash[:Single_Payment_Corp_Req][:Header][:Corp_ID] = request.corpID
36
36
  dataHash[:Single_Payment_Corp_Req][:Header][:Maker_ID] = request.makerID
37
37
  dataHash[:Single_Payment_Corp_Req][:Header][:Checker_ID] = request.checkerID
38
38
  dataHash[:Single_Payment_Corp_Req][:Header][:Approver_ID] = request.approverID
39
-
39
+
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
@@ -44,7 +44,7 @@ module ApiBanking
44
44
  dataHash[:Single_Payment_Corp_Req][:Body][:Debit_Mobile] = request.remitter.mobileNo
45
45
  dataHash[:Single_Payment_Corp_Req][:Body][:Debit_TrnParticulars] = request.remitter.tranParticulars
46
46
  dataHash[:Single_Payment_Corp_Req][:Body][:Debit_PartTrnRmks] = request.remitter.partTranRemarks
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
50
50
  dataHash[:Single_Payment_Corp_Req][:Body][:Ben_Name] = request.beneficiary.fullName
@@ -61,15 +61,15 @@ module ApiBanking
61
61
  dataHash[:Single_Payment_Corp_Req][:Body][:Remarks] = request.remarks
62
62
  dataHash[:Single_Payment_Corp_Req][:Body][:RptCode] = request.rptCode
63
63
 
64
-
65
- reply = do_remote_call(dataHash)
66
-
64
+
65
+ reply = do_remote_call(dataHash, callbacks)
66
+
67
67
  parse_reply(:transferResponse, reply)
68
68
  end
69
-
70
-
69
+
70
+
71
71
  private
72
-
72
+
73
73
  def self.uri()
74
74
  if self.configuration.environment.kind_of?ApiBanking::Environment::RBL::UAT
75
75
  return '/test/sb/rbl/v1/payments/corp/payment'
@@ -77,7 +77,7 @@ module ApiBanking
77
77
  return '/sb/rbl/v1/payments/corp/payment'
78
78
  end
79
79
  end
80
-
80
+
81
81
  def self.parse_reply(operationName, reply)
82
82
  if reply.kind_of?Fault
83
83
  return reply
@@ -1,11 +1,11 @@
1
1
  module ApiBanking
2
2
  class AadhaarVerificationService < Soap11Client
3
-
3
+
4
4
  SERVICE_NAMESPACE = 'http://xmlns.yesbank.com/WS/EKYCDataElement'
5
5
  SERVICE_VERSION = "1.0"
6
-
6
+
7
7
  attr_accessor :request, :result
8
-
8
+
9
9
  #verification
10
10
  module Verification
11
11
  Request = Struct.new(:getDemoAuthDataReq)
@@ -15,10 +15,10 @@ module ApiBanking
15
15
  ServiceContext = Struct.new(:serviceName, :reqRefNum, :reqRefTimeStamp, :serviceVersionNo)
16
16
  ReqBody = Struct.new(:demographicDataModel)
17
17
  DemographicDataModel = Struct.new(:aadhaarName, :aadhaarNo, :agentID, :dob, :gender, :loginKey, :merchantId, :merchantTransactionId, :pincode, :terminalID)
18
-
18
+
19
19
  Result = Struct.new(:getDemoAuthDataRes)
20
20
  GetDemoAuthDataRes = Struct.new(:resHdr)
21
- ResHdr = Struct.new(:consumerContext, :serviceContext, :serviceResponse, :errorDetails)
21
+ ResHdr = Struct.new(:consumerContext, :serviceContext, :serviceResponse, :errorDetails)
22
22
  ServiceResponse = Struct.new(:esbResTimeStamp, :esbResStatus)
23
23
  ErrorDetails = Struct.new(:errorInfo)
24
24
  ErrorInfo = Struct.new(:errSrc, :hostErrCode, :hostErrDesc)
@@ -27,18 +27,18 @@ module ApiBanking
27
27
  class << self
28
28
  attr_accessor :configuration
29
29
  end
30
-
30
+
31
31
  def self.configure
32
32
  self.configuration ||= Configuration.new
33
33
  yield(configuration)
34
34
  end
35
-
35
+
36
36
  class Configuration
37
37
  attr_accessor :environment, :proxy, :timeout
38
38
  end
39
-
40
- def self.getDemoAuthData(env, request)
41
- reply = do_remote_call(env, "http://xmlns.yesbank.com/WS/EKYCService/GetDemoAuthData") do |xml|
39
+
40
+ def self.getDemoAuthData(env, request, callbacks)
41
+ reply = do_remote_call(env, callbacks, "http://xmlns.yesbank.com/WS/EKYCService/GetDemoAuthData") do |xml|
42
42
  xml.GetDemoAuthDataReq("xmlns:eky" => SERVICE_NAMESPACE ) do
43
43
  xml.parent.namespace = xml.parent.namespace_definitions.first
44
44
  xml['eky'].ReqHdr do |header|
@@ -74,7 +74,7 @@ module ApiBanking
74
74
  end
75
75
  parse_reply(:getDemoAuthData, reply)
76
76
  end
77
-
77
+
78
78
  private
79
79
 
80
80
  def self.uri()
@@ -83,7 +83,7 @@ module ApiBanking
83
83
 
84
84
  Result = Struct.new(:getDemoAuthDataRes)
85
85
  getDemoAuthDataRes = Struct.new(:resHdr)
86
- ResHdr = Struct.new(:consumerContext, :serviceContext, :serviceResponse, :errorDetails)
86
+ ResHdr = Struct.new(:consumerContext, :serviceContext, :serviceResponse, :errorDetails)
87
87
  ServiceResponse = Struct.new(:esbResTimeStamp, :esbResStatus)
88
88
  ConsumerContext = Struct.new(:requesterID)
89
89
  ServiceContext = Struct.new(:serviceName, :reqRefNum, :reqRefTimeStamp, :serviceVersionNo)
@@ -121,15 +121,15 @@ module ApiBanking
121
121
  consumer_context,
122
122
  service_context,
123
123
  service_response,
124
- error_details
124
+ error_details
125
125
  )
126
126
  res = Verification::GetDemoAuthDataRes.new(
127
- header
127
+ header
128
128
  )
129
129
  return Verification::Result.new(
130
130
  res
131
- )
132
- end
131
+ )
132
+ end
133
133
  end
134
134
  end
135
135
 
@@ -138,4 +138,4 @@ module ApiBanking
138
138
  end
139
139
 
140
140
  end
141
- end
141
+ end
@@ -0,0 +1,17 @@
1
+ module ApiBanking
2
+ class Callbacks
3
+ def initialize
4
+ yield(self) if block_given?
5
+ end
6
+
7
+ def before_send(&block)
8
+ @before_send = block if block_given?
9
+ @before_send
10
+ end
11
+
12
+ def on_complete(&block)
13
+ @on_complete = block if block_given?
14
+ @on_complete
15
+ end
16
+ end
17
+ end
@@ -1,9 +1,9 @@
1
1
  module ApiBanking
2
2
  class FundsTransferByCustomerService2 < Soap12Client
3
-
3
+
4
4
  SERVICE_NAMESPACE = 'http://www.quantiguous.com/services'
5
5
  SERVICE_VERSION = 1
6
-
6
+
7
7
  attr_accessor :request, :result
8
8
 
9
9
  #transfer
@@ -11,26 +11,26 @@ module ApiBanking
11
11
  Address = Struct.new(:address1, :address2, :address3, :postalCode, :city, :stateOrProvince, :country)
12
12
  Beneficiary = Struct.new(:fullName, :address, :accountNo, :accountIFSC, :mobileNo, :mmid, :beneCode)
13
13
  Request = Struct.new(:uniqueRequestNo, :appID, :customerID, :debitAccountNo, :beneficiary, :transferAmount, :transferType, :purposeCode, :remitterToBeneficiaryInfo)
14
-
14
+
15
15
  TransactionStatus = Struct.new(:statusCode, :subStatusCode, :bankReferenceNo, :beneficiaryReferenceNo)
16
16
  Result = Struct.new(:version, :uniqueResponseNo, :attemptNo, :transferType, :lowBalanceAlert, :transactionStatus)
17
17
  end
18
-
18
+
19
19
  #getStatus
20
20
  module GetStatus
21
21
  Request = Struct.new(:version, :appID, :customerID, :requestReferenceNo)
22
22
  TransactionStatus = Struct.new(:statusCode, :subStatusCode, :bankReferenceNo, :beneficiaryReferenceNo)
23
23
  Result = Struct.new(:version, :transferType, :reqTransferType, :transactionDate, :transferAmount, :transferCurrencyCode, :transactionStatus)
24
24
  end
25
-
25
+
26
26
  #getBalance
27
27
  module GetBalance
28
28
  Request = Struct.new(:version, :appID, :customerID, :AccountNumber)
29
29
  Result = Struct.new(:Version, :accountCurrencyCode, :accountBalanceAmount, :lowBalanceAlert)
30
30
  end
31
-
32
- def self.transfer(env, request)
33
- reply = do_remote_call(env) do |xml|
31
+
32
+ def self.transfer(env, request, callbacks = nil)
33
+ reply = do_remote_call(env, callbacks) do |xml|
34
34
  xml.transfer("xmlns:ns" => SERVICE_NAMESPACE ) do
35
35
  xml.parent.namespace = xml.parent.namespace_definitions.first
36
36
  xml['ns'].version SERVICE_VERSION
@@ -47,7 +47,7 @@ module ApiBanking
47
47
  xml.fullName request.beneficiary.fullName
48
48
  end
49
49
  xml.beneficiaryAddress do |xml|
50
- if request.beneficiary.address.kind_of? Transfer::Address
50
+ if request.beneficiary.address.kind_of? Transfer::Address
51
51
  xml.address1 request.beneficiary.address.address1
52
52
  xml.address2 request.beneficiary.address.address2 unless request.beneficiary.address.address2.nil?
53
53
  xml.address3 request.beneficiary.address.address3 unless request.beneficiary.address.address3.nil?
@@ -72,13 +72,13 @@ module ApiBanking
72
72
  xml.remitterToBeneficiaryInfo request.remitterToBeneficiaryInfo
73
73
  end
74
74
  end
75
-
75
+
76
76
  parse_reply(:transfer, reply)
77
77
  end
78
78
 
79
-
80
- def self.get_status(env, request)
81
- reply = do_remote_call(env) do |xml|
79
+
80
+ def self.get_status(env, request, callbacks = nil)
81
+ reply = do_remote_call(env, callbacks) do |xml|
82
82
  xml.getStatus("xmlns:ns" => SERVICE_NAMESPACE ) do
83
83
  xml.parent.namespace = xml.parent.namespace_definitions.first
84
84
  xml['ns'].version SERVICE_VERSION
@@ -89,9 +89,9 @@ module ApiBanking
89
89
  end
90
90
  parse_reply(:getStatus, reply)
91
91
  end
92
-
93
- def self.get_balance(env, request)
94
- reply = do_remote_call(env) do |xml|
92
+
93
+ def self.get_balance(env, request, callbacks = nil)
94
+ reply = do_remote_call(env, callbacks) do |xml|
95
95
  xml.getBalance("xmlns:ns" => SERVICE_NAMESPACE ) do
96
96
  xml.parent.namespace = xml.parent.namespace_definitions.first
97
97
  xml['ns'].version SERVICE_VERSION
@@ -104,11 +104,11 @@ module ApiBanking
104
104
  end
105
105
 
106
106
  private
107
-
107
+
108
108
  def self.uri()
109
109
  return '/fundsTransferByCustomerService2'
110
110
  end
111
-
111
+
112
112
  def self.parse_reply(operationName, reply)
113
113
  if reply.kind_of?Fault
114
114
  return reply
@@ -144,18 +144,18 @@ module ApiBanking
144
144
  content_at(reply.at_xpath('//ns:getStatusResponse/ns:transferAmount', 'ns' => SERVICE_NAMESPACE)),
145
145
  content_at(reply.at_xpath('//ns:getStatusResponse/ns:transferCurrencyCode', 'ns' => SERVICE_NAMESPACE)),
146
146
  transactionStatus
147
- )
147
+ )
148
148
  when :getBalance
149
149
  return GetBalance::Result.new(
150
150
  content_at(reply.at_xpath('//ns:getBalanceResponse/ns:Version', 'ns' => SERVICE_NAMESPACE)),
151
151
  content_at(reply.at_xpath('//ns:getBalanceResponse/ns:accountCurrencyCode', 'ns' => SERVICE_NAMESPACE)),
152
152
  content_at(reply.at_xpath('//ns:getBalanceResponse/ns:accountBalanceAmount', 'ns' => SERVICE_NAMESPACE)),
153
153
  content_at(reply.at_xpath('//ns:getBalanceResponse/ns:lowBalanceAlert', 'ns' => SERVICE_NAMESPACE))
154
- )
155
- end
154
+ )
155
+ end
156
156
  end
157
157
  end
158
-
158
+
159
159
  def url
160
160
  return '/fundsTransferByCustomerService2'
161
161
  end
@@ -1,11 +1,11 @@
1
1
  module ApiBanking
2
2
  class InstantMoneyTransferService < Soap12Client
3
-
3
+
4
4
  SERVICE_NAMESPACE = 'http://www.quantiguous.com/services'
5
5
  SERVICE_VERSION = 1
6
-
6
+
7
7
  attr_accessor :request, :result
8
-
8
+
9
9
  module AddBeneficiary
10
10
  Request = Struct.new(:uniqueRequestNo, :appID, :customerID, :beneficiaryMobileNo, :beneficiaryName, :beneficiaryAddress)
11
11
  Address = Struct.new(:addressLine, :cityName, :postalCode)
@@ -27,8 +27,8 @@ module ApiBanking
27
27
 
28
28
  module GetBeneficiaries
29
29
  Request = Struct.new(:uniqueRequestNo, :appID, :customerID, :dateRange, :numBeneficiaries)
30
-
31
- DateRange = Struct.new(:fromDate, :toDate)
30
+
31
+ DateRange = Struct.new(:fromDate, :toDate)
32
32
  Beneficiary = Struct.new(:beneficiaryName, :beneficiaryMobileNo, :registrationDate, :addressLine, :postalCode)
33
33
  BeneficiariesArray = Struct.new(:beneficiary)
34
34
 
@@ -41,22 +41,22 @@ module ApiBanking
41
41
  Result = Struct.new(:uniqueResponseNo, :initiateTransferResult)
42
42
  TransferResult = Struct.new(:bankReferenceNo, :imtReferenceNo)
43
43
  end
44
-
44
+
45
45
  class << self
46
46
  attr_accessor :configuration
47
47
  end
48
-
48
+
49
49
  def self.configure
50
50
  self.configuration ||= Configuration.new
51
51
  yield(configuration)
52
52
  end
53
-
53
+
54
54
  class Configuration
55
55
  attr_accessor :environment, :proxy, :timeout
56
56
  end
57
-
58
- def self.transfer(env, request)
59
- reply = do_remote_call(env) do |xml|
57
+
58
+ def self.transfer(env, request, callbacks = nil)
59
+ reply = do_remote_call(env, callbacks) do |xml|
60
60
  xml.initiateTransfer("xmlns:ns" => SERVICE_NAMESPACE ) do
61
61
  xml.parent.namespace = xml.parent.namespace_definitions.first
62
62
  xml['ns'].version SERVICE_VERSION
@@ -69,12 +69,12 @@ module ApiBanking
69
69
  xml['ns'].remitterToBeneficiaryInfo request.remitterToBeneficiaryInfo
70
70
  end
71
71
  end
72
-
72
+
73
73
  parse_reply(:initiateTransfer, reply)
74
74
  end
75
75
 
76
- def self.add_beneficiary(env, request)
77
- reply = do_remote_call(env) do |xml|
76
+ def self.add_beneficiary(env, request, callbacks = nil)
77
+ reply = do_remote_call(env, callbacks) do |xml|
78
78
  xml.addBeneficiary("xmlns:ns" => SERVICE_NAMESPACE ) do
79
79
  xml.parent.namespace = xml.parent.namespace_definitions.first
80
80
  xml['ns'].version SERVICE_VERSION
@@ -84,7 +84,7 @@ module ApiBanking
84
84
  xml['ns'].beneficiaryMobileNo request.beneficiaryMobileNo
85
85
  xml['ns'].beneficiaryName request.beneficiaryName
86
86
  xml['ns'].beneficiaryAddress do |xml|
87
- if request.beneficiaryAddress.kind_of? AddBeneficiary::Address
87
+ if request.beneficiaryAddress.kind_of? AddBeneficiary::Address
88
88
  xml.addressLine request.beneficiaryAddress.addressLine
89
89
  xml.cityName request.beneficiaryAddress.cityName unless request.beneficiaryAddress.cityName.nil?
90
90
  xml.postalCode request.beneficiaryAddress.postalCode unless request.beneficiaryAddress.postalCode.nil?
@@ -94,12 +94,12 @@ module ApiBanking
94
94
  end
95
95
  end
96
96
  end
97
-
97
+
98
98
  parse_reply(:addBeneficiary, reply)
99
99
  end
100
100
 
101
- def self.delete_beneficiary(env, request)
102
- reply = do_remote_call(env) do |xml|
101
+ def self.delete_beneficiary(env, request, callbacks = nil)
102
+ reply = do_remote_call(env, callbacks) do |xml|
103
103
  xml.deleteBeneficiary("xmlns:ns" => SERVICE_NAMESPACE ) do
104
104
  xml.parent.namespace = xml.parent.namespace_definitions.first
105
105
  xml['ns'].version SERVICE_VERSION
@@ -109,12 +109,12 @@ module ApiBanking
109
109
  xml['ns'].beneficiaryMobileNo request.beneficiaryMobileNo
110
110
  end
111
111
  end
112
-
112
+
113
113
  parse_reply(:deleteBeneficiary, reply)
114
114
  end
115
115
 
116
- def self.get_beneficiaries(env, request)
117
- reply = do_remote_call(env) do |xml|
116
+ def self.get_beneficiaries(env, request, callbacks = nil)
117
+ reply = do_remote_call(env, callbacks) do |xml|
118
118
  xml.getBeneficiaries("xmlns:ns" => SERVICE_NAMESPACE ) do
119
119
  xml.parent.namespace = xml.parent.namespace_definitions.first
120
120
  xml['ns'].version SERVICE_VERSION
@@ -130,8 +130,8 @@ module ApiBanking
130
130
  parse_reply(:getBeneficiaries, reply)
131
131
  end
132
132
 
133
- def self.cancel_transfer(env, request)
134
- reply = do_remote_call(env) do |xml|
133
+ def self.cancel_transfer(env, request, callbacks = nil)
134
+ reply = do_remote_call(env, callbacks) do |xml|
135
135
  xml.cancelTransfer("xmlns:ns" => SERVICE_NAMESPACE ) do
136
136
  xml.parent.namespace = xml.parent.namespace_definitions.first
137
137
  xml['ns'].version SERVICE_VERSION
@@ -142,12 +142,12 @@ module ApiBanking
142
142
  xml['ns'].reasonToCancel request.reasonToCancel
143
143
  end
144
144
  end
145
-
145
+
146
146
  parse_reply(:cancelTransfer, reply)
147
147
  end
148
-
148
+
149
149
  private
150
-
150
+
151
151
  def self.parse_reply(operationName, reply)
152
152
  if reply.kind_of?Fault
153
153
  return reply
@@ -1,39 +1,42 @@
1
1
  module ApiBanking
2
-
3
- class SoapClient
4
-
2
+
3
+ class SoapClient
4
+
5
5
  def self.last_response
6
6
  Thread.current[:last_response]
7
7
  end
8
-
9
- def self.do_remote_call(env, soapAction = nil, &block)
8
+
9
+ def self.do_remote_call(env, callbacks = nil, soapAction = nil, &block)
10
10
  data = construct_envelope(&block)
11
11
  options = {}
12
12
  options[:method] = :post
13
13
  options[:body] = data.to_xml
14
-
14
+
15
15
  # add soap11/12 specific headers
16
16
  add_soap_headers(options, soapAction)
17
-
17
+
18
18
  # TODO: configuration removed for thread-safety, the assumption that one app at one time will connect to one environment
19
19
  # isn't valid anymore (starkit)
20
20
  # options[:proxy] = self.configuration.proxy
21
21
  # options[:timeout] = self.configuration.timeout
22
-
22
+
23
23
  set_options_for_environment(env, options)
24
-
24
+
25
25
  options[:headers]['User-Agent'] = "Quantiguous; API Banking, Ruby Gem #{ApiBanking::VERSION}"
26
-
26
+
27
27
  request = Typhoeus::Request.new(env.endpoints[self.name.split('::').last.to_sym], options)
28
+
29
+ callbacks.before_send.call(request) if (callbacks && callbacks.before_send.respond_to?(:call))
28
30
  response = request.run
29
-
30
- Thread.current[:last_response] = response
31
+ callbacks.on_complete.call(request.response) if (callbacks && callbacks.on_complete.respond_to?(:call))
32
+
33
+ Thread.current[:last_response] = response
31
34
 
32
35
  parse_response(response)
33
36
  end
34
-
35
37
 
36
- private
38
+
39
+ private
37
40
 
38
41
  def self.set_options_for_environment(env, options)
39
42
  if env.kind_of?ApiBanking::Environment::YBL::PRD
@@ -58,7 +61,7 @@ module ApiBanking
58
61
  end
59
62
 
60
63
 
61
-
64
+
62
65
  def self.parse_response(response)
63
66
  if response.success?
64
67
  if response.headers['Content-Type'] =~ /xml/ then
@@ -66,41 +69,41 @@ module ApiBanking
66
69
  end
67
70
  elsif response.timed_out?
68
71
  return Fault.new("502", "", "#{response.return_message}")
69
- elsif response.code == 0
72
+ elsif response.code == 0
70
73
  return Fault.new(response.code, "", response.return_message)
71
74
  else
72
75
  # http status indicating error, is either a datapower failure or a soap fault
73
76
  if response.headers['Content-Type'] =~ /xml/ then
74
77
  reply = Nokogiri::XML(response.response_body)
75
-
78
+
76
79
  # datapower failures return an xml
77
80
  unless reply.at_xpath('//errorResponse').nil? then
78
81
  return parse_dp_reply(reply)
79
82
  end
80
-
83
+
81
84
  # has to be a soapfault
82
85
  return parse_fault(reply)
83
-
86
+
84
87
  end
85
88
  return Fault.new("#{response.code.to_s}", "", response.status_message)
86
89
  end
87
90
  end
88
-
91
+
89
92
  def self.parse_dp_reply(reply)
90
93
  code = content_at(reply.at_xpath('/errorResponse/httpCode'))
91
94
  reasonText = content_at(reply.at_xpath('/errorResponse/moreInformation'))
92
95
  return Fault.new(code, "", reasonText)
93
96
  end
94
-
97
+
95
98
  def self.content_at(node)
96
99
  node.content unless node.nil?
97
100
  end
98
-
101
+
99
102
  end
100
-
103
+
101
104
  class Soap12Client < SoapClient
102
- private
103
-
105
+ private
106
+
104
107
  def self.add_soap_headers(options, soapAction)
105
108
  options[:headers] = {'Content-Type' => "application/xml; charset=utf-8"}
106
109
 
@@ -108,31 +111,31 @@ module ApiBanking
108
111
  # options[:headers][:SOAPAction] = data.doc.at_xpath('/soapenv12:Envelope/soapenv12:Body/*', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope').name
109
112
 
110
113
  end
111
-
114
+
112
115
  def self.construct_envelope(&block)
113
116
  Nokogiri::XML::Builder.new do |xml|
114
117
  xml.Envelope("xmlns:soap12" => "http://www.w3.org/2003/05/soap-envelope",
115
118
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
116
119
  "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema") do
117
120
  xml.parent.namespace = xml.parent.namespace_definitions.first
118
- xml['soap12'].Header
121
+ xml['soap12'].Header
119
122
  xml['soap12'].Body(&block)
120
123
  end
121
124
  end
122
- end
123
-
125
+ end
126
+
124
127
  def self.parse_fault(reply)
125
128
  code = content_at(reply.at_xpath('//soapenv12:Fault/soapenv12:Code/soapenv12:Subcode/soapenv12:Value', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope'))
126
129
  subcode = content_at(reply.at_xpath('//soapenv12:Fault/soapenv12:Code/soapenv12:Subcode/soapenv12:Subcode/soapenv12:Value', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope'))
127
130
  reasonText = content_at(reply.at_xpath('//soapenv12:Fault/soapenv12:Reason/soapenv12:Text', 'soapenv12' => 'http://www.w3.org/2003/05/soap-envelope'))
128
-
131
+
129
132
  code ||= 'ns:E500' # in certain cases, a fault code isn't set by the server
130
133
  return Fault.new(code, subcode, reasonText)
131
134
  end
132
135
 
133
-
136
+
134
137
  end
135
-
138
+
136
139
  class Soap11Client < SoapClient
137
140
  private
138
141
 
@@ -149,20 +152,20 @@ module ApiBanking
149
152
  "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
150
153
  "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema") do
151
154
  xml.parent.namespace = xml.parent.namespace_definitions.first
152
- xml['soap11'].Header
155
+ xml['soap11'].Header
153
156
  xml['soap11'].Body(&block)
154
157
  end
155
158
  end
156
- end
157
-
159
+ end
160
+
158
161
  def self.parse_fault(reply)
159
162
  code = nil # soap11 fault codes are meaningless
160
163
  reasonText = content_at(reply.at_xpath('//soapenv11:Fault/faultstring', 'soapenv11' => 'http://schemas.xmlsoap.org/soap/envelope/'))
161
-
164
+
162
165
  code ||= 'ns:E500' # in certain cases, a fault code isn't set by the server
163
166
  return Fault.new(code, nil, reasonText)
164
167
  end
165
-
166
-
168
+
169
+
167
170
  end
168
171
  end
@@ -1,11 +1,11 @@
1
1
  module ApiBanking
2
2
  class SocialBankingService < Soap12Client
3
-
3
+
4
4
  SERVICE_NAMESPACE = 'http://www.quantiguous.com/services'
5
5
  SERVICE_VERSION = 1
6
-
6
+
7
7
  attr_accessor :request, :result
8
-
8
+
9
9
  #getTransactions
10
10
  module GetTransactions
11
11
  Request = Struct.new(:version, :appID, :customerIdentity, :deviceID, :accountIdentity, :numTransactions)
@@ -13,7 +13,7 @@ module ApiBanking
13
13
  CustomerAlternateID = Struct.new(:mobileNo, :emailID, :twitterID, :genericID)
14
14
  GenericID = Struct.new(:idType, :idValue)
15
15
  AccountIdentity = Struct.new(:accountNo, :registeredAccount)
16
-
16
+
17
17
  Transaction = Struct.new(:transactionID, :recordDate, :transactionType, :currencyCode, :amount, :narrative)
18
18
  Result = Struct.new(:version, :customerID, :accountNo, :numTransactions, :transactionsArray)
19
19
  end
@@ -21,18 +21,18 @@ module ApiBanking
21
21
  class << self
22
22
  attr_accessor :configuration
23
23
  end
24
-
24
+
25
25
  def self.configure
26
26
  self.configuration ||= Configuration.new
27
27
  yield(configuration)
28
28
  end
29
-
29
+
30
30
  class Configuration
31
31
  attr_accessor :environment, :proxy, :timeout
32
32
  end
33
-
34
- def self.getTransactions(env, request)
35
- reply = do_remote_call(env) do |xml|
33
+
34
+ def self.getTransactions(env, request, callbacks = nil)
35
+ reply = do_remote_call(env, callbacks) do |xml|
36
36
  xml.getTransactions("xmlns:ns" => SERVICE_NAMESPACE ) do
37
37
  xml.parent.namespace = xml.parent.namespace_definitions.first
38
38
  xml['ns'].version SERVICE_VERSION
@@ -63,7 +63,7 @@ module ApiBanking
63
63
  end
64
64
  parse_reply(:getTransactions, reply)
65
65
  end
66
-
66
+
67
67
  private
68
68
 
69
69
  def self.uri()
@@ -76,7 +76,7 @@ module ApiBanking
76
76
  else
77
77
  case operationName
78
78
  when :getTransactions
79
- txnArray = Array.new
79
+ txnArray = Array.new
80
80
  i = 1
81
81
  numTxns = content_at(reply.at_xpath("//ns:getTransactionsResponse/ns:numTransactions", 'ns' => SERVICE_NAMESPACE)).to_i
82
82
  until i > numTxns
@@ -98,7 +98,7 @@ module ApiBanking
98
98
  txnArray.size,
99
99
  txnArray
100
100
  )
101
- end
101
+ end
102
102
  end
103
103
  end
104
104
 
@@ -107,4 +107,4 @@ module ApiBanking
107
107
  end
108
108
 
109
109
  end
110
- end
110
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiBanking
2
- VERSION = "0.1.17"
2
+ VERSION = "0.1.18"
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.17
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - akil
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2017-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -135,6 +135,7 @@ files:
135
135
  - lib/api_banking/json/json_client.rb
136
136
  - lib/api_banking/json/singlePayment.rb
137
137
  - lib/api_banking/soap/aadhaarVerificationService.rb
138
+ - lib/api_banking/soap/callbacks.rb
138
139
  - lib/api_banking/soap/domesticRemittanceByPartnerService.rb
139
140
  - lib/api_banking/soap/fault.rb
140
141
  - lib/api_banking/soap/fundsTransferByCustomerService.rb
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
170
  version: '0'
170
171
  requirements: []
171
172
  rubyforge_project:
172
- rubygems_version: 2.4.6
173
+ rubygems_version: 2.4.5
173
174
  signing_key:
174
175
  specification_version: 4
175
176
  summary: Ruby SDK to Connect to Banks