R package to easily add a Stripe subscription with multiple price tiers to a Shiny app using the polished R package.
- This package requires the most recent version of the
{polished}
package. Install it fromCRAN
using the following command:
# Install `polished` if you don't already have it
install.packages("polished")
# Alternatively, install the most recent development version
# - NOTE: The most recent development version of `polished` may contain bugs or breaking changes. We recommend using the most recent CRAN version.
remotes::install_github("tychobra/polished")
-
Create a Polished account at the Polished Dashboard if you don't have one already.
-
Then install the most recent version of
{polishedpayments}
:
remotes::install_github("tychobra/polishedpayments")
-
Create a Stripe account
-
Create a new Stripe Product.
- Create 1 to 4 Stripe Prices
-
Configure your Shiny app with your Stripe information using
polished_payments_config()
inglobal.R
.polishedpayments::polished_payments_config( stripe_secret_key = <your Stripe secret key>, stripe_public_key = <your Stripe public key>, subscription_prices = <your Stripe subscription price(s)>, trial_period_days = <Stripe subscription trial period days> )
-
Wrap your Shiny server in
polishedpayments::payments_server()
andpolished::secure_server()
. e.g.my_server <- polishedpayments::payments_server( server = function(input, output, session) ( # your custom Shiny app's server logic ) ) polished::secure_server(my_server)
-
Wrap your Shiny UI in
polishedpayments::payments_ui()
andpolished::secure_ui()
.my_ui <- polishedpayments::payments_ui(fluidPage( h1("My Shiny App") )) polished::secure_ui(my_ui)
Each user's subscription status will be checked before the Shiny app's server logic starts. If the user does not have a subscription, polishedpayments
will set them up with the default subscription. If the user has a subscription that is either in it's free trial period, or the user has set up a payment method for a subscription, then polishedpayments
will allow the user to continue to the Shiny app after signing in. If the user has a subscription in which the free trial has expired, and they still have not enabled a payment method, polishedpayments
will redirect the user to the Payments page to enable billing for their subscription. In this case (expired trial period), the user will not be able to access the main Shiny app until they've enabled billing.
- (Optional) Add a button or link to redirect user to the Payments page with
go_to_payments()
- Source code for example apps is available here