We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 41143b07 authored by Alessio Zampatti's avatar Alessio Zampatti Committed by GitHub

PW-256 Support multiple partial Captures for open invoice payment methods (#276)

* PW-256: Added multiple partial captures for OpenInvoice payments

* PW-256: Added adyen_invoice table, added support for acquirerReference.

* PW-256: Moved OpenInvoiceLineData function in the helper. refactored getItemVatAmount, changed description of the entityID

* PW-256: Refactor openinvoicedata functions

* PW-256: Refactor __construct
parent 7d7792c5
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2018 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Api\Data;
interface InvoiceInterface
{
/**
* Constants for keys of data array. Identical to the name of the getter in snake case.
*/
/*
* Entity ID.
*/
const ENTITY_ID = 'entity_id';
/*
* Pspreference of the capture.
*/
const PSPREFERENCE = 'pspreference';
/*
* Original Pspreference of the payment.
*/
const ORIGINAL_REFERENCE = 'original_reference';
/*
* Acquirer reference.
*/
const ACQUIRER_REFERENCE = 'acquirer_reference';
/*
* Invoice ID.
*/
const INVOICE_ID = 'invoice_id';
/**
* Gets the ID for the invoice.
*
* @return int|null Entity ID.
*/
public function getEntityId();
/**
* Sets entity ID.
*
* @param int $entityId
* @return $this
*/
public function setEntityId($entityId);
/**
* Gets the Pspreference for the invoice(capture).
*
* @return int|null Pspreference.
*/
public function getPspreference();
/**
* Sets Pspreference.
*
* @param string $pspreference
* @return $this
*/
public function setPspreference($pspreference);
/**
* @return mixed
*/
public function getOriginalReference();
/**
* @param $originalReference
* @return mixed
*/
public function setOriginalReference($originalReference);
/**
* Gets the AcquirerReference for the invoice.
*
* @return int|null Acquirerreference.
*/
public function getAcquirerReference();
/**
* Sets AcquirerReference.
*
* @param string $acquirerReference
* @return $this
*/
public function setAcquirerReference($acquirerReference);
/**
* Gets the InvoiceID for the invoice.
*
* @return int|null Invoice ID.
*/
public function getInvoiceId();
/**
* Sets InvoiceID.
*
* @param int $invoiceId
* @return $this
*/
public function setInvoiceId($invoiceId);
}
\ No newline at end of file
...@@ -445,31 +445,22 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -445,31 +445,22 @@ class Redirect extends \Magento\Payment\Block\Form
foreach ($this->_order->getAllVisibleItems() as $item) { foreach ($this->_order->getAllVisibleItems() as $item) {
++$count; ++$count;
$description = str_replace("\n", '', trim($item->getName()));
$itemAmount = $this->_adyenHelper->formatAmount($item->getPrice(), $currency);
$itemVatAmount =
($item->getTaxAmount() > 0 && $item->getPriceInclTax() > 0) ?
$this->_adyenHelper->formatAmount(
$item->getPriceInclTax(),
$currency
) - $this->_adyenHelper->formatAmount(
$item->getPrice(),
$currency
) : $this->_adyenHelper->formatAmount($item->getTaxAmount(), $currency);
// Calculate vat percentage
$itemVatPercentage = $this->_adyenHelper->getMinorUnitTaxPercent($item->getTaxPercent());
$numberOfItems = (int)$item->getQtyOrdered(); $numberOfItems = (int)$item->getQtyOrdered();
$formFields = $this->setOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount, $formFields = $this->_adyenHelper->createOpenInvoiceLineItem(
$itemVatAmount, $itemVatPercentage, $numberOfItems); $formFields,
$count,
$item->getName(),
$item->getPrice(),
$currency,
$item->getTaxAmount(),
$item->getPriceInclTax(),
$item->getTaxPercent(),
$numberOfItems,
$this->_order->getPayment()
);
} }
// Discount cost // Discount cost
if ($this->_order->getDiscountAmount() > 0 || $this->_order->getDiscountAmount() < 0) { if ($this->_order->getDiscountAmount() > 0 || $this->_order->getDiscountAmount() < 0) {
++$count; ++$count;
...@@ -480,35 +471,23 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -480,35 +471,23 @@ class Redirect extends \Magento\Payment\Block\Form
$itemVatPercentage = "0"; $itemVatPercentage = "0";
$numberOfItems = 1; $numberOfItems = 1;
$formFields = $this->setOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount, $formFields = $this->_adyenHelper->getOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems); $itemVatAmount, $itemVatPercentage, $numberOfItems, $this->_order->getPayment());
} }
// Shipping cost // Shipping cost
if ($this->_order->getShippingAmount() > 0 || $this->_order->getShippingTaxAmount() > 0) { if ($this->_order->getShippingAmount() > 0 || $this->_order->getShippingTaxAmount() > 0) {
++$count; ++$count;
$description = $this->_order->getShippingDescription(); $formFields = $this->_adyenHelper->createOpenInvoiceLineShipping(
$itemAmount = $this->_adyenHelper->formatAmount($this->_order->getShippingAmount(), $currency); $formFields,
$itemVatAmount = $this->_adyenHelper->formatAmount($this->_order->getShippingTaxAmount(), $currency); $count,
$this->_order,
// Create RateRequest to calculate the Tax class rate for the shipping method $this->_order->getShippingAmount(),
$rateRequest = $this->_taxCalculation->getRateRequest( $this->_order->getShippingTaxAmount(),
$this->_order->getShippingAddress(), $currency,
$this->_order->getBillingAddress(), $this->_order->getPayment()
null,
$this->_order->getStoreId(), $this->_order->getCustomerId()
); );
$taxClassId = $this->_taxConfig->getShippingTaxClass($this->_order->getStoreId());
$rateRequest->setProductClassId($taxClassId);
$rate = $this->_taxCalculation->getRate($rateRequest);
$itemVatPercentage = $this->_adyenHelper->getMinorUnitTaxPercent($rate);
$numberOfItems = 1;
$formFields = $this->setOpenInvoiceLineData($formFields, $count, $currency, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems);
} }
$formFields['openinvoicedata.refundDescription'] = "Refund / Correction for " . $formFields['merchantReference']; $formFields['openinvoicedata.refundDescription'] = "Refund / Correction for " . $formFields['merchantReference'];
...@@ -517,40 +496,6 @@ class Redirect extends \Magento\Payment\Block\Form ...@@ -517,40 +496,6 @@ class Redirect extends \Magento\Payment\Block\Form
return $formFields; return $formFields;
} }
/**
* Set the openinvoice line
*
* @param $count
* @param $currencyCode
* @param $description
* @param $itemAmount
* @param $itemVatAmount
* @param $itemVatPercentage
* @param $numberOfItems
*/
protected function setOpenInvoiceLineData($formFields, $count, $currencyCode, $description, $itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems
)
{
$linename = "line" . $count;
$formFields['openinvoicedata.' . $linename . '.currencyCode'] = $currencyCode;
$formFields['openinvoicedata.' . $linename . '.description'] = $description;
$formFields['openinvoicedata.' . $linename . '.itemAmount'] = $itemAmount;
$formFields['openinvoicedata.' . $linename . '.itemVatAmount'] = $itemVatAmount;
$formFields['openinvoicedata.' . $linename . '.itemVatPercentage'] = $itemVatPercentage;
$formFields['openinvoicedata.' . $linename . '.numberOfItems'] = $numberOfItems;
if ($this->_adyenHelper->isVatCategoryHigh($this->_order->getPayment()->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE))
) {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "High";
} else {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "None";
}
return $formFields;
}
/** /**
* @param $genderId * @param $genderId
* @return string * @return string
......
...@@ -48,7 +48,7 @@ class CaptureDataBuilder implements BuilderInterface ...@@ -48,7 +48,7 @@ class CaptureDataBuilder implements BuilderInterface
/** /**
* Create capture request * Create capture request
* *
* @param array $buildSubject * @param array $buildSubject
* @return array * @return array
*/ */
...@@ -57,21 +57,84 @@ class CaptureDataBuilder implements BuilderInterface ...@@ -57,21 +57,84 @@ class CaptureDataBuilder implements BuilderInterface
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$amount = \Magento\Payment\Gateway\Helper\SubjectReader::readAmount($buildSubject); $amount = \Magento\Payment\Gateway\Helper\SubjectReader::readAmount($buildSubject);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$pspReference = $payment->getCcTransId(); $pspReference = $payment->getCcTransId();
$currency = $payment->getOrder()->getOrderCurrencyCode(); $currency = $payment->getOrder()->getOrderCurrencyCode();
//format the amount to minor units
$amount = $this->adyenHelper->formatAmount($amount, $currency); $amount = $this->adyenHelper->formatAmount($amount, $currency);
$modificationAmount = ['currency' => $currency, 'value' => $amount]; $modificationAmount = ['currency' => $currency, 'value' => $amount];
$request = [
return [
"modificationAmount" => $modificationAmount, "modificationAmount" => $modificationAmount,
"reference" => $payment->getOrder()->getIncrementId(), "reference" => $payment->getOrder()->getIncrementId(),
"originalReference" => $pspReference "originalReference" => $pspReference
]; ];
$brandCode = $payment->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE
);
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
$openInvoiceFields = $this->getOpenInvoiceData($payment);
$request["additionalData"] = $openInvoiceFields;
}
return $request;
}
/**
* @param $payment
* @return mixed
* @internal param $formFields
*/
protected function getOpenInvoiceData($payment)
{
$formFields = [];
$count = 0;
$currency = $payment->getOrder()->getOrderCurrencyCode();
$invoices = $payment->getOrder()->getInvoiceCollection();
// The latest invoice will contain only the selected items(and quantities) for the (partial) capture
$latestInvoice = $invoices->getLastItem();
foreach ($latestInvoice->getItemsCollection() as $invoiceItem) {
++$count;
$numberOfItems = (int)$invoiceItem->getQty();
$formFields = $this->adyenHelper->createOpenInvoiceLineItem(
$formFields,
$count,
$invoiceItem->getName(),
$invoiceItem->getPrice(),
$currency,
$invoiceItem->getTaxAmount(),
$invoiceItem->getPriceInclTax(),
$invoiceItem->getTaxPercent(),
$numberOfItems,
$payment
);
}
// Shipping cost
if ($latestInvoice->getShippingAmount() > 0) {
++$count;
$formFields = $this->adyenHelper->createOpenInvoiceLineShipping(
$formFields,
$count,
$payment->getOrder(),
$latestInvoice->getShippingAmount(),
$latestInvoice->getShippingTaxAmount(),
$currency,
$payment
);
}
$formFields['openinvoicedata.numberOfLines'] = $count;
return $formFields;
} }
} }
\ No newline at end of file
...@@ -74,6 +74,16 @@ class Data extends AbstractHelper ...@@ -74,6 +74,16 @@ class Data extends AbstractHelper
*/ */
protected $_notificationFactory; protected $_notificationFactory;
/**
* @var \Magento\Tax\Model\Config
*/
protected $_taxConfig;
/**
* @var \Magento\Tax\Model\Calculation
*/
protected $_taxCalculation;
/** /**
* Data constructor. * Data constructor.
* *
...@@ -95,9 +105,10 @@ class Data extends AbstractHelper ...@@ -95,9 +105,10 @@ class Data extends AbstractHelper
\Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory, \Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory,
\Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\View\Asset\Repository $assetRepo,
\Magento\Framework\View\Asset\Source $assetSource, \Magento\Framework\View\Asset\Source $assetSource,
\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory $notificationFactory \Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory $notificationFactory,
) \Magento\Tax\Model\Config $taxConfig,
{ \Magento\Tax\Model\Calculation $taxCalculation
) {
parent::__construct($context); parent::__construct($context);
$this->_encryptor = $encryptor; $this->_encryptor = $encryptor;
$this->_dataStorage = $dataStorage; $this->_dataStorage = $dataStorage;
...@@ -107,6 +118,8 @@ class Data extends AbstractHelper ...@@ -107,6 +118,8 @@ class Data extends AbstractHelper
$this->_assetRepo = $assetRepo; $this->_assetRepo = $assetRepo;
$this->_assetSource = $assetSource; $this->_assetSource = $assetSource;
$this->_notificationFactory = $notificationFactory; $this->_notificationFactory = $notificationFactory;
$this->_taxConfig = $taxConfig;
$this->_taxCalculation = $taxCalculation;
} }
/** /**
...@@ -973,4 +986,149 @@ class Data extends AbstractHelper ...@@ -973,4 +986,149 @@ class Data extends AbstractHelper
return "https://" . $environment . ".adyen.com/hpp/cse/js/" . $this->getLibraryToken($storeId) . ".shtml"; return "https://" . $environment . ".adyen.com/hpp/cse/js/" . $this->getLibraryToken($storeId) . ".shtml";
} }
/**
* @param $formFields
* @param $count
* @param $name
* @param $price
* @param $currency
* @param $taxAmount
* @param $priceInclTax
* @param $taxPercent
* @param $numberOfItems
* @param $payment
* @return mixed
*/
public function createOpenInvoiceLineItem(
$formFields,
$count,
$name,
$price,
$currency,
$taxAmount,
$priceInclTax,
$taxPercent,
$numberOfItems,
$payment
) {
$description = str_replace("\n", '', trim($name));
$itemAmount = $this->formatAmount($price, $currency);
$itemVatAmount = $this->getItemVatAmount($taxAmount,
$priceInclTax, $price, $currency);
// Calculate vat percentage
$itemVatPercentage = $this->getMinorUnitTaxPercent($taxPercent);
return $this->getOpenInvoiceLineData($formFields, $count, $currency, $description,
$itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems, $payment);
}
/**
* @param $formFields
* @param $count
* @param $order
* @param $shippingAmount
* @param $shippingTaxAmount
* @param $currency
* @param $payment
* @return mixed
*/
public function createOpenInvoiceLineShipping(
$formFields,
$count,
$order,
$shippingAmount,
$shippingTaxAmount,
$currency,
$payment
) {
$description = $order->getShippingDescription();
$itemAmount = $this->formatAmount($shippingAmount, $currency);
$itemVatAmount = $this->formatAmount($shippingTaxAmount, $currency);
// Create RateRequest to calculate the Tax class rate for the shipping method
$rateRequest = $this->_taxCalculation->getRateRequest(
$order->getShippingAddress(),
$order->getBillingAddress(),
null,
$order->getStoreId(),
$order->getCustomerId()
);
$taxClassId = $this->_taxConfig->getShippingTaxClass($order->getStoreId());
$rateRequest->setProductClassId($taxClassId);
$rate = $this->_taxCalculation->getRate($rateRequest);
$itemVatPercentage = $this->getMinorUnitTaxPercent($rate);
$numberOfItems = 1;
return $this->getOpenInvoiceLineData($formFields, $count, $currency, $description,
$itemAmount,
$itemVatAmount, $itemVatPercentage, $numberOfItems, $payment);
}
/**
* @param $taxAmount
* @param $priceInclTax
* @param $price
* @param $currency
* @return string
*/
public function getItemVatAmount(
$taxAmount,
$priceInclTax,
$price,
$currency
) {
if ($taxAmount > 0 && $priceInclTax > 0) {
return $this->formatAmount($priceInclTax, $currency) - $this->formatAmount($price, $currency);
}
return $this->formatAmount($taxAmount, $currency);
}
/**
* Set the openinvoice line
*
* @param $formFields
* @param $count
* @param $currencyCode
* @param $description
* @param $itemAmount
* @param $itemVatAmount
* @param $itemVatPercentage
* @param $numberOfItems
* @param $payment
* @return
*/
public function getOpenInvoiceLineData(
$formFields,
$count,
$currencyCode,
$description,
$itemAmount,
$itemVatAmount,
$itemVatPercentage,
$numberOfItems,
$payment
) {
$linename = "line" . $count;
$formFields['openinvoicedata.' . $linename . '.currencyCode'] = $currencyCode;
$formFields['openinvoicedata.' . $linename . '.description'] = $description;
$formFields['openinvoicedata.' . $linename . '.itemAmount'] = $itemAmount;
$formFields['openinvoicedata.' . $linename . '.itemVatAmount'] = $itemVatAmount;
$formFields['openinvoicedata.' . $linename . '.itemVatPercentage'] = $itemVatPercentage;
$formFields['openinvoicedata.' . $linename . '.numberOfItems'] = $numberOfItems;
if ($this->isVatCategoryHigh($payment->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE))
) {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "High";
} else {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "None";
}
return $formFields;
}
} }
\ No newline at end of file
...@@ -112,6 +112,11 @@ class Cron ...@@ -112,6 +112,11 @@ class Cron
*/ */
protected $_merchantReference; protected $_merchantReference;
/**
* @var
*/
protected $_acquirerReference;
/** /**
* @var * @var
*/ */
...@@ -172,6 +177,11 @@ class Cron ...@@ -172,6 +177,11 @@ class Cron
*/ */
protected $_adyenOrderPaymentCollectionFactory; protected $_adyenOrderPaymentCollectionFactory;
/**
* @var ResourceModel\InvoiceFactory
*/
protected $_adyenInvoiceFactory;
/** /**
* @var AreaList * @var AreaList
*/ */
...@@ -209,9 +219,9 @@ class Cron ...@@ -209,9 +219,9 @@ class Cron
\Adyen\Payment\Model\Api\PaymentRequest $paymentRequest, \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest,
\Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory, \Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory,
\Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory, \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
\Adyen\Payment\Model\InvoiceFactory $adyenInvoiceFactory,
AreaList $areaList AreaList $areaList
) ) {
{
$this->_scopeConfig = $scopeConfig; $this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger; $this->_adyenLogger = $adyenLogger;
$this->_notificationFactory = $notificationFactory; $this->_notificationFactory = $notificationFactory;
...@@ -225,6 +235,7 @@ class Cron ...@@ -225,6 +235,7 @@ class Cron
$this->_adyenPaymentRequest = $paymentRequest; $this->_adyenPaymentRequest = $paymentRequest;
$this->_adyenOrderPaymentFactory = $adyenOrderPaymentFactory; $this->_adyenOrderPaymentFactory = $adyenOrderPaymentFactory;
$this->_adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory; $this->_adyenOrderPaymentCollectionFactory = $adyenOrderPaymentCollectionFactory;
$this->_adyenInvoiceFactory = $adyenInvoiceFactory;
$this->_areaList = $areaList; $this->_areaList = $areaList;
} }
...@@ -479,6 +490,10 @@ class Cron ...@@ -479,6 +490,10 @@ class Cron
if ($additionalData2 && is_array($additionalData2)) { if ($additionalData2 && is_array($additionalData2)) {
$this->_klarnaReservationNumber = isset($additionalData2['acquirerReference']) ? trim($additionalData2['acquirerReference']) : ""; $this->_klarnaReservationNumber = isset($additionalData2['acquirerReference']) ? trim($additionalData2['acquirerReference']) : "";
} }
$acquirerReference = isset($additionalData['acquirerReference']) ? $additionalData['acquirerReference'] : null;
if ($acquirerReference != "") {
$this->_acquirerReference = $acquirerReference;
}
} }
} }
...@@ -799,6 +814,22 @@ class Cron ...@@ -799,6 +814,22 @@ class Cron
*/ */
if (!$this->_isAutoCapture()) { if (!$this->_isAutoCapture()) {
$this->_setPaymentAuthorized(false, true); $this->_setPaymentAuthorized(false, true);
/*
* Add invoice in the adyen_invoice table
*/
$invoiceCollection = $this->_order->getInvoiceCollection();
foreach ($invoiceCollection as $invoice) {
if ($invoice->getTransactionId() == $this->_pspReference) {
$this->_adyenInvoiceFactory->create()
->setInvoiceId($invoice->getEntityId())
->setPspreference($this->_pspReference)
->setOriginalReference($this->_originalReference)
->setAcquirerReference($this->_acquirerReference)
->save();
$this->_adyenLogger->addAdyenNotificationCronjob('Created invoice entry in the Adyen table');
}
}
} }
} else { } else {
// FOR POS authorize the payment on the CAPTURE notification // FOR POS authorize the payment on the CAPTURE notification
...@@ -1446,6 +1477,19 @@ class Cron ...@@ -1446,6 +1477,19 @@ class Cron
$invoice->save(); $invoice->save();
$this->_adyenLogger->addAdyenNotificationCronjob('Created invoice'); $this->_adyenLogger->addAdyenNotificationCronjob('Created invoice');
/*
* Add invoice in the adyen_invoice table
*/
$this->_adyenInvoiceFactory->create()
->setInvoiceId($invoice->getEntityId())
->setPspreference($this->_pspReference)
->setOriginalReference($this->_pspReference)
->setAcquirerReference($this->_acquirerReference)
->save();
$this->_adyenLogger->addAdyenNotificationCronjob('Created invoice entry in the Adyen table');
} catch (Exception $e) { } catch (Exception $e) {
$this->_adyenLogger->addAdyenNotificationCronjob( $this->_adyenLogger->addAdyenNotificationCronjob(
'Error saving invoice. The error message is: ' . $e->getMessage() 'Error saving invoice. The error message is: ' . $e->getMessage()
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2018 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
use Adyen\Payment\Api\Data\InvoiceInterface;
class Invoice extends \Magento\Framework\Model\AbstractModel
implements InvoiceInterface
{
/**
* Notification constructor.
*
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}
/**
* Initialize resource model
*
* @return void
*/
protected function _construct()
{
$this->_init('Adyen\Payment\Model\ResourceModel\Invoice');
}
/**
* Gets the Pspreference for the invoice(capture).
*
* @return int|null Pspreference.
*/
public function getPspreference()
{
return $this->getData(self::PSPREFERENCE);
}
/**
* Sets Pspreference.
*
* @param string $pspreference
* @return $this
*/
public function setPspreference($pspreference)
{
return $this->setData(self::PSPREFERENCE, $pspreference);
}
/**
* Gets the Pspreference of the original Payment
* @return mixed
*/
public function getOriginalReference()
{
return $this->getData(self::ORIGINAL_REFERENCE);
}
/**
* Sets the OriginalReference
*
* @param $originalReference
* @return $this
*/
public function setOriginalReference($originalReference)
{
return $this->setData(self::ORIGINAL_REFERENCE, $originalReference);
}
/**
* Gets the AcquirerReference for the invoice.
*
* @return int|null Acquirerreference.
*/
public function getAcquirerReference()
{
return $this->getData(self::ACQUIRER_REFERENCE);
}
/**
* Sets AcquirerReference.
*
* @param string $acquirerReference
* @return $this
*/
public function setAcquirerReference($acquirerReference)
{
return $this->setData(self::ACQUIRER_REFERENCE, $acquirerReference);
}
/**
* Gets the InvoiceID for the invoice.
*
* @return int|null Invoice ID.
*/
public function getInvoiceId()
{
return $this->getData(self::INVOICE_ID);
}
/**
* Sets InvoiceID.
*
* @param int $invoiceId
* @return $this
*/
public function setInvoiceId($invoiceId)
{
return $this->setData(self::INVOICE_ID, $invoiceId);
}
}
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2018 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\ResourceModel;
class Invoice extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
/**
* Resource initialization
*
* @return void
*/
protected function _construct()
{
$this->_init('adyen_invoice', 'entity_id');
}
}
\ No newline at end of file
...@@ -35,6 +35,7 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -35,6 +35,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
{ {
const ADYEN_ORDER_PAYMENT = 'adyen_order_payment'; const ADYEN_ORDER_PAYMENT = 'adyen_order_payment';
const ADYEN_INVOICE = 'adyen_invoice';
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -63,6 +64,10 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -63,6 +64,10 @@ class UpgradeSchema implements UpgradeSchemaInterface
$this->updateSchemaVersion207($setup); $this->updateSchemaVersion207($setup);
} }
if (version_compare($context->getVersion(), '2.2.1', '<')) {
$this->updateSchemaVersion221($setup);
}
$setup->endSetup(); $setup->endSetup();
} }
...@@ -100,7 +105,7 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -100,7 +105,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
$connection->addColumn($setup->getTable('sales_order_payment'), 'adyen_psp_reference', $pspReferenceColumn); $connection->addColumn($setup->getTable('sales_order_payment'), 'adyen_psp_reference', $pspReferenceColumn);
} }
/** /**
* Upgrade to 1.0.0.2 * Upgrade to 1.0.0.2
* *
...@@ -220,7 +225,7 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -220,7 +225,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
) )
->setComment('Adyen Order Payment'); ->setComment('Adyen Order Payment');
$setup->getConnection()->createTable($table); $setup->getConnection()->createTable($table);
// add originalReference to notification table // add originalReference to notification table
...@@ -231,7 +236,7 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -231,7 +236,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
'length' => 255, 'length' => 255,
'nullable' => true, 'nullable' => true,
'comment' => 'Original Reference', 'comment' => 'Original Reference',
'after' => \Adyen\Payment\Model\Notification::PSPREFRENCE 'after' => \Adyen\Payment\Model\Notification::PSPREFRENCE
]; ];
$connection->addColumn( $connection->addColumn(
...@@ -268,9 +273,9 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -268,9 +273,9 @@ class UpgradeSchema implements UpgradeSchemaInterface
} }
/** /**
* Upgrade to 2.0.7 * Upgrade to 2.0.7
* *
* @param SchemaSetupInterface $setup * @param SchemaSetupInterface $setup
* @return void * @return void
*/ */
...@@ -285,7 +290,7 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -285,7 +290,7 @@ class UpgradeSchema implements UpgradeSchemaInterface
'nullable' => true, 'nullable' => true,
'default' => 0, 'default' => 0,
'comment' => 'Adyen Notification Cron Processing', 'comment' => 'Adyen Notification Cron Processing',
'after' => \Adyen\Payment\Model\Notification::DONE 'after' => \Adyen\Payment\Model\Notification::DONE
]; ];
$connection->addColumn( $connection->addColumn(
...@@ -294,4 +299,59 @@ class UpgradeSchema implements UpgradeSchemaInterface ...@@ -294,4 +299,59 @@ class UpgradeSchema implements UpgradeSchemaInterface
$adyenNotificationProcessingColumn $adyenNotificationProcessingColumn
); );
} }
public function updateSchemaVersion221(SchemaSetupInterface $setup)
{
$table = $setup->getConnection()
->newTable($setup->getTable(self::ADYEN_INVOICE))
->addColumn(
'entity_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Adyen Invoice Entity ID'
)
->addColumn(
'pspreference',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['unsigned' => true, 'nullable' => false],
'Adyen pspreference of the capture'
)
->addColumn(
'original_reference',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['unsigned' => true, 'nullable' => true],
'Adyen OriginalReference of the payment'
)
->addColumn('acquirer_reference',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['unsigned' => true, 'nullable' => true],
'Adyen AcquirerReference of the capture')
->addColumn(
'invoice_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
11,
['unsigned' => true, 'nullable' => false],
'Invoice Id'
)
->addForeignKey(
$setup->getFkName(
self::ADYEN_INVOICE,
'invoice_id',
'sales_invoice',
'entity_id'
),
'invoice_id',
$setup->getTable('sales_invoice'),
'entity_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)
->setComment('Adyen Invoice');
$setup->getConnection()->createTable($table);
}
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment