Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

ruby on rails - Subscriptions in stripe

I've read this https://stripe.com/docs/tutorials/subscriptions but don't really understand the idea of subscriptions in respect to implementation.

What I need is being to charge the user but the amount of charge is to be calculated by myself because I have a special algorithm for it. So this code:

 # create a plan - once!
  Stripe::Plan.create(
    :amount => 2000,
    :interval => 'month',
    :name => 'Amazing Gold Plan',
    :currency => 'cad',
    :id => 'gold'
  )


# every month? or also once?

maybe_customer = Stripe::Customer.retrieve(....)
unless maybe_customer
  customer = Stripe::Customer.create(
    :card => token,
    :plan => "gold",
    :email => "[email protected]"
  )
end

When (how often) do I have to run it: only once or every month (:interval => 'month')?

If every month, I'll run it as a cron task. But how to get the user to enter in their credit card details? Or do they have to enter them in only the first time, then I save them and then will be able to re-use them?

UPDATE:

  1. Since it's a subscription, it's to occur automatically. Does that mean that it's completely automatic for the user? Or do they have to enter their card details into the pop up from Stripe once and from that moment on it'll become automatic for the user, meaning they won't have to enter their bank card details anymore, they will be charged automatically by stripe each month later?

  2. How do charge the user zero cents as a monthly pay if some (my) condition is true and using account_balance? From this https://support.stripe.com/questions/metered-subscription-billing I don't understand how to do that.

  3. I don't see any difference between a subscription and just charging a customer like if it were the normal payments. If both cases I have to run a code once a month on the server. What's the difference?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Sorry, but the only thing I could understand clearly from your question was that you need to know how to execute one-time payments rather than proper subscriptions.

Reading the link you've shared, I've gathered that you should be able to set an interval_count option for the number of months (or intervals) after which the customer is charged. So setting interval_count to 0 should make the payment happen only once.

Also, this is from the same page:

Customer objects can also store a credit card, which is how they'll be billed later on.

In other words, yes - the customer enters his/her card details the first time. You can (optionally ?) save the card info in the Customer object.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...