lib/alipay/service.rb in alipay-0.16.0 vs lib/alipay/service.rb in alipay-0.17.0

- old
+ new

@@ -207,9 +207,95 @@ }.merge(params) request_uri(params, options).to_s end + CREATE_MERCHANT_QR_CODE_REQUIRED_PARAMS = %w( biz_type biz_data ) + CREATE_MERCHANT_QR_CODE_REQUIRED_BIZ_DATA_PARAMS = %w( secondary_merchant_industry secondary_merchant_id secondary_merchant_name trans_currency currency ) + def self.create_merchant_qr_code(params, options = {}) + params = Utils.stringify_keys(params) + check_required_params(params, CREATE_MERCHANT_QR_CODE_REQUIRED_PARAMS) + biz_data = nil + + if params['biz_data'] + params['biz_data'] = Utils.stringify_keys(params['biz_data']) + check_required_params(params['biz_data'], CREATE_MERCHANT_QR_CODE_REQUIRED_BIZ_DATA_PARAMS) + + data = params.delete('biz_data') + biz_data = data.map do |key, value| + "\"#{key}\": \"#{value}\"" + end.join(',') + end + + biz_data = "{#{biz_data}}" + + params = { + 'service' => 'alipay.commerce.qrcode.create', + '_input_charset' => 'utf-8', + 'partner' => options[:pid] || Alipay.pid, + 'timestamp' => Time.now.utc.strftime('%Y-%m-%d %H:%M:%S').to_s, + 'biz_data' => biz_data + }.merge(params) + + request_uri(params, options).to_s + end + + UPDATE_MERCHANT_QR_CODE_REQUIRED_PARAMS = %w( biz_type biz_data qr_code ) + def self.update_merchant_qr_code(params, options = {}) + params = Utils.stringify_keys(params) + check_required_params(params, UPDATE_MERCHANT_QR_CODE_REQUIRED_PARAMS) + biz_data = nil + + if params['biz_data'] + params['biz_data'] = Utils.stringify_keys(params['biz_data']) + + data = params.delete('biz_data') + biz_data = data.map do |key, value| + "\"#{key}\": \"#{value}\"" + end.join(',') + end + + biz_data = "{#{biz_data}}" + + params = { + 'service' => 'alipay.commerce.qrcode.modify', + '_input_charset' => 'utf-8', + 'partner' => options[:pid] || Alipay.pid, + 'timestamp' => Time.now.utc.strftime('%Y-%m-%d %H:%M:%S').to_s, + 'biz_data' => biz_data + }.merge(params) + + request_uri(params, options).to_s + end + + ACQUIRER_OVERSEAS_QUERY_REQUIRED_PARAMS = %w(partner_trans_id) + def self.acquirer_overseas_query(params, options = {}) + params = Utils.stringify_keys(params) + check_required_params(params, ACQUIRER_OVERSEAS_QUERY_REQUIRED_PARAMS) + + params = { + 'service' => 'alipay.acquire.overseas.query', + '_input_charset' => 'utf-8', + 'partner' => options[:pid] || Alipay.pid, + }.merge(params) + + request_uri(params, options).to_s + end + + ACQUIRER_OVERSEAS_SPOT_REFUND_REQUIRED_PARAMS = %w( partner_trans_id partner_refund_id refund_amount currency ) + def self.acquirer_overseas_spot_refund_url(params, options= {}) + params = Utils.stringify_keys(params) + check_required_params(params, ACQUIRER_OVERSEAS_SPOT_REFUND_REQUIRED_PARAMS) + + params = { + 'service' => 'alipay.acquire.overseas.spot.refund', + '_input_charset' => 'utf-8', + 'partner' => options[:pid] || Alipay.pid, + }.merge(params) + + request_uri(params, options).to_s + end + def self.request_uri(params, options = {}) uri = URI(GATEWAY_URL) uri.query = URI.encode_www_form(sign_params(params, options)) uri end