#Stripe API에서 스케줄 등록을 발표하면 어떤 일이 발생합니까? 서브스크립션은 스케줄 등록의 손을 떠나 독자적으로 달리는 것 같다. (#ruby + Stripe API)
포인트
스케줄 등록이 출시된 후
BEFORE
AFTER
Ruby Code example
# Docs
# https://stripe.com/docs/api/subscription_schedules/release
# https://support.stripe.com/questions/create-update-and-schedule-subscriptions
# https://stripe.com/docs/billing/subscriptions/subscription-schedules
# Code
require 'stripe'
Stripe::api_key = ENV['STRIPE_SECRET_KEY']
product1 = Stripe::Product.create(name: "Gold plan #{rand(9999999999)}")
plan1 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 5000, product: product1.id, usage_type: 'licensed')
product2 = Stripe::Product.create(name: "Silver plan #{rand(9999999999)}")
plan2 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 3000, product: product2.id, usage_type: 'licensed')
product3 = Stripe::Product.create(name: "Bronse plan #{rand(9999999999)}")
plan3 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 1000, product: product3.id, usage_type: 'licensed')
tax_rate = Stripe::TaxRate.create(display_name: 'Tax Rate', percentage: 10.0, inclusive: false)
customer = Stripe::Customer.create
payment_method = Stripe::PaymentMethod.create(type: 'card', card: { number: '4242424242424242', exp_year: 2030, exp_month: 01})
customer_payment_method = Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
def put_subscription_schedule(subscription_schedule, message)
puts '-' * 100
puts "Subscription Schedule"
puts message
puts "https://dashboard.stripe.com/test/subscription_schedules/#{subscription_schedule.id}"
puts '-' * 100
puts subscription_schedule
end
# https://stripe.com/docs/api/subscription_schedules/create
subscription_schedule = Stripe::SubscriptionSchedule.create(
{
customer: customer.id,
start_date: Time.now.to_i + 5,
default_settings: {
default_payment_method: customer_payment_method.id,
},
phases: [
{
plans:
[
{ plan: plan1.id, quantity: 1 },
{ plan: plan2.id, quantity: 4 },
],
default_tax_rates: [tax_rate],
iterations: 3,
},
{
plans:
[
{ plan: plan2.id, quantity: 1 },
{ plan: plan3.id, quantity: 1 },
],
default_tax_rates: [tax_rate],
iterations: 5,
},
{
plans:
[
{ plan: plan3.id, quantity: 3 },
{ plan: plan1.id, quantity: 2 },
],
default_tax_rates: [tax_rate],
iterations: 7,
}
],
}
)
put_subscription_schedule(subscription_schedule, 'CREATED')
puts '-' * 100
puts "Wait until subscription schedule starts"
puts '-' * 100
until subscription_schedule.status == 'active' do
subscription_schedule = Stripe::SubscriptionSchedule.retrieve(subscription_schedule.id)
puts subscription_schedule.status
sleep 2
end
started_subscription_schedule = Stripe::SubscriptionSchedule.retrieve(id: subscription_schedule.id, expand: ['subscription'])
put_subscription_schedule(started_subscription_schedule, 'STARTED')
subscription = started_subscription_schedule.subscription
started_subscription_schedule.subscription # #<StripeSubscription: ...
started_subscription_schedule.phases.size # 3
puts '-' * 100
puts "Subscription created"
puts "https://dashboard.stripe.com/test/subscriptions/#{subscription.id}"
puts '-' * 100
puts subscription
Stripe::SubscriptionSchedule.release(started_subscription_schedule.id)
released_subscription_schedule = Stripe::SubscriptionSchedule.retrieve(id: subscription_schedule.id, expand: ['subscription'])
# SubscriptionSchedule now has no "subscription" but has phases ( not used ? )
released_subscription_schedule.subscription # nil
released_subscription_schedule.phases.size # 3
released_subscription = Stripe::Subscription.retrieve(subscription.id)
removed_from_subscription_by_released_schedule = subscription.to_a - released_subscription.to_a
# Subscription "cancel_at" removed by Subscription release
# e.g
# => [[:cancel_at, 1585720051], [:canceled_at, 1577857651], [:schedule, "sub_sched_1Fw03HCmti5jpytUpJMypWcA"]]
Original by Github issue
Reference
이 문제에 관하여(#Stripe API에서 스케줄 등록을 발표하면 어떤 일이 발생합니까? 서브스크립션은 스케줄 등록의 손을 떠나 독자적으로 달리는 것 같다. (#ruby + Stripe API)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/faec0500b25b469a195f
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Ruby Code example
# Docs
# https://stripe.com/docs/api/subscription_schedules/release
# https://support.stripe.com/questions/create-update-and-schedule-subscriptions
# https://stripe.com/docs/billing/subscriptions/subscription-schedules
# Code
require 'stripe'
Stripe::api_key = ENV['STRIPE_SECRET_KEY']
product1 = Stripe::Product.create(name: "Gold plan #{rand(9999999999)}")
plan1 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 5000, product: product1.id, usage_type: 'licensed')
product2 = Stripe::Product.create(name: "Silver plan #{rand(9999999999)}")
plan2 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 3000, product: product2.id, usage_type: 'licensed')
product3 = Stripe::Product.create(name: "Bronse plan #{rand(9999999999)}")
plan3 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 1000, product: product3.id, usage_type: 'licensed')
tax_rate = Stripe::TaxRate.create(display_name: 'Tax Rate', percentage: 10.0, inclusive: false)
customer = Stripe::Customer.create
payment_method = Stripe::PaymentMethod.create(type: 'card', card: { number: '4242424242424242', exp_year: 2030, exp_month: 01})
customer_payment_method = Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
def put_subscription_schedule(subscription_schedule, message)
puts '-' * 100
puts "Subscription Schedule"
puts message
puts "https://dashboard.stripe.com/test/subscription_schedules/#{subscription_schedule.id}"
puts '-' * 100
puts subscription_schedule
end
# https://stripe.com/docs/api/subscription_schedules/create
subscription_schedule = Stripe::SubscriptionSchedule.create(
{
customer: customer.id,
start_date: Time.now.to_i + 5,
default_settings: {
default_payment_method: customer_payment_method.id,
},
phases: [
{
plans:
[
{ plan: plan1.id, quantity: 1 },
{ plan: plan2.id, quantity: 4 },
],
default_tax_rates: [tax_rate],
iterations: 3,
},
{
plans:
[
{ plan: plan2.id, quantity: 1 },
{ plan: plan3.id, quantity: 1 },
],
default_tax_rates: [tax_rate],
iterations: 5,
},
{
plans:
[
{ plan: plan3.id, quantity: 3 },
{ plan: plan1.id, quantity: 2 },
],
default_tax_rates: [tax_rate],
iterations: 7,
}
],
}
)
put_subscription_schedule(subscription_schedule, 'CREATED')
puts '-' * 100
puts "Wait until subscription schedule starts"
puts '-' * 100
until subscription_schedule.status == 'active' do
subscription_schedule = Stripe::SubscriptionSchedule.retrieve(subscription_schedule.id)
puts subscription_schedule.status
sleep 2
end
started_subscription_schedule = Stripe::SubscriptionSchedule.retrieve(id: subscription_schedule.id, expand: ['subscription'])
put_subscription_schedule(started_subscription_schedule, 'STARTED')
subscription = started_subscription_schedule.subscription
started_subscription_schedule.subscription # #<StripeSubscription: ...
started_subscription_schedule.phases.size # 3
puts '-' * 100
puts "Subscription created"
puts "https://dashboard.stripe.com/test/subscriptions/#{subscription.id}"
puts '-' * 100
puts subscription
Stripe::SubscriptionSchedule.release(started_subscription_schedule.id)
released_subscription_schedule = Stripe::SubscriptionSchedule.retrieve(id: subscription_schedule.id, expand: ['subscription'])
# SubscriptionSchedule now has no "subscription" but has phases ( not used ? )
released_subscription_schedule.subscription # nil
released_subscription_schedule.phases.size # 3
released_subscription = Stripe::Subscription.retrieve(subscription.id)
removed_from_subscription_by_released_schedule = subscription.to_a - released_subscription.to_a
# Subscription "cancel_at" removed by Subscription release
# e.g
# => [[:cancel_at, 1585720051], [:canceled_at, 1577857651], [:schedule, "sub_sched_1Fw03HCmti5jpytUpJMypWcA"]]
Original by Github issue
Reference
이 문제에 관하여(#Stripe API에서 스케줄 등록을 발표하면 어떤 일이 발생합니까? 서브스크립션은 스케줄 등록의 손을 떠나 독자적으로 달리는 것 같다. (#ruby + Stripe API)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/faec0500b25b469a195f
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
# Docs
# https://stripe.com/docs/api/subscription_schedules/release
# https://support.stripe.com/questions/create-update-and-schedule-subscriptions
# https://stripe.com/docs/billing/subscriptions/subscription-schedules
# Code
require 'stripe'
Stripe::api_key = ENV['STRIPE_SECRET_KEY']
product1 = Stripe::Product.create(name: "Gold plan #{rand(9999999999)}")
plan1 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 5000, product: product1.id, usage_type: 'licensed')
product2 = Stripe::Product.create(name: "Silver plan #{rand(9999999999)}")
plan2 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 3000, product: product2.id, usage_type: 'licensed')
product3 = Stripe::Product.create(name: "Bronse plan #{rand(9999999999)}")
plan3 = Stripe::Plan.create(interval: 'month', currency: 'jpy', amount: 1000, product: product3.id, usage_type: 'licensed')
tax_rate = Stripe::TaxRate.create(display_name: 'Tax Rate', percentage: 10.0, inclusive: false)
customer = Stripe::Customer.create
payment_method = Stripe::PaymentMethod.create(type: 'card', card: { number: '4242424242424242', exp_year: 2030, exp_month: 01})
customer_payment_method = Stripe::PaymentMethod.attach(payment_method.id, customer: customer.id)
def put_subscription_schedule(subscription_schedule, message)
puts '-' * 100
puts "Subscription Schedule"
puts message
puts "https://dashboard.stripe.com/test/subscription_schedules/#{subscription_schedule.id}"
puts '-' * 100
puts subscription_schedule
end
# https://stripe.com/docs/api/subscription_schedules/create
subscription_schedule = Stripe::SubscriptionSchedule.create(
{
customer: customer.id,
start_date: Time.now.to_i + 5,
default_settings: {
default_payment_method: customer_payment_method.id,
},
phases: [
{
plans:
[
{ plan: plan1.id, quantity: 1 },
{ plan: plan2.id, quantity: 4 },
],
default_tax_rates: [tax_rate],
iterations: 3,
},
{
plans:
[
{ plan: plan2.id, quantity: 1 },
{ plan: plan3.id, quantity: 1 },
],
default_tax_rates: [tax_rate],
iterations: 5,
},
{
plans:
[
{ plan: plan3.id, quantity: 3 },
{ plan: plan1.id, quantity: 2 },
],
default_tax_rates: [tax_rate],
iterations: 7,
}
],
}
)
put_subscription_schedule(subscription_schedule, 'CREATED')
puts '-' * 100
puts "Wait until subscription schedule starts"
puts '-' * 100
until subscription_schedule.status == 'active' do
subscription_schedule = Stripe::SubscriptionSchedule.retrieve(subscription_schedule.id)
puts subscription_schedule.status
sleep 2
end
started_subscription_schedule = Stripe::SubscriptionSchedule.retrieve(id: subscription_schedule.id, expand: ['subscription'])
put_subscription_schedule(started_subscription_schedule, 'STARTED')
subscription = started_subscription_schedule.subscription
started_subscription_schedule.subscription # #<StripeSubscription: ...
started_subscription_schedule.phases.size # 3
puts '-' * 100
puts "Subscription created"
puts "https://dashboard.stripe.com/test/subscriptions/#{subscription.id}"
puts '-' * 100
puts subscription
Stripe::SubscriptionSchedule.release(started_subscription_schedule.id)
released_subscription_schedule = Stripe::SubscriptionSchedule.retrieve(id: subscription_schedule.id, expand: ['subscription'])
# SubscriptionSchedule now has no "subscription" but has phases ( not used ? )
released_subscription_schedule.subscription # nil
released_subscription_schedule.phases.size # 3
released_subscription = Stripe::Subscription.retrieve(subscription.id)
removed_from_subscription_by_released_schedule = subscription.to_a - released_subscription.to_a
# Subscription "cancel_at" removed by Subscription release
# e.g
# => [[:cancel_at, 1585720051], [:canceled_at, 1577857651], [:schedule, "sub_sched_1Fw03HCmti5jpytUpJMypWcA"]]
Reference
이 문제에 관하여(#Stripe API에서 스케줄 등록을 발표하면 어떤 일이 발생합니까? 서브스크립션은 스케줄 등록의 손을 떠나 독자적으로 달리는 것 같다. (#ruby + Stripe API)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/YumaInaura/items/faec0500b25b469a195f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)