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

Fix a regression whereby payment details are not saved from the AdditionalPayment form #15537

Merged
merged 1 commit into from
Oct 21, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Oct 18, 2019

Overview

I discovered the Payment.create api is not respecting a bunch of parameters - since this is now called from the AdditionalPaymentForm they are not being saved.

payment_instrument_id, card_type_id, pan_truncation & other field were not being passed through - resulting in incorrect payment saves

Before

Add a pending contribution & then submit a credit card payment using the additional payment form

Screen Shot 2019-10-18 at 7 24 48 PM

After

Screen Shot 2019-10-18 at 7 41 03 PM

Technical Details

This looks worse than it is because I also had to pull in my upstream param renaming commit #15535

Comments

@monishdeb @jitendrapurohit can one of you check

@civibot
Copy link

civibot bot commented Oct 18, 2019

(Standard links)

@mattwire
Copy link
Contributor

@eileenmcnaughton test fails look related - they're all returning

CiviCRM_API3_Exception: DB Error: constraint violation

@@ -390,6 +390,9 @@ function _civicrm_api3_get_BAO($name) {
// not the other cache info like search results (which could in fact be in Redis or another cache engine)
$name = 'PrevNextCache';
}
if ($name === 'Payment') {
$name = 'FinancialTrxn';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton Is this change required for this PR? As I understand it Payment does not map directly to FinancialTrxn but wraps the financial entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mattwire yes - otherwise the pseudoconstant doesn't work.

Payment is a psuedo-api that represents one specific type of FinancialTrxn - hence the presence of 'is_payment' as a fixed parameter when creating a financial_trxn from the payment api.

Ie it's a subset of the FinancialTrxn entity

Comment on lines 297 to 312
'order_reference' => [
'name' => 'order_reference',
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Order Reference'),
'description' => ts('Payment Processor external order reference'),
'maxlength' => 255,
'size' => 25,
'where' => 'civicrm_financial_trxn.order_reference',
'table_name' => 'civicrm_financial_trxn',
'entity' => 'FinancialTrxn',
'bao' => 'CRM_Financial_DAO_FinancialTrxn',
'localizable' => 0,
'html' => [
'type' => 'Text',
],
],
Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton order_reference was only added in 5.20 - will this cause problems on 5.19 as the column won't exist in the DB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - I think it's the cause of the test fails - I just pulled it out again

'type' => CRM_Utils_Type::T_INT,
'description' => ts('Payment processor ID - required for payment processor payments'),
'title' => ts('Payment Processor'),
'description' => ts('Payment Processor for this financial transaction'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use Payment processor for this payment. As the payment API will be creating one or more financial transactions depending on the action.

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 - good point

@@ -59,27 +59,36 @@ public static function create($params) {

$isPaymentCompletesContribution = self::isPaymentCompletesContribution($params['contribution_id'], $params['total_amount']);

$whiteList = ['check_number', 'payment_processor_id', 'fee_amount', 'total_amount', 'contribution_id', 'net_amount', 'card_type_id', 'pan_truncation', 'trxn_result_code', 'payment_instrument_id', 'order_reference', '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.

@eileenmcnaughton See comment on order_reference which is only available from 5.20 - though I don't think it will cause problems in this list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep - removed

Copy link
Contributor

@mattwire mattwire left a comment

Choose a reason for hiding this comment

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

@eileenmcnaughton I've added a couple of comments. The main concern is around order_reference which did not exist in 5.19.
Is there a minimum version of this PR without the variable rename that could be merged for 5.19 and then do the rest for 5.20?
As this is modifying the internals of CRM_Financial_BAO_Payment::create it has the potential to break badly if we've missed anything!

@eileenmcnaughton eileenmcnaughton force-pushed the pay_check branch 2 times, most recently from 72b09f5 to 275b4c9 Compare October 18, 2019 21:40
@eileenmcnaughton
Copy link
Contributor Author

@mattwire I've fixed the order_reference part. To be honest I started working on 5.20 & then moved back to 5.19 once I realised I'd hit a regression.

The variable rename is 'safe' & hopefully my comments on the other PR address your concerns. If so we can merge that to sync this with current master & rebase this to be cleaner

@eileenmcnaughton
Copy link
Contributor Author

test this please

@eileenmcnaughton
Copy link
Contributor Author

@magnolia61

@mattwire
Copy link
Contributor

@eileenmcnaughton Please rebase and I'll take another look

@eileenmcnaughton
Copy link
Contributor Author

@mattwire done - also FYI - the reason I moved the param gathering outside the IF is that the same params are actually required if total_amount < 0 - that code is for historical reasons in it's own function but over a few refactors it would start to share that paymentParams array

@eileenmcnaughton eileenmcnaughton force-pushed the pay_check branch 2 times, most recently from 69c028d to 3643945 Compare October 20, 2019 23:40
@eileenmcnaughton
Copy link
Contributor Author

Hopefully that sorts the test. Along with #15561 we should aim for 5.18

@eileenmcnaughton eileenmcnaughton force-pushed the pay_check branch 2 times, most recently from d4cbc42 to 7d628f4 Compare October 21, 2019 07:20
@mattwire
Copy link
Contributor

test this please

@jitendrapurohit
Copy link
Contributor

I've tested this on contribution, event payments and confirm that the params are correctly set after the submission. The payment.create api call can also set these values in the record.

Failing test is SyntaxConformanceTest.php::testLimit for Payment Entity. Should this entity be added to static::toBeSkipped_getlimit() as well?

On some digging I found that various payment related fields like pan_truncation & card_type_id were
being quietly ignored rather than saved by Payment.create

The additional payment form now uses this api so it is a regression on that form.

This fixes the metadata, tests & support for payment-related trxn fields
@eileenmcnaughton eileenmcnaughton dismissed mattwire’s stale review October 21, 2019 22:43

Agreed elsewhere that the param name change is fine

@seamuslee001
Copy link
Contributor

merging as per the collective reviews

@seamuslee001 seamuslee001 merged commit f8fdba9 into civicrm:5.19 Oct 21, 2019
@seamuslee001 seamuslee001 deleted the pay_check branch October 21, 2019 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants