Skip to content

Commit

Permalink
Merge pull request #2558 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 9.4.0
  • Loading branch information
candemiralp authored Mar 25, 2024
2 parents f0e8f18 + 9d44c14 commit 9014493
Show file tree
Hide file tree
Showing 49 changed files with 1,972 additions and 397 deletions.
8 changes: 5 additions & 3 deletions Api/AdyenStateDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
interface AdyenStateDataInterface
{
/**
* Persist the Adyen state data for the quote so it can be used in the payment request
* Persist the Adyen state data for the quote and returns the stateDataId.
* So it can be used in the payment request.
*
*
* @param string $stateData
* @param int $cartId
* @return void
* @return int
*/
public function save(string $stateData, int $cartId): void;
public function save(string $stateData, int $cartId): int;

/**
* Removes the Adyen state data with the given entity id
Expand Down
7 changes: 4 additions & 3 deletions Api/GuestAdyenStateDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
interface GuestAdyenStateDataInterface
{
/**
* Persist the Adyen state data for the quote so it can be used in the payment request
* Persist the Adyen state data for the quote and returns the stateDataId.
* So it can be used in the payment request.
*
* @param string $stateData
* @param string $cartId
* @return void
* @return int
*/
public function save(string $stateData, string $cartId): void;
public function save(string $stateData, string $cartId): int;

/**
* Removes the Adyen state data with the given entity id
Expand Down
10 changes: 8 additions & 2 deletions Gateway/Request/CaptureDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function build(array $buildSubject): array

//Check additionaldata
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceDataForOrder($order);
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceDataForInvoice($latestInvoice);
$requestBody = array_merge($requestBody, $openInvoiceFields);
}
$request['body'] = $requestBody;
Expand Down Expand Up @@ -179,7 +179,13 @@ public function buildPartialOrMultipleCaptureData($payment, $currency, $adyenOrd
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod(
$adyenOrderPayment[OrderPaymentInterface::PAYMENT_METHOD]
)) {
$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceDataForLastInvoice($payment);
$order = $payment->getOrder();
$invoices = $order->getInvoiceCollection();
// The latest invoice will contain only the selected items(and quantities) for the (partial) capture
/** @var Invoice $invoice */
$invoice = $invoices->getLastItem();

$openInvoiceFields = $this->openInvoiceHelper->getOpenInvoiceDataForInvoice($invoice);
$authToCapture = array_merge($authToCapture, $openInvoiceFields);
}

Expand Down
2 changes: 1 addition & 1 deletion Gateway/Request/RefundDataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function build(array $buildSubject): array
);

if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
$openInvoiceFieldsCreditMemo = $this->openInvoiceHelper->getOpenInvoiceDataForCreditMemo($payment);
$openInvoiceFieldsCreditMemo = $this->openInvoiceHelper->getOpenInvoiceDataForCreditMemo($creditMemo);
//There is only one payment, so we add the fields to the first(and only) result
$requestBody[0] = array_merge($requestBody[0], $openInvoiceFieldsCreditMemo);
}
Expand Down
121 changes: 66 additions & 55 deletions Helper/ChargedCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,55 +80,57 @@ public function getQuoteAmountCurrency(Quote $quote)
return new AdyenAmountCurrency($quote->getGrandTotal(), $quote->getQuoteCurrencyCode());
}

/**
* @param Quote\Item $item
* @return AdyenAmountCurrency
*/
public function getQuoteItemAmountCurrency(Quote\Item $item)
public function getQuoteItemAmountCurrency(Quote\Item $item): AdyenAmountCurrency
{
$chargedCurrency = $this->config->getChargedCurrency($item->getStoreId());

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
$item->getBasePrice(),
$item->getBaseRowTotal() / $item->getQty(),
$item->getQuote()->getBaseCurrencyCode(),
$item->getBaseDiscountAmount(),
$item->getBasePriceInclTax() - $item->getBasePrice(),
$item->getBaseDiscountAmount() / $item->getQty(),
$item->getBaseTaxAmount() / $item->getQty(),
null,
$item->getBasePriceInclTax()
$item->getBaseRowTotalInclTax() / $item->getQty(),
$item->getBaseDiscountTaxCompensationAmount() / $item->getQty()
);
}
$amount = $item->getRowTotal()/$item->getQty();
$amountIncludingTax = $item->getRowTotalInclTax()/$item->getQty();

return new AdyenAmountCurrency(
$amount,
$item->getRowTotal() / $item->getQty(),
$item->getQuote()->getQuoteCurrencyCode(),
$item->getDiscountAmount(),
$amountIncludingTax - $amount,
$item->getDiscountAmount() / $item->getQty(),
$item->getTaxAmount() / $item->getQty(),
null,
$amountIncludingTax
$item->getRowTotalInclTax() / $item->getQty(),
$item->getDiscountTaxCompensationAmount() / $item->getQty()
);
}

/**
* @param Invoice\Item $item
* @return AdyenAmountCurrency
*/
public function getInvoiceItemAmountCurrency(Invoice\Item $item)
public function getInvoiceItemAmountCurrency(Invoice\Item $item): AdyenAmountCurrency
{
$chargedCurrency = $item->getInvoice()->getOrder()->getAdyenChargedCurrency();

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
$item->getBasePrice(),
$item->getBaseRowTotal() / $item->getQty(),
$item->getInvoice()->getBaseCurrencyCode(),
$item->getBaseDiscountAmount() / $item->getQty(),
$item->getBaseTaxAmount() / $item->getQty(),
null,
$item->getBaseTaxAmount() / $item->getQty()
$item->getBaseRowTotalInclTax() / $item->getQty(),
$item->getBaseDiscountTaxCompensationAmount() / $item->getQty()
);
}

return new AdyenAmountCurrency(
$item->getPrice(),
$item->getRowTotal() / $item->getQty(),
$item->getInvoice()->getOrderCurrencyCode(),
$item->getDiscountAmount() / $item->getQty(),
$item->getTaxAmount() / $item->getQty(),
null,
($item->getQty() > 0) ? $item->getTaxAmount() / $item->getQty() : 0
$item->getRowTotalInclTax() / $item->getQty(),
$item->getDiscountTaxCompensationAmount() / $item->getQty()
);
}

Expand Down Expand Up @@ -175,100 +177,109 @@ public function getCreditMemoAdjustmentAmountCurrency(CreditmemoInterface $credi
);
}

/**
* @param CreditmemoInterface $creditMemo
* @return AdyenAmountCurrency
*/
public function getCreditMemoShippingAmountCurrency(CreditmemoInterface $creditMemo)
public function getCreditMemoShippingAmountCurrency(CreditmemoInterface $creditMemo): AdyenAmountCurrency
{
$chargedCurrency = $creditMemo->getOrder()->getAdyenChargedCurrency();

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
$creditMemo->getBaseShippingAmount(),
$creditMemo->getBaseCurrencyCode(),
null,
$creditMemo->getBaseShippingTaxAmount()
$creditMemo->getBaseShippingTaxAmount(),
null,
$creditMemo->getBaseShippingInclTax(),
$creditMemo->getBaseShippingDiscountTaxCompensationAmnt()
);
}
return new AdyenAmountCurrency(
$creditMemo->getShippingAmount(),
$creditMemo->getOrderCurrencyCode(),
null,
$creditMemo->getShippingTaxAmount()
$creditMemo->getShippingTaxAmount(),
null,
$creditMemo->getShippingInclTax(),
$creditMemo->getShippingDiscountTaxCompensationAmount()
);
}

/**
* @param CreditmemoItemInterface $item
* @return AdyenAmountCurrency
*/
public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item)
public function getCreditMemoItemAmountCurrency(CreditmemoItemInterface $item): AdyenAmountCurrency
{
$chargedCurrency = $item->getCreditMemo()->getOrder()->getAdyenChargedCurrency();

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
$item->getBasePrice(),
$item->getBaseRowTotal() / $item->getQty(),
$item->getCreditMemo()->getBaseCurrencyCode(),
$item->getBaseDiscountAmount() / $item->getQty(),
$item->getBaseTaxAmount() / $item->getQty(),
null,
$item->getBaseTaxAmount() / $item->getQty()
$item->getBaseRowTotalInclTax() / $item->getQty(),
$item->getBaseDiscountTaxCompensationAmount() / $item->getQty()
);
}
return new AdyenAmountCurrency(
$item->getPrice(),
$item->getRowTotal() / $item->getQty(),
$item->getCreditMemo()->getOrderCurrencyCode(),
$item->getDiscountAmount() / $item->getQty(),
$item->getTaxAmount() / $item->getQty(),
null,
$item->getTaxAmount() / $item->getQty()
$item->getRowTotalInclTax() / $item->getQty(),
$item->getDiscountTaxCompensationAmount() / $item->getQty()
);
}


/**
* @param Quote $quote
* @return AdyenAmountCurrency
*/
public function getQuoteShippingAmountCurrency(Quote $quote)
public function getQuoteShippingAmountCurrency(Quote $quote): AdyenAmountCurrency
{
$chargedCurrency = $this->config->getChargedCurrency($quote->getStoreId());

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
$quote->getShippingAddress()->getBaseShippingAmount(),
$quote->getBaseCurrencyCode(),
$quote->getShippingAddress()->getBaseShippingDiscountAmount(),
$quote->getShippingAddress()->getBaseShippingTaxAmount(),
null,
$quote->getShippingAddress()->getBaseShippingInclTax()
$quote->getShippingAddress()->getBaseShippingInclTax(),
$quote->getShippingAddress()->getBaseShippingDiscountTaxCompensationAmnt()
);
}

return new AdyenAmountCurrency(
$quote->getShippingAddress()->getShippingAmount(),
$quote->getQuoteCurrencyCode(),
$quote->getShippingAddress()->getShippingDiscountAmount(),
$quote->getShippingAddress()->getShippingTaxAmount(),
null,
$quote->getShippingAddress()->getShippingInclTax()
$quote->getShippingAddress()->getShippingInclTax(),
$quote->getShippingAddress()->getShippingDiscountTaxCompensationAmount()
);
}

/**
* @param Invoice $invoice
* @return AdyenAmountCurrency
*/
public function getInvoiceShippingAmountCurrency(Invoice $invoice)
public function getInvoiceShippingAmountCurrency(Invoice $invoice): AdyenAmountCurrency
{
$chargedCurrency = $invoice->getOrder()->getAdyenChargedCurrency();

if ($chargedCurrency == self::BASE) {
return new AdyenAmountCurrency(
$invoice->getBaseShippingAmount(),
$invoice->getBaseCurrencyCode(),
null,
$invoice->getBaseShippingTaxAmount()
$invoice->getBaseShippingTaxAmount(),
null,
$invoice->getBaseShippingInclTax(),
$invoice->getBaseShippingDiscountTaxCompensationAmnt()
);
}

return new AdyenAmountCurrency(
$invoice->getShippingAmount(),
$invoice->getOrderCurrencyCode(),
null,
$invoice->getShippingTaxAmount()
$invoice->getShippingTaxAmount(),
null,
$invoice->getShippingInclTax(),
$invoice->getShippingDiscountTaxCompensationAmount()
);
}

Expand Down
11 changes: 11 additions & 0 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Config
const XML_WEBHOOK_NOTIFICATION_PROCESSOR = 'webhook_notification_processor';
const AUTO_CAPTURE_OPENINVOICE = 'auto';
const XML_RECURRING_CONFIGURATION = 'recurring_configuration';
const XML_ALLOW_MULTISTORE_TOKENS = 'allow_multistore_tokens';

protected ScopeConfigInterface $scopeConfig;
private EncryptorInterface $encryptor;
Expand Down Expand Up @@ -559,6 +560,16 @@ public function getRatePayId(int $storeId = null)
return $this->getConfigData("ratepay_id", self::XML_ADYEN_RATEPAY, $storeId);
}

public function getAllowMultistoreTokens(int $storeId = null): ?bool
{
return $this->getConfigData(
self::XML_ALLOW_MULTISTORE_TOKENS,
self::XML_ADYEN_ABSTRACT_PREFIX,
$storeId,
true
);
}

public function getConfigData(string $field, string $xmlPrefix, ?int $storeId, bool $flag = false): mixed
{
$path = implode("/", [self::XML_PAYMENT_PREFIX, $xmlPrefix, $field]);
Expand Down
Loading

0 comments on commit 9014493

Please sign in to comment.