Giter VIP home page Giter VIP logo

jasl_tenpay's Introduction

Jasl_Tenpay

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/ .

Why Jasl_Tenpay?

Cause tenpay has been taken and seems not maintain anymore.

Demo

see https://github.com/jasl/tenpay_demo .

Installation

Add this line to your application's Gemfile:

gem 'jasl_tenpay'

or development version

gem 'jasl_tenpay', :github => 'jasl/jasl_tenpay'

And then execute:

$ bundle

Usage

Config

JaslTenpay.pid = 'YOUR_PID'
JaslTenpay.key = 'YOUR_KEY'

Generate payment url

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)
# => '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.

Verify notify

# 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)) && 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

Contributing

Bug report or pull request are welcome.

Make a pull request

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Please write unit test with your code if necessary.

License

This project rocks and uses MIT-LICENSE.

jasl_tenpay's People

Contributors

jasl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.