class Newebpay::CloseFund::Base
Constants
- REQUIRED_ATTRS
Attributes
attrs[RW]
merchant_id[RW]
response[RW]
Public Class Methods
new(options)
click to toggle source
# File lib/newebpay/close_fund/base.rb, line 8 def initialize(options) check_valid(options) @attrs = {} @merchant_id = options[:merchant_id] || Newebpay.config.merchant_id parse_attr(options) @attrs['Version'] = version @attrs['TimeStamp'] = Time.now.to_i @attrs['RespondType'] = 'JSON' @attrs['CloseType'] = close_type result = HTTP.post(Newebpay.config.close_fund_url, form: form_attrs).body.to_s @response = Response.new(result) end
Public Instance Methods
encode_url_params()
click to toggle source
# File lib/newebpay/close_fund/base.rb, line 34 def encode_url_params URI.encode_www_form(attrs) end
form_attrs()
click to toggle source
# File lib/newebpay/close_fund/base.rb, line 23 def form_attrs @form_attrs ||= { MerchantID_: merchant_id, PostData_: trade_info } end
trade_info()
click to toggle source
# File lib/newebpay/close_fund/base.rb, line 30 def trade_info @trade_info ||= Newebpay::NewebpayHelper.encrypt_data(encode_url_params) end
version()
click to toggle source
# File lib/newebpay/close_fund/base.rb, line 38 def version '1.1' end
Private Instance Methods
check_valid(options)
click to toggle source
# File lib/newebpay/close_fund/base.rb, line 59 def check_valid(options) unless options.is_a? Hash raise ArgumentError, "When initializing #{self.class.name}, you must pass a hash as an argument." end REQUIRED_ATTRS.each do |argument| raise ArgumentError, "Missing required argument: #{argument}." unless options[argument] end end
parse_attr(options)
click to toggle source
# File lib/newebpay/close_fund/base.rb, line 44 def parse_attr(options) attrs['Amt'] = options[:price] attrs['IndexType'] = options[:number_type] || '1' attrs['Cancel'] = '1' if options[:cancel] case attrs['IndexType'].to_s when '1' attrs['MerchantOrderNo'] = options[:order_number] when '2' attrs['TradeNo'] = options[:order_number] else raise ArgumentError, "Invalid number_type: #{options[:number_type]}" end end