Skip to content

Commit

Permalink
doPayment params - munge country / country_id into billingCountry
Browse files Browse the repository at this point in the history
  • Loading branch information
ufundo committed Jul 10, 2024
1 parent c7b6b32 commit d4e1d65
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/WebformCivicrmPostProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,21 @@ private function submitIPNPayment() {
}
}
}

// doPayment using PropertyBag expects an iso_code in the 'billingCountry' param
$countryName = $params['country'] ?? NULL;
$countryId = $params['country_id'] ?? NULL;
// providing country name throws deprecation warnings, which break the transaction
unset($params['country']);

// country id seems more reliable, so use that first
if ($countryId) {
$params['billingCountry'] = \Civi\Api4\Country::get(FALSE)->addSelect('iso_code')->addWhere('id', '=', $countryId)->execute()->first()['iso_code'] ?? '';
}
elseif ($countryName) {
$params['billingCountry'] = \Civi\Api4\Country::get(FALSE)->addSelect('iso_code')->addWhere('name', '=', $countryName)->execute()->first()['iso_code'] ?? '';
}

// Ideally we would pass the correct id for the test processor through but that seems not to be the
// case so load it here.
if (!empty($params['is_test'])) {
Expand Down

0 comments on commit d4e1d65

Please sign in to comment.