Commit 687c0ce02185ec08ee333818dfc4b61eaca0a674

Authored by Jun Jiang
Committed by GitHub
2 parents c9108b84 cf6cd855
Exists in master

Merge pull request #103 from vkill/patch-1

Add Grape example for notify process
Showing 1 changed file with 34 additions and 1 deletions   Show diff stats
@@ -197,7 +197,7 @@ r = WxPay::Service.generate_js_pay_req params @@ -197,7 +197,7 @@ r = WxPay::Service.generate_js_pay_req params
197 197
198 #### Notify Process 198 #### Notify Process
199 199
200 -A simple example of processing notify. 200 +A simple example of processing notify for Rails Action Controller.
201 201
202 ```ruby 202 ```ruby
203 # config/routes.rb 203 # config/routes.rb
@@ -219,6 +219,39 @@ def notify @@ -219,6 +219,39 @@ def notify
219 end 219 end
220 ``` 220 ```
221 221
  222 +A simple example of processing notify for Grape v1.2.2 .
  223 +
  224 +```ruby
  225 +# Gemfile
  226 +gem 'multi_xml'
  227 +
  228 +# config/routes.rb
  229 +mount WechatPay::Api => '/'
  230 +
  231 +# app/api/wechat_pay/api.rb
  232 +module WechatPay
  233 + class Api < Grape::API
  234 + content_type :xml, 'text/xml'
  235 + format :xml
  236 + formatter :xml, lambda { |object, env| object.to_xml(root: 'xml', dasherize: false) }
  237 +
  238 + post "notify" do
  239 + result = params["xml"]
  240 + if WxPay::Sign.verify?(result)
  241 + # find your order and process the post-paid logic.
  242 +
  243 + status 200
  244 + {return_code: "SUCCESS"}
  245 + else
  246 + status 200
  247 + {return_code: "FAIL", return_msg: "签名失败"}
  248 + end
  249 + end
  250 + end
  251 +end
  252 +```
  253 +
  254 +
222 ### Integrate with QRCode(二维码) 255 ### Integrate with QRCode(二维码)
223 256
224 Wechat payment integrating with QRCode is a recommended process flow which will bring users comfortable experience. It is recommended to generate QRCode using `rqrcode` and `rqrcode_png`. 257 Wechat payment integrating with QRCode is a recommended process flow which will bring users comfortable experience. It is recommended to generate QRCode using `rqrcode` and `rqrcode_png`.