Skip to content

Commit

Permalink
UNZER-527 -=:8 draft: pl-invoice unz-sec b2b 8:=-
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Nov 29, 2024
1 parent d597887 commit a472d77
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/PaymentExtensions/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use UnzerSDK\Resources\TransactionTypes\Authorization;
use OxidEsales\Eshop\Application\Model\Basket;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Registry;


class Invoice extends UnzerPayment
{
Expand Down
4 changes: 3 additions & 1 deletion src/Service/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use UnzerSDK\Resources\AbstractUnzerResource;
use UnzerSDK\Resources\PaymentTypes\BasePaymentType;
use UnzerSDK\Resources\PaymentTypes\InstallmentSecured;
use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice;
use UnzerSDK\Resources\PaymentTypes\Prepayment as UnzerSDKPrepayment;
use UnzerSDK\Resources\PaymentTypes\Invoice as UnzerSDKInvoice;
use UnzerSDK\Resources\TransactionTypes\Authorization;
Expand Down Expand Up @@ -510,7 +511,8 @@ public function isInvoice(): bool
return false;
}

return $sessionPayment->getPaymentType() instanceof UnzerSDKInvoice;
return $sessionPayment->getPaymentType() instanceof UnzerSDKInvoice
|| $sessionPayment->getPaymentType() instanceof PaylaterInvoice;
}

public function isPrepayment(): bool
Expand Down
20 changes: 5 additions & 15 deletions src/Service/TmpOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,19 @@ public function getOrderBySessionOrderId(string $sessionOrderId): Order
return oxNew(Order::class);
}

/**
* @throws \Doctrine\DBAL\Exception
* @throws \Doctrine\DBAL\Driver\Exception
*/
public function getPaymentType(string $sessionOrderId, Order $order): string
{
$paymentType = $order->getFieldData('oxpaymenttype');

if (empty($paymentType)) {
$order = $this->tmpOrder->getTmpOrderByOxOrderId($sessionOrderId);
if ($order !== null) {
$paymentType = $order->getFieldData('oxpaymenttype');
$this->order = $order;
}
$paymentType = $order->oxorder__oxpaymenttype->value ?? '';
}

if (is_string($paymentType) && !empty($paymentType)) {
return $paymentType;
}

$paymentType = $tmpOrder->oxorder__oxpaymenttype->value ?? '';

return $paymentType;
return '';
}

/**
Expand All @@ -77,10 +67,10 @@ public function getOrderCurrency(string $sessionOrderId, Order $order, string $p
$currency = $order->getFieldData('oxcurrency') ?? '';

if ($this->isPaylaterInvoice($paymentType)) {
$tmpOrder = $this->tmpOrder->getTmpOrderByOxOrderId($sessionOrderId);
if ($tmpOrder !== null) {
$order = $this->tmpOrder->getTmpOrderByOxOrderId($sessionOrderId);
if ($order !== null) {
/** @var \stdClass {name: string} $orderCurrency */
$orderCurencyStdCls = $tmpOrder->getOrderCurrency();
$orderCurencyStdCls = $order->getOrderCurrency();
$currency = $orderCurencyStdCls->name;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Service/UnzerSDKLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public function __construct(
public function getUnzerSDK(string $paymentId = '', string $currency = '', string $customerType = ''): Unzer
{
if (UnzerDefinitions::INVOICE_UNZER_PAYMENT_ID === $paymentId) {
if (empty($customerType) || empty($currency)) {
throw new UnzerException('Customer type and currency must be set for invoice payment');
}
$key = $this->moduleSettings->getInvoicePrivateKeyByCustomerTypeAndCurrency(
$customerType,
$currency
Expand Down

0 comments on commit a472d77

Please sign in to comment.