Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. email = 'donor@example.com'
  2. card_token = '123'
  3. plan_name = 'magazine' #in Stripe it's a plan with interval 3 months and amount 1.0
  4. amount = 12
  5. today = Time.now
  6. trial_end = today.beginning_of_quarter.to_date.eql?(today.to_date) ? nil : today.end_of_quarter + 2.seconds
  7.  
  8. customer = Stripe::Customer.create(email: email, source: card_token)
  9. subscription = Stripe::Subscription.create(customer: customer.id, items: [{plan: plan_name, quantity: amount}])
  10. unless trial_end.nil?
  11. subscription.delete(at_period_end: true)
  12. subscription = Stripe::Subscription.create(customer: customer.id, items: [{plan: plan_name, quantity: amount}], trial_end: trial_end)
  13. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement