lib/alipay/service.rb in alipay-0.7.0 vs lib/alipay/service.rb in alipay-0.7.1

- old
+ new

@@ -40,12 +40,12 @@ # direct def self.create_direct_pay_by_user_url(params, options = {}) params = Utils.stringify_keys(params) check_required_params(params, CREATE_DIRECT_PAY_BY_USER_REQUIRED_PARAMS) - if params['total_fee'].nil? and (params['price'].nil? || params['quantity'].nil?) - warn("Ailpay Warn: total_fee or (price && quantiry) must have one") + if Alipay.debug_mode? and params['total_fee'].nil? and (params['price'].nil? || params['quantity'].nil?) + warn("Alipay Warn: total_fee or (price && quantity) must be set") end params = { 'service' => 'create_direct_pay_by_user', '_input_charset' => 'utf-8', @@ -101,31 +101,31 @@ request_uri(params, options).to_s end SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_PARAMS = %w( trade_no logistics_name ) + SEND_GOODS_CONFIRM_BY_PLATFORM_OPTIONAL_PARAMS = %w( transport_type create_transport_type ) def self.send_goods_confirm_by_platform(params, options = {}) params = Utils.stringify_keys(params) check_required_params(params, SEND_GOODS_CONFIRM_BY_PLATFORM_REQUIRED_PARAMS) + check_optional_params(params, SEND_GOODS_CONFIRM_BY_PLATFORM_OPTIONAL_PARAMS) - if params['transport_type'].nil? and params['create_transport_type'].nil? - warn("Ailpay Warn: transport_type or create_transport_type must have one") - end - params = { 'service' => 'send_goods_confirm_by_platform', 'partner' => options[:pid] || Alipay.pid, '_input_charset' => 'utf-8' }.merge(params) Net::HTTP.get(request_uri(params, options)) end - CREATE_FOREX_TRADE_REQUIRED_PARAMS = %w( notify_url subject out_trade_no currency total_fee) + CREATE_FOREX_TRADE_REQUIRED_PARAMS = %w( notify_url subject out_trade_no currency ) + CREATE_FOREX_TRADE_OPTIONAL_PARAMS = %w( total_fee rmb_fee ) def self.create_forex_trade_url(params, options = {}) params = Utils.stringify_keys(params) check_required_params(params, CREATE_FOREX_TRADE_REQUIRED_PARAMS) + check_optional_params(params, CREATE_FOREX_TRADE_OPTIONAL_PARAMS) params = { 'service' => 'create_forex_trade', '_input_charset' => 'utf-8', 'partner' => options[:pid] || Alipay.pid, @@ -195,15 +195,16 @@ def self.check_required_params(params, names) return if !Alipay.debug_mode? names.each do |name| - warn("Ailpay Warn: missing required option: #{name}") unless params.has_key?(name) + warn("Alipay Warn: missing required option: #{name}") unless params.has_key?(name) end end def self.check_optional_params(params, names) return if !Alipay.debug_mode? - warn("Ailpay Warn: must specify either #{names.join(' or ')}") if names.all? {|name| params[name].nil? } + + warn("Alipay Warn: must specify either #{names.join(' or ')}") if names.all? {|name| params[name].nil? } end end end