A simple Tenpay ruby gem, without unnecessary magic or wraper, it's directly facing how Tenpay api works. copied from alipay .
It contain this API:
- Generate payment url
- Verify notify
Please read Tenpay official document first: http://help.tenpay.com/mch/ .
Cause tenpay has been taken and seems not maintain anymore.
see https://github.com/jasl/tenpay_demo .
Add this line to your application's Gemfile:
gem 'jasl_tenpay'
or development version
gem 'jasl_tenpay', :github => 'jasl/tenpay'
And then execute:
$ bundle
e.g:
options = {
:out_trade_no => 'YOUR_ORDER_ID', # 20130801000001
:subject => 'YOUR_ORDER_SUBJECCT', # Fitbit flex
:body => 'YOUR_ORDER_DESCRIPTION',# from knewone.com
:total_fee => 1, # price, unit: cent
:spbill_create_ip => request.ip, # user ip
:return_url => 'YOUR_ORDER_RETURN_URL', # http://knewone.com/orders/1/tenpay_callback
:notify_url => 'YOUR_ORDER_NOTIFY_URL' # http://knewone.com/orders/1/tenpay_notify
}
JaslTenpay::Service.create_interactive_mode_url(options, pid, jkey)
# => 'https://gw.tenpay.com/gateway/pay.htm?...'
BTW: Wechat payment using the same api, addition needs provide argument :bank_type => 'WX'
You can redirect user to this payment url, and user will see a payment page for his/her order.
read Tenpay integration manual to get more options.
# example in rails
# The notify url MUST be set when generate payment url
# IMPORTANT: Notify may reach earlier than callback
def tenpay_notify
if JaslTenpay::Notify.verify?(params.except(*request.path_parameters.keys), pid, jkey) && callback_params[:trade_state] == '0'
# TODO: valid notify, code your business logic here.
else
# TODO: invalid, something went wrong, handle it.
end
render text: 'success'
end
Bug report or pull request are welcome.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Please write unit test with your code if necessary.
This project rocks and uses MIT-LICENSE.