Skip to content

Migrations

QuickPay credit cards to Frisbii

Migrates stored cards from QuickPay to Frisbii using the mapping file Frisbii returns after importing the cards on their side.

wp payment-hub frisbii import-quickpay-cards \
  --file=/srv/private/cards-import.csv \
  --expect-handle-prefix=prod- \
  --dry-run

The mapping file

Semicolon separated, no header row, three columns:

479600290;10748-rqM;ct_1521aa11bb22cc33dd44ee55ff66aa77
│         │          └── Frisbii one-time token
│         └───────────── subscription ID, with an optional suffix
└───────────────────────  QuickPay transaction ID

Column 2 is the order ID QuickPay was given. For a subscription that is the subscription's WooCommerce ID, with -<3 random characters> appended when the checkout was a request to change payment method (OrderPaymentsUtils::get_order_number_for_api() in the QuickPay plugin). The subscription ID is therefore everything before the first hyphen.

What gets migrated

A row is migrated only when all of the following hold:

Requirement Why
Column 2 resolves to a WooCommerce subscription Single orders must never be touched
OrderUtils::get_transaction_id() equals column 1 Proves the row and the subscription belong together, and picks the active card when the file holds several transactions for one subscription
The subscription's payment method is exactly quickpay Anything already migrated or on another gateway is left alone
The subscription has a registered customer A guest has no Frisbii customer handle
The next renewal is more than --min-hours-to-next-payment away A brand new card should not be charged minutes after it is attached
No active Frisbii agreement exists yet Avoids a second card on the same subscription

Everything else is written to the skipped report with a reason. not_active_transaction is the expected outcome for the extra rows of a subscription with several transactions, and is counted separately from real failures.

On success

  1. A paymenthub_agreements row: provider=frisbii, gateway=credit_card, status=ACTIVE, is_default=1, ext_agreement_id=ca_…, and the card's expiry in expires_at.
  2. Agreement meta recording where the card came from: migrated_from, legacy_quickpay_transaction_id, legacy_quickpay_order_reference, card_last4, card_brand, card_exp_month, card_exp_year.
  3. The subscription's payment method switched to frisbii_credit_card, plus an order note.

The QuickPay meta on the subscription is left untouched, so a row can always be re-verified and rolled back.

What a dry run does

A dry run never contacts Frisbii. Not the token exchange, and not the harmless GET /v1/customer either. A ct_ token can only be exchanged once, so an analysis that spent one would destroy the very card it was meant to report on.

A dry run only:

  • reads subscriptions and existing agreements from the database,
  • reads the ledger file,
  • writes its reports to dry-run.-prefixed files, so a real report is never overwritten.

Two independent things enforce this: the command returns after the read-only pass, and the import service refuses to go past preflight when it is in dry-run mode. Both are covered by tests (test_the_analysis_pass_never_calls_frisbii, test_a_dry_run_import_never_calls_frisbii).

Options

Option Default
--file required Absolute path. The file holds card tokens, so keep it outside the web root
--expect-handle-prefix required The PAYMENTHUB_HANDLE_PREFIX this environment must have. A mismatch aborts before anything is sent
--dry-run off Analysis only. No Frisbii calls at all, no database writes. Reports get a dry-run. prefix
--limit, --offset – Applied to file line numbers, so an offset means the same across runs
--sleep 250 Milliseconds between API calls
--min-hours-to-next-payment 6 0 disables the check
--stop-on-error 10 Aborts after this many consecutive real failures
--send-emails off Keeps WooCommerce emails enabled during the run
--verify – Re-checks every row in the success report against the database. Read-only
--rollback – Reverts every subscription in the success report back to QuickPay, across all batches run so far. There is no preview: with --dry-run it looks for dry-run.<file>.success.csv, which does not exist, and stops. Read <file>.success.csv instead to see what would be reverted

Reports

Written next to the input file:

  • <file>.success.csv — one row per migrated subscription
  • <file>.skipped.csv — everything not migrated, with a reason
  • <file>.ledger.csv — every token exchanged, written the moment the exchange succeeds

Tokens appear in the reports only as a truncated, hashed label, never in full.

Each run adds to the reports rather than overwriting them, so they cover every batch run on the file so far. --verify therefore checks all batches, and --rollback reverts all of them. To roll back only one batch, copy <file>.success.csv before running it, and afterwards cut the report down to the rows from that batch before running --rollback.

Reading the summary

A run prints two tables. Pass 1 is the analysis: it only reads the database and the ledger, so no token is spent. Pass 2 takes the eligible rows from pass 1 and migrates them one at a time.

expected = yes means the outcome is part of a healthy run and does not count towards --stop-on-error.

Pass 1 – analysis (token never sent to Frisbii, so the row can always be run again)

Outcome What it means What to do
eligible Passed every check. Not a final outcome: it is attempted in pass 2 –
not_active_transaction The subscription pays with a different QuickPay transaction. The row is an old card Nothing
already_migrated The row's token is already in the ledger from an earlier run. See the note below Nothing
payment_method_not_quickpay The subscription is on another payment method. The detail names which one Nothing, unless the method is unexpected
subscription_not_found Column 2 is not a WooCommerce subscription: a single order, or a deleted subscription Nothing
guest_customer The subscription has no registered customer, so there is no Frisbii customer handle Handle by hand
renewal_imminent The next renewal is less than --min-hours-to-next-payment away Re-run the same batch after the renewal
subscription_already_has_active_frisbii_agreement Still on QuickPay but already has an active Frisbii agreement Investigate by hand
multiple_rows_match_active_transaction Several rows in the batch point at the same subscription and transaction, so none of them is used Investigate by hand
duplicate_csv_row Same transaction and token as an earlier line in the batch. The detail names that line Nothing
csv_malformed The line does not have exactly three columns Fix the file
invalid_transaction_id Column 1 is not a number Fix the file
invalid_subscription_reference Column 2 does not start with a subscription ID Fix the file
invalid_token_format Column 3 is not a ct_ token Fix the file

Pass 2 – migration

Outcome Token spent? What it means What to do
imported Yes Card attached and the subscription is on frisbii_credit_card Nothing. The row is in the success report
card_expired Yes Frisbii created the card, but it has already expired, so it is not attached. The subscription stays on QuickPay The customer has to enter a new card. The row cannot be retried
agreement_not_active Yes Frisbii created the card, but not as active. The subscription stays on QuickPay Check the card at Frisbii. The row cannot be retried
customer_provisioning_failed No The Frisbii customer could not be created or looked up Fix the cause and re-run. See When a row fails
token_exchange_rejected No Frisbii rejected the token with a definitive 4xx Check the Frisbii code in the detail. See When a row fails
token_exchange_indeterminate Unknown 429, 5xx or timeout, so we do not know if the card was created Follow up by hand before retrying
agreement_persist_failed Yes The card exists at Frisbii, but the agreement could not be saved Follow up by hand
payment_method_switch_failed Yes The agreement is saved, but the subscription is still on QuickPay Follow up by hand

Once a token has been spent, it is in the ledger. On a re-run, that row shows up as already_migrated in pass 1, including rows that ended as card_expired or agreement_not_active, even though those subscriptions are still on QuickPay. Their original outcome is in the skipped report.

Validating a batch

Take a handful at a time and check them before moving on.

Automated, and the one to trust:

wp payment-hub frisbii import-quickpay-cards --file=… --verify

Read-only. It re-reads every row in the success report through the same accessors production uses — not the report itself — and prints PASS/FAIL per subscription with the specific problems named. It exits non-zero if anything failed, so it also works in a script. Each row is checked for:

Check
payment_method_is_* The subscription is on frisbii_credit_card
quickpay_transaction_id_changed The original QuickPay transaction is still on the subscription
agreement_missing The ca_ reference from the report exists as an agreement
agreement_status_is_* That agreement is ACTIVE
wrong_provider, wrong_gateway It is frisbii / credit_card
not_default It is the subscription's default
session_id_set session_id is null, keeping it out of the webhook handler's fallback lookup
active_frisbii_agreements_N Exactly one active Frisbii agreement, not two
card_expired The stored expiry is in the future
agreement_meta_transaction_id_mismatch The agreement records the transaction it was migrated from
customer_changed The subscription still belongs to the same customer

By hand: docs/sql/verify-quickpay-frisbii-migration.sql

wp db query < docs/sql/verify-quickpay-frisbii-migration.sql

Sections 1 and 2 list every migrated card next to its subscription so you can eyeball a batch — migrated_from_txn and sub_quickpay_txn must match on every row. Sections 3 to 7 are the red flags and should all return zero rows; the one to care most about is section 4, a subscription set to Frisbii with no agreement to charge, which would fail at its next renewal. Subscriptions moved on purpose by switch-quickpay are left out of it and counted in section 4b. Sections 8 and 9 show progress and let you confirm no orders were touched.

Pick the HPOS or the legacy variant depending on the shop:

wp eval 'var_dump( Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() );'

Beyond the data, one thing only a real renewal proves: let a migrated subscription renew (or bring its next payment date forward) and confirm the charge goes through Frisbii. Do that once, on the first small batch, before running the rest.

When a row fails

The skipped report names the reason and, for an API failure, what Frisbii said:

reason                        what it means
token_exchange_rejected       Frisbii gave a definitive 4xx. The token was not accepted and no
                              card was created, so the row can be retried once the cause is fixed.
token_exchange_indeterminate  429, 5xx, a timeout, or an unexpected error. We do not know whether
                              the exchange happened. Do not blindly retry - check the customer's
                              payment methods at Frisbii first.
customer_provisioning_failed  The customer could not be created or looked up. The token was never
                              sent, so nothing is lost. The detail names the cause - including the
                              one case that needs Frisbii support: a customer that was deleted at
                              Frisbii still answers the lookup and still occupies its handle, so it
                              can neither be used nor replaced, and there is no API to restore one.

Frisbii documents these errors for POST /v1/payment_method, and the reason usually tells you straight away whether the token is still usable:

Frisbii code HTTP Meaning
9 404 Customer not found
34 400 Invalid card token provided as source
103 400 Card token already used
104 400 Card token has expired

A 422 is not in that list. It means the request body itself did not validate, which is a bug on our side rather than a problem with the token.

To check whether a card was actually created for a customer before retrying:

wp eval '$c = ygd_get_container()->get( Subscribed\PaymentsHub\Core\Gateways\Frisbii\Clients\FrisbiiClient::class );
         echo $c->get( "https://api.frisbii.com/v1/customer/PREFIX+CUSTOMERID/payment_method", [] )->getBody();'

An empty list means the token was not consumed and the row is safe to retry.

Re-running a file

The Frisbii token is single use. The ledger is written the moment Frisbii answers with a card, before any database write. A token recorded there is never sent to Frisbii again, so re-running the same file resumes rather than repeats. ext_agreement_id also has a unique index as a second line of defence.

Exception: token_exchange_indeterminate. We never got an answer, so nothing was written to the ledger, even though Frisbii may have created the card. On a re-run the row is eligible again and the token would be sent a second time. Check the customer's payment methods at Frisbii first (see When a row fails), and only re-run the row if the list is empty.

Three outcomes mean a card exists at Frisbii but our own data does not reflect it, and always need a human: token_exchange_indeterminate, agreement_persist_failed and payment_method_switch_failed. The command warns about them and the details are in the skipped report and the WooCommerce log.

card_expired and agreement_not_active also spend the token and leave the subscription on QuickPay, but the command does not warn about them and does not log them. They only appear in the pass 2 summary and in the skipped report, so look for them there after each batch.

Suggested order

# 1. Confirm the container can build the repository under WP-CLI
wp eval 'ygd_get_container()->get( \Subscribed\PaymentsHub\Core\Contracts\Repositories\AgreementRepositoryInterface::class );'

# 2. Analyse without touching anything
wp payment-hub frisbii import-quickpay-cards --file=… --expect-handle-prefix=prod- --dry-run

# 3. Canary batch, then verify one real renewal before going further
wp payment-hub frisbii import-quickpay-cards --file=… --expect-handle-prefix=prod- --limit=5

# 4. Verify the batch against the database
wp payment-hub frisbii import-quickpay-cards --file=… --verify

# 5. Re-run the same batch: all five should be skipped as already_migrated
wp payment-hub frisbii import-quickpay-cards --file=… --expect-handle-prefix=prod- --limit=5

# 6. Let one migrated subscription renew and confirm the charge goes through Frisbii

# 7. The rest, in batches, running --verify between them

Delete the mapping file once the migration is done.

Switching what is left on QuickPay

After the card import, some subscriptions and unpaid orders are still on QuickPay, for example card_expired rows and subscriptions that were not in Frisbii's file. Many also still carry a QUICKPAY_PAYMENT_LINK that stops working once the QuickPay plugin is removed. This command moves them to frisbii_credit_card and removes the link:

# Everything, dry run first
wp payment-hub frisbii switch-quickpay --dry-run

# Only a few, results in the terminal
wp payment-hub frisbii switch-quickpay --ids=1001,1002,1003

# Everything, with a report
wp payment-hub frisbii switch-quickpay --report=/srv/private/quickpay-switch.csv

Nothing is charged, and no card is created. A switched subscription has no agreement, so its next renewal order is set to failed (see Dunning). When the customer pays it with a card, that card becomes the subscription's agreement.

What gets touched

On quickpay On another method, with a QuickPay link
Subscriptions, any status Switched to frisbii_credit_card, link removed Link removed
Orders: pending, failed, on-hold Switched to frisbii_credit_card, link removed Link removed
Orders in any other status Not touched Not touched

Paid orders keep quickpay as the record of how they were paid. QUICKPAY_PAYMENT_ID and the transaction ID are never removed, because the import's --verify and --rollback use them.

A switched subscription or order gets an order note and the meta _payment_hub_switched_from_quickpay. Section 4 of the verification SQL leaves those subscriptions out, and section 4b counts them.

Check the on-hold orders first. At QuickPay, on-hold can mean an authorization that was never captured. Once the order is switched, it cannot be captured from WooCommerce any more. The quickpay_transaction column shows which on-hold orders have a QuickPay transaction.

Options

Option Default
--ids – Comma separated IDs. Only these are processed
--file – One ID per line. Can be combined with --ids
--report – Append every row to this CSV. A dry run writes to a dry-run.-prefixed file. The file is opened before anything changes, so a bad path stops the run first
--dry-run off No writes
--min-age-hours 24 Skip unpaid orders on QuickPay that changed within this many hours, so a payment in progress is not cut off. 0 disables. Anything but a whole number of 0 or more stops the run
--limit – Process at most this many candidates. Must be 1 or more
--send-emails off Keeps WooCommerce emails enabled during the run

Without --ids or --file, the command finds every candidate itself. Every row is printed in the terminal with its outcome, whether or not --report is given.

Outcome Meaning
switched Moved to frisbii_credit_card, link removed
link_removed Already on another method. Only the QuickPay link was removed, including an empty one
skipped_recent_activity An unpaid order changed within --min-age-hours. Run it again later
skipped_status An order that is not pending, failed or on-hold
skipped_not_quickpay Not on QuickPay and has no QuickPay link. Nothing to do
not_found No order or subscription with that ID

There is no rollback. The link cannot be recreated. The old payment method is in the output and the report if something has to be put back by hand.

Suggested order

# 1. See everything that would change, and check the on-hold orders with a transaction
wp payment-hub frisbii switch-quickpay --dry-run --report=/srv/private/quickpay-switch.csv

# 2. A handful, then check them in admin
wp payment-hub frisbii switch-quickpay --limit=5

# 3. The rest
wp payment-hub frisbii switch-quickpay --report=/srv/private/quickpay-switch.csv

# 4. Nothing should be left
wp payment-hub frisbii switch-quickpay --dry-run

Deactivate the QuickPay plugin once step 4 reports Nothing left on QuickPay.