Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PaymentSystem
- class << self
- def get_coupon(coupon_id)
- Stripe::Coupon.retrieve coupon_id
- end
- def get_plan(plan_id)
- Stripe::Plan.retrieve plan_id
- end
- def get_subscription(sub_id)
- Stripe::Subscription.retrieve sub_id
- end
- def get_customer(customer_id)
- Stripe::Customer.retrieve customer_id
- end
- def update_customer(customer, data)
- customer.source = data[:source]
- customer.save
- end
- def delete_customer(customer)
- customer.delete
- end
- def get_invoices(customer_id)
- Stripe::Invoice.list customer: customer_id
- end
- def create_customer(data)
- Stripe::Customer.create data
- end
- def create_subscription(customer, data)
- customer.subscriptions.create data
- end
- def end_subscription(subscription)
- subscription.delete at_period_end: true
- end
- def validate_plan_and_coupon(plan_id, coupon_id)
- plan = get_plan plan_id
- subscription_data = {
- plan: plan.id
- }
- if coupon_id.present?
- coupon = get_coupon coupon_id
- subscription_data[:coupon] = coupon.id unless !coupon.valid
- end
- subscription_data
- end
- end
- end
Add Comment
Please, Sign In to add comment