Code Monkey home page Code Monkey logo

alipay's Introduction

Alipay

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 https://doc.open.alipay.com before using this gem.

Installation

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

gem 'alipay', '~> 0.15.1'

Then run:

$ bundle

Or you can manually install using RubyGems:

$ 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 on generating RSA key for use with this gem to get you started.

Setup

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
)

Create a payment

@alipay_client.page_execute_url(
  method: 'alipay.trade.page.pay',
  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
# => 'https://openapi.alipaydev.com/gateway.do?app_id=201600...'

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

Contributing

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.

License

MIT License

alipay's People

Contributors

agonzalezro avatar chloerei avatar dulao5 avatar fx-hao avatar graysonchen avatar halczy avatar hungyuhei avatar jasl avatar jimhj avatar linjunpop avatar ryancheung avatar saberma avatar sen avatar serco-chen avatar tzzzoz avatar xiaohesong avatar xiejiangzhi avatar

Watchers

 avatar

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.