Rwepay 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +78 -1
- data/lib/Rwepay.rb +16 -0
- data/lib/Rwepay/common.rb +2 -2
- data/lib/Rwepay/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49e4e8cb023849d3810dfba5b934657c85cff91d
|
4
|
+
data.tar.gz: 2e14533e3e8bbd4132f5ceb8964f7b52debd3554
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5097f0304fe3bc6098d9f825200019c79ffc3a0a4d5b976297bf50bcfe7a4105ec2cc54e85227f99f609a7ee3a0e74b9feb6296d352bb5b6d5cf74d0628edbf2
|
7
|
+
data.tar.gz: bb03f24be90298718ce377e079b9bd1dc30df575c00a2889e30f5682b1117374dc89c89f5082cf48bb8b6a950ecaaa24a9c65cccc7aeef951974c3efc80d8ae6
|
data/README.md
CHANGED
@@ -32,16 +32,93 @@ Or install it yourself as:
|
|
32
32
|
|
33
33
|
### JSPayment
|
34
34
|
|
35
|
+
- 初始化 [new]
|
36
|
+
|
37
|
+
configs = {
|
38
|
+
:app_id => 'wxf8b4f85f3a794e77',
|
39
|
+
:partner_id => '1900000109',
|
40
|
+
:app_key => 'xxxx',
|
41
|
+
:partner_key => '8934e7d15453e97507ef794cf7b0519d'
|
42
|
+
}
|
43
|
+
payment = Rwepay::JSPayment.new configs
|
44
|
+
|
35
45
|
- 创建支付请求 [get_brand_request]
|
46
|
+
options参数用于构建package,示例中写了必填参数,可选参数也可使用hash方式传入,参见文档。
|
47
|
+
|
48
|
+
In Controller:
|
49
|
+
|
50
|
+
options = {
|
51
|
+
:body => '测试商品',
|
52
|
+
:notify_url => 'http://domain.com/to/path',
|
53
|
+
:out_trade_no => 'TEST123456',
|
54
|
+
:total_fee => '1',
|
55
|
+
:spbill_create_ip => '127.0.0.1',
|
56
|
+
}
|
57
|
+
@brand_json = js_payment.get_brand_request(options)
|
58
|
+
|
59
|
+
In View:
|
60
|
+
|
61
|
+
<%= link_to '微信支付', "javascript:void(0)", :id => 'wechat' %>
|
62
|
+
<script Language="javascript">
|
63
|
+
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
|
64
|
+
$('#wechat').click(function(){
|
65
|
+
WeixinJSBridge.invoke('getBrandWCPayRequest', <%= raw @brand_json %>,function(res){
|
66
|
+
if(res.err_msg == "get_brand_wcpay_request:ok" ) {
|
67
|
+
alert('支付成功!');
|
68
|
+
}else{
|
69
|
+
alert(res.err_msg);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
});
|
73
|
+
}, false);
|
74
|
+
</script>
|
36
75
|
|
37
76
|
- 回调验证 [notify_verify?]
|
38
77
|
|
78
|
+
status = payment.notify_verify?(params)
|
79
|
+
if status
|
80
|
+
#这里请自行验证params[:total_fee]的值与订单是否相符,按需要存储其他内容特别是transaction_id
|
81
|
+
render :text => 'success'
|
82
|
+
else
|
83
|
+
render :text => 'fail'
|
84
|
+
end
|
85
|
+
|
39
86
|
- 发货通知 [deliver_notify]
|
40
87
|
|
88
|
+
此接口调用需传入开放平台的access_token,由于access_token有时限且有请求限制,需要自行获取并按7200秒缓存,可使用下方的get_access_token方法
|
89
|
+
|
90
|
+
options = {
|
91
|
+
:access_token => access_token,
|
92
|
+
:open_id => 'oVGDVjni9uU30O9TGrlIWp-BcuYw',
|
93
|
+
:trans_id => '1217737101201403308373364651',
|
94
|
+
:out_trade_no => '1246154588',
|
95
|
+
:deliver_timestamp => Time.now.to_i.to_s,
|
96
|
+
:deliver_status => '1',
|
97
|
+
:deliver_msg => 'ok'
|
98
|
+
}
|
99
|
+
status, error = js_payment.deliver_notify(options)
|
100
|
+
|
41
101
|
- 获取订单状态 [get_order_query]
|
42
102
|
|
103
|
+
options = {
|
104
|
+
:access_token => access_token,
|
105
|
+
:out_trade_no => '1246154588'
|
106
|
+
}
|
107
|
+
status, response = js_payment.get_order_query(options)
|
108
|
+
|
43
109
|
- 获取access_token [get_access_token]
|
44
110
|
|
111
|
+
access_token = js_payment.get_access_token('your app_secret hear')
|
112
|
+
|
113
|
+
- 更新维权信息 [update_feedback]
|
114
|
+
|
115
|
+
options = {
|
116
|
+
:access_token => access_token,
|
117
|
+
:open_id => open_id,
|
118
|
+
:feedback_id => feedback_id
|
119
|
+
}
|
120
|
+
js_payment.update_feedback(options)
|
121
|
+
|
45
122
|
### NativePayment
|
46
123
|
|
47
124
|
TODO
|
@@ -52,4 +129,4 @@ Or install it yourself as:
|
|
52
129
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
130
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
131
|
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
-
5. Create new Pull Request
|
132
|
+
5. Create new Pull Request
|
data/lib/Rwepay.rb
CHANGED
@@ -83,6 +83,22 @@ module Rwepay
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
+
def update_feedback(options = {})
|
87
|
+
options = Rwepay::Common.configs_check options,
|
88
|
+
[:access_token, :open_id, :feedback_id]
|
89
|
+
begin
|
90
|
+
response = Faraday.get("https://api.weixin.qq.com/payfeedback/update?access_token=#{options[:access_token]}&openid=#{options[:open_id]}&feedbackid=#{options[:feedback_id]}")
|
91
|
+
response = JSON.parse response.body
|
92
|
+
if response['errcode'] == 0
|
93
|
+
true
|
94
|
+
else
|
95
|
+
false
|
96
|
+
end
|
97
|
+
rescue
|
98
|
+
false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
86
102
|
end
|
87
103
|
|
88
104
|
# @TODO
|
data/lib/Rwepay/common.rb
CHANGED
@@ -143,7 +143,7 @@ module Rwepay::Common
|
|
143
143
|
begin
|
144
144
|
conn = Faraday.new(:url => "https://api.weixin.qq.com/pay/delivernotify?access_token=#{access_token}")
|
145
145
|
response = conn.post do |req|
|
146
|
-
req.body = for_sign_data.to_json
|
146
|
+
req.body = for_sign_data.to_json.gsub(/\\u([0-9a-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
|
147
147
|
end
|
148
148
|
response = JSON.parse response.body
|
149
149
|
if response['errcode'] == 0
|
@@ -183,7 +183,7 @@ module Rwepay::Common
|
|
183
183
|
begin
|
184
184
|
conn = Faraday.new(:url => "https://api.weixin.qq.com/pay/orderquery?access_token=#{access_token}")
|
185
185
|
response = conn.post do |req|
|
186
|
-
req.body = for_sign_data.to_json
|
186
|
+
req.body = for_sign_data.to_json.gsub(/\\u([0-9a-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
|
187
187
|
end
|
188
188
|
response = JSON.parse response.body
|
189
189
|
if response['errcode'] == 0
|
data/lib/Rwepay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Rwepay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RaymondChou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|