Skip to content

Commit

Permalink
Initiated data for paynl-cse form
Browse files Browse the repository at this point in the history
  • Loading branch information
szhalba-sm committed Nov 28, 2022
1 parent 9b78161 commit ebad437
Show file tree
Hide file tree
Showing 12 changed files with 12,248 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Components/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,4 +543,11 @@ public function getInstoreTerminals(string $salesChannelId): array

return (array)Instore::getAllTerminals()->getList();
}

public function getPublicKeys(string $salesChannelId): array
{
$this->setCredentials($salesChannelId);

return Payment::paymentEncryptionKeys()->getKeys();
}
}
1 change: 1 addition & 0 deletions src/Enums/PaynlPaymentMethodsIdsEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
class PaynlPaymentMethodsIdsEnum
{
const PIN_PAYMENT = 1927;
const VISA_MASTERCARD_PAYMENT = 706;
}
42 changes: 42 additions & 0 deletions src/Helper/PublicKeysHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace PaynlPayment\Shopware6\Helper;

use PaynlPayment\Shopware6\Components\Api;
use Psr\Cache\CacheItemPoolInterface;

class PublicKeysHelper
{
const CACHE_KEY = 'paynl_public_encryption_keys';
const CACHE_TTL = 15768000;

/** @var Api */
private $paynlApi;

/** @var CacheItemPoolInterface */
private $cache;

public function __construct(Api $api, CacheItemPoolInterface $cache)
{
$this->paynlApi = $api;
$this->cache = $cache;
}

public function getKeys(string $salesChannelId): array
{
$keysCacheItem = $this->cache->getItem(self::CACHE_KEY);

if (!$keysCacheItem->isHit() || !$keysCacheItem->get()) {
$keys = $this->paynlApi->getPublicKeys($salesChannelId);
$keysCacheItem->set(json_encode($keys));

$this->cache->save($keysCacheItem);
} else {
$keys = json_decode($keysCacheItem->get(), true);
}

return $keys;
}
}
Loading

0 comments on commit ebad437

Please sign in to comment.