Fundraising/Data and flow/Recurring
Overview
Recurring donations are supported via PayPal (both legacy and Express Checkout integrations), Adyen, Dlocal, Braintree (venmo), and Gravy.
In CiviCRM, recurring donations are stored in the civicrm_contribution_recur table and each installment has an entry in civicrm_contribution with a value in the contribution_recur_id pointing to the civicrm_contribution_recur row. We store them slightly idiosyncratically - while core CiviCRM's payment processors interpret the 'Completed' status to mean that there are no more installments expected, we use 'Completed' to mean that the subscription is in a good state.
Frequencies - Monthly and Annual
Historically recurring donations were every month, in late 2024 we added an annual recurring option which would be every year.
url parameters for monthly
recurring=1&frequency_unit=month
url parameters for yearly
recurring=1&frequency_unit=year
Setup
At Payments-wiki, we interpret any truthy value sent for the query string parameter 'recurring' to mean we should set up a recurring payment for the donor.
Will start a recurring recurring=1 recurring=true
Will not start a recurring recurring=0 recurring=false
PayPal
PayPal recurring donations are all driven by PayPal - that is, we indicate that we want to set up a monthly donation for a specific amount, and PayPal takes care of the scheduling, charging, and retry attempts on failed charges.
For PayPal Express Checkout, we use the MAXFAILEDPAYMENTS parameter to instruct PayPal to stop trying to charge the donor after N failed attempts. Express Checkout subscriptions set up prior to October 15th, 2019 had this value set to 3, and after that date have the value set to 0, meaning to retry indefinitely. On failure, PayPal retries every 5 days. PayPal's documentation
Adyen
Adyen recurring donations are driven by us - after setting up a recurring donation, Adyen gives us a
recurring_payment_token
to store and refer to in future donation attempts. We schedule the donations and make API calls to charge them once each month. Our
hourly scheduled jobs
check the civicrm_contribution_recur table for rows where the next_sched_contribution_date is now or before, and charge a batch of them.
Adyen recurring donations (coded as gateway=adyen) are tokenized. That is, we receive a payment token at the time of the setup and store it in the civicrm_payment_token table. The code to charge each monthly installment is in the CiviCRM extension
org.wikimedia.smashpig
, which uses the
SmashPig library
to interface with the Connect API. The scheduled job is configured in
recurring_smashpig_charge.yaml
, which runs
drush cvapi job.process_smashpig_recurring
.
There is more information on the details of Adyen recurring on the main Adyen page .
Dlocal
Like Adyen, Dlocal recurring jobs are driven by us.
More information on dlocal recurring on the main dlocal page
Gravy
Like Adyen, Gravy recurring jobs are driven by us.
Recurring Convert is a system to give the donor an option to start a recurring donation after a one time donation. They do not need to reinput their payment information.
We started with offering monthly convert and have added yearly convert
Recurring Test from Civicrm
In order to charge the test recur in prod before next scheduled date,
1: We need to find the contribution recur id (first column) from this civicrm page https://civicrm.wikimedia.org/civicrm/contribution_recur_id by filter contact id.
2: Go to api3 then entity job, action: process_smashpig_recurring, name Contribution Recur ID equal the id from first step
then hit execute, will charge the donation again.
Recurring queue
A somewhat misleading name, the recurring queue mainly handles Paypal recurrings. It also is where initial monthly convert messages are sent as well as [something for the dlocal flow figure out exactly what.]
Smashpig civi extension/Smashing recurring charge job/Recurring charge job
We call this many different things but it is the nightly job that charges all the donations we have control over the charging of. It lives in the civi extension org.wikimedia.smashpig
More documentation here: https://wikitech.wikimedia.org/wiki/Fundraising/SmashPig
Failures and retry logic
We currently have two recurring flows: recurrings controlled by the payment processor (legacy paypal_ec and paypal) and recurrings we control (everything else).
For the Paypal legacy flow, these are all older subscriptions that paypal sends us notifications each day of which ones charged.
For recurrings we control we have a configurable retry schedule in civicrm. It's currently every 3,7,14 days after the first failure. When the last retry happens and is unsuccessful we send the first recurring failure email. If 7 days pass and the donor hasn't restarted the recurring, we send the second recurring failure email.
The templates for these two emails can be seen in civi under Message Templates.
Processor Retries (Adyen Autorescue)
While we still have recurrings through adyen we are using their retry system instead of ours as mentioned above. If the recurring fails and is deemed retryable by adyen it goes into their autorescue flow and we get an update from adyen if the charge is successful/not successful.
Once we migrate these to gravy we won't have a processor level retry live until gravy implements their version of it.
Testing
You can send a test failure email by going to a recurring record in civi and clicking on the hamburger menu/more on the right hand side. This brings up the option to send the 1st or 2nd failure email.
Failure Reasons
| column | description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| cancel_reason |
|