On a page there's a textbox where a customer or payer enters an amount to donate to me via Stripe, as one time payment. And there's also a checkbox "subscribe for $5/mo" which, if checked, would charge him that amount afterwards.
The thing is:
it's a one time payment in any case and charged immediatelly; a custom amount -- whaterver a customer enters. And, optionally, a customer would be charged $5/mo within a subscription, automatically, starting in a month - if, and only if, he checks a checkbox.
I know how to create a session for charging a customer one time, and here's code, partially:
stripeParams := &stripe.CheckoutSessionParams{
PaymentMethodTypes: stripe.StringSlice([]string{
"card",
}),
LineItems: []*stripe.CheckoutSessionLineItemParams{
&stripe.CheckoutSessionLineItemParams{
PriceData: &stripe.CheckoutSessionLineItemPriceDataParams{
Currency: stripe.String(string(stripe.CurrencyUSD)),
ProductData: &stripe.CheckoutSessionLineItemPriceDataProductDataParams{
Name: stripe.String("test123"),
},
UnitAmount: stripe.Int64(amount * 100),
},
Quantity: stripe.Int64(1),
},
},
Mode: stripe.String(string(stripe.CheckoutSessionModePayment)),
//........
How would I implement the "plus a subscription of $5/mo on top" thing?
If you want to create a Subscription through a Checkout Session you should follow this guide: https://stripe.com/docs/billing/subscriptions/checkout
To summarize, if you want to add a $5 subscription on top of the one-time payment amount entered by your customer you would do the following:
mode: payment
to mode: subscription
(see apiref)subscription_data.trial_end
(apiref) or subscription_data.trial_period_days
(apiref) so that the recurring price is not charged until after the trial is over. The one-time price will still be charged upfront, even if the recurring price is on a trial.If you don't want to use trials, you could also look into adding a one-time $5 discount to the Session.