Skip to content

Importing subscriptions

David de Boer edited this page Mar 22, 2018 · 25 revisions

It's possible to import existing SEPA direct debit (recurring) payments into a WooCommerce shop with WooCommerce Subscriptions and Mollie Payments for WooCommerce if all required information is available. The import can be done if all required data is available in a CSV file in the correct format. Mollie provides a PHP script which can then process the CSV file and import the data into WooCommerce in the correct way.

Introduction

  • Importing existing credit card (recurring) payments is not possible.

  • Importing with other import plugins or tools for WooCommerce or WooCommerce Subscriptions is not possible, as these do not handle the payments part for Mollie.

  • PHP and WordPress coding experience is required. It is likely that custom modifications have to be made to this PHP script to allow it to better fit your situation and data.

  • The data that is required, is a combination of customer (general, billing, shipping) data for WooCommerce and payment information for Mollie (IBAN, BIC etc).

  • The amount of records that you can put into the CSV depends on the server on which the script is used. If your server is not performant enough, split your CSV file into smaller parts. For example, a CSV file with 10.000 records can be split into two CSV files with 5.000 records each.

  • When orders are imported, WooCommerce wil automatically send an email to the shop-owner and shop-customer. You can disable these e-mails during the import under WooCommerce > Settings > Emails.

  • The CSV file should use quotes like "data" to wrap information in a CSV column.

  • During the import, keep a close eye on the logs as success and failure is communicated there. The logs can be found at WooCommerce > System status > Logs > mollie-payments-for-woocommerce.

  • The script will automatically try to create a mandate for the recurring payment, so subscription renewals payments are processed automatically. You do not have to create the mandates yourself! If this fails for a subscription import, this will be communicated in the logs at WooCommerce > System status > Logs > mollie-payments-for-woocommerce.

  • The import script will create a mandatory "first" order and a subscription. On the next payment date (as added in the CSV) a renewal order will be automatically created by WooCommerce Subscriptions for that order.

  • For subscriptions in WooCommerce, a WordPress user account is required. The script will try to create one for every subscription.

  • All subscription products that you will import will need to be created in WooCommerce before the import. The ID of those products will need to be added to the CSV.

  • WooCommerce, WooCommerce Subscriptions and Mollie Payments for WooCommerce needs to be completely set up before the import. Test imports should be done with Mollie Payments for WooCommerce set to test mode, so "Enable test mode" should be checked and the final production import should be done with "Enable test mode" unchecked (on the correct live API key. You can not change your API key after the subscriptions are imported, as the mandates are connected to that single API key.

Import workflow

  • The import script can be called via a cron job (to automate things). If you don't have a lot of experience with cron jobs, consider a service like easycron.com.

  • The script will process one subscription record per load. This is because a lot of shared hosting accounts have difficulty processing more then one import per run (server time-outs). Of course the script can be adjusted to process more then one subscription per load.

  • If an import is successful, this will be stored in the database. On the next load, the next subscription row in the CSV will be processed.

  • During import, details about the subscription will be stored at WooCommerce > Status > Logs > mollie-payments-for-woocommerce-[current-date]. Keep checking the log and keep an eye out for log messages with the message "ERROR" or "IMPORT FAILED".

  • Only when you see "IMPORT FAILED" the import of a subscription is completely failed. With message "ERROR" the script will try to fix the import by switching the subscription to "manual renewal" instead of "Automatic renewal with SEPA". This will all be described in the logs.

  • If a one subscription import permanently fails, the script will continue with the next subscription import on the next load.

So after completing the import, it is a good idea to check the logs for the message "IMPORT FAILED". Check all logs for all days that you imported. Use CTRL + F or CMD + F shortcuts to quickly search long log files for that message. Read why the subscription import failed in the log, adjust the subscription data in a new CSV (with all failed subscriptions) and try importing those failed subscriptions again.

Tips

  • Install a plugin like Mail Logs to see what emails are created and sent by WordPress during import
  • Subscriptions or renewal payments can be tested at Tools > Scheduled Actions > Run
  • Download the script and place it in te root of the website.
  • In the same location add a file with name subscriptions.csv (if needed, the name can be changed in the script).

Required data

  • customer_iban

  • customer_bic

  • customer_email - required for creating the mandatory WordPress account, if unknown, add fake but unique emails to the CSV.

  • billing_interval

  • billing_period

  • next_payment_date - WooCommerce Subscriptions can't handle subscriptions with a date in the past, so next_payment_date should be at least 48 hours in the future from the current date (today+48 hours). The script will automatically adjust older dates to today+7 days.

Optional data

  • order_shipping (integer) - an amount for the shipping costs. Now uses default description "Verzendkosten" on the subscription and default tax "21%". For other descriptions or tax rates, contact [email protected].
  • customer_bank_name - not required, add if the actual name connected to the IBAN account is known. Otherwise we will use shipping first name + shipping last name.

Importing other data

It's possible to also import other customer or subscription data into WordPress. This data will be added to the user or subscription that will be created for the import, as custom user meta or custom post meta (for subscriptions).

Please note that adding other customer data will increase the size of the CSV file and can result in server timeouts on less performant servers. Therefor, only add the customer data that is essential to your website or business.

Adding custom data to the WordPress database on import does not immediately make this data visible in the WordPress UI. To show this custom meta in the user edit view or the subscription edit view, you will need to do additional programming. This page about Custom Fields is a good starting point if you haven't done this before. Showing the data in the WordPress UI can be done at a later moment, after the import the data is already safely stored in the database.

To add other information to the WooCommerce subscription, add that information (string of text) to the CSV row for that subscription with a prefix of custom_post_meta_ and then your preferred post meta key for that information. So a complete column header could be custom_post_meta__my_custom_field.

To add other information to the WooCommerce customer/WordPress user, add that information (string of text) to the CSV row for that subscription with a prefix of custom_user_meta_ and then your preferred user meta key for that information. So a complete column header could be custom_user_meta__my_custom_field.

Clone this wiki locally