Skip to content


Repository files navigation


Unofficial Alipay ruby gem.

Note: Alipay::Client API does not have enough feedback in production yet, please fully test in your staging environment before production. You can find legacy API document here.

You should read before using this gem.


To install using Bundler. Add this line to your application's Gemfile:

gem 'alipay'

Then run:

$ bundle

Or you can manually install using RubyGems:

$ gem install alipay

Getting Started

This gem needs to be configured with your application's private key for Alipay and Alipay's public key. Here is a quick guide on generating RSA key for use with this gem to get you started.


require 'alipay'

# setup the client to communicate with either production API or sandbox API
# (Production)
# (Sandbox)
API_URL =  ''

# setup your own credentials and certificates
APP_ID = '2016xxxxxxxxxxxx'
APP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nxkbt...4Wt7tl\n-----END RSA PRIVATE KEY-----\n"

# initialize a client to communicate with the Alipay API
@alipay_client =
  url: API_URL,
  app_id: APP_ID,
  app_private_key: APP_PRIVATE_KEY,
  alipay_public_key: ALIPAY_PUBLIC_KEY

Create a payment

  method: '',
  biz_content: JSON.generate({
    out_trade_no: '20160401000000',
    product_code: 'FAST_INSTANT_TRADE_PAY',
    total_amount: '0.01',
    subject: 'test'
  }, ascii_only: true), # ascii_only is important!
  timestamp: '2016-04-01 00:00:00'

# This method will then return a payment url
# => ''

Read Alipay::Client or the Quick Start Guide for usage detail.


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.


MIT License