alipay 0.6.0.beta1 → 0.6.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +0,0 @@
1
- module Alipay
2
- module Notify
3
- module Wap
4
- def self.verify?(params)
5
- params = Utils.stringify_keys(params)
6
- notify_id = params['notify_data'].scan(/\<notify_id\>(.*)\<\/notify_id\>/).flatten.first
7
-
8
- Sign::Wap.verify?(params) && Notify.verify_notify_id?(notify_id)
9
- end
10
- end
11
- end
12
- end
@@ -1,69 +0,0 @@
1
- module Alipay
2
- module Service
3
- module Wap
4
- GATEWAY_URL = 'https://wappaygw.alipay.com/service/rest.htm'
5
-
6
- REQ_DATA_REQUIRED_OPTIONS = %w( subject out_trade_no total_fee seller_account_name call_back_url )
7
- WAP_TRADE_REQUIRED_OPTIONS = %w( service format v partner req_id req_data )
8
-
9
- def self.trade_create_direct_token(options)
10
- options = Utils.stringify_keys(options)
11
-
12
- req_data_options = { 'seller_account_name' => Alipay.seller_email }.merge(
13
- Utils.stringify_keys(options.delete('req_data'))
14
- )
15
-
16
- Alipay::Service.check_required_options(req_data_options, REQ_DATA_REQUIRED_OPTIONS)
17
-
18
- xml = req_data_options.map {|k, v| "<#{k}>#{v.encode(:xml => :text)}</#{k}>" }.join
19
- req_data_xml = "<direct_trade_create_req>#{xml}</direct_trade_create_req>"
20
-
21
- # About req_id: http://club.alipay.com/read-htm-tid-10078020-fpage-2.html
22
- options = {
23
- 'service' => 'alipay.wap.trade.create.direct',
24
- 'req_data' => req_data_xml,
25
- 'partner' => Alipay.pid,
26
- 'req_id' => Time.now.strftime('%Y%m%d%H%M%s'),
27
- 'format' => 'xml',
28
- 'v' => '2.0'
29
- }.merge(options)
30
-
31
- Alipay::Service.check_required_options(options, WAP_TRADE_REQUIRED_OPTIONS)
32
-
33
- xml = Net::HTTP.get(request_uri(options))
34
- CGI.unescape(xml).scan(/\<request_token\>(.*)\<\/request_token\>/).flatten.first
35
- end
36
-
37
- AUTH_AND_EXECUTE_REQUIRED_OPTIONS = %w( service format v partner )
38
-
39
- def self.auth_and_execute_url(options)
40
- options = Utils.stringify_keys(options)
41
- Alipay::Service.check_required_options(options, ['request_token'])
42
-
43
- req_data_xml = "<auth_and_execute_req><request_token>#{options.delete('request_token')}</request_token></auth_and_execute_req>"
44
-
45
- options = {
46
- 'service' => 'alipay.wap.auth.authAndExecute',
47
- 'req_data' => req_data_xml,
48
- 'partner' => Alipay.pid,
49
- 'format' => 'xml',
50
- 'v' => '2.0'
51
- }.merge(options)
52
-
53
- Alipay::Service.check_required_options(options, AUTH_AND_EXECUTE_REQUIRED_OPTIONS)
54
- request_uri(options).to_s
55
- end
56
-
57
- def self.request_uri(options)
58
- uri = URI(GATEWAY_URL)
59
- uri.query = URI.encode_www_form(sign_params(options))
60
- uri
61
- end
62
-
63
- def self.sign_params(params)
64
- sign_type = (params['sec_id'] ||= Alipay.sign_type)
65
- params.merge('sign' => Alipay::Sign.generate(params.merge('sign_type' => sign_type)))
66
- end
67
- end
68
- end
69
- end
@@ -1,17 +0,0 @@
1
- module Alipay
2
- module Sign
3
- module Wap
4
- SORTED_VERIFY_PARAMS = %w( service v sec_id notify_data )
5
-
6
- def self.verify?(params)
7
- params = Utils.stringify_keys(params)
8
-
9
- query = SORTED_VERIFY_PARAMS.map do |key|
10
- "#{key}=#{params[key]}"
11
- end.join('&')
12
-
13
- params['sign'] == Digest::MD5.hexdigest("#{query}#{Alipay.key}")
14
- end
15
- end
16
- end
17
- end