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

d8 port of #180- Use the payment processor payment method instead of the default c… #471

Merged
merged 3 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/WebformCivicrmPostProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -1977,13 +1977,6 @@ private function createDeferredPayment() {
$params = $this->contributionParams();
$params['contribution_status_id'] = 'Pending';
$params['is_pay_later'] = $this->contributionIsPayLater;
//Fix IPN payments marked as paid by cheque
if (empty($params['payment_instrument_id'])) {
if (!empty($params['payment_processor_id'])) {
$defaultPaymentInstrument = \CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1');
$params['payment_instrument_id'] = key($defaultPaymentInstrument);
}
}

$numInstallments = wf_crm_aval($params, 'installments', NULL, TRUE);
$frequencyInterval = wf_crm_aval($params, 'frequency_unit');
Expand Down Expand Up @@ -2148,6 +2141,9 @@ private function contributionParams() {
'domain_id' => $domain,
));
}
if (empty($params['payment_instrument_id']) && !empty($params['payment_processor_id'])) {
Copy link
Collaborator Author

@jitendrapurohit jitendrapurohit Feb 9, 2021

Choose a reason for hiding this comment

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

included the changes from #289 which was a fix for the regression caused by #180

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jitendrapurohit - can you please add a few lines to the ContributionIatsTest -> section line 180-186 to check that with this PR the payment_instrument_id is indeed no longer check (default) but credit card?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Thanks for the pointer 👍 @KarinG

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome - it's just a few lines but nice to secure this 👍

$params['payment_instrument_id'] = $this->getPaymentInstrument($params['payment_processor_id']);
}

// doPayment requries payment_processor and payment_processor_mode fields.
$params['payment_processor'] = wf_crm_aval($params, 'payment_processor_id');
Expand Down Expand Up @@ -2698,4 +2694,15 @@ private function unsetEmptyValueIndexes($values, $entity) {

return $values;
}

/**
* Retrieve payment instrument.
*
* @param int $paymentProcessorId
*/
private function getPaymentInstrument($paymentProcessorId) {
$processor = \Civi\Payment\System::singleton()->getById($paymentProcessorId);
return $processor->getPaymentInstrumentID();
}

}
8 changes: 7 additions & 1 deletion tests/src/FunctionalJavascript/ContributionIatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,16 @@ public function testSubmitContribution() {
// Also retrieve tax_amount (have to ask for it to be returned):
$api_result = $utils->wf_civicrm_api('contribution', 'get', [
'sequential' => 1,
'return' => 'tax_amount',
'return' => ['tax_amount', 'payment_instrument_id'],
]);
$contribution = reset($api_result['values']);
$creditCardID = $utils->wf_civicrm_api('OptionValue', 'getvalue', [
'return' => "value",
'label' => "Credit Card",
'option_group_id' => "payment_instrument",
]);
$this->assertEquals('1.48', $contribution['tax_amount']);
$this->assertEquals($creditCardID, $contribution['payment_instrument_id']);
$tax_total_amount = $contribution['tax_amount'];

$api_result = $utils->wf_civicrm_api('line_item', 'get', [
Expand Down