Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A Ruby on Rails plugin for Tenpay (Online pay solution from Tencent).

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time


A Ruby on Rails plugin for Tenpay (Online pay solution from Tencent).


$ script/plugin install git://


1. After you installing the plugin, there should be a tenpay.yml 
in your RAILS_ENV/config dir, you should edit that file and set
your spid and key you got from Tencent.

2. To start a transaction, you will need create a new Tenpay::Request 
instance, for example:

  @request ='test product', # Product name
                  1, # Order id, should be unique
                  4500, # Product price, in cent
                  'http://return', # Url user will return after the transaction, support Get/Post
                  request.remote_ip, # Use for ip validation, ignored in development mode.
                  'attach data') # Attach data, will be pass to the return url.
  redirect_to @request.url

This will redirect user to pay page.

3. After user finishing the paying, the return url will be called, below
code will demo if the request is legal and user finish the paying.

  @response =
  if @response.successful?
    # paying is successful
    # it's failed

If you want to query if user has paid for an order, use below interface:

  @query =, # Order id
                    # Order date
  @query.response.successful? # true => paid, false => unpaid.
It's all, feedbacks are always welcome, feel free to contact me at

Copyright (c) 2009 Yuanyi Zhang, released under the MIT license
Something went wrong with that request. Please try again.