Stripe has multiple options for payments
- Stripe Checkout - Hosted pages for payments (you'll redirect users to Stripe)
- Stripe Elements - Payment fields on your site
Stripe introduced Products & Prices to support more payment options. Previously, they had a concept called Plan that was for subscriptions. Pay supports both Price IDs
and Plan IDs
when subscribing.
@user.payment_processor.subscribe(plan: "price_1234")
@user.payment_processor.subscribe(plan: "plan_1234")
Multiple subscription items in a single subscription can be passed in as items
:
@user.payment_processor.subscribe(
items: [
{price: "price_1234"},
{price: "price_5678"}
]
)
See: https://stripe.com/docs/api/subscriptions/create
Promotion codes are customer-facing coupon codes that can be applied in several ways.
You can apply a promotion code on the Stripe::Customer to have it automatically apply to all Subscriptions.
@user.payment_processor.update_customer!(promotion_code: "promo_1234")
Promotion codes can also be applied directly to a subscription:
@user.payment_processor.subscribe(plan: "plan_1234", promotion_code: "promo_1234")
Stripe Checkout can also accept promotion codes by enabling the flag:
@checkout_session = current_user.payment_processor.checkout(
mode: "payment",
line_items: "price_1ILVZaKXBGcbgpbZQ26kgXWG",
allow_promotion_codes: true
)
See Credentials