Module: Myclear::Service
- Defined in:
- lib/myclear/service.rb
Constant Summary collapse
- BE_URI =
BE
'/FPXMain/RetrieveBankList'
- AR_URI =
AR fpx_msgToken: B2C => ‘01’, B2B => ‘02’
'/FPXMain/seller2DReceiver.jsp'
- AR_REQUIRED_PARAMS =
%w(fpx_msgToken fpx_sellerExOrderNo fpx_sellerTxnTime fpx_sellerOrderNo fpx_txnCurrency fpx_txnAmount fpx_buyerEmail fpx_buyerName fpx_buyerBankId fpx_buyerBankBranch fpx_buyerAccNo fpx_buyerId fpx_makerName fpx_buyerIban fpx_productDesc)
- AE_URI =
AE fpx_msgToken: B2C => ‘01’, B2B => ‘02’
'/FPXMain/sellerNVPTxnStatus.jsp'
- AE_REQUIRED_PARAMS =
%w(fpx_msgToken fpx_sellerExOrderNo fpx_sellerTxnTime fpx_sellerOrderNo fpx_txnCurrency fpx_txnAmount fpx_buyerEmail fpx_buyerName fpx_buyerBankId fpx_buyerBankBranch fpx_buyerAccNo fpx_buyerId fpx_makerName fpx_buyerIban fpx_productDesc)
- VERIFY_REQUIRED_PARAMS =
%w(fpx_buyerBankBranch fpx_buyerBankId fpx_buyerIban fpx_buyerId fpx_buyerName fpx_creditAuthCode fpx_creditAuthNo fpx_debitAuthCode fpx_debitAuthNo fpx_fpxTxnId fpx_fpxTxnTime fpx_makerName fpx_msgToken fpx_msgType fpx_sellerExId fpx_sellerExOrderNo fpx_sellerId fpx_sellerOrderNo fpx_sellerTxnTime fpx_txnAmount fpx_txnCurrency fpx_checkSum)
Class Method Summary collapse
- .ae_url ⇒ Object
- .ar_url ⇒ Object
- .authorization_enquiry(params, options = {}) ⇒ Object
- .authorization_request_params(params, options = {}) ⇒ Object
- .bank_list_enquiry(options = {}) ⇒ Object
- .be_url ⇒ Object
- .check_params(params, names) ⇒ Object
- .package_params(params) ⇒ Object
- .request(uri, params, options = {}) ⇒ Object
- .request_uri(params, options = {}) ⇒ Object
- .sign_params(params, options) ⇒ Object
- .verify_params(params, options = {}) ⇒ Object
Class Method Details
.ae_url ⇒ Object
61 62 63 |
# File 'lib/myclear/service.rb', line 61 def self.ae_url Myclear.service_host + AE_URI end |
.ar_url ⇒ Object
39 40 41 |
# File 'lib/myclear/service.rb', line 39 def self.ar_url Myclear.service_host + AR_URI end |
.authorization_enquiry(params, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/myclear/service.rb', line 47 def self.(params, = {}) params = Utils.stringify_keys(params) check_params(params, AE_REQUIRED_PARAMS) params = { 'fpx_msgType' => 'AE', 'fpx_sellerBankCode' => '01', 'fpx_sellerExId' => Myclear.seller_exchange_id, 'fpx_version' => Myclear.fpx_version, 'fpx_sellerId' => Myclear.seller_id }.merge(params) request(AE_URI, params, ) end |
.authorization_request_params(params, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/myclear/service.rb', line 24 def self.(params, = {}) params = Utils.stringify_keys(params) check_params(params, AR_REQUIRED_PARAMS) params = { 'fpx_msgType' => 'AR', 'fpx_sellerBankCode' => '01', 'fpx_sellerExId' => Myclear.seller_exchange_id, 'fpx_version' => Myclear.fpx_version, 'fpx_sellerId' => Myclear.seller_id }.merge(params) # request_uri(params, options) sign_params(params, ) end |
.bank_list_enquiry(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/myclear/service.rb', line 5 def self.bank_list_enquiry = {} params = { 'fpx_msgType' => 'BE', 'fpx_msgToken' => '01', 'fpx_sellerExId' => Myclear.seller_exchange_id, 'fpx_version' => Myclear.fpx_version } request(BE_URI, params, ) end |
.be_url ⇒ Object
16 17 18 |
# File 'lib/myclear/service.rb', line 16 def self.be_url Myclear.service_host + BE_URI end |
.check_params(params, names) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/myclear/service.rb', line 99 def self.check_params(params, names) return if !Myclear.debug_mode? (params.keys - names).each { |key| warn("Myclear Warn: unknown option: #{key}") } names.each do |name| warn("Myclear Warn: missing required option: #{name}") unless params.has_key?(name) end end |
.package_params(params) ⇒ Object
95 96 97 |
# File 'lib/myclear/service.rb', line 95 def self.package_params(params) params.sort_by { |key, value| key }.to_h.values.join("|") end |
.request(uri, params, options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/myclear/service.rb', line 78 def self.request(uri, params, = {}) host_uri = URI(Myclear.service_host) http = Net::HTTP.new(host_uri.host, host_uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE req = Net::HTTP::Post.new(uri) req['Accept'] = 'application/json' req.set_form_data(sign_params(params, )) http.request(req) end |
.request_uri(params, options = {}) ⇒ Object
72 73 74 75 76 |
# File 'lib/myclear/service.rb', line 72 def self.request_uri(params, = {}) uri = URI(GATEWAY_URL) uri.query = URI.encode_www_form(sign_params(params, )) uri end |
.sign_params(params, options) ⇒ Object
89 90 91 92 93 |
# File 'lib/myclear/service.rb', line 89 def self.sign_params(params, ) params.merge( 'fpx_checkSum' => Myclear::Sign.generate(package_params(params), ) ) end |
.verify_params(params, options = {}) ⇒ Object
66 67 68 69 70 |
# File 'lib/myclear/service.rb', line 66 def self.verify_params(params, = {}) params = Utils.stringify_keys(params) check_params(params, VERIFY_REQUIRED_PARAMS) Myclear::Sign.verify?(params.delete('fpx_checkSum'), package_params(params)) end |