# Recurring Charges
There are two ways to enroll customers in automatic payments with paysly:
# Using a Checkout Flow
To create a recurring charge using the checkout flow, set up and install the script as you would for a non-recurring checkout flow, but call redirectToCheckout
with recurring parameters:
paysly.redirectToCheckout({
payment_method_types: ['card'],
subscription_data: {
items: [{
plan: 'plan_GHec7BZO8ZUpnM',
}],
},
success_url: 'http://example.com/success',
cancel_url: 'https://example.com/cancel',
});
2
3
4
5
6
7
8
9
10
As redirectToCheckout
accepts a stripe session object, you can customize subscription_data
(as well as any other parameters) to suit your needs. You can set up and customize plans from the stripe dashboard.
To verify your payment, follow the same procedure as you would with a regular, non-recurring charge.
# Using Stripe Elements
To create a customer enrollment using stripe Elements, install the script, create an elements
instance, and style your element exactly as you would for a non-recurring flow. But, instead of creating a charge, instead:
Create a recurring customer enrollment via paysly.createRecurring
:
// Handle form submission.
const form = document.getElementById('payment-form');
form.addEventListener('submit', (event) => {
event.preventDefault();
paysly.createRecurring(
{ type: 'card', card }
{},
{
items: [{
plan: 'plan_GHec7BZO8ZUpnM'
}]
}
).then((result) => {
// handle result
}).catch((result) => {
// handle validation or charge errors
});
});
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
The paysly.createRecurring
function takes three parameters:
- Stripe paymentMethodData, including a Stripe elements card element (described above), and a
type
. - customer data (pass in
{}
if you don't need to use any customer data, as done in the example above) - Stripe subscription information, except for
customer
- (a customer will be created based on your customer data).
The returned result
is a stripe payment intent object, with a signed version of this object in result.token
. To verify the payment, you will want to supply this token to a secure environment (typically a web server), then decode it and ensure it contains the data you expect. This can be done with one of the numerous JWT libraries.