Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate civicrm_contribution_recur.trxn_id #21539

Merged
merged 2 commits into from Feb 13, 2022

Conversation

mattwire
Copy link
Contributor

Overview

See discussion on https://lab.civicrm.org/dev/financial/-/issues/57

The civicrm_contribution_recur table has both trxn_id and processor_id. Various parts of the core code require that you use processor_id (eg. UpdateBilling/UpdateSubscription historically it was the only value passed that could be used to identify the recurring contribution).

I'm not aware of any payment processor that actually uses both - it's basically impossible to do so because of the way core has handled them - and those that do rely on one of those fields generally copy the same value into both to make sure - eg. https://lab.civicrm.org/extensions/gocardless/-/blob/main/CRM/GoCardlessUtils.php#L389

Before

Not clear which parameter should be used.

After

Clearer..

Technical Details

Comments

@civibot
Copy link

civibot bot commented Sep 19, 2021

(Standard links)

@artfulrobot
Copy link
Contributor

GoCardless, mentioned above, started off using trxn_id and then migrated to processor_id. Currently it uses both for ease of transition; we intend to only use processor_id in the future.

I think this PR ought to also update the comment on the processor_id column, which is currently:

Possibly needed to store a unique identifier for this recurring payment order - if this is available from the processor??

Suggest:

May store an identifier used to link this recurring contribution record to a third party payment processor's system.

The current text is wrong because: (1) it doesn't have to be unique. e.g. two different processors might use "sub0001" as an ID; it's probably unique within the domain of the third party processor, but it doesn't have to be unique in Civi's table.

But I'm generally onboard, though I think we'll need an upgrade migration for - e.g. PayPal - if it's working differently now.

@@ -74,6 +74,9 @@ public function view() {
NULL, TRUE, NULL, FALSE, CRM_Core_Permission::VIEW);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contributionRecur['id']);

if ($contributionRecur['processor_id'] === $contributionRecur['trxn_id']) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need guards here against index not found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

// we need to add a unique trxn_id to avoid a unique key error
// in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
$recurParams['trxn_id'] = $params['trxn_id'] ?? $params['invoiceID'];
$recurParams['processor_id'] = $recurParams['trxn_id'] = $params['trxn_id'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lost the functionality that if there's no trxn_id invoice_id is copied to trxn_id. If this doesn't matter, I think it needs documenting / commenting on as to why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I thought it didn't matter but looks like paypal may rely on it. Have updated the comment and left it in.

@mattwire mattwire force-pushed the deprecaterecurtrxnid branch 2 times, most recently from 095c0f4 to f7114a3 Compare September 23, 2021 16:02
@mattwire mattwire force-pushed the deprecaterecurtrxnid branch 2 times, most recently from 0f98621 to d660361 Compare January 25, 2022 22:21
@mattwire
Copy link
Contributor Author

Merging per @artfulrobot review and so we don't have to regenerate the upgrader again.

@mattwire mattwire merged commit 6b31f9a into civicrm:master Feb 13, 2022
@mattwire mattwire deleted the deprecaterecurtrxnid branch February 13, 2022 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants