wx_pay 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f60e9ab955e8797883c4befead6e4de2a0f65d0e
4
- data.tar.gz: 7a299e0d07bf2eb5f3b8c899e73d1d93805d3ecf
3
+ metadata.gz: 811646dddfb4af0870059948ab4d3e94f6107a23
4
+ data.tar.gz: be26df10ae106084dac31c92f76e93e70d265578
5
5
  SHA512:
6
- metadata.gz: 76b692ac8affd84e344736645d44742af351540dac7ac56cb94feed71c939d3c80b997c1d41078756612e9da4ccdf1d8cfc39fb7d83c051a2efb36cd68ba0afa
7
- data.tar.gz: e435dbdf3d63f7245556d55e8b55443915716289c4f0fa096192ad1fb91c13a5c819149b4fcd2502b5dfdd3702dcedab38c0d6656a361ad678453e2ae73c2b95
6
+ metadata.gz: caeee55cd0c865032892ebafa34d9b44c7dab88c3652b496169303771954f8d147d51defb5821e8367b01c697e6b1758774b60095b2080808674bb27747c1062
7
+ data.tar.gz: 4a3a785ec580149c98f688606b9f83f662bd24bd1728665d21126049ba2ad7b801027bc31006e1cb8668d824b68ea2cfe6da85c5e9f4d95507aad17cb46fe945
@@ -46,13 +46,13 @@ module WxPay
46
46
  nonce_str: SecureRandom.uuid.tr('-', ''),
47
47
  op_user_id: WxPay.mch_id
48
48
  }.merge(params)
49
-
49
+
50
50
  check_required_options(params, INVOKE_REFUND_REQUIRED_FIELDS)
51
51
 
52
52
  # 微信退款需要双向证书
53
53
  # https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
54
54
  # https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3
55
-
55
+
56
56
  WxPay.extra_rest_client_options = {
57
57
  ssl_client_cert: WxPay.apiclient_cert.certificate,
58
58
  ssl_client_key: WxPay.apiclient_cert.key,
@@ -76,7 +76,9 @@ module WxPay
76
76
  end
77
77
 
78
78
  def self.make_payload(params)
79
- "<xml>#{params.map { |k, v| "<#{k}>#{v}</#{k}>" }.join}<sign>#{WxPay::Sign.generate(params)}</sign></xml>"
79
+ sign = WxPay::Sign.generate(params)
80
+ params.delete(:key) if params[:key]
81
+ "<xml>#{params.map { |k, v| "<#{k}>#{v}</#{k}>" }.join}<sign>#{sign}</sign></xml>"
80
82
  end
81
83
 
82
84
  def self.invoke_remote(url, payload)
data/lib/wx_pay/sign.rb CHANGED
@@ -3,11 +3,13 @@ require 'digest/md5'
3
3
  module WxPay
4
4
  module Sign
5
5
  def self.generate(params)
6
+ key = params.delete(:key)
7
+
6
8
  query = params.sort.map do |key, value|
7
9
  "#{key}=#{value}"
8
10
  end.join('&')
9
11
 
10
- Digest::MD5.hexdigest("#{query}&key=#{WxPay.key}").upcase
12
+ Digest::MD5.hexdigest("#{query}&key=#{key || WxPay.key}").upcase
11
13
  end
12
14
 
13
15
  def self.verify?(params)
@@ -1,3 +1,3 @@
1
1
  module WxPay
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,5 +1,7 @@
1
1
 
2
2
  class ServiceTest < MiniTest::Test
3
+
4
+ # TODO why put the params of refun in setup method
3
5
  def setup
4
6
  @params = {
5
7
  transaction_id: '1217752501201407033233368018',
@@ -12,7 +14,7 @@ class ServiceTest < MiniTest::Test
12
14
 
13
15
  @apiclient_cert = Minitest::Mock.new
14
16
  @apiclient_cert.expect(:certificate, 'certificate')
15
- @apiclient_cert.expect(:key, 'key')
17
+ @apiclient_cert.expect(:key, 'key')
16
18
  end
17
19
 
18
20
  def test_invoke_refund
@@ -34,7 +36,7 @@ class ServiceTest < MiniTest::Test
34
36
  <refund_channel><![CDATA[]]></refund_channel>
35
37
  <refund_fee>1</refund_fee>
36
38
  <coupon_refund_fee>0</coupon_refund_fee>
37
- </xml>
39
+ </xml>
38
40
  EOF
39
41
 
40
42
  FakeWeb.register_uri(
@@ -45,7 +47,24 @@ class ServiceTest < MiniTest::Test
45
47
 
46
48
  WxPay.stub :apiclient_cert, @apiclient_cert do
47
49
  r = WxPay::Service.invoke_refund(@params)
48
- assert_equal r.success?, true
50
+ assert_equal r.success?, true
49
51
  end
50
52
  end
51
- end
53
+
54
+ def test_accept_multiple_app_id_when_invoke
55
+ params = {
56
+ body: '测试商品',
57
+ out_trade_no: 'test003',
58
+ total_fee: 1,
59
+ spbill_create_ip: '127.0.0.1',
60
+ notify_url: 'http://making.dev/notify',
61
+ trade_type: 'JSAPI',
62
+ openid: 'OPENID',
63
+ app_id: 'app_id',
64
+ mch_id: 'mch_id',
65
+ key: 'key'
66
+ }
67
+ xml_str = '<xml><body>测试商品</body><out_trade_no>test003</out_trade_no><total_fee>1</total_fee><spbill_create_ip>127.0.0.1</spbill_create_ip><notify_url>http://making.dev/notify</notify_url><trade_type>JSAPI</trade_type><openid>OPENID</openid><app_id>app_id</app_id><mch_id>mch_id</mch_id><sign>172A2D487A37D13FDE32B874BA823DD6</sign></xml>'
68
+ assert_equal xml_str, WxPay::Service.send(:make_payload, params)
69
+ end
70
+ end
@@ -28,4 +28,10 @@ class WxPay::SignTest < MiniTest::Test
28
28
  def test_verify_sign_when_fails
29
29
  assert !WxPay::Sign.verify?(@params.merge(:danger => 'danger', :sign => @sign))
30
30
  end
31
+
32
+ def test_accept_pars_key_to_generate_sign
33
+ @params.merge!(key: "key")
34
+
35
+ assert_equal "1454C32E885B8D9E4A05E976D1C45B88", WxPay::Sign.generate(@params)
36
+ end
31
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wx_pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jasl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.4.6
135
+ rubygems_version: 2.4.5
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: An unofficial simple wechat pay gem