R package to easily add a Stripe subscription with multiple price tiers to a Shiny app using the polished R package.
# Install `polished` if you don't already have it
remotes::install_github("tychobra/polished")
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
.
polishedpayments::polished_payments_config(
stripe_secret_key = <stripe_secret_key>,
stripe_public_key = <stripe_public_key>,
stripe_prices = <stripe_price(s)>,
trial_period_days = <stripe_trial_period_days>,
free_roles = <polished_role_for_free_users>
)
Wrap your Shiny server in payments_server()
. e.g.
``` my_server <- polishedpayments::payments_server(function(input, output, session) (
# your custom Shiny app's server logic
))
```
Add the "Account" page to your app using app_module_ui
in secure_ui
& app_module
in secure_server
id
for app_module_ui
```
polished::secure_server(my_server, account_module = polishedpayments::app_module)
polished::secure_ui( ui, account_module_ui = polishedpayments::app_module_ui("account") ) ```
Your user's subscription status will now be checked before your 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, then polishedpayments
will allow the user to continue to your Shiny app. If your user has a subscription in which the free trial has expired, but they have not yet enabled a payment method, then polishedpayments
will redirect them to their account page where they can set up their subscription.
(Optional) Add button or link to redirect user to 'Account' page with go_to_account()
Example app available: https://github.com/Tychobra/polishedpayments/tree/master/inst/examples/polished_payments_min
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.