Skip to content

Commit

Permalink
Release 1.0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
edgaraswallee committed Feb 12, 2024
1 parent 34f1394 commit 7db63d6
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 224 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ account dashboard.

## Documentation

[Documentation](https://plugin-documentation.wallee.com/wallee-payment/jtl-5/1.0.20/docs/en/documentation.html)
[Documentation](https://plugin-documentation.wallee.com/wallee-payment/jtl-5/1.0.21/docs/en/documentation.html)

## License

Expand Down
8 changes: 7 additions & 1 deletion Services/WalleeTransactionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ public function updateTransaction(int $transactionId)
$pendingTransaction->setId($transactionId);

$transaction = $this->getTransactionFromPortal($transactionId);
$pendingTransaction->setVersion($transaction->getVersion() + 1);
if (empty($transaction) || empty($transaction->getVersion())) {
$_SESSION['transactionId'] = null;
$createdTransactionId = $this->createTransaction();
$_SESSION['transactionId'] = $createdTransactionId;
return;
}
$pendingTransaction->setVersion($transaction->getVersion());

$lineItems = $this->getLineItems($_SESSION['Warenkorb']->PositionenArr);
$pendingTransaction->setLineItems($lineItems);
Expand Down
349 changes: 180 additions & 169 deletions WalleeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,174 +14,185 @@
*/
class WalleeHelper extends Helper
{
const PAYMENT_METHOD_PREFIX = 'wallee_payment';
const USER_ID = 'jtl_wallee_user_id';
const SPACE_ID = 'jtl_wallee_space_id';
const APPLICATION_KEY = 'jtl_wallee_application_key';
const SPACE_VIEW_ID = 'jtl_wallee_space_view_id';
const SEND_CONFIRMATION_EMAIL = 'jtl_wallee_send_confirmation_email';

const PAYMENT_METHOD_CONFIGURATION = 'PaymentMethodConfiguration';
const REFUND = 'Refund';
const TRANSACTION = 'Transaction';
const TRANSACTION_INVOICE = 'TransactionInvoice';

const PLUGIN_CUSTOM_PAGES = [
'thank-you-page' => [
'ger' => 'wallee-danke-seite',
'eng' => 'wallee-thank-you-page'
],
'payment-page' => [
'ger' => 'wallee-zahlungsseite',
'eng' => 'wallee-payment-page'
],
'fail-page' => [
'ger' => 'wallee-bezahlung-fehlgeschlagen',
'eng' => 'wallee-failed-payment'
],
];


/**
* @param string $text
* @param string $divider
* @return string
*/
public static function slugify(string $text, string $divider = '_'): string
{
// replace non letter or digits by divider
$text = preg_replace('~[^\pL\d]+~u', $divider, $text);

// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);

// trim
$text = trim($text, $divider);

// remove duplicate divider
$text = preg_replace('~-+~', $divider, $text);

// lowercase
$text = strtolower($text);

return $text;
}

/**
* @return string
*/
public static function getLanguageString(): string
{
switch ($_SESSION['currentLanguage']->iso) {
case 'ger':
return 'de_DE';

case 'fra':
return 'fr_FR';

case 'ita':
return 'it_IT';

default:
return 'en_GB';
}
}

/**
* @param $isAdmin
* @return string
*/
public static function getLanguageIso($isAdmin = true): string
{
if (!$isAdmin) {
return $_SESSION['cISOSprache'];
}

$gettext = Shop::Container()->getGetText();
$langTag = $_SESSION['AdminAccount']->language ?? $gettext->getLanguage();

switch (substr($langTag, 0, 2)) {
case 'de':
return 'ger';

case 'en':
return 'eng';

case 'fr':
return 'fra';

case 'it':
return 'ita';
}
}

/**
* @param Localization $localization
* @param array $keys
* @param $isAdmin
* @return array
*/
public static function getTranslations(Localization $localization, array $keys, $isAdmin = true): array
{
$translations = [];
foreach ($keys as $key) {
$translations[$key] = $localization->getTranslation($key, self::getLanguageIso($isAdmin));
}

return $translations;
}

/**
* @param Localization $localization
* @return array
*/
public static function getPaymentStatusWithTransations(Localization $localization): array
{
$translations = WalleeHelper::getTranslations($localization, [
'jtl_wallee_order_status_cancelled',
'jtl_wallee_order_status_open',
'jtl_wallee_order_status_in_processing',
'jtl_wallee_order_status_paid',
'jtl_wallee_order_status_shipped',
'jtl_wallee_order_status_partially_shipped',
]);

return [
'-1' => $translations['jtl_wallee_order_status_cancelled'],
'1' => $translations['jtl_wallee_order_status_open'],
'2' => $translations['jtl_wallee_order_status_in_processing'],
'3' => $translations['jtl_wallee_order_status_paid'],
'4' => $translations['jtl_wallee_order_status_shipped'],
'5' => $translations['jtl_wallee_order_status_partially_shipped'],
];
}

/**
* @param int $pluginId
* @return ApiClient|null
*/
public static function getApiClient(int $pluginId): ?ApiClient
{
if (class_exists('Wallee\Sdk\ApiClient')) {
$apiClient = new WalleeApiClient($pluginId);
return $apiClient->getApiClient();
} else {

if (isset($_POST['Setting'])) {
$plugin = PluginHelper::getLoaderByPluginID($pluginId)->init($pluginId);
$translations = WalleeHelper::getTranslations($plugin->getLocalization(), [
'jtl_wallee_need_to_install_sdk',
]);
Shop::Container()->getAlertService()->addDanger(
$translations['jtl_wallee_need_to_install_sdk'],
'getApiClient'
);
}
return null;
}
}
const EN_ISO3 = 'eng';
const DE_ISO3 = 'ger';
const IT_ISO3 = 'ita';
const FR_ISO3 = 'fre';

const PAYMENT_METHOD_PREFIX = 'wallee_payment';
const USER_ID = 'jtl_wallee_user_id';
const SPACE_ID = 'jtl_wallee_space_id';
const APPLICATION_KEY = 'jtl_wallee_application_key';
const SPACE_VIEW_ID = 'jtl_wallee_space_view_id';
const SEND_CONFIRMATION_EMAIL = 'jtl_wallee_send_confirmation_email';

const PAYMENT_METHOD_CONFIGURATION = 'PaymentMethodConfiguration';
const REFUND = 'Refund';
const TRANSACTION = 'Transaction';
const TRANSACTION_INVOICE = 'TransactionInvoice';

const PLUGIN_CUSTOM_PAGES = [
'thank-you-page' => [
self::DE_ISO3 => 'wallee-danke-seite',
self::EN_ISO3 => 'wallee-thank-you-page',
self::IT_ISO3 => 'wallee-pagina-di-ringraziamento',
self::FR_ISO3 => 'wallee-page-de-remerciement',
],
'payment-page' => [
self::DE_ISO3 => 'wallee-zahlungsseite',
self::EN_ISO3 => 'wallee-payment-page',
self::IT_ISO3 => 'wallee-pagina-di-pagamento',
self::FR_ISO3 => 'wallee-page-de-paiement',
],
'fail-page' => [
self::DE_ISO3 => 'wallee-bezahlung-fehlgeschlagen',
self::EN_ISO3 => 'wallee-failed-payment',
self::IT_ISO3 => 'wallee-pagamento-fallito',
self::FR_ISO3 => 'wallee-paiement-echoue',
],
];


/**
* @param string $text
* @param string $divider
* @return string
*/
public static function slugify(string $text, string $divider = '_'): string
{
// replace non letter or digits by divider
$text = preg_replace('~[^\pL\d]+~u', $divider, $text);

// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);

// trim
$text = trim($text, $divider);

// remove duplicate divider
$text = preg_replace('~-+~', $divider, $text);

// lowercase
$text = strtolower($text);

return $text;
}

/**
* @return string
*/
public static function getLanguageString(): string
{
switch ($_SESSION['currentLanguage']->iso) {
case self::DE_ISO3:
return 'de_DE';

case self::FR_ISO3:
return 'fr_FR';

case self::IT_ISO3:
return 'it_IT';

default:
return 'en_GB';
}
}

/**
* @param $isAdmin
* @return string
*/
public static function getLanguageIso($isAdmin = true): string
{
if (!$isAdmin) {
return $_SESSION['cISOSprache'];
}

$gettext = Shop::Container()->getGetText();
$langTag = $_SESSION['AdminAccount']->language ?? $gettext->getLanguage();

switch (substr($langTag, 0, 2)) {
case 'de':
return self::DE_ISO3;

case 'en':
return self::EN_ISO3;

case 'fr':
return self::FR_ISO3;

case 'it':
return self::IT_ISO3;
}
}

/**
* @param Localization $localization
* @param array $keys
* @param $isAdmin
* @return array
*/
public static function getTranslations(Localization $localization, array $keys, $isAdmin = true): array
{
$translations = [];
foreach ($keys as $key) {
$translations[$key] = $localization->getTranslation($key, self::getLanguageIso($isAdmin));
}

return $translations;
}

/**
* @param Localization $localization
* @return array
*/
public static function getPaymentStatusWithTransations(Localization $localization): array
{
$translations = WalleeHelper::getTranslations($localization, [
'jtl_wallee_order_status_cancelled',
'jtl_wallee_order_status_open',
'jtl_wallee_order_status_in_processing',
'jtl_wallee_order_status_paid',
'jtl_wallee_order_status_shipped',
'jtl_wallee_order_status_partially_shipped',
]);

return [
'-1' => $translations['jtl_wallee_order_status_cancelled'],
'1' => $translations['jtl_wallee_order_status_open'],
'2' => $translations['jtl_wallee_order_status_in_processing'],
'3' => $translations['jtl_wallee_order_status_paid'],
'4' => $translations['jtl_wallee_order_status_shipped'],
'5' => $translations['jtl_wallee_order_status_partially_shipped'],
];
}

/**
* @param int $pluginId
* @return ApiClient|null
*/
public static function getApiClient(int $pluginId): ?ApiClient
{
if (class_exists('Wallee\Sdk\ApiClient')) {
$apiClient = new WalleeApiClient($pluginId);
return $apiClient->getApiClient();
} else {

if (isset($_POST['Setting'])) {
$plugin = PluginHelper::getLoaderByPluginID($pluginId)->init($pluginId);
$translations = WalleeHelper::getTranslations($plugin->getLocalization(), [
'jtl_wallee_need_to_install_sdk',
]);
Shop::Container()->getAlertService()->addDanger(
$translations['jtl_wallee_need_to_install_sdk'],
'getApiClient'
);
}
return null;
}
}
}

5 changes: 3 additions & 2 deletions docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="keywords" value="Wallee, JTL5, JTL5 Plugin, Payment, Payment Integration, Documentation"><meta name="description" value="The documentation for the JTL5 plugin that enables processing payments with wallee."> <link rel="canonical" href="https://plugin-documentation.wallee.com/wallee-payment/jtl-5/master/wallee/docs/en/documentation.html" />
<meta name="keywords" value="Wallee, JTL5, JTL5 Plugin, Payment, Payment Integration, Documentation"><meta name="description" value="The documentation for the JTL5 plugin that enables processing payments with wallee.">
<link rel="canonical" href="https://plugin-documentation.wallee.com/wallee-payment/jtl-5/master/wallee/docs/en/documentation.html" />
<title>Wallee JTL5 Documentation</title>
<link href="assets/monokai-sublime.css" rel="stylesheet" />
<link href="assets/base.css" rel="stylesheet" />
Expand All @@ -22,7 +23,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/wallee-payment/jtl-5/releases/tag/1.0.20/">
<a href="https://github.com/wallee-payment/jtl-5/releases/tag/1.0.21/">
Source
</a>
</li>
Expand Down
Loading

0 comments on commit 7db63d6

Please sign in to comment.