Add support for payment method on delivery
This commit is contained in:
parent
9d8eb2256c
commit
91a7c02e25
@ -1,3 +1,6 @@
|
||||
## 2022-08-10 4.4.7
|
||||
* Add support for payment method on delivery
|
||||
|
||||
## 2022-08-06 4.4.6
|
||||
* Add automatically upload ICML in CRM
|
||||
* Add filter for changing ICML product information
|
||||
|
@ -475,7 +475,7 @@ if (!class_exists('WC_Retailcrm_Orders')) :
|
||||
return (array) $this->ordersGetRequestCache[$orderId];
|
||||
}
|
||||
|
||||
$crmOrder = array();
|
||||
$crmOrder = [];
|
||||
$response = $this->retailcrm->ordersGet($orderId);
|
||||
|
||||
if (!empty($response) && $response->isSuccessful() && isset($response['order'])) {
|
||||
|
@ -170,7 +170,7 @@ function getShippingRates()
|
||||
/**
|
||||
* Write base logs in retailcrm file.
|
||||
*
|
||||
* @codeCoverageIgnore Check in another tests
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
function writeBaseLogs($message)
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 5.6
|
||||
*
|
||||
@ -59,19 +60,32 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data
|
||||
];
|
||||
|
||||
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()])) {
|
||||
$paymentData['type'] = $this->settings[$order->get_payment_method()];
|
||||
if (isset($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 (isset($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);
|
||||
|
||||
return $this;
|
||||
@ -112,4 +132,4 @@ class WC_Retailcrm_Order_Payment extends WC_Retailcrm_Abstracts_Data
|
||||
'order' => []
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
|
||||
Requires PHP: 5.6
|
||||
Requires at least: 5.3
|
||||
Tested up to: 5.9
|
||||
Stable tag: 4.4.5
|
||||
Stable tag: 4.4.7
|
||||
License: GPLv1 or later
|
||||
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 ==
|
||||
= 4.4.7 =
|
||||
* Add support for payment method on delivery
|
||||
|
||||
= 4.4.6 =
|
||||
* Add automatically upload ICML in CRM
|
||||
* Add filter for changing ICML product information
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Description: Integration plugin for WooCommerce & Simla.com
|
||||
* Author: RetailDriver LLC
|
||||
* Author URI: http://retailcrm.pro/
|
||||
* Version: 4.4.6
|
||||
* Version: 4.4.7
|
||||
* Tested up to: 5.9
|
||||
* WC requires at least: 5.4
|
||||
* WC tested up to: 6.7
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
*
|
||||
* @version 4.4.6
|
||||
* @version 4.4.7
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
@ -21,7 +21,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$this->apiMock = $this->getMockBuilder('\WC_Retailcrm_Proxy')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(
|
||||
array(
|
||||
[
|
||||
'ordersGet',
|
||||
'ordersCreate',
|
||||
'ordersEdit',
|
||||
@ -37,7 +37,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
'getSingleSiteForKey',
|
||||
'customersCorporateAddressesCreate',
|
||||
'customersCorporateCompaniesCreate'
|
||||
)
|
||||
]
|
||||
)
|
||||
->getMock();
|
||||
|
||||
@ -130,10 +130,10 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$this->setMockResponse($responseMockSearch, 'isSuccessful', true);
|
||||
|
||||
$responseMockSearch->setResponse(
|
||||
array(
|
||||
[
|
||||
'success' => true,
|
||||
'customersCorporate' => array()
|
||||
)
|
||||
'customersCorporate' => []
|
||||
]
|
||||
);
|
||||
|
||||
// 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);
|
||||
|
||||
$responseMockCustomerCorporate->setResponse(
|
||||
array(
|
||||
[
|
||||
'success' => true,
|
||||
'id' => 1
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
// 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);
|
||||
|
||||
$responseMockCompany->setResponse(
|
||||
array(
|
||||
[
|
||||
'success' => true,
|
||||
'companies' => array(
|
||||
array('name' => 'WooCompany', 'id' => 777)
|
||||
)
|
||||
)
|
||||
'companies' => [
|
||||
['name' => 'WooCompany', 'id' => 777]
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
$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()
|
||||
{
|
||||
$this->createTestOrder();
|
||||
@ -358,11 +441,11 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$this->assertEquals(
|
||||
true,
|
||||
WC_Retailcrm_Orders::isCorporateCrmOrder(
|
||||
array(
|
||||
'customer' => array(
|
||||
[
|
||||
'customer' => [
|
||||
'type' => 'customer_corporate'
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@ -370,11 +453,11 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$this->assertEquals(
|
||||
false,
|
||||
WC_Retailcrm_Orders::isCorporateCrmOrder(
|
||||
array(
|
||||
'customer' => array(
|
||||
[
|
||||
'customer' => [
|
||||
'type' => 'customer'
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -390,11 +473,11 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
true,
|
||||
WC_Retailcrm_Orders::isOrderCustomerWasChanged(
|
||||
$this->order,
|
||||
array(
|
||||
'customer' => array(
|
||||
[
|
||||
'customer' => [
|
||||
'type' => 'customer'
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@ -403,14 +486,14 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
true,
|
||||
WC_Retailcrm_Orders::isOrderCustomerWasChanged(
|
||||
$this->order,
|
||||
array(
|
||||
'customer' => array(
|
||||
[
|
||||
'customer' => [
|
||||
'type' => 'customer_corporate'
|
||||
),
|
||||
'company' => array(
|
||||
],
|
||||
'company' => [
|
||||
'name' => 'Test1'
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@ -421,15 +504,15 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
true,
|
||||
WC_Retailcrm_Orders::isOrderCustomerWasChanged(
|
||||
$this->order,
|
||||
array(
|
||||
'customer' => array(
|
||||
[
|
||||
'customer' => [
|
||||
'type' => 'customer_corporate',
|
||||
'externalId' => 2
|
||||
),
|
||||
'company' => array(
|
||||
],
|
||||
'company' => [
|
||||
'name' => 'Test'
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@ -440,16 +523,16 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
true,
|
||||
WC_Retailcrm_Orders::isOrderCustomerWasChanged(
|
||||
$this->order,
|
||||
array(
|
||||
'customer' => array(
|
||||
[
|
||||
'customer' => [
|
||||
'type' => 'customer_corporate',
|
||||
'externalId' => 1,
|
||||
'email' => 'test1@mail.es'
|
||||
),
|
||||
'company' => array(
|
||||
],
|
||||
'company' => [
|
||||
'name' => 'Test'
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
@ -458,16 +541,16 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
false,
|
||||
WC_Retailcrm_Orders::isOrderCustomerWasChanged(
|
||||
$this->order,
|
||||
array(
|
||||
'customer' => array(
|
||||
[
|
||||
'customer' => [
|
||||
'type' => 'customer_corporate',
|
||||
'externalId' => 1,
|
||||
'email' => 'test@mail.es'
|
||||
),
|
||||
'company' => array(
|
||||
],
|
||||
'company' => [
|
||||
'name' => 'Test'
|
||||
)
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -476,38 +559,38 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
{
|
||||
$this->setUp();
|
||||
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'is_successful' => true,
|
||||
'retailcrm' => $this->apiMock
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'is_successful' => true,
|
||||
'retailcrm' => false
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'is_successful' => false,
|
||||
'retailcrm' => false
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'is_successful' => false,
|
||||
'retailcrm' => $this->apiMock
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function dataProviderRetailcrm()
|
||||
{
|
||||
$this->setUp();
|
||||
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'retailcrm' => $this->apiMock
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'retailcrm' => false
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function createTestOrder()
|
||||
@ -528,18 +611,18 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
|
||||
private function getResponseData($externalId)
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'success' => true,
|
||||
'order' => array(
|
||||
'payments' => array(
|
||||
array(
|
||||
'order' => [
|
||||
'payments' => [
|
||||
[
|
||||
'id' => 1,
|
||||
'externalId' => $externalId,
|
||||
'type' => 'payment2'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -572,7 +655,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
{
|
||||
return $this->getMockBuilder('\WC_Retailcrm_Response_Helper')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('isSuccessful'))
|
||||
->setMethods(['isSuccessful'])
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user