README.md in alipay-0.0.4 vs README.md in alipay-0.0.5
- old
+ new
@@ -2,13 +2,13 @@
A simple alipay ruby gem, without unnecessary magic or wraper, it's directly facing how alipay api works.
It contain this API:
-* Generate payment url
+* Generate payment url (web, wap)
* Send goods
-* Verify notify
+* Verify notify (web, wap, app)
Please read alipay official document first: https://b.alipay.com/order/techService.htm .
## Installation
@@ -38,11 +38,11 @@
Alipay.pid = 'YOUR_PID'
Alipay.key = 'YOUR_KEY'
Alipay.seller_email = 'YOUR_SELLER_EMAIL'
```
-### Generate payment url
+### Generate payment url for web
```ruby
options = {
:out_trade_no => 'YOUR_ORDER_ID', # 20130801000001
:subject => 'YOUR_ORDER_SUBJECCT', # Writings.io Base Account x 12
@@ -66,10 +66,34 @@
Alipay::Service#create_partner_trade_by_buyer_url # 担保交易
Alipay::Service#trade_create_by_buyer_url # 标准双接口
Alipay::Service#create_direct_pay_by_user_url # 即时到帐
+### Generate payment url for wap
+
+```ruby
+options = {
+ :req_data => {
+ :out_trade_no => 'YOUR_ORDER_ID', # 20130801000001
+ :subject => 'YOUR_ORDER_SUBJECCT', # Writings.io Base Account x 12
+ :total_fee => 'TOTAL_FEE',
+ :notify_url => 'YOUR_ORDER_NOTIFY_URL', # https://writings.io/orders/20130801000001/alipay_notify
+ :call_back_url => 'YOUR_ORDER_RETURN_URL' # https://writings.io/orders/20130801000001
+ }
+}
+
+token = Alipay::Service::Wap.trade_create_direct_token(options)
+Alipay::Service::Wap.auth_and_execute(request_token: token)
+# => 'http://wappaygw.alipay.com/service/rest.htm?req_data=...'
+```
+
+You can redirect user to this payment url, and user will see a payment page for his/her order.
+
+Current only support this payment type:
+
+ Alipay::Service::Wap.auth_and_execute # 即时到帐
+
### Send goods
```ruby
options = {
:trade_no => 'TRADE_NO',
@@ -98,22 +122,50 @@
Notify Url Demo: http://git.io/pst4Tw
### Verify notify
```ruby
-# example in rails
-# The notify url MUST be set when generate payment url
-def alipay_notify
+# Example in rails,
+# notify url MUST be set when generate payment url
+
+def alipay_web_notify
# except :controller_name, :action_name, :host, etc.
notify_params = params.except(*request.path_parameters.keys)
+
if Alipay::Notify.verify?(notify_params)
# valid notify, code your business logic.
render :text => 'success'
else
render :text => 'error'
end
end
+
+def alipay_wap_notify
+ # except :controller_name, :action_name, :host, etc.
+ notify_params = params.except(*request.path_parameters.keys)
+
+ if Alipay::Notify::Wap.verify?(notify_params)
+ # valid notify, code your business logic.
+ # you may want to get you order id:
+ # order_id = Hash.from_xml(params[:notify_data])['notify']['out_trade_no']
+ render :text => 'success'
+ else
+ render :text => 'error'
+ end
+end
+
+def alipay_app_notify
+ # except :controller_name, :action_name, :host, etc.
+ notify_params = params.except(*request.path_parameters.keys)
+
+ if Alipay::Notify::App.verify?(notify_params)
+ # valid notify, code your business logic.
+ render :text => 'success'
+ else
+ render :text => 'error'
+ end
+end
```
## Contributing
Bug report or pull request are welcome.
@@ -130,6 +182,6 @@
## Donate
Donate to maintainer let him make this gem better.
-Alipay donate link: https://me.alipay.com/chloerei .
+Alipay donate link: http://chloerei.com/donate/ .