diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index dfa3ba6..e3d1afd 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -280,15 +280,30 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration ]; } - foreach ($wc_payment->payment_gateways() as $payment) { + foreach ($wc_payment->get_available_payment_gateways() as $payment) { + $title = ''; + $description = ''; + + if (empty($payment->method_title)) { + $title = $payment->id; + } else { + $title = $payment->method_title; + } + + if (empty($payment->method_description)) { + $description = $payment->description; + } else { + $description = $payment->method_description; + } + $this->form_fields[$payment->id] = [ 'css' => 'min-width:350px;', 'type' => 'select', - 'title' => __($payment->method_title, 'woocommerce'), + 'title' => __($title, 'woocommerce'), 'class' => 'select', 'options' => $paymentsList, 'desc_tip' => true, - 'description' => __($payment->method_description, 'woocommerce'), + 'description' => __($description, 'woocommerce'), ]; } } diff --git a/tests/abstracts/test-wc-retailcrm-abstract-builder.php b/tests/abstracts/test-wc-retailcrm-abstract-builder.php index 15ae18f..3671846 100644 --- a/tests/abstracts/test-wc-retailcrm-abstract-builder.php +++ b/tests/abstracts/test-wc-retailcrm-abstract-builder.php @@ -45,6 +45,50 @@ class WC_Retailcrm_Abstracts_Settings_Test extends WC_Retailcrm_Test_Case_Helpe } } + public function test_validate_payments() + { + $paymentGateway = new WC_Payment_Gateways(); + + $enabledPayments = $paymentGateway->get_available_payment_gateways(); + $this->assertCount(0, $enabledPayments); + + $payments = $paymentGateway->payment_gateways(); + $keys = array_keys($payments); + $payments[$keys[0]]->method_title = null; + $payments[$keys[2]]->method_description = null; + $preparePayments = []; + + foreach ($payments as $payment) { + $title = ''; + $description = ''; + + if (empty($payment->method_title)) { + $title = $payment->id; + } else { + $title = $payment->method_title; + } + + if (empty($payment->method_description)) { + $description = $payment->description; + } else { + $description = $payment->method_description; + } + + $preparePayments[$payment->id] = [ + 'css' => 'min-width:350px;', + 'type' => 'select', + 'title' => $title, + 'class' => 'select', + 'desc_tip' => true, + 'description' => $description, + ]; + } + + $this->assertEquals($payments[$keys[0]]->id, $preparePayments[$keys[0]]['title']); + $this->assertEquals($payments[$keys[2]]->description, $preparePayments[$keys[2]]['description']); + + + } public function dataProviderAssistant() {