README.md in alipay-0.15.0 vs README.md in alipay-0.15.1

- old
+ new

@@ -1,50 +1,76 @@ # Alipay -Unofficial alipay ruby gem. +Unofficial Alipay ruby gem. -Note: Alipay::Client Api have not enough feedback in production yet, please fully test in your staging environment before production. You can find legacy API document [here](doc/legacy_api.md). +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](doc/legacy_api.md). You should read [https://doc.open.alipay.com](https://doc.open.alipay.com) before using this gem. ## Installation -Add this line to your application's Gemfile: +To install using [Bundler](http://bundler.io/). Add this line to your +application's Gemfile: ```ruby -gem 'alipay', '~> 0.15.0' +gem 'alipay', '~> 0.15.1' ``` Then run: - -```console +```bash $ bundle ``` -## Usage +Or you can manually install using [RubyGems](http://rubygems.org/): +```bash +$ gem install alipay -v 0.15.1 +``` +## 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](doc/rsa_key_en.md) on generating RSA key for use with this gem to get you started. + +### Setup ```ruby -alipay_client = Alipay::Client.new( - url: 'https://openapi.alipaydev.com/gateway.do', - app_id: '2016000000000000', +require 'alipay' + +# setup the client to communicate with either production API or sandbox API +# https://openapi.alipay.com/gateway.do (Production) +# https://openapi.alipaydev.com/gateway.do (Sandbox) +API_URL = 'https://openapi.alipaydev.com/gateway.do' + +# setup your own credentials and certificates +APP_ID = '2016xxxxxxxxxxxx' +APP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nxkbt...4Wt7tl\n-----END RSA PRIVATE KEY-----\n" +ALIPAY_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\nTq43T5...OVUAQb3R\n-----END PUBLIC KEY-----\n" + +# initialize a client to communicate with the Alipay API +@alipay_client = Alipay::Client.new( + url: API_URL, + app_id: APP_ID, app_private_key: APP_PRIVATE_KEY, alipay_public_key: ALIPAY_PUBLIC_KEY ) +``` -alipay_client.page_execute_url( +### Create a payment +```ruby +@alipay_client.page_execute_url( method: 'alipay.trade.page.pay', biz_content: { out_trade_no: '20160401000000', product_code: 'FAST_INSTANT_TRADE_PAY', total_amount: '0.01', subject: 'test' - }.to_json, # to_json is important! + }.to_json(ascii_only: true), # to_json(ascii_only: true) is important! timestamp: '2016-04-01 00:00:00' ) + +# This method will then return a payment url # => 'https://openapi.alipaydev.com/gateway.do?app_id=201600...' ``` -Read [Alipay::Client](lib/alipay/client.rb) for usage detail. +Read [Alipay::Client](lib/alipay/client.rb) or the [Quick Start Guide](doc/quick_start_en.md) for usage detail. ## Contributing Bug report or pull request are welcome.