From 9aab02c189ccd20782e29270d822d21474f15095 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 24 Jul 2017 15:12:13 +0300 Subject: [PATCH] Payment delete & custom dictionary creation fix (#46) --- lib/RetailCrm/Methods/V5/CustomFields.php | 2 +- lib/RetailCrm/Methods/V5/Orders.php | 37 +++++++++++++++---- .../Methods/Version5/ApiClientOrdersTest.php | 11 ++++-- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/lib/RetailCrm/Methods/V5/CustomFields.php b/lib/RetailCrm/Methods/V5/CustomFields.php index 9e87ba7..898878c 100644 --- a/lib/RetailCrm/Methods/V5/CustomFields.php +++ b/lib/RetailCrm/Methods/V5/CustomFields.php @@ -196,7 +196,7 @@ trait CustomFields } return $this->client->makeRequest( - "/custom-fields/dictionaries/{$customDictionary['code']}/create", + "/custom-fields/dictionaries/create", "POST", ['customDictionary' => json_encode($customDictionary)] ); diff --git a/lib/RetailCrm/Methods/V5/Orders.php b/lib/RetailCrm/Methods/V5/Orders.php index 5c2e7b2..182e677 100644 --- a/lib/RetailCrm/Methods/V5/Orders.php +++ b/lib/RetailCrm/Methods/V5/Orders.php @@ -94,14 +94,14 @@ trait Orders } /** - * Edit an order payment - * - * @param array $payment order data - * @param string $by by key - * @param null $site site code - * - * @return \RetailCrm\Response\ApiResponse - */ + * Edit an order payment + * + * @param array $payment order data + * @param string $by by key + * @param null $site site code + * + * @return \RetailCrm\Response\ApiResponse + */ public function ordersPaymentEdit(array $payment, $by = 'id', $site = null) { if (!count($payment)) { @@ -127,4 +127,25 @@ trait Orders ) ); } + + /** + * Edit an order payment + * + * @param string $id payment id + * + * @return \RetailCrm\Response\ApiResponse + */ + public function ordersPaymentDelete($id) + { + if (!$id) { + throw new \InvalidArgumentException( + 'Parameter `id` must be set' + ); + } + + return $this->client->makeRequest( + sprintf('/orders/payments/%s/delete', $id), + "POST" + ); + } } diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php index 1f52337..eb89928 100644 --- a/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientOrdersTest.php @@ -403,10 +403,8 @@ class ApiClientOrdersTest extends TestCase $paymentEdit = [ 'id' => $response['id'], - 'externalId' => $externalId, 'amount' => 1500, 'comment' => 'test payment!', - 'type' => 'cash', 'status' => 'paid' ]; @@ -414,7 +412,14 @@ class ApiClientOrdersTest extends TestCase static::assertTrue( $responseAgain->isSuccessful(), - 'Got payment' + 'Edit payment' + ); + + $responseLast = $client->request->ordersPaymentDelete($response['id']); + + static::assertTrue( + $responseLast->isSuccessful(), + 'Delete payment' ); } }