1
0
mirror of synced 2025-01-19 01:11:42 +03:00

Add support for payment method on delivery

This commit is contained in:
Dima Uryvskiy 2022-08-11 21:17:55 +03:00 committed by GitHub
parent 9d8eb2256c
commit 91a7c02e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 198 additions and 89 deletions

View File

@ -1,3 +1,6 @@
## 2022-08-10 4.4.7
* Add support for payment method on delivery
## 2022-08-06 4.4.6 ## 2022-08-06 4.4.6
* Add automatically upload ICML in CRM * Add automatically upload ICML in CRM
* Add filter for changing ICML product information * Add filter for changing ICML product information

View File

@ -1 +1 @@
4.4.6 4.4.7

View File

@ -475,7 +475,7 @@ if (!class_exists('WC_Retailcrm_Orders')) :
return (array) $this->ordersGetRequestCache[$orderId]; return (array) $this->ordersGetRequestCache[$orderId];
} }
$crmOrder = array(); $crmOrder = [];
$response = $this->retailcrm->ordersGet($orderId); $response = $this->retailcrm->ordersGet($orderId);
if (!empty($response) && $response->isSuccessful() && isset($response['order'])) { if (!empty($response) && $response->isSuccessful() && isset($response['order'])) {

View File

@ -170,7 +170,7 @@ function getShippingRates()
/** /**
* Write base logs in retailcrm file. * Write base logs in retailcrm file.
* *
* @codeCoverageIgnore Check in another tests * @codeCoverageIgnore
*/ */
function writeBaseLogs($message) function writeBaseLogs($message)
{ {

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* PHP version 5.6 * PHP version 5.6
* *
@ -59,19 +60,32 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data
]; ];
if ($order->is_paid()) { if ($order->is_paid()) {
$paymentData['status'] = 'paid'; if ($order->get_status() != 'completed' && $order->get_payment_method() == 'cod') {
writeBaseLogs(
implode(
' ',
[
'Payment for order: ' . $order->get_id(),
'Payment status cannot be changed as it is cash (or other payment method) on delivery.',
'The status will be changed when the order is in status completed.',
]
)
);
} else {
$paymentData['status'] = 'paid';
if (isset($this->settings[$order->get_payment_method()])) { if (isset($this->settings[$order->get_payment_method()])) {
$paymentData['type'] = $this->settings[$order->get_payment_method()]; $paymentData['type'] = $this->settings[$order->get_payment_method()];
}
$paidAt = $order->get_date_paid();
if (!empty($paidAt)) {
$paymentData['paidAt'] = $paidAt->date('Y-m-d H:i:s');
}
} }
} }
$paidAt = $order->get_date_paid();
if (!empty($paidAt)) {
$paymentData['paidAt'] = $paidAt->date('Y-m-d H:i:s');
}
if ($this->isNew) { if ($this->isNew) {
if (isset($this->settings[$order->get_payment_method()])) { if (isset($this->settings[$order->get_payment_method()])) {
$paymentData['type'] = $this->settings[$order->get_payment_method()]; $paymentData['type'] = $this->settings[$order->get_payment_method()];
@ -80,6 +94,12 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data
} }
} }
$paymentData = apply_filters(
'retailcrm_process_payment',
WC_Retailcrm_Plugin::clearArray($paymentData),
$order
);
$this->set_data_fields($paymentData); $this->set_data_fields($paymentData);
return $this; return $this;

View File

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 5.6 Requires PHP: 5.6
Requires at least: 5.3 Requires at least: 5.3
Tested up to: 5.9 Tested up to: 5.9
Stable tag: 4.4.5 Stable tag: 4.4.7
License: GPLv1 or later License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html License URI: http://www.gnu.org/licenses/gpl-1.0.html
@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
== Changelog == == Changelog ==
= 4.4.7 =
* Add support for payment method on delivery
= 4.4.6 = = 4.4.6 =
* Add automatically upload ICML in CRM * Add automatically upload ICML in CRM
* Add filter for changing ICML product information * Add filter for changing ICML product information

View File

@ -5,7 +5,7 @@
* Description: Integration plugin for WooCommerce & Simla.com * Description: Integration plugin for WooCommerce & Simla.com
* Author: RetailDriver LLC * Author: RetailDriver LLC
* Author URI: http://retailcrm.pro/ * Author URI: http://retailcrm.pro/
* Version: 4.4.6 * Version: 4.4.7
* Tested up to: 5.9 * Tested up to: 5.9
* WC requires at least: 5.4 * WC requires at least: 5.4
* WC tested up to: 6.7 * WC tested up to: 6.7

View File

@ -16,7 +16,7 @@
* *
* @link https://wordpress.org/plugins/woo-retailcrm/ * @link https://wordpress.org/plugins/woo-retailcrm/
* *
* @version 4.4.6 * @version 4.4.7
* *
* @package RetailCRM * @package RetailCRM
*/ */

View File

@ -21,7 +21,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy') $this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods( ->setMethods(
array( [
'ordersGet', 'ordersGet',
'ordersCreate', 'ordersCreate',
'ordersEdit', 'ordersEdit',
@ -37,7 +37,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
'getSingleSiteForKey', 'getSingleSiteForKey',
'customersCorporateAddressesCreate', 'customersCorporateAddressesCreate',
'customersCorporateCompaniesCreate' 'customersCorporateCompaniesCreate'
) ]
) )
->getMock(); ->getMock();
@ -130,10 +130,10 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->setMockResponse($responseMockSearch, 'isSuccessful', true); $this->setMockResponse($responseMockSearch, 'isSuccessful', true);
$responseMockSearch->setResponse( $responseMockSearch->setResponse(
array( [
'success' => true, 'success' => true,
'customersCorporate' => array() 'customersCorporate' => []
) ]
); );
// Mock response for create customer corporate, his addresses and companies // Mock response for create customer corporate, his addresses and companies
@ -141,10 +141,10 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->setMockResponse($responseMockCustomerCorporate, 'isSuccessful', true); $this->setMockResponse($responseMockCustomerCorporate, 'isSuccessful', true);
$responseMockCustomerCorporate->setResponse( $responseMockCustomerCorporate->setResponse(
array( [
'success' => true, 'success' => true,
'id' => 1 'id' => 1
) ]
); );
// Mock response for get companies // Mock response for get companies
@ -152,12 +152,12 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->setMockResponse($responseMockCompany, 'isSuccessful', true); $this->setMockResponse($responseMockCompany, 'isSuccessful', true);
$responseMockCompany->setResponse( $responseMockCompany->setResponse(
array( [
'success' => true, 'success' => true,
'companies' => array( 'companies' => [
array('name' => 'WooCompany', 'id' => 777) ['name' => 'WooCompany', 'id' => 777]
) ]
) ]
); );
$this->setMockResponse($retailcrm, 'ordersCreate', $responseMock); $this->setMockResponse($retailcrm, 'ordersCreate', $responseMock);
@ -325,6 +325,89 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
} }
} }
/**
* @param $isSuccessful
* @param $retailcrm
*
* @throws Exception
* @dataProvider dataProviderUpdateOrder
*/
public function test_payment_on_delivery($isSuccessful, $retailcrm)
{
$this->createTestOrder();
$this->order->set_payment_method('cod');
$this->order->save();
if ($retailcrm) {
$responseMock = $this->createResponseMock();
$this->setMockResponse($responseMock, 'isSuccessful', $isSuccessful);
$this->setMockResponse($retailcrm, 'ordersEdit', $responseMock);
$this->setMockResponse($retailcrm, 'ordersPaymentDelete', $responseMock);
$response = $this->getResponseData($this->order->get_id());
$responseMock->setResponse($response);
$this->setMockResponse($retailcrm, 'ordersGet', $responseMock);
}
$retailcrmOrders = $this->getRetailcrmOrders($retailcrm);
$order = $retailcrmOrders->updateOrder($this->order->get_id());
$orderData = $retailcrmOrders->getOrder();
if ($retailcrm) {
$this->assertInstanceOf('WC_Order', $order);
$this->assertInternalType('array', $orderData);
$payment = $retailcrmOrders->getPayment();
$this->assertInternalType('array', $payment);
if (!empty($payment)) {
$this->assertArrayHasKey('type', $payment);
$this->assertArrayHasKey('order', $payment);
$this->assertArrayHasKey('externalId', $payment);
$this->assertEquals('payment3', $payment['type']);
$this->assertArrayNotHasKey('amount', $payment);
$this->assertArrayNotHasKey('status', $payment);
$this->assertArrayNotHasKey('paidAt', $payment);
} else {
$this->assertEquals([], $payment);
}
// Check payment status
$this->order->set_status('completed');
$this->order->save();
$order = $retailcrmOrders->updateOrder($this->order->get_id());
$orderData = $retailcrmOrders->getOrder();
$this->assertInstanceOf('WC_Order', $order);
$this->assertInternalType('array', $orderData);
$this->assertArrayHasKey('status', $orderData);
$this->assertEquals('status4', $orderData['status']);
$payment = $retailcrmOrders->getPayment();
$this->assertInternalType('array', $payment);
if (!empty($payment)) {
$this->assertArrayHasKey('type', $payment);
$this->assertArrayHasKey('order', $payment);
$this->assertArrayHasKey('externalId', $payment);
$this->assertArrayHasKey('status', $payment);
$this->assertArrayHasKey('paidAt', $payment);
$this->assertEquals('payment3', $payment['type']);
$this->assertEquals('paid', $payment['status']);
} else {
$this->assertEquals([], $payment);
}
} else {
$this->assertEquals(null, $order);
}
}
public function test_is_corporate_order() public function test_is_corporate_order()
{ {
$this->createTestOrder(); $this->createTestOrder();
@ -358,11 +441,11 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals( $this->assertEquals(
true, true,
WC_Retailcrm_Orders::isCorporateCrmOrder( WC_Retailcrm_Orders::isCorporateCrmOrder(
array( [
'customer' => array( 'customer' => [
'type' => 'customer_corporate' 'type' => 'customer_corporate'
) ]
) ]
) )
); );
@ -370,11 +453,11 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals( $this->assertEquals(
false, false,
WC_Retailcrm_Orders::isCorporateCrmOrder( WC_Retailcrm_Orders::isCorporateCrmOrder(
array( [
'customer' => array( 'customer' => [
'type' => 'customer' 'type' => 'customer'
) ]
) ]
) )
); );
} }
@ -390,11 +473,11 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
true, true,
WC_Retailcrm_Orders::isOrderCustomerWasChanged( WC_Retailcrm_Orders::isOrderCustomerWasChanged(
$this->order, $this->order,
array( [
'customer' => array( 'customer' => [
'type' => 'customer' 'type' => 'customer'
) ]
) ]
) )
); );
@ -403,14 +486,14 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
true, true,
WC_Retailcrm_Orders::isOrderCustomerWasChanged( WC_Retailcrm_Orders::isOrderCustomerWasChanged(
$this->order, $this->order,
array( [
'customer' => array( 'customer' => [
'type' => 'customer_corporate' 'type' => 'customer_corporate'
), ],
'company' => array( 'company' => [
'name' => 'Test1' 'name' => 'Test1'
) ]
) ]
) )
); );
@ -421,15 +504,15 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
true, true,
WC_Retailcrm_Orders::isOrderCustomerWasChanged( WC_Retailcrm_Orders::isOrderCustomerWasChanged(
$this->order, $this->order,
array( [
'customer' => array( 'customer' => [
'type' => 'customer_corporate', 'type' => 'customer_corporate',
'externalId' => 2 'externalId' => 2
), ],
'company' => array( 'company' => [
'name' => 'Test' 'name' => 'Test'
) ]
) ]
) )
); );
@ -440,16 +523,16 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
true, true,
WC_Retailcrm_Orders::isOrderCustomerWasChanged( WC_Retailcrm_Orders::isOrderCustomerWasChanged(
$this->order, $this->order,
array( [
'customer' => array( 'customer' => [
'type' => 'customer_corporate', 'type' => 'customer_corporate',
'externalId' => 1, 'externalId' => 1,
'email' => 'test1@mail.es' 'email' => 'test1@mail.es'
), ],
'company' => array( 'company' => [
'name' => 'Test' 'name' => 'Test'
) ]
) ]
) )
); );
@ -458,16 +541,16 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
false, false,
WC_Retailcrm_Orders::isOrderCustomerWasChanged( WC_Retailcrm_Orders::isOrderCustomerWasChanged(
$this->order, $this->order,
array( [
'customer' => array( 'customer' => [
'type' => 'customer_corporate', 'type' => 'customer_corporate',
'externalId' => 1, 'externalId' => 1,
'email' => 'test@mail.es' 'email' => 'test@mail.es'
), ],
'company' => array( 'company' => [
'name' => 'Test' 'name' => 'Test'
) ]
) ]
) )
); );
} }
@ -476,38 +559,38 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
{ {
$this->setUp(); $this->setUp();
return array( return [
array( [
'is_successful' => true, 'is_successful' => true,
'retailcrm' => $this->apiMock 'retailcrm' => $this->apiMock
), ],
array( [
'is_successful' => true, 'is_successful' => true,
'retailcrm' => false 'retailcrm' => false
), ],
array( [
'is_successful' => false, 'is_successful' => false,
'retailcrm' => false 'retailcrm' => false
), ],
array( [
'is_successful' => false, 'is_successful' => false,
'retailcrm' => $this->apiMock 'retailcrm' => $this->apiMock
) ]
); ];
} }
public function dataProviderRetailcrm() public function dataProviderRetailcrm()
{ {
$this->setUp(); $this->setUp();
return array( return [
array( [
'retailcrm' => $this->apiMock 'retailcrm' => $this->apiMock
), ],
array( [
'retailcrm' => false 'retailcrm' => false
) ]
); ];
} }
private function createTestOrder() private function createTestOrder()
@ -528,18 +611,18 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
private function getResponseData($externalId) private function getResponseData($externalId)
{ {
return array( return [
'success' => true, 'success' => true,
'order' => array( 'order' => [
'payments' => array( 'payments' => [
array( [
'id' => 1, 'id' => 1,
'externalId' => $externalId, 'externalId' => $externalId,
'type' => 'payment2' 'type' => 'payment2'
) ]
) ]
) ]
); ];
} }
/** /**
@ -572,7 +655,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
{ {
return $this->getMockBuilder('\WC_Retailcrm_Response_Helper') return $this->getMockBuilder('\WC_Retailcrm_Response_Helper')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(array('isSuccessful')) ->setMethods(['isSuccessful'])
->getMock(); ->getMock();
} }
} }