Sooey

2010-10-22 01:10:30 +0900

今月のRubyInsideのスポンサー一覧に、Recurlyという見たことがないサービスが入っていたのでちょっと調べてみたところ、どうやらサブスクリプションサービスの決済代行をやってくれるみたい。料金は1ヶ月200トランザクションまでのBasicプランが一番安くて「基本料金$29とトランザクション毎に$0.20」、上位プランだとトランザクション毎のフィーがどんどん割安になる。実際に使う予定があるわけではないのでそのあたりはどうでもよいのだけど、APIに加えて各種言語のライブラリがちゃんと提供されているところがいい。Rubyの場合はgemも用意されていてGitHubでソースも見れる(Rails3対応!)。コード例はこんな感じ。

# 口座作成
account = Recurly::Account.new(
  :account_code => 'rachael',
  :first_name => 'Rachael',
  :last_name => 'Test',
  :email => '[email protected]',
  :company_name => 'Chicago, Inc'
)

# 支払い情報作成
account.billing_info = Recurly::BillingInfo.new(
  :first_name => account.first_name,
  :last_name => account.last_name,
  :address1 => '123 Test St',
  :city => 'Chicago',
  :state => 'IL',
  :country => 'US',
  :zip => '60654',
  :credit_card => {
    :number => '1',
    :year => Time.now.year + 1,
    :month => Time.now.month,
    :verification_value => '123'
  },
  :ip_address => '127.0.0.1'
)

# サブスクリプションを開始
subscription = Recurly::Subscription.create(
  :account_code => account.account_code,
  :plan_code => PLAN_CODE,
  :quantity => 2, # Defaults to 1
  :account => account
)

# サブスクリプションプランをアップグレード
subscription = Recurly::Subscription.find('rachael')
subscription.change('now', :plan_code => 'platinum', :quantity => 3)

なんと試してみたくなるコードであろうか。こういうのを見ると、とにかくこのAPIを使って何かやってみたくなってきますね。日本の決済代行業者もこれくらい使いやすくしてくれるといいんだけど。