china_pay 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,17 @@
1
1
  # encoding: utf-8
2
2
  require 'digest'
3
+ require 'uri'
4
+ require 'net/http'
3
5
 
4
6
  module ChinaPay
5
7
  module Alipay
8
+ GATEWAY_URL = 'https://mapi.alipay.com/gateway.do'
9
+
6
10
  module Product
7
11
  class Base
8
12
  DEFAULT_CHARSET = 'utf-8'
9
13
  SIGN_TYPE_MD5 = 'MD5'
10
14
 
11
- GATEWAY_URL = 'https://mapi.alipay.com/gateway.do'
12
15
 
13
16
  ATTR_REQUIRED = [:service, :partner, :_input_charset,
14
17
  :sign_type, :sign, :notify_url, :return_url,
@@ -141,7 +144,6 @@ module ChinaPay
141
144
  def direct_pay
142
145
  Product::DirectPay.new(self)
143
146
  end
144
-
145
147
  end
146
148
 
147
149
  class Merchant
@@ -158,6 +160,30 @@ module ChinaPay
158
160
  order
159
161
  end
160
162
  end
163
+
164
+ class Notification
165
+ def initialize(partner, notification_id)
166
+ @partner = partner
167
+ @notification_id = notification_id
168
+ end
169
+
170
+ def valid?
171
+ uri = URI(GATEWAY_URL)
172
+ params = {
173
+ :service => :notify_verify,
174
+ :partner => @partner,
175
+ :notify_id => @notification_id
176
+ }
177
+ uri.query = params.map {|k, v| "#{k}=#{URI.escape(v.to_s)}"}.join('&')
178
+
179
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
180
+ req = Net::HTTP::Get.new uri.request_uri
181
+
182
+ response = http.request(req)
183
+ response.body == 'true'
184
+ end
185
+ end
186
+ end
161
187
  end
162
188
  end
163
189
 
@@ -1,3 +1,3 @@
1
1
  module ChinaPay
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: china_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-30 00:00:00.000000000 Z
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This gem can help you integrate Alipay, Tenpay and 99bill to your application.
15
15
  email: