Git Product home page Git Product logo

allpay's Introduction

Build Status

Allpay 歐付寶

這是歐付寶 API 的 Ruby 包裝,更多資訊參考他們的官方文件

  • 這不是 Rails 插件,只是個 API 包裝。
  • 使用時只需要傳送需要的參數即可,不用產生檢查碼,allpay_client 會自己產生。
  • 錯誤代碼太多且會不斷增加,筆者不另行撰寫,官方也建議查網站上的代碼清單。

安裝

gem install allpay_client

使用

test_client = Allpay::Client.new(mode: :test)
production_client = Allpay::Client.new({
  merchant_id: 'MERCHANT_ID',
  hash_key: 'HASH_KEY',
  hash_iv: 'HASH_IV'
})

test_client.request '/Cashier/QueryTradeInfo',
  MerchantTradeNo: '0457ce27',
  TimeStamp: Time.now.to_i

歐付寶共有 5 個 API:

  • /Cashier/AioCheckOut
  • /Cashier/QueryTradeInfo
  • /Cashier/QueryPeriodCreditCardTradeInfo
  • /CreditDetail/DoAction
  • /Cashier/AioChargeback

每個 API 有哪些參數建議直接參考歐付寶文件,注意幾點:

  • 使用時不用煩惱 MerchantIDCheckMacValue,正如上述範例一樣。
  • /Cashier/AioCheckOut 回傳的內容是 HTML,這個請求應該是交給瀏覽器發送的,所以不應該寫出 client.request '/Cashier/AioCheckOut' 這樣的程式碼。

Allpay::Client

實體方法 回傳 說明
request(path, **params) Net::HTTPResponse 發送 API 請求
make_mac(**params) String 用於產生 CheckMacValue,單純做加密,params 需要完整包含到 MerchantID
verify_mac(**params)                                       Boolean           用於檢查收到的參數,其檢查碼是否正確,這用在歐付寶物的 ReturnURLPeriodReturnURL 參數上。
query_trade_info(merchant_trade_number, platform = nil) Hash /Cashier/QueryTradeInfo 的捷徑方法,將 TimeStamp 設定為當前時間
query_period_credit_card_trade_info(merchant_trade_number) Hash /Cashier/QueryPeriodCreditCardTradeInfo 的捷徑方法,將 TimeStamp 設定為當前時間
generate_checkout_params Hash 用於產生 /Cashier/AioCheckOut 表單需要的參數,MerchantTradeDateMerchantTradeNoPaymentType,可省略。

使用範例

git clone [email protected]:tonytonyjan/allpay.git
cd allpay
bundle install
ruby examples/server.rb

allpay's People

Contributors

otaq avatar tonytonyjan avatar trantorliu avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

allpay's Issues

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.