Skip to content

Commit

Permalink
Merge pull request #16 from anoziere/fix/manage_max_length
Browse files Browse the repository at this point in the history
Fix/manage max length
  • Loading branch information
anoziere committed May 7, 2024
2 parents 47239bf + 618ab0a commit 632b029
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>2.0.6</version>
<version>2.0.7</version>
<authors>
<author>
<name>Vincent Lopes-Vicente</name>
Expand Down
10 changes: 7 additions & 3 deletions Event/PayPlugPaymentEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ class PayPlugPaymentEvent extends ActionEvent
'brand' => [
'type' => "string",
'required' => true,
'access' => 'getBrand'
'access' => 'getBrand',
'maxLength' => 100
],
'expected_delivery_date' => [
'type' => "string",
Expand All @@ -272,7 +273,8 @@ class PayPlugPaymentEvent extends ActionEvent
'delivery_label' => [
'type' => "string",
'required' => true,
'access' => "getDeliveryLabel"
'access' => "getDeliveryLabel",
'maxLength' => 100
],
'delivery_type' => [
'type' => "string",
Expand Down Expand Up @@ -666,12 +668,14 @@ protected function buildArrayParameters($parameterDefinitions, &$array, $parentK
continue;
}

$value = null;
$value = property_exists($target, $access) ? $target->{$access} :null;
if (null === $value && method_exists($target, $access)) {
$parameters = isset($parameterDefinition['accessParameters']) ? $parameterDefinition['accessParameters'] : [];
$value = call_user_func([$target, $access], ...$parameters);
}
if (isset($parameterDefinition['maxLength']) && strlen($value) > $parameterDefinition['maxLength']) {
$value = substr($value, 0, $parameterDefinition['maxLength']);
}

// If still null or empty no need to fill this parameter
if (null == $value) {
Expand Down
11 changes: 9 additions & 2 deletions Event/PayPlugProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ public function buildFromOrderProduct(OrderProduct $orderProduct, PayPlugModuleD
);

$deliveryType = $payPlugModuleDeliveryType !== null ? $payPlugModuleDeliveryType->getDeliveryType() : 'carrier';
// Brand can't be find from order product but it's required so set store name as brand or "Unknown"
$this->setBrand($storeName);
$this->setExpectedDeliveryDate(date('Y-m-d'));
$this->setDeliveryLabel($storeName);
$deliveryLabel = $storeName;
$order = $orderProduct->getOrder();
if (null !== $order) {
$deliveryLabelModule = $order->getDeliveryModuleInstance()->getCode();
if($deliveryLabelModule !== null) {
$deliveryLabel = $deliveryLabelModule;
}
}
$this->setDeliveryLabel($deliveryLabel);
$this->setDeliveryType($deliveryType);
$this->setMerchantItemId($orderProduct->getId());
$this->setName($orderProduct->getTitle());
Expand Down
22 changes: 17 additions & 5 deletions EventListener/PaymentListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ protected function formatErrorMessage(PayplugException $exception)

$details = "";


if (isset($response['details'])) {
$details = implode(' -', array_map(
function ($v, $k) {
$errors = [];
foreach ($v as $field => $error) {
$errors[] = "$field : $error";
if (is_array($v)) {
return " [$k] " . $this->processArray($v) . " .";
}
return " [$k] ".implode(";", $errors)." .";

return " [$k] $v .";
},
$response['details'],
array_keys($response['details'])
Expand All @@ -191,6 +190,19 @@ function ($v, $k) {
return $response['message'] . $details;
}

private function processArray($array): string
{
$result = [];
foreach ($array as $key => $value) {
if (is_array($value)) {
$result[] = $this->processArray($value);
} else {
$result[] = "$key : $value";
}
}
return implode(";", $result);
}

/**
* @inheritDoc
*/
Expand Down
4 changes: 3 additions & 1 deletion PayPlugModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public function pay(Order $order)
if ($this->getRequest()->isXmlHttpRequest()) {
return new JsonResponse(['error' => $exception->getMessage()], 400);
}
Tlog::getInstance()->addError('Error PayPlugModule::pay() : '. $exception->getMessage());
Tlog::getInstance()->addError(
'Error PayPlugModule::pay() : ' . $exception->getMessage()
);
return new RedirectResponse(URL::getInstance()->absoluteUrl('error'));
}

Expand Down

0 comments on commit 632b029

Please sign in to comment.