+--------------------------------------------------------------------+
*/
+use Civi\Api4\PaymentProcessor;
+
/**
* Upgrade logic for the 5.64.x series.
*
$this->addTask('Drop unused civicrm_action_mapping table', 'dropTable', 'civicrm_action_mapping');
$this->addTask('Update post_URL/cancel_URL in logging tables', 'updateLogging');
$this->addTask('Add in Everybody ACL Role option value', 'addEveryBodyAclOptionValue');
+ $this->addTask('Fix double json encoding of accepted_credit_cards field in payment processor table', 'fixDoubleEscapingPaymentProcessorCreditCards');
}
public static function updateLogging($ctx): bool {
return TRUE;
}
+ /**
+ * Fix any double json encoding in Payment Processor accepted_credit_cards field
+ */
+ public static function fixDoubleEscapingPaymentProcessorCreditCards() {
+ $paymentProcessors = PaymentProcessor::get(FALSE)->execute();
+ foreach ($paymentProcessors as $paymentProcessor) {
+ if (is_numeric(array_keys($paymentProcessor['accepted_credit_cards'])[0])) {
+ PaymentProcessor::update(FALSE)->addValue('accepted_credit_cards', json_decode($paymentProcessor['accepted_credit_cards'], TRUE))->addWhere('id', '=', $paymentProcessor['id'])->execute();
+ }
+ }
+ return TRUE;
+ }
+
}
--- /dev/null
+<?php
+
+use Civi\Api4\PaymentProcessor;
+
+/**
+ * Class CRM_Upgrade_Incremental_php_FiveSixtyFour
+ * @group headless
+ */
+class CRM_Upgrade_Incremental_php_FiveSixtyFourTest extends CiviUnitTestCase {
+
+ use CRM_Core_Payment_AuthorizeNetTrait;
+
+ /**
+ * Test that fixing the double json encode works as expected
+ */
+ public function testFixDobuleJsonEncode() {
+ $this->createAuthorizeNetProcessor();
+ $this->paymentProcessorAuthorizeNetCreate();
+ $creditCards = [
+ 'visa' => 'visa',
+ 'mastercard' => 'mastercard',
+ ];
+ PaymentProcessor::update()->addValue('accepted_credit_cards', $creditCards)->addWhere('id', '=', $this->ids['PaymentProcessor']['anet'])->execute();
+ PaymentProcessor::update()->addValue('accepted_credit_cards', json_encode($creditCards))->addWhere('id', '=', $this->ids['PaymentProcessor']['authorize_net'])->execute();
+ CRM_Upgrade_Incremental_php_FiveSixtyFour::fixDoubleEscapingPaymentProcessorCreditCards();
+ $paymentProcessors = PaymentProcessor::get()->execute();
+ foreach ($paymentProcessors as $paymentProcessor) {
+ $this->assertEquals($creditCards, $paymentProcessor['accepted_credit_cards']);
+ }
+ }
+
+}