Commit c4aac313b488dd20c1c282fc8877044e086df22f

Authored by vkill
Committed by GitHub
1 parent c9108b84
Exists in master

Update README.md

Showing 1 changed file with 34 additions and 1 deletions   Show diff stats
README.md
... ... @@ -197,7 +197,7 @@ r = WxPay::Service.generate_js_pay_req params
197 197  
198 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 202 ```ruby
203 203 # config/routes.rb
... ... @@ -219,6 +219,39 @@ def notify
219 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 Wechat::Api => '/notify'
  230 +
  231 +# app/api/wechat/api.rb
  232 +module Wechat
  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 "" 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 255 ### Integrate with QRCode(二维码)
223 256  
224 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`.
... ...