Migrating from Charge 1.x

Migration from Charge 1.x is a simple thing.

You'll need to make just one update to your current payment forms to migrate over, but you might also want to take advantage of the new 2.0 features available.


1. Make a Backup #

Before upgrading make sure you've got a fresh backup of the files and database, just incase.

2. Replace your plugin files #

Replace the charge plugin files in your charge/plugins folder with the updated version.

3. Run the migration #

Visit the Craft CP, and you'll be prompted to run the Charge migration. This will update your db schema for all the new 2.0 changes.

4. Update your Charge templates #

There is only one required change in your templates. The new setPaymentOptions within your payment form.

Previously you'd have had your payment form setup like so :

<form method="post" id="charge_form">
    <input type="hidden" name="action" value="charge/charge"/>
    <input type="hidden" name="redirect" value="thanks/{{ hash }}"/>

    <input type="hidden" name="planAmount" value="5"/>
    <input type="hidden" name="planInterval" value="month"/>
    <input type="hidden" name="planIntervalCount" value="1"/>
    ..

To update, you now need to include the following :

<form method="post" id="charge_form">
    <input type="hidden" name="action" value="charge/charge"/>
    <input type="hidden" name="redirect" value="thanks/{{ hash }}"/>

    {{ craft.charge.setPaymentOptions( { allowDynamic : true } ) }}

    <input type="hidden" name="planAmount" value="5"/>
    <input type="hidden" name="planInterval" value="month"/>
    <input type="hidden" name="planIntervalCount" value="1"/>
    ..

The allowDynamic setting is all that's required to upgrade from 1.x. By setting that to true, all the same functions as in 1.x will now work.

setPaymentOptions() adds a hidden input called opts to the form, which is encrypted containing the extra details for the request.

5. Take it further #

With 2.0 you can now specify additional options and securely pass extra information, trigger actions, give customer plan options, saved cards and more.

For all the new 2.0 options, have a look at the full setPaymentOptions reference.


Need a hand migrating? Get in touch and we'll be happy to help directly or give any extra pointers you might need.