lib/qtpay/service.rb in qtpay-0.0.1 vs lib/qtpay/service.rb in qtpay-0.0.2
- old
+ new
@@ -31,34 +31,100 @@
def self.create_pre_order(params, options = {})
make_request(:post, create_pre_order_url(params, options))
end
+ # ==== params ====
+ # (required)
+ # token: auth token created in get_user_token
+ # order_token: order token created in create_pre_order
+ # total_amt: total payment amount in cents
+ # pay_type: payment type (1: alipay, 2: wechat)
+ # pay_source: payment source (4: scan code)
+ # goods_name: name of goods
+ #
+ # (optional)
+ # pay_amt: payment amount
+ # balance_amt
+ # coupon_amt
+ # coupon_code
+ # point_amt
+ # point_num
+ # goods_info
+ # mobile
+ # openid: openid when creating wechat qrcode
+ # limit_pay
+
+ def self.create_order(params, options = {})
+ make_request(:post, create_order_url(params, options))
+ end
+
+ # ==== params ====
+ # (optional)
+ # token: auth token created in get_user_token, required when caller is app or h5
+ # order_id: either order_id or out_sn is required
+ # out_sn: either order_id or out_sn is required
+
+ def self.get_order(params, options ={})
+ make_request(:get, get_order_url(params, options))
+ end
+
+ # ==== params ====
+ # (required)
+ # order_id
+ #
+ # (optional)
+ # amt: amount
+
+ def self.refund_order(params, options = {})
+ make_request(:post, refund_order_url(params, options))
+ end
+
GET_USER_TOKEN_REQUIRED_PARAMS = %w( out_user )
def self.get_user_token_url(params, options = {})
- params = Utils.stringify_keys(params)
- check_required_params(params, GET_USER_TOKEN_REQUIRED_PARAMS)
+ params = handle_params(params, GET_USER_TOKEN_REQUIRED_PARAMS, options)
- params = {
- 'caller' => 'server',
- 'app_code' => options[:app_code] || Qtpay.app_code,
- }.merge(params)
-
request_uri('/auth/v1/token', params, options)
end
CREATE_PRE_ORDER_REQUIRED_PARAMS = %w( total_amt out_sn )
def self.create_pre_order_url(params, options = {})
+ params = handle_params(params, CREATE_PRE_ORDER_REQUIRED_PARAMS, options)
+
+ request_uri('/order/v1/pre_create', params, options)
+ end
+
+ CREATE_ORDER_REQUIRED_PARAMS = %w( token order_token total_amt pay_type pay_source goods_name )
+ def self.create_order_url(params, options = {})
+ params = handle_params(params, CREATE_ORDER_REQUIRED_PARAMS, options)
+
+ request_uri('/order/v1/create', params, options)
+ end
+
+ GET_ORDER_REQUIRED_PARAMS = %w()
+ def self.get_order_url(params, options = {})
+ params = handle_params(params, GET_ORDER_REQUIRED_PARAMS, options)
+
+ request_uri('/order/v1/query', params, options)
+ end
+
+ REFUND_ORDER_REQUIRED_PARAMS = %w(order_id)
+ def self.refund_order_url(params, options = {})
+ params = handle_params(params, REFUND_ORDER_REQUIRED_PARAMS, options)
+
+ request_uri('/order/v1/refund', params, options)
+ end
+
+ def self.handle_params(params, required_params, options = {})
params = Utils.stringify_keys(params)
- check_required_params(params, CREATE_PRE_ORDER_REQUIRED_PARAMS)
+ check_required_params(params, required_params)
- params = {
+ {
'caller' => 'server',
'app_code' => options[:app_code] || Qtpay.app_code,
}.merge(params)
-
- request_uri('/order/v1/pre_create', params, options)
end
+
def self.request_uri(path, params, options = {})
uri = URI("#{Qtpay.gateway_url}#{path}")
uri.query = URI.encode_www_form(sign_params(params, options))
uri
\ No newline at end of file