Skip to content

Commit

Permalink
Merge pull request #273 from OXID-eSales/UNZER-385_348-for-o7
Browse files Browse the repository at this point in the history
Unzer 385 348 for o7
  • Loading branch information
mariolorenz authored Jun 4, 2024
2 parents e6ecc23 + 9854be4 commit d9cf3b8
Show file tree
Hide file tree
Showing 37 changed files with 674 additions and 717 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### FIXED
- fix: PayPal sporadically fails on GHA CC Tests
- [0007638](https://bugs.oxid-esales.com/view.php?id=7638) - Fix: Sometimes duplicate order-positions in Backend, and dublicate ordermails ...
- refactor of the correct use of the appropriate credentials depending on the payment method used

## [2.1.4] - 2023-11-23

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"minimum-stability": "dev",
"require": {
"unzerdev/php-sdk": "^v3.4.1",
"unzerdev/php-sdk": "^v3.6.0",
"guzzlehttp/guzzle": "^7.4"
},
"require-dev": {
Expand Down
79 changes: 45 additions & 34 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,149 +281,160 @@
'type' => 'str',
'value' => ''
],
// unzer invoice keypairs

// live Paylater Invoice B2C EUR
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPublicKeyB2CEUR',
'name' => 'production-UnzerPayLaterInvoiceB2CEURPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPrivateKeyB2CEUR',
'name' => 'production-UnzerPayLaterInvoiceB2CEURPublicKey',
'type' => 'str',
'value' => ''
],
// live Paylater Invoice B2B EUR
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPublicKeyB2BEUR',
'name' => 'production-UnzerPayLaterInvoiceB2BEURPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPrivateKeyB2BEUR',
'name' => 'production-UnzerPayLaterInvoiceB2BEURPublicKey',
'type' => 'str',
'value' => ''
],
// live Paylater Invoice B2C CHF
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPublicKeyB2CCHF',
'name' => 'production-UnzerPayLaterInvoiceB2CCHFPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPrivateKeyB2CCHF',
'name' => 'production-UnzerPayLaterInvoiceB2CCHFPublicKey',
'type' => 'str',
'value' => ''
],
// live Paylater Invoice B2B CHF
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPublicKeyB2BCHF',
'name' => 'production-UnzerPayLaterInvoiceB2BCHFPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPrivateKeyB2BCHF',
'name' => 'production-UnzerPayLaterInvoiceB2BCHFPublicKey',
'type' => 'str',
'value' => ''
],
// live Paylater Installment B2C EUR
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPublicKeyB2CEUR',
'group' => 'unzerpaylater',
'name' => 'production-UnzerPayLaterInstallmentB2CEURPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPrivateKeyB2CEUR',
'group' => 'unzerpaylater',
'name' => 'production-UnzerPayLaterInstallmentB2CEURPublicKey',
'type' => 'str',
'value' => ''
],
// live Paylater Installment B2C CHF
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPublicKeyB2BEUR',
'group' => 'unzerpaylater',
'name' => 'production-UnzerPayLaterInstallmentB2CCHFPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPrivateKeyB2BEUR',
'group' => 'unzerpaylater',
'name' => 'production-UnzerPayLaterInstallmentB2CCHFPublicKey',
'type' => 'str',
'value' => ''
],

// sandbox Paylater Invoice B2C EUR
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPublicKeyB2CCHF',
'name' => 'sandbox-UnzerPayLaterInvoiceB2CEURPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPrivateKeyB2CCHF',
'name' => 'sandbox-UnzerPayLaterInvoiceB2CEURPublicKey',
'type' => 'str',
'value' => ''
],
// sandbox Paylater Invoice B2B EUR
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPublicKeyB2BCHF',
'name' => 'sandbox-UnzerPayLaterInvoiceB2BEURPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerinvoice',
'name' => 'production-UnzerPrivateKeyB2BCHF',
'name' => 'sandbox-UnzerPayLaterInvoiceB2BEURPublicKey',
'type' => 'str',
'value' => ''
],
// sandbox Paylater Invoice B2C CHF
[
'group' => 'unzerpaylater',
'name' => 'sandbox-UnzerPaylaterPublicKeyB2CEUR',
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPayLaterInvoiceB2CCHFPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerpaylater',
'name' => 'sandbox-UnzerPaylaterPrivateKeyB2CEUR',
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPayLaterInvoiceB2CCHFPublicKey',
'type' => 'str',
'value' => ''
],
// sandbox Paylater Invoice B2B CHF
[
'group' => 'unzerpaylater',
'name' => 'sandbox-UnzerPaylaterPublicKeyB2CCHF',
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPayLaterInvoiceB2BCHFPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerpaylater',
'name' => 'sandbox-UnzerPaylaterPrivateKeyB2CCHF',
'group' => 'unzerinvoice',
'name' => 'sandbox-UnzerPayLaterInvoiceB2BCHFPublicKey',
'type' => 'str',
'value' => ''
],
// sandbox Paylater Installment B2C EUR
[
'group' => 'unzerpaylater',
'name' => 'production-UnzerPaylaterPublicKeyB2CEUR',
'name' => 'sandbox-UnzerPayLaterInstallmentB2CEURPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerpaylater',
'name' => 'production-UnzerPaylaterPrivateKeyB2CEUR',
'name' => 'sandbox-UnzerPayLaterInstallmentB2CEURPublicKey',
'type' => 'str',
'value' => ''
],
// sandbox Paylater Installment B2C CHF
[
'group' => 'unzerpaylater',
'name' => 'production-UnzerPaylaterPublicKeyB2CCHF',
'name' => 'sandbox-UnzerPayLaterInstallmentB2CCHFPrivateKey',
'type' => 'str',
'value' => ''
],
[
'group' => 'unzerpaylater',
'name' => 'production-UnzerPaylaterPrivateKeyB2CCHF',
'name' => 'sandbox-UnzerPayLaterInstallmentB2CCHFPublicKey',
'type' => 'str',
'value' => ''
],
Expand Down
75 changes: 41 additions & 34 deletions src/Controller/AccountSavedPaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@

use OxidEsales\Eshop\Application\Controller\AccountController;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidSolutionCatalysts\Unzer\Exception\UnzerException;
use OxidSolutionCatalysts\Unzer\Service\DebugHandler;
use OxidSolutionCatalysts\Unzer\Service\Transaction;
use OxidSolutionCatalysts\Unzer\Service\UnzerSDKLoader;
use OxidSolutionCatalysts\Unzer\Traits\ServiceContainer;
use OxidEsales\Eshop\Core\Registry;
use UnzerSDK\Exceptions\UnzerApiException;

class AccountSavedPaymentController extends AccountController
{
Expand Down Expand Up @@ -51,50 +55,53 @@ public function render()

protected function setPaymentListsToView(): void
{
$UnzerSdk = $this->getServiceFromContainer(UnzerSDKLoader::class);
$unzerSDK = $UnzerSdk->getUnzerSDK();

$ids = $this->getTransactionIds();
$transactionService = $this->getServiceFromContainer(Transaction::class);
$ids = $transactionService->getTransactionIds($this->getUser());
$paymentTypes = false;
foreach ($ids as $typeId) {
if (empty($typeId['PAYMENTTYPEID'])) {
foreach ($ids as $typeData) {
$paymentTypeId = $typeData['PAYMENTTYPEID'];
$paymentId = (string)$typeData['OXPAYMENTTYPE'];
$currency = $typeData['CURRENCY'];
$customerType = $typeData['CUSTOMERTYPE'];
$transactionOxId = $typeData['OXID'];

if (empty($paymentTypeId)) {
continue;
}
$paymentType = $unzerSDK->fetchPaymentType($typeId['PAYMENTTYPEID']);

if (strpos($typeId['PAYMENTTYPEID'], 'crd') && method_exists($paymentType, 'getBrand')) {
$paymentTypes[$paymentType->getBrand()][$typeId['OXID']] = $paymentType->expose();
}
if (strpos($typeId['PAYMENTTYPEID'], 'ppl')) {
$paymentTypes['paypal'][$typeId['OXID']] = $paymentType->expose();
}
if (strpos($typeId['PAYMENTTYPEID'], 'sdd')) {
$paymentTypes['sepa'][$typeId['OXID']] = $paymentType->expose();
try {
$unzerSDK = $this->getServiceFromContainer(UnzerSDKLoader::class)->getUnzerSDK(
$paymentId,
$currency,
$customerType
);
$paymentType = $unzerSDK->fetchPaymentType($paymentTypeId);
if (strpos($paymentTypeId, 'crd') && method_exists($paymentType, 'getBrand')) {
$paymentTypes[$paymentType->getBrand()][$transactionOxId] = $paymentType->expose();
}
if (strpos($paymentTypeId, 'ppl')) {
$paymentTypes['paypal'][$transactionOxId] = $paymentType->expose();
}
if (strpos($paymentTypeId, 'sdd')) {
$paymentTypes['sepa'][$transactionOxId] = $paymentType->expose();
}
} catch (UnzerApiException | UnzerException $e) {
if ($e->getCode() !== 'API.500.100.001') {
$logEntry = sprintf(
'Unknown error code while creating the PaymentList: "%s"',
$e->getCode()
);
$logger = $this->getServiceFromContainer(DebugHandler::class);
$logger->log($logEntry);
continue;
}
$paymentTypes['invalid_payment_method_with_id'][$transactionOxId] = $paymentTypeId;
}
}

$this->_aViewData['unzerPaymentType'] = $paymentTypes;
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
protected function getTransactionIds(): array
{
$result = [];
if ($this->getUser()) {
$oDB = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
$result = $oDB->getAll(
"SELECT OXID, PAYMENTTYPEID from oscunzertransaction
where OXUSERID = :oxuserid
AND PAYMENTTYPEID IS NOT NULL
GROUP BY PAYMENTTYPEID ",
[':oxuserid' => $this->getUser()->getId()]
);
}
return $result;
}

/**
* @SuppressWarnings(PHPMD.StaticAccess)
*/
Expand Down
Loading

0 comments on commit d9cf3b8

Please sign in to comment.