Project

tappay

0.0
No commit activity in last 3 years
No release in over 3 years
A very simple TapPay API wrapper for ruby. Currently support pay_by_prime, pay_by_token and refund.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.1
~> 13.0
~> 3.9
~> 3.8
 Project Readme

TapPay

Ruby Gem 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 the requests sent to sandbox or production server. The partner_key is optional, they could also be specified in request params.

TapPay.setup do |config|
  config.mode = Rails.env.production? ? :production : :sandbox # sandbox or production
  config.partner_key = 'your_partner_key' # 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: https://sandbox.tappaysdk.com/tpc/payment/pay-by-prime , the last two parts of the url are payment and pay-by-prime. The first part payment is mapped to namespace Payment, and the last part pay-by-prime is mapped to action pay_by_prime, so it can be called by TapPay::Payment.pay_by_prime(params).

Another example is bind card, the bind card api: https://sandbox.tappaysdk.com/tpc/card/bind , the last two parts of the url arecard and bind, so the api can 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',
  merchant_id: 'your_merchant_id',
  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 = {
  merchant_id: 'your_merchant_id',
  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 = {
  prime: 'test_3a2fb2b7e892b914a03c95dd4dd5dc7970c908df67a49527c0a648b2bc9',
  merchant_id: 'your_merchant_id',
  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.