Commit e0e94cb6 authored by Andy J's avatar Andy J

Merge branch 'issue-43' into 'master'

shorting-function moved into helper-class. fix #43

Closes #43

See merge request jtlshop/paypal!18
parents 164b427c 5894bcba
......@@ -7,6 +7,7 @@
// HOOK_BESTELLVORGANG_PAGE_STEPZAHLUNG
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPalPlus.class.php';
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPal.helper.class.php';
if (isset($_GET['refresh'])) {
header('location: bestellvorgang.php');
......@@ -28,31 +29,6 @@ $api = new PayPalPlus();
$items = PayPalHelper::getProducts();
$shippingId = $_SESSION['Versandart']->kVersandart;
/**
* shorten a long payment-name to 'nLimit', by inserting a placholder 'szPlaceHolder' and
* show the 'nLastShownChars' characters
*
* @param $szPaymentDesc string to shorten
* @return string string of length 'nLimit'
*/
function shortenPaymentName($szPaymentDesc) {
$nLimit = 25; // hard limit of the payment-wall (should not be altered)
$nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...';
$szShortedDesc = $szPaymentDesc;
if ($nLimit < strlen($szPaymentDesc)) {
$szShortedDesc =
substr($szPaymentDesc, 0, ($nLimit - (strlen($szPlaceHolder) + $nLastShownChars)))
. $szPlaceHolder
. ($nLastShownChars ? substr($szPaymentDesc, - $nLastShownChars) : '')
;
}
return $szShortedDesc;
}
if ($api->isConfigured(false) && $api->isUseable($items, $shippingId)) {
$payment = $api->createPayment();
......@@ -90,7 +66,7 @@ if ($api->isConfigured(false) && $api->isUseable($items, $shippingId)) {
}
$thirdParty = [
'methodName' => shortenPaymentName(utf8_encode($p->angezeigterName[Shop::$cISO])),
'methodName' => PayPalHelper::shortenPaymentName(utf8_encode($p->angezeigterName[Shop::$cISO])),
'redirectUrl' => sprintf('%s/index.php?s=%d&a=payment_method&id=%d',
$shopUrl, $link->kLink, $p->kZahlungsart)
];
......
......@@ -696,4 +696,28 @@ class PayPalHelper
$d = is_object($d) ? get_object_vars($d) : $d;
return is_array($d) ? array_map([__CLASS__, __METHOD__], $d) : $d;
}
/**
* shorten a long payment-name to 'nLimit', by inserting a placholder 'szPlaceHolder' and
* show the 'nLastShownChars' characters
*
* @param $szPaymentDesc string to shorten
* @return string string of length 'nLimit'
*/
function shortenPaymentName($szPaymentDesc) {
$nLimit = 25; // hard limit of the payment-wall (should not be altered)
$nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...';
$szShortedDesc = $szPaymentDesc;
if ($nLimit < strlen($szPaymentDesc)) {
$szShortedDesc =
substr($szPaymentDesc, 0, ($nLimit - (strlen($szPlaceHolder) + $nLastShownChars)))
. $szPlaceHolder
. ($nLastShownChars ? substr($szPaymentDesc, - $nLastShownChars) : '')
;
}
return $szShortedDesc;
}
}
......@@ -7,6 +7,7 @@
// HOOK_BESTELLVORGANG_PAGE_STEPZAHLUNG
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPalPlus.class.php';
require_once realpath(dirname(__FILE__) . '/../paymentmethod/class') . '/PayPal.helper.class.php';
if (isset($_GET['refresh'])) {
header('location: bestellvorgang.php');
......@@ -90,7 +91,7 @@ if ($api->isConfigured(false) && $api->isUseable($items, $shippingId)) {
}
$thirdParty = [
'methodName' => shortenPaymentName(utf8_encode($p->angezeigterName[Shop::$cISO])),
'methodName' => PayPalHelper::shortenPaymentName(utf8_encode($p->angezeigterName[Shop::$cISO])),
'redirectUrl' => sprintf('%s/index.php?s=%d&a=payment_method&id=%d',
$shopUrl, $link->kLink, $p->kZahlungsart)
];
......
......@@ -725,4 +725,27 @@ class PayPalHelper
}
}
}
/**
* shorten a long payment-name to 'nLimit', by inserting a placholder 'szPlaceHolder' and
* show the 'nLastShownChars' characters
*
* @param $szPaymentDesc string to shorten
* @return string string of length 'nLimit'
*/
function shortenPaymentName($szPaymentDesc) {
$nLimit = 25; // hard limit of the payment-wall (should not be altered)
$nLastShownChars = 0; // (maybe 3 looks good)
$szPlaceHolder = '...';
$szShortedDesc = $szPaymentDesc;
if ($nLimit < strlen($szPaymentDesc)) {
$szShortedDesc =
substr($szPaymentDesc, 0, ($nLimit - (strlen($szPlaceHolder) + $nLastShownChars)))
. $szPlaceHolder
. ($nLastShownChars ? substr($szPaymentDesc, - $nLastShownChars) : '')
;
}
return $szShortedDesc;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment