From d4e1d6578af3f54c57bb35b14bbff2a4350df8ee Mon Sep 17 00:00:00 2001 From: benjamin Date: Wed, 10 Jul 2024 18:20:45 +0100 Subject: [PATCH] doPayment params - munge country / country_id into billingCountry --- src/WebformCivicrmPostProcess.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/WebformCivicrmPostProcess.php b/src/WebformCivicrmPostProcess.php index e1231eca..39eb2749 100644 --- a/src/WebformCivicrmPostProcess.php +++ b/src/WebformCivicrmPostProcess.php @@ -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'])) {