30天了解30种技术系列---(25)开源的计费及支付平台--killbill

    Kill Bill 是一个开源的计费及支付平台。主要目的是对相关的支付平台等进行了整合。

    官网:http://killbill.io/

  

  1.     有计划管理的订阅引擎,支持添加绑定多个订阅
  2.     计价赢钱,支持多种方式的账单
  3.     有状态改变路由的支付状态及,支持多种支付网关
  4.     插件架构,允许使用java或ruby根据你的业务逻辑增加更多的个性化功能

    支持Java,Ruby,Python等多种语言

    一般使用方式如下:

    

  •     初始化

    

curl http://killbill.io/wp-content/uploads/2014/11/killbill-0.12.0.ddl | mysql -h 127.0.0.1 -ukillbill -pkillbill killbill
curl https://raw.githubusercontent.com/killbill/killbill-stripe-plugin/master/db/ddl.sql | mysql -h 127.0.0.1 -ukillbill -pkillbill killbill
curl https://raw.githubusercontent.com/killbill/killbill-paypal-express-plugin/master/db/ddl.sql | mysql -h 127.0.0.1 -ukillbill -pkillbill killbill
  •   安装Tomcat
  •   Kill 初始化
killbill:
  version: 0.12.1
  webapp_path: /var/tmp/tomcat/webapps/ROOT.war
  plugins_dir: /var/tmp/bundles
  plugins:
    ruby:
      - name: paypal-express-plugin
        version: 1.8.1
      - name: stripe-plugin
        version: 1.0.0

   

kpm install kpm.yml

    Paypal setup

    

:paypal_express:
  :signature: 'your-paypal-signature'
  :login: 'your-username-facilitator.something.com'
  :password: 'your-password'
  :test: true

:database:
  :adapter: 'jdbcmysql'
  :jndi: 'killbill/osgi/jdbc'
  :connection_alive_sql: 'select 1'
  :pool: 25

    建立集成账户

    

curl -v \
     -X POST \
     -u admin:password \
     -H 'Content-Type: application/json' \
     -H 'X-Killbill-CreatedBy: admin' \
     -d '{"apiKey": "bob", "apiSecret": "lazar"}' \
     "http://127.0.0.1:8080/1.0/kb/tenants"

   

   接下来,就可以在应用中集成Kill了。示例如下

    建立账户,这个是假设在电商中已经存在账户,所以需要建立完以后,到Kill 中建立账户

curl -v \
     -u admin:password \
     -H "X-Killbill-ApiKey: bob" \
     -H "X-Killbill-ApiSecret: lazar" \
     -H "Content-Type: application/json" \
     -H "X-Killbill-CreatedBy: demo" \
     -X POST \
     --data-binary '{"name":"John Doe","email":"[email protected]","externalKey":"john-doe-1234","currency":"USD"}' \
     "http://127.0.0.1:8080/1.0/kb/accounts"

   

   将用户的paypal 账户集成到kill bill中

   

curl -v \
     -X POST \
     -u admin:password \
     -H 'Content-Type: application/json' \
     -H 'X-Killbill-ApiKey:bob' \
     -H 'X-Killbill-ApiSecret:lazar' \
     -H 'X-Killbill-CreatedBy: creator' \
     --data-binary '{
       "pluginName": "killbill-stripe",
       "pluginInfo": {
         "properties": [
           {
             "key": "token",
             "value": "t3GER3BP3JHLASZe"
           }
         ]
       }
     }' \
     "http://127.0.0.1:8080/1.0/kb/accounts/268983f2-5443-47e4-a967-b8962fc699c5/paymentMethods?isDefault=true"

    

   接下来可以使用Paypal 进行支付,首先需要在Paypal 中申请Token

   

curl -v \
     -X POST \
     -u admin:password \
     -H 'Content-Type: application/json' \
     -H 'X-Killbill-ApiKey:bob' \
     -H 'X-Killbill-ApiSecret:lazar' \
     -H 'X-Killbill-CreatedBy: creator' \
     --data-binary '{
       "kb_account_id": "13d26090-b8d7-11e2-9e96-0800200c9a66",
       "currency": "USD",
       "options": {
         "return_url": "http://www.google.com/?q=SUCCESS",
         "cancel_return_url": "http://www.google.com/?q=FAILURE",
         "billing_agreement": {
           "description": "Your subscription"
         }
       }
     }' \
     "http://127.0.0.1:8080/plugins/killbill-paypal-express/1.0/setup-checkout"

   获取token以后可以开始支付第二步

   

curl -v \
     -X POST \
     -u admin:password \
     -H 'Content-Type: application/json' \
     -H 'X-Killbill-ApiKey:bob' \
     -H 'X-Killbill-ApiSecret:lazar' \
     -H 'X-Killbill-CreatedBy: creator' \
     --data-binary '{
       "pluginName": "killbill-paypal-express",
       "pluginInfo": {
         "properties": [
           {
             "key": "token",
             "value": "EC-20G53990M6953444J"
           }
         ]
       }
     }' \
     "http://127.0.0.1:8080/1.0/kb/accounts/268983f2-5443-47e4-a967-b8962fc699c5/paymentMethods?isDefault=true"

    第三步:开始支付

    

curl -v \
     -u admin:password \
     -H "X-Killbill-ApiKey: bob" \
     -H "X-Killbill-ApiSecret: lazar" \
     -H "Content-Type: application/json" \
     -H "X-Killbill-CreatedBy: demo" \
     --data-binary '{"transactionType":"PURCHASE","amount":"10","currency":"USD"}' \
     "http://127.0.0.1:8080/1.0/kb/accounts/268983f2-5443-47e4-a967-b8962fc699c5/payments"

   所以整体来讲,是老外对Paypal等常见的支付模式进行了一个封装。大家有兴趣可以仔细研究。

   更多精彩请关注微信 : 图灵搜索

   请大家使用中国第一个为程序员打造的搜索引擎:图灵搜索,https://www.tulingss.com

相关推荐