Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
91ecaa5
feat: endpoint and throtteling
N-Feist Apr 14, 2026
5b31310
fix: missing value
N-Feist Apr 14, 2026
6d04586
.
N-Feist Apr 14, 2026
8a1dc31
feat: use webshop repository
N-Feist Apr 14, 2026
8c945c8
feat: use dto
N-Feist Apr 15, 2026
ce1990d
feat: add cancellation reason
N-Feist Apr 15, 2026
addc12f
fix: working error handling
N-Feist Apr 16, 2026
5358de1
feat: pass recipient from payload
N-Feist Apr 16, 2026
b6bdbad
fix: bug
N-Feist Apr 17, 2026
7b7c2d1
test
ivladu-plenty Apr 17, 2026
65dbac2
revert
ivladu-plenty Apr 17, 2026
27505e2
fix: right handling of payload from cancellation form
N-Feist Apr 20, 2026
590f2b3
fix: recipient usage
N-Feist Apr 20, 2026
0353919
Revert "fix: recipient usage"
N-Feist Apr 23, 2026
44c5a4d
Revert "fix: right handling of payload from cancellation form"
N-Feist Apr 23, 2026
dca769a
Reapply "fix: right handling of payload from cancellation form"
N-Feist Apr 23, 2026
fd38fff
Reapply "fix: recipient usage"
N-Feist Apr 23, 2026
3916b24
testing
ivladu-plenty Apr 28, 2026
267b29a
test disable recaptcha on contact mail
N-Feist Apr 28, 2026
3fe5655
chore: adjust route to expected data and add error handling
N-Feist Apr 29, 2026
f3ddd07
Revert "test disable recaptcha on contact mail"
N-Feist Apr 29, 2026
307bd15
chore: stricter checks
N-Feist Apr 29, 2026
dd63a9d
fix: remove redundant fallbacks
N-Feist Apr 29, 2026
7126c33
refactoring
ivladu-plenty Apr 29, 2026
5580000
test
N-Feist Apr 29, 2026
4bf71f3
Update Debug.properties
N-Feist Apr 29, 2026
ad8686a
chore: beautify logging message
N-Feist Apr 29, 2026
b509b62
fix: uncomment recaptcha and set early return
N-Feist Apr 29, 2026
ebef81b
chore: error msg in const
N-Feist Apr 29, 2026
81ce8bb
feat: update log message and level
N-Feist Apr 29, 2026
1226d59
test disable recaptcha check
N-Feist Apr 29, 2026
be58aef
Update CancellationResource.php
N-Feist Apr 29, 2026
3b2f016
Update CancellationResource.php
N-Feist Apr 29, 2026
f82cd9c
chore: enable recaptcha again
N-Feist Apr 29, 2026
daedd2c
feat: add error message for general issues
N-Feist Apr 29, 2026
35630d4
chore: change submit error message
N-Feist Apr 30, 2026
9381785
fix: correct responses
N-Feist Apr 30, 2026
915e005
fix: remove error msg
N-Feist Apr 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions resources/lang/en/Debug.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ ContactMailService_noMailContent = "Cannot send mail: Mail content is empty."
; CountryService
CountryService_noNameFound = "No names configured for the country with the given ID."

; CancellationResource
CancellationResource_missingFields = "Required fields are missing and couldn't be mapped to the email template."

; CustomerAuthenticationResource
CustomerAuthenticationResource_loginFailed = "Cannot perform login."

Expand Down
103 changes: 103 additions & 0 deletions src/Api/Resources/CancellationResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace IO\Api\Resources;

use IO\Api\ApiResource;
use IO\Api\ApiResponse;
use IO\Api\ResponseCode;
use IO\Constants\LogLevel;
use IO\Helper\ReCaptcha;
use IO\Helper\Utils;
use IO\Services\NotificationService;
use Plenty\Modules\Webshop\Storefront\Contracts\CancellationRepositoryContract;
use Plenty\Modules\Webshop\Storefront\Exceptions\StorefrontException;
use Plenty\Plugin\Http\Request;
use Plenty\Plugin\Http\Response;
use Plenty\Plugin\Log\Loggable;

/**
* Class CancellationResource
*
* Resource class for the route `io/cancellation`.
* @package IO\Api\Resources
*/
class CancellationResource extends ApiResource
{
use Loggable;

/**
* @var CancellationRepositoryContract
*/
private $cancellationRepository;

/**
* CancellationResource constructor.
* @param Request $request
* @param ApiResponse $response
* @param CancellationRepositoryContract $cancellationRepository
*/
public function __construct(Request $request, ApiResponse $response, CancellationRepositoryContract $cancellationRepository)
{
parent::__construct($request, $response);
$this->cancellationRepository = $cancellationRepository;
}

/**
* Submit a cancellation request.
* @return Response
*/
public function store(): Response
{
if (!ReCaptcha::verify($this->request->get('recaptchaToken', null), true)) {
/** @var NotificationService $notificationService */
$notificationService = pluginApp(NotificationService::class);
$notificationService->addNotificationCode(LogLevel::ERROR, 13);

return $this->response->create('', ResponseCode::BAD_REQUEST);
}

try {
$requestData = $this->request->all();
$formData = $requestData['data'] ?? [];
$errors = [];

if(empty($formData)){
return $this->response->create(false, ResponseCode::BAD_REQUEST);
}

foreach (['email', 'name', 'order'] as $field) {
if(empty($formData[$field]['value'])) {
$errors[] = $field;
}
}

if(!empty($errors)) {
$message = 'Keys "' . implode('", "', $errors) . '" of the contract withdrawal form couldn\'t be mapped to the email template.';

$this->getLogger(self::class)->error(
"IO::Debug.CancellationResource_missingFields",
[
"code" => ResponseCode::BAD_REQUEST,
"message" => $message
]
);

return $this->response->create(false, ResponseCode::BAD_REQUEST);
}

$this->cancellationRepository->submitCancellationRequest([
'email' => $formData['email']['value'],
'name' => $formData['name']['value'],
'lang' => Utils::getLang(),
'orderId' => (int) ($formData['order']['value']),
'reason' => $formData['reason']['value'] ?? '',
'recipient' => $requestData['recipient'] ?? '',
]);

return $this->response->create(true, ResponseCode::OK);
} catch (\Exception $exception) {
$code = $exception->getCode() ?: ResponseCode::INTERNAL_SERVER_ERROR;
return $this->response->create(false, $code);
}
}
}
8 changes: 8 additions & 0 deletions src/Providers/IORouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ function (ApiRouter $api) {
}
);

$api->version(
['v1'],
['namespace' => 'IO\Api\Resources', 'middleware' => ['throttleFrontend:cancellation-form']],
function (ApiRouter $api) {
$api->post('io/cancellation', 'CancellationResource@store');
}
);

$api->version(['v1'], ['namespace' => 'IO\Api\Resources'], function (ApiRouter $api) {
$api->get('io/basket', 'BasketResource@index');
$api->resource('io/basket/items', 'BasketItemResource');
Expand Down
Loading