diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index e75c247..2519584 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -310,4 +310,11 @@ msgstr "Sincronización de inventario" msgid "Don't send to CRM" msgstr "No enviar al CRM" +msgid "Integration payment" +msgstr "Integración pago" +msgid "Attention!" +msgstr "¡Atención!" + +msgid "If payment type linked to the CRM integration module choosed, payment must be proceed in the CRM" +msgstr "Al seleccionar en el enlace de tipos de pago un método de pago de integración en CRM, el pago se debe realizar por parte del CRM" \ No newline at end of file diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 72ddc7b..d0713cd 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -319,6 +319,14 @@ msgstr "Синхронизация запасов" msgid "Don't send to CRM" msgstr "Не отправлять в CRM" +msgid "Integration payment" +msgstr "Интеграционная оплата" + +msgid "Attention!" +msgstr "Внимание!" + +msgid "If payment type linked to the CRM integration module choosed, payment must be proceed in the CRM" +msgstr "При указании в соответствии типа оплаты, привязанного к интеграционному модулю в CRM, оплата должна происходить на стороне CRM" diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index e9b97ff..b2f2fce 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -175,7 +175,7 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration /** * Shipping options */ - $shipping_option_list = array(); + $shipping_option_list = []; $retailcrm_shipping_list = $this->apiClient->deliveryTypesList(); if (!empty($retailcrm_shipping_list) && $retailcrm_shipping_list->isSuccessful()) { @@ -189,12 +189,12 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration $wc_shipping_list = get_wc_shipping_methods(); - $this->form_fields[] = array( + $this->form_fields[] = [ 'title' => __('Delivery types', 'retailcrm'), 'type' => 'heading', 'description' => '', 'id' => 'shipping_options' - ); + ]; foreach ($wc_shipping_list as $shipping_code => $shipping) { if (isset($shipping['enabled']) && $shipping['enabled'] == static::YES) { @@ -214,40 +214,64 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration /** * Payment options */ - $payment_option_list = array(); - $retailcrm_payment_list = $this->apiClient->paymentTypesList(); + $crmPaymentsList = $this->apiClient->paymentTypesList(); - if (!empty($retailcrm_payment_list) && $retailcrm_payment_list->isSuccessful()) { - foreach ($retailcrm_payment_list['paymentTypes'] as $retailcrm_payment_type) { - if ($retailcrm_payment_type['active'] == false) { + if (!empty($crmPaymentsList) && $crmPaymentsList->isSuccessful()) { + $paymentsList = []; + $integrationPayments = []; + + foreach ($crmPaymentsList['paymentTypes'] as $crmPaymentType) { + if ($crmPaymentType['active'] == false) { continue; } - $payment_option_list[$retailcrm_payment_type['code']] = $retailcrm_payment_type['name']; + if (isset($crmPaymentType['integrationModule'])) { + $integrationPayments['code'][] = $crmPaymentType['code']; + $integrationPayments['name'][] = $crmPaymentType['name']; + + $crmPaymentType['name'] .= ' - ' . __('Integration payment', 'retailcrm'); + } + + $paymentsList[$crmPaymentType['code']] = $crmPaymentType['name']; } $wc_payment = WC_Payment_Gateways::instance(); - $this->form_fields[] = array( - 'title' => __('Payment types', 'retailcrm'), - 'type' => 'heading', - 'description' => '', - 'id' => 'payment_options' - ); + $this->form_fields[] = [ + 'id' => 'payment_options', + 'type' => 'heading', + 'title' => __('Payment types', 'retailcrm'), + ]; + + if (!empty($integrationPayments['name'])) { + $this->form_fields['payment_notification'] = [ + 'id' => 'payment_options', + 'css' => 'max-width:400px;resize: none;', + 'type' => 'textarea', + 'title' => __('Attention!', 'retailcrm'), + 'value' => '', + 'placeholder' => __('If payment type linked to the CRM integration module choosed, payment must be proceed in the CRM', 'retailcrm'), + 'custom_attributes' => ['readonly' => 'readonly'], + ]; + } foreach ($wc_payment->payment_gateways() as $payment) { - $this->form_fields[$payment->id] = array( - 'title' => __($payment->method_title, 'woocommerce'), - 'description' => __($payment->method_description, 'woocommerce'), - 'css' => 'min-width:350px;', - 'class' => 'select', - 'type' => 'select', - 'options' => $payment_option_list, + $this->form_fields[$payment->id] = [ + 'css' => 'min-width:350px;', + 'type' => 'select', + 'title' => __($payment->method_title, 'woocommerce'), + 'class' => 'select', + 'options' => $paymentsList, 'desc_tip' => true, - ); + 'description' => __($payment->method_description, 'woocommerce'), + ]; } } + if (!empty($integrationPayments['code'])) { + update_option('retailcrm_integration_payments', $integrationPayments['code']); + } + /** * Statuses options */ diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index e15fb5f..2a96e1d 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -39,13 +39,13 @@ if (!class_exists('WC_Retailcrm_Orders')) : private $ordersGetRequestCache = array(); /** @var array */ - private $order = array(); + private $order = []; /** @var array */ - private $payment = array(); + private $payment = []; /**@var array */ - private $customFields = array(); + private $customFields = []; public function __construct( $retailcrm, @@ -290,29 +290,31 @@ if (!class_exists('WC_Retailcrm_Orders')) : $retailcrmOrder = $this->getCrmOrder($order->get_id()); - if (!empty($retailcrmOrder)) { - foreach ($retailcrmOrder['payments'] as $payment_data) { - $payment_external_id = explode('-', $payment_data['externalId']); + if (empty($retailcrmOrder)) { + return null; + } - if ($payment_external_id[0] == $order->get_id()) { - $payment = $payment_data; - } + foreach ($retailcrmOrder['payments'] as $paymentData) { + $paymentId = explode('-', $paymentData['externalId']); + + if ($paymentId[0] == $order->get_id()) { + $payment = $paymentData; } } - if (isset($payment) && $payment['type'] == $this->retailcrm_settings[$order->get_payment_method()] && $order->is_paid()) { - $payment = $this->sendPayment($order, true, $payment['externalId']); - - return $payment; + if (empty($payment)) { + return null; } - if (isset($payment) && $payment['type'] != $this->retailcrm_settings[$order->get_payment_method()]) { + if ($payment['type'] == $this->retailcrm_settings[$order->get_payment_method()] && $order->is_paid()) { + return $this->sendPayment($order, true, $payment['externalId']); + } + + if ($payment['type'] != $this->retailcrm_settings[$order->get_payment_method()]) { $response = $this->retailcrm->ordersPaymentDelete($payment['id']); if (!empty($response) && $response->isSuccessful()) { - $payment = $this->sendPayment($order); - - return $payment; + return $this->sendPayment($order); } } @@ -362,11 +364,11 @@ if (!class_exists('WC_Retailcrm_Orders')) : $service = retailcrm_get_delivery_service($shipping['method_id'], $shipping['instance_id']); if ($service) { - $orderData['delivery']['service'] = array( + $orderData['delivery']['service'] = [ 'name' => $service['title'], 'code' => $service['instance_id'], 'active' => true - ); + ]; } } @@ -380,17 +382,16 @@ if (!class_exists('WC_Retailcrm_Orders')) : } $orderData['delivery']['address'] = $this->order_address->build($order)->get_data(); - $order_items = array(); + $orderItems = []; /** @var WC_Order_Item_Product $item */ foreach ($order->get_items() as $item) { - $order_items[] = $this->order_item->build($item)->get_data(); + $orderItems[] = $this->order_item->build($item)->get_data(); $this->order_item->reset_data(); } - $orderData['items'] = $order_items; - - $orderData['discountManualAmount'] = 0; + $orderData['items'] = $orderItems; + $orderData['discountManualAmount'] = 0; $orderData['discountManualPercent'] = 0; if (!$update && $order->get_total() > 0) { @@ -432,6 +433,16 @@ if (!class_exists('WC_Retailcrm_Orders')) : $this->order_payment->is_new = !$update; $payment = $this->order_payment->build($order, $externalId)->get_data(); + $integrationPayments = get_option('retailcrm_integration_payments'); + + if (is_array($integrationPayments)) { + $integrationPayments = array_flip($integrationPayments); + } + + if ($update === true && isset($integrationPayments[$payment['type']])) { + return $payment; + } + if ($update === false) { $this->retailcrm->ordersPaymentCreate($payment); } else { diff --git a/src/include/order/class-wc-retailcrm-order-payment.php b/src/include/order/class-wc-retailcrm-order-payment.php index 3e621e0..bcedb30 100644 --- a/src/include/order/class-wc-retailcrm-order-payment.php +++ b/src/include/order/class-wc-retailcrm-order-payment.php @@ -49,7 +49,7 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data public function build($order, $externalId = false) { $this->reset_data(); - $data = array(); + $data = []; if (!$this->is_new) { $data['externalId'] = $externalId; @@ -57,9 +57,9 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data $data['externalId'] = uniqid($order->get_id() . "-"); } - $data['order'] = array( + $data['order'] = [ 'externalId' => $order->get_id() - ); + ]; if ($order->is_paid()) { $data['status'] = 'paid'; @@ -77,7 +77,7 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data if (isset($this->settings[$order->get_payment_method()])) { $data['type'] = $this->settings[$order->get_payment_method()]; } else { - $data = array(); + $data = []; } } diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo index 54ed902..3af405c 100644 Binary files a/src/languages/retailcrm-es_ES.mo and b/src/languages/retailcrm-es_ES.mo differ diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index 34b6ffa..2b07ad7 100644 Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ diff --git a/tests/datasets/data-base-retailcrm.php b/tests/datasets/data-base-retailcrm.php index f790000..e70e6b4 100644 --- a/tests/datasets/data-base-retailcrm.php +++ b/tests/datasets/data-base-retailcrm.php @@ -17,77 +17,86 @@ class DataBaseRetailCrm { public static function getResponseStatuses() { - return array( + return [ 'success' => true, - 'statuses' => array( - array( + 'statuses' => [ + [ 'name' => 'status1', 'code' => 'status1', 'active' => true - ), - array( + ], + [ 'name' => 'status2', 'code' => 'status2', 'active' => false - ) - ) - ); + ] + ] + ]; } public static function getResponsePaymentTypes() { - return array( + return [ 'success' => true, - 'paymentTypes' => array( - array( + 'paymentTypes' => [ + [ 'name' => 'payment1', 'code' => 'payment1', 'active' => true - ), - array( + ], + [ 'name' => 'payment2', 'code' => 'payment2', 'active' => false - ) - ) - ); + ], + [ + 'name' => 'payment3', + 'code' => 'payment3', + 'integrationModule' => [ + 'name' => 'test', + 'active' => true, + ], + 'active' => true + ], + ] + ]; } public static function getResponseDeliveryTypes() { - return array( + return [ 'success' => true, - 'deliveryTypes' => array( - array( + 'deliveryTypes' => [ + [ 'name' => 'delivery1', 'code' => 'delivery1', 'active' => true - ), - array( + ], + [ 'name' => 'delivery2', 'code' => 'delivery2', 'active' => false - ) - ) - ); + ] + ] + ]; } public static function getResponseOrderMethods() { - return array( + return [ 'success' => true, - 'orderMethods' => array( - array( + 'orderMethods' => [ + [ 'name' => 'orderMethod1', 'code' => 'orderMethod1', 'active' => true - ), - array( + ], + [ 'name' => 'orderMethod2', 'code' => 'orderMethod2', 'active' => false - ) - ) - ); + ] + ] + ]; } -} \ No newline at end of file +} diff --git a/tests/test-wc-retailcrm-base.php b/tests/test-wc-retailcrm-base.php index c514192..6e97d95 100644 --- a/tests/test-wc-retailcrm-base.php +++ b/tests/test-wc-retailcrm-base.php @@ -76,29 +76,49 @@ class WC_Retailcrm_Base_Test extends WC_Retailcrm_Test_Case_Helper } } + $integrationPayments = get_option('retailcrm_integration_payments'); + + $this->assertNotEmpty($integrationPayments); + $this->assertInternalType('array', $integrationPayments); + $this->assertEquals('payment3', $integrationPayments[0]); + foreach (wc_get_order_statuses() as $idx => $name) { $uid = str_replace('wc-', '', $idx); $this->assertArrayHasKey($uid, $this->baseRetailcrm->form_fields); } - $this->assertArrayHasKey('corporate_enabled', $this->baseRetailcrm->form_fields); - $this->assertArrayHasKey('online_assistant', $this->baseRetailcrm->form_fields); - + //Order settings $this->assertArrayHasKey('order_methods', $this->baseRetailcrm->form_fields); $this->assertInternalType('array', $this->baseRetailcrm->form_fields['order_methods']); + //Payment settings + $this->assertArrayHasKey('payment_notification', $this->baseRetailcrm->form_fields); + $this->assertInternalType('array', $this->baseRetailcrm->form_fields['payment_notification']); + $this->assertEquals('textarea', $this->baseRetailcrm->form_fields['payment_notification']['type']); + + //WhatsApp settings $this->assertArrayHasKey('whatsapp_active', $this->baseRetailcrm->form_fields); $this->assertArrayHasKey('whatsapp_location_icon', $this->baseRetailcrm->form_fields); $this->assertArrayHasKey('whatsapp_number', $this->baseRetailcrm->form_fields); + + //Cron settings $this->assertArrayHasKey('icml', $this->baseRetailcrm->form_fields); + $this->assertArrayHasKey('history', $this->baseRetailcrm->form_fields); + + //Export orders/customers settings $this->assertArrayHasKey('export_selected_orders_ids', $this->baseRetailcrm->form_fields); $this->assertArrayHasKey('export_selected_orders_btn', $this->baseRetailcrm->form_fields); - $this->assertArrayHasKey('history', $this->baseRetailcrm->form_fields); + + //Debug info settings + $this->assertArrayHasKey('debug_mode', $this->baseRetailcrm->form_fields); + $this->assertArrayHasKey('debug-info', $this->baseRetailcrm->form_fields); + + //Other settings + $this->assertArrayHasKey('corporate_enabled', $this->baseRetailcrm->form_fields); + $this->assertArrayHasKey('online_assistant', $this->baseRetailcrm->form_fields); $this->assertArrayHasKey('deactivate_update_order', $this->baseRetailcrm->form_fields); $this->assertArrayHasKey('bind_by_sku', $this->baseRetailcrm->form_fields); $this->assertArrayHasKey('update_number', $this->baseRetailcrm->form_fields); - $this->assertArrayHasKey('debug_mode', $this->baseRetailcrm->form_fields); - $this->assertArrayHasKey('debug-info', $this->baseRetailcrm->form_fields); } public function test_retailcrm_form_fields_value() diff --git a/tests/test-wc-retailcrm-orders.php b/tests/test-wc-retailcrm-orders.php index 66c1c12..c6d649e 100644 --- a/tests/test-wc-retailcrm-orders.php +++ b/tests/test-wc-retailcrm-orders.php @@ -241,8 +241,10 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper $this->assertEquals('US', $orderData['countryIso']); $this->assertEquals(0, $orderData['discountManualAmount']); $this->assertEquals(0, $orderData['discountManualPercent']); + $this->assertEquals($orderData['customFields']['crm_order'], 'test_custom_fields'); + if (mb_strlen($orderData['delivery']['address']['index']) === 6) { $this->assertEquals('123456', $orderData['delivery']['address']['index']); } else { @@ -263,7 +265,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper $this->assertEquals('payment1', $payment['type']); $this->assertArrayNotHasKey('amount', $payment); } else { - $this->assertEquals(array(), $payment); + $this->assertEquals([], $payment); } } else { $this->assertEquals(null, $order);