-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSE implementation #229
base: rc-1.4.17
Are you sure you want to change the base?
CSE implementation #229
Changes from 4 commits
30d9ebe
5f06cab
9b78161
8967812
ec4c660
5f3b346
80ccf2f
f0c0c37
be19594
51ceb79
9cb288d
f109b5b
7084f16
eed0fb3
60f14b2
3162f76
dc5d67c
fe13ec2
28e263f
663da16
3a5f42d
c413700
c69a4fa
8d34b01
4e7a700
4a844de
79efee5
057ea19
d1f890b
c011d4f
ec2c7f8
1ae0d50
612f827
6034919
c5d988c
bd50be5
baf6e23
25ff2c1
c90d29d
433122b
f371d1c
4cfde66
0701d87
83e5359
23d06f8
4dce5ca
ee675bd
0ad80a2
08fc363
83dd302
97aa811
5789dd2
86be825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,12 @@ | |
|
||
use Paynl\Config as SDKConfig; | ||
use Paynl\Instore; | ||
use Paynl\Payment; | ||
use Paynl\Paymentmethods; | ||
use Paynl\Result\Instore\Payment; | ||
use Paynl\Result\Transaction\Start; | ||
use Paynl\Transaction; | ||
use Paynl\Result\Transaction\Transaction as ResultTransaction; | ||
use Paynl\Api\Payment\Model; | ||
use PaynlPayment\Shopware6\Enums\CustomerCustomFieldsEnum; | ||
use PaynlPayment\Shopware6\Enums\PaynlPaymentMethodsIdsEnum; | ||
use PaynlPayment\Shopware6\Exceptions\PaynlPaymentException; | ||
|
@@ -129,6 +130,175 @@ public function getTransaction(string $transactionId, string $salesChannelId): R | |
return Transaction::get($transactionId); | ||
} | ||
|
||
public function startEncryptedTransaction( | ||
OrderEntity $order, | ||
array $payload, | ||
SalesChannelContext $salesChannelContext, | ||
string $returnUrl, | ||
string $exchangeUrl, | ||
string $shopwareVersion, | ||
string $pluginVersion | ||
) { | ||
$transaction = $this->getTransactionInitialData( | ||
$order, | ||
$salesChannelContext, | ||
$returnUrl, | ||
$exchangeUrl, | ||
$shopwareVersion, | ||
$pluginVersion | ||
); | ||
|
||
$this->setCredentials($salesChannelContext->getSalesChannel()->getId()); | ||
|
||
$objTransaction = new Model\Authenticate\Transaction(); | ||
$objTransaction | ||
->setServiceId(\Paynl\Config::getServiceId()) | ||
->setDescription($transaction['description']) | ||
->setExchangeUrl($transaction['exchangeUrl']) | ||
->setReference($transaction['orderNumber']) | ||
->setAmount($transaction['amount'] * 100) | ||
->setCurrency($transaction['currency']) | ||
->setIpAddress($transaction['ipaddress']) | ||
->setLanguage($transaction['address']['country']); | ||
|
||
$address = new Model\Address(); | ||
$address | ||
->setStreetName($transaction['invoiceAddress']['streetName']) | ||
->setStreetNumber($transaction['invoiceAddress']['houseNumber']) | ||
->setZipCode($transaction['invoiceAddress']['zipCode']) | ||
->setCity($transaction['invoiceAddress']['city']) | ||
->setCountryCode($transaction['invoiceAddress']['country']); | ||
|
||
$invoice = new Model\Invoice(); | ||
$invoice | ||
->setFirstName($transaction['invoiceAddress']['initials']) | ||
->setLastName($transaction['invoiceAddress']['lastName']) | ||
->setGender($transaction['enduser']['gender'] ?? null) | ||
->setAddress($address); | ||
|
||
$customer = new Model\Customer(); | ||
$customer | ||
->setFirstName($transaction['enduser']['initials']) | ||
->setLastName($transaction['enduser']['lastName']) | ||
->setAddress($address) | ||
->setInvoice($invoice); | ||
|
||
$cse = new Model\CSE(); | ||
$cse->setIdentifier($payload['identifier']); | ||
$cse->setData($payload['data']); | ||
|
||
$statistics = new Model\Statistics(); | ||
$statistics->setObject($transaction['object']); | ||
|
||
$browser = new Model\Browser(); | ||
$paymentOrder = new Model\Order(); | ||
|
||
if(!empty($transaction['products']) && is_array($transaction['products'])) { | ||
foreach ($transaction['products'] as $arrProduct) { | ||
$product = new Model\Product(); | ||
$product->setId($arrProduct['id']); | ||
$product->setType($arrProduct['type']); | ||
$product->setDescription($arrProduct['name']); | ||
$product->setAmount($arrProduct['price'] * 100); | ||
$product->setQuantity($arrProduct['qty']); | ||
$product->setVat($arrProduct['tax']); | ||
$paymentOrder->addProduct($product); | ||
} | ||
} | ||
|
||
return Payment::authenticate( | ||
$objTransaction, | ||
$customer, | ||
$cse, | ||
$browser, | ||
$statistics, | ||
$paymentOrder | ||
); | ||
} | ||
|
||
public function status(string $transactionId, string $salesChannelId) | ||
{ | ||
$this->setCredentials($salesChannelId); | ||
|
||
return Payment::authenticationStatus($transactionId); | ||
} | ||
|
||
public function authentication(array $params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
$salesChannelId = $params['salesChannelId'] ?? null; | ||
$ped = $params['pay_encrypted_data'] ?? null; | ||
$transId = $params['transaction_id'] ?? null; | ||
$ecode = $params['entrance_code'] ?? null; | ||
$acquirerId = $params['acquirer_id'] ?? null; | ||
$tdsTransactionId = $params['threeds_transaction_id'] ?? null; | ||
|
||
$payload = json_decode($ped, true); | ||
|
||
$transaction = new Model\Authenticate\TransactionMethod(); | ||
$transaction->setOrderId($transId)->setEntranceCode($ecode); | ||
|
||
|
||
$cse = new Model\CSE(); | ||
$cse->setIdentifier($payload['identifier'])->setData($payload['data']); | ||
|
||
$payment = new Model\Payment(); | ||
$payment->setMethod(Model\Payment::METHOD_CSE)->setCse($cse); | ||
|
||
if (!empty($tdsTransactionId)) { | ||
$auth = new Model\Auth(); | ||
$auth->setPayTdsAcquirerId($acquirerId)->setPayTdsTransactionId($tdsTransactionId); | ||
$payment->setAuth($auth); | ||
} | ||
|
||
$browser = new Model\Browser(); | ||
$browser | ||
->setJavaEnabled('false') | ||
->setJavascriptEnabled('false') | ||
->setLanguage('nl-NL') | ||
->setColorDepth('24') | ||
->setScreenWidth('1920') | ||
->setScreenHeight('1080') | ||
->setTz('-120'); | ||
|
||
$payment->setBrowser($browser); | ||
|
||
$this->setCredentials($salesChannelId); | ||
|
||
return Payment::authenticateMethod($transaction, $payment); | ||
} | ||
|
||
public function authorization(array $params) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
{ | ||
$salesChannelId = $params['salesChannelId'] ?? null; | ||
$ped = $params['pay_encrypted_data'] ?? null; | ||
$transId = $params['transaction_id'] ?? null; | ||
$ecode = $params['entrance_code'] ?? null; | ||
$acquirerId = $params['acquirer_id'] ?? null; | ||
$tdsTransactionId = $params['threeds_transaction_id'] ?? null; | ||
|
||
$payload = json_decode($ped, true); | ||
|
||
$transaction = new Model\Authorize\Transaction(); | ||
$transaction->setOrderId($transId)->setEntranceCode($ecode); | ||
|
||
$cse = new Model\CSE(); | ||
$cse->setIdentifier($payload['identifier']); | ||
$cse->setData($payload['data']); | ||
|
||
$auth = new Model\Auth(); | ||
$auth->setPayTdsAcquirerId($acquirerId); | ||
$auth->setPayTdsTransactionId($tdsTransactionId); | ||
|
||
$payment = new Model\Payment(); | ||
$payment->setMethod(Model\Payment::METHOD_CSE); | ||
$payment->setCse($cse); | ||
$payment->setAuth($auth); | ||
|
||
$this->setCredentials($salesChannelId); | ||
|
||
return Payment::authorize($transaction, $payment); | ||
} | ||
|
||
/** | ||
* @param OrderEntity $order | ||
* @param SalesChannelContext $salesChannelContext | ||
|
@@ -373,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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
class PaynlPaymentMethodsIdsEnum | ||
{ | ||
const PIN_PAYMENT = 1927; | ||
const VISA_MASTERCARD_PAYMENT = 706; | ||
} |
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
getAuthenticationStatus
is more self-explanatory