A very simple TapPay API wrapper
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib
spec
.gitignore
.rspec
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
tappay.gemspec

README.md

TapPay

Build Status Maintainability

A very simple TapPay API wrapper written in the Ruby language.

Installation

Add this line to your application's Gemfile:

gem 'tappay'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tappay

API Documentation

See TapPay Backend API.

Usage

Settings

You need to setup mode which affects requests sent to sandbox or production server. The partner_key and merchant_id are optional, they could also be specified in request params.

# sandbox or production
TapPay.mode = :sandbox

TapPay.setup do |config|
  config.partner_key = 'your_partner_key' # optional
  config.merchant_id = 'your_merchant_id' # optional
end

Map API Resources to Module and Action

It is easy to map api resources to the TapPay module's namespace and action. For example, the pay by prime api is: https://sandbox.tappaysdk.com/tpc/payment/pay-by-prime , the last two parts payment and pay-by-prime are mapped to namespace Payment and action pay_by_prime, so it could be called by TapPay::Payment.pay_by_prime(params).

Another example is bind card, the bind card api is: https://sandbox.tappaysdk.com/tpc/card/bind , so the api could be called by TapPay::Card.bind(params) as you expect.

Supported APIs

Payment

  • pay_by_prime
  • pay_by_token

Card

  • bind
  • remove

Transaction

  • cap
  • query
  • refund
  • trade_history

For more details about api request params and responses, please refer to the TapPay Backend API Documentation.

More Examples

Pay By Prime

params = {
  prime: 'test_3a2fb2b7e892b914a03c95dd4dd5dc7970c908df67a49527c0a648b2bc9',
  details: "TapPay Test",
  amount: 100,
  cardholder: {
    phone_number: '0912345678',
    name: "王小明",
    email: "LittleMing@Wang.com",
    zip_code: "100",
    address: "台北市天龍區芝麻街1號1樓",
    national_id: "A123456789"
  },
  remember: true
}

res = TapPay::Payment.pay_by_prime(params)
res #=> {"status"=>0, "msg"=>"Success", "amount"=>100, ...}
res['status'] #=> 0
res['msg'] #=> Success

# Block Style
TapPay::Payment.pay_by_prime(params) do |res|
  res #=> {"status"=>0, "msg"=>"Success", "amount"=>100, ...}
end

Pay By Token

params = {
  card_key: 'your_card_key_after_pay_by_prime_with_remember_true',
  card_token: 'your_card_token_after_pay_by_prime_with_remember_true',
  amount: 1,
  currency: "TWD",
  details: "An apple and a pen."
}

res = TapPay::Payment.pay_by_token(params)

# Block Style
TapPay::Payment.pay_by_token(params) do |res|
  res #=> {"status"=>0, "msg"=>"Success", "amount"=>100, ...}
end

Refund

params = {
  rec_trade_id: 'your_rec_trade_id'
}

res = TapPay::Transaction.refund(params)

# Block Style
TapPay::Transaction.refund(params) do |res|
  res 
end

Card

# bind
params = {
  currency: 'TWD',
  cardholder: {
        phone_number: "+886923456789",
        name: "Jane Doe",
        email: "Jane@Doe.com",
        zip_code: "12345",
        address: "123 1st Avenue, City, Country",
        national_id: "A123456789"
  }
}

TapPay::Card.bind(params) do |res|
  res
end

# remove
params = {
  card_key: "your_card_key",
  card_token: "your_card_token"
}

TapPay::Card.remove(params) do |res|
  res
end

License

The gem is available as open source under the terms of the MIT License.