R package to easily add a Stripe subscription with multiple price tiers to a Shiny app using the polished R package.
{polished}
package. Install it from CRAN
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.
Configure your Shiny app with your Stripe information using polished_payments_config()
in global.R
.
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()
and polished::secure_server()
. e.g.
```R 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()
and polished::secure_ui()
.
```R 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.