Last active
December 18, 2015 07:49
-
-
Save kikumoto/5749504 to your computer and use it in GitHub Desktop.
WebPay sample. retrieve customer information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require "stripe" | |
require "date" | |
Stripe.api_key = "test_secret_XXXXXXXXXXXXXXXXXXX" | |
Stripe.api_base = "https://api.webpay.jp" | |
customer = Stripe::Customer.retrieve("cus_c4F1nGgK7eEwegF") | |
puts "顧客情報の詳細" | |
puts " ID: #{customer.id}" | |
puts " 作成日: " + Time.at(customer.created).strftime("%Y/%m/%d %H:%M %Z") | |
puts " メールアドレス: " + (customer.email ? customer.email : "未登録") | |
puts " メモ: #{customer.description}" | |
puts | |
card = customer.active_card | |
puts "クレジットカード情報" | |
puts " 名前: #{card.name}" | |
puts " カード番号(下4桁): #{card.last4}" | |
puts " 有効期限: #{card.exp_month} / #{card.exp_year}" | |
puts " タイプ: #{card.type}" | |
puts | |
puts "課金履歴" | |
charges = Stripe::Charge.all(:count => 100, :customer => "cus_c4F1nGgK7eEwegF") | |
charges.each do |charge| | |
puts " 金額 => #{charge.amount} (#{charge.currency}), メモ => #{charge.description ? charge.description : charge.id}, 課金日時 => #{Time.at(charge.created).strftime("%Y/%m/%d %H:%M %Z")}" | |
end | |
puts | |
subscription = customer.subscription | |
puts "加入中の定期課金プラン" | |
puts " ステータス: " + (subscription ? "加入中" : "プランに加入していません。") | |
puts " プラン: #{subscription.plan.name}(#{subscription.plan.amount} / #{subscription.plan.interval})" | |
puts " 次回の課金日: " + Time.at(subscription.current_period_end + 1).strftime("%Y/%m/%d %H:%M %Z") | |
puts | |
puts "定期課金の請求情報" | |
invoices = Stripe::Invoice.all(:count => 100, :customer => "cus_c4F1nGgK7eEwegF") | |
invoices.each do |invoice| | |
puts " 金額 => #{invoice.total} (#{invoice.currency}), ID => #{invoice.id}, 請求日時 => #{Time.at(invoice.date).strftime("%Y/%m/%d %H:%M %Z")}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment