We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 9063aa5a authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #109 from Adyen/develop

Merge 'develop' into master
parents 2e4de85c 7a7741c9
......@@ -27,10 +27,6 @@ use Symfony\Component\Config\Definition\Exception\Exception;
class Pos extends \Magento\Payment\Block\Form
{
/**
* quest prefix
*/
const GUEST_ID = 'customer_';
protected $_orderFactory;
/**
......@@ -118,13 +114,13 @@ class Pos extends \Magento\Payment\Block\Form
$currencyCode = $orderCurrencyCode;
$paymentAmount = $amount;
$merchantReference = $realOrderId;
$shopperReference = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
$shopperEmail = $shopperEmail;
$recurringParams = "";
if ($this->_order->getPayment()->getAdditionalInformation("store_cc") != "") {
if ($this->_order->getPayment()->getAdditionalInformation("store_cc") != ""
&& $customerId > 0
) {
$recurringParams = "&recurringContract=" . urlencode($recurringContract) . "&shopperReference=" .
urlencode($shopperReference) . "&shopperEmail=" . urlencode($shopperEmail);
urlencode($customerId) . "&shopperEmail=" . urlencode($shopperEmail);
}
$receiptOrderLines = "";
......
......@@ -28,11 +28,6 @@ use Symfony\Component\Config\Definition\Exception\Exception;
class Redirect extends \Magento\Payment\Block\Form
{
/**
* quest prefix
*/
const GUEST_ID = 'customer_';
/**
* @var \Magento\Sales\Model\OrderFactory
*/
......@@ -233,8 +228,11 @@ class Redirect extends \Magento\Payment\Block\Form
$recurringType = "RECURRING";
}
$formFields['recurringContract'] = $recurringType;
$formFields['shopperReference'] = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
if ($customerId > 0) {
$formFields['recurringContract'] = $recurringType;
$formFields['shopperReference'] = $customerId;
}
//blocked methods
$formFields['blockedMethods'] = "";
......@@ -441,18 +439,12 @@ class Redirect extends \Magento\Payment\Block\Form
$item->getPrice(),
$currency
) : $this->_adyenHelper->formatAmount($item->getTaxAmount(), $currency);
// $product = $item->getProduct();
// Calculate vat percentage
$percentageMinorUnits = $this->_adyenHelper->getMinorUnitTaxPercent($item->getTaxPercent());
$formFields['openinvoicedata.' . $linename . '.itemVatPercentage'] = $percentageMinorUnits;
$formFields['openinvoicedata.' . $linename . '.numberOfItems'] = (int) $item->getQtyOrdered();
if ($this->_order->getPayment()->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE) == "klarna"
) {
......@@ -460,6 +452,11 @@ class Redirect extends \Magento\Payment\Block\Form
} else {
$formFields['openinvoicedata.' . $linename . '.vatCategory'] = "None";
}
if ($item->getSku() != "") {
$formFields['openinvoicedata.' . $linename . '.itemId'] = $item->getSku();
}
}
$formFields['openinvoicedata.refundDescription'] = "Refund / Correction for ".$formFields['merchantReference'];
......
......@@ -29,11 +29,6 @@ use Magento\Payment\Gateway\CommandInterface;
class PayByMailCommand implements CommandInterface
{
/**
* quest prefix
*/
const GUEST_ID = 'customer_';
/**
* @var \Adyen\Payment\Helper\Data
*/
......@@ -190,10 +185,7 @@ class PayByMailCommand implements CommandInterface
$formFields['shopperEmail'] = $shopperEmail;
// recurring
$recurringType = trim($this->_adyenHelper->getAdyenAbstractConfigData('recurring_type'));
$formFields['recurringContract'] = $recurringType;
$sessionValidity = $this->_adyenHelper->getAdyenPayByMailConfigData('session_validity');
if ($sessionValidity == "") {
......@@ -201,7 +193,11 @@ class PayByMailCommand implements CommandInterface
}
$formFields['sessionValidity'] = date("c", strtotime("+". $sessionValidity. " days"));
$formFields['shopperReference'] = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
if ($customerId > 0) {
$formFields['recurringContract'] = $recurringType;
$formFields['shopperReference'] = $customerId;
}
// Sort the array by key using SORT_STRING order
ksort($formFields, SORT_STRING);
......
......@@ -29,10 +29,6 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
*/
class CustomerDataBuilder implements BuilderInterface
{
/**
* quest prefix
*/
const GUEST_ID = 'customer_';
/**
* Add shopper data into request
......@@ -42,19 +38,22 @@ class CustomerDataBuilder implements BuilderInterface
*/
public function build(array $buildSubject)
{
$result = [];
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder();
$billingAddress = $order->getBillingAddress();
$customerEmail = $billingAddress->getEmail();
$realOrderId = $order->getOrderIncrementId();
$customerId = $order->getCustomerId();
$shopperReference = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
return [
"shopperEmail" => $customerEmail,
"shopperReference" => $shopperReference
];
if ($customerId > 0) {
$result['shopperReference'] = $customerId;
}
$result ['shopperEmail'] = $customerEmail;
return $result;
}
}
......@@ -63,6 +63,7 @@ class RecurringDataBuilder implements BuilderInterface
$payment = $paymentDataObject->getPayment();
// Needs to change when oneclick,cc using facade impl.
$paymentMethodCode = $payment->getMethodInstance()->getCode();
$customerId = $payment->getOrder()->getCustomerId();
$storeId = null;
if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
......@@ -95,7 +96,8 @@ class RecurringDataBuilder implements BuilderInterface
}
}
if ($recurringContractType) {
// only when recurringContractType is set and when a customer is loggedIn
if ($recurringContractType && $customerId > 0) {
$recurring = ['contract' => $recurringContractType];
$result['recurring'] = $recurring;
}
......
......@@ -58,8 +58,6 @@ class PaymentRequest extends DataObject
*/
protected $_appState;
const GUEST_ID = 'customer_';
/**
* PaymentRequest constructor.
*
......
......@@ -35,7 +35,6 @@ class Cron
*/
protected $_logger;
/**
* @var Resource\Notification\CollectionFactory
*/
......@@ -176,6 +175,8 @@ class Cron
* @param Billing\AgreementFactory $billingAgreementFactory
* @param Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param Api\PaymentRequest $paymentRequest
* @param Order\PaymentFactory $adyenOrderPaymentFactory
* @param Resource\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
......@@ -461,7 +462,9 @@ class Cron
// If notification is pending status and pending status is set add the status change to the comment history
if ($this->_eventCode == Notification::PENDING) {
$pendingStatus = $this->_getConfigData('pending_status', 'adyen_abstract', $this->_order->getStoreId());
$pendingStatus = $this->_getConfigData(
'pending_status', 'adyen_abstract', $this->_order->getStoreId()
);
if ($pendingStatus != "") {
$this->_order->addStatusHistoryComment($comment, $pendingStatus);
$this->_adyenLogger->addAdyenNotificationCronjob(
......@@ -598,7 +601,9 @@ class Cron
*/
protected function _holdCancelOrder($ignoreHasInvoice)
{
$orderStatus = $this->_getConfigData('payment_cancelled', 'adyen_abstract', $this->_order->getStoreId());
$orderStatus = $this->_getConfigData(
'payment_cancelled', 'adyen_abstract', $this->_order->getStoreId()
);
// check if order has in invoice only cancel/hold if this is not the case
if ($ignoreHasInvoice || !$this->_order->hasInvoices()) {
......@@ -664,8 +669,7 @@ class Cron
$isBankTransfer = $this->_isBankTransfer();
if ($isBankTransfer || $this->_paymentMethod == 'sepadirectdebit') {
if (!$this->_order->getEmailSent()) {
$this->_orderSender->send($this->_order);
$this->_adyenLogger->addAdyenNotificationCronjob('Send orderconfirmation email to shopper');
$this->_sendOrderMail();
}
}
}
......@@ -969,9 +973,9 @@ class Cron
if ($this->_paymentMethod != "adyen_boleto") {
// send order confirmation mail after invoice creation so merchant can add invoicePDF to this mail
if (!$this->_order->getEmailSent()) {
$this->_orderSender->send($this->_order);
$this->_adyenLogger->addAdyenNotificationCronjob('Send orderconfirmation email to shopper');
$this->_sendOrderMail();
}
}
if (($this->_paymentMethod == "c_cash" &&
......@@ -983,12 +987,34 @@ class Cron
}
}
/**
* Send order Mail
*
* @return void
*/
private function _sendOrderMail()
{
try {
$this->_orderSender->send($this->_order);
$this->_adyenLogger->addAdyenNotificationCronjob('Send orderconfirmation email to shopper');
} catch(\Exception $exception) {
$this->_adyenLogger->addAdyenNotificationCronjob(
"Exception in Send Mail in Magento. This is an issue in the the core of Magento" .
$exception->getMessage()
);
}
}
/**
* Set status on authorisation
*
* @return void
*/
private function _setPrePaymentAuthorized()
{
$status = $this->_getConfigData('payment_pre_authorized', 'adyen_abstract', $this->_order->getStoreId());
$status = $this->_getConfigData(
'payment_pre_authorized', 'adyen_abstract', $this->_order->getStoreId()
);
// only do this if status in configuration is set
if (!empty($status)) {
......@@ -1003,6 +1029,7 @@ class Cron
/**
* @throws Exception
* @return void
*/
protected function _prepareInvoice()
{
......@@ -1084,8 +1111,12 @@ class Cron
{
// validate if payment methods allowes manual capture
if ($this->_manualCaptureAllowed()) {
$captureMode = trim($this->_getConfigData('capture_mode', 'adyen_abstract', $this->_order->getStoreId()));
$sepaFlow = trim($this->_getConfigData('sepa_flow', 'adyen_abstract', $this->_order->getStoreId()));
$captureMode = trim($this->_getConfigData(
'capture_mode', 'adyen_abstract', $this->_order->getStoreId())
);
$sepaFlow = trim($this->_getConfigData(
'sepa_flow', 'adyen_abstract', $this->_order->getStoreId())
);
$_paymentCode = $this->_paymentMethodCode();
$captureModeOpenInvoice = $this->_getConfigData(
'auto_capture_openinvoice', 'adyen_abstract', $this->_order->getStoreId()
......@@ -1210,7 +1241,8 @@ class Cron
/**
* @return bool
*/
protected function _isBankTransfer() {
protected function _isBankTransfer()
{
if (strlen($this->_paymentMethod) >= 12 && substr($this->_paymentMethod, 0, 12) == "bankTransfer") {
$isBankTransfer = true;
} else {
......@@ -1224,7 +1256,9 @@ class Cron
*/
protected function _getFraudManualReviewStatus()
{
return $this->_getConfigData('fraud_manual_review_status', 'adyen_abstract', $this->_order->getStoreId());
return $this->_getConfigData(
'fraud_manual_review_status', 'adyen_abstract', $this->_order->getStoreId()
);
}
/**
......@@ -1238,7 +1272,8 @@ class Cron
}
/**
* @param $orderAmount
* @param int $paymentId
* @param string $orderCurrencyCode
* @return bool
*/
protected function _isTotalAmount($paymentId, $orderCurrencyCode)
......@@ -1255,10 +1290,15 @@ class Cron
->create()
->getTotalAmount($paymentId);
if($res && isset($res[0]) && is_array($res[0])) {
if ($res && isset($res[0]) && is_array($res[0])) {
$amount = $res[0]['total_amount'];
$orderAmount = $this->_adyenHelper->formatAmount($amount, $orderCurrencyCode);
$this->_adyenLogger->addAdyenNotificationCronjob(sprintf('The grandtotal amount is %s and the total order amount that is authorised is: %s', $grandTotal, $orderAmount));
$this->_adyenLogger->addAdyenNotificationCronjob(
sprintf('The grandtotal amount is %s and the total order amount that is authorised is: %s',
$grandTotal,
$orderAmount
)
);
if ($grandTotal == $orderAmount) {
$this->_adyenLogger->addAdyenNotificationCronjob('AUTHORISATION has the full amount');
......@@ -1276,6 +1316,7 @@ class Cron
/**
* @throws Exception
* @throws \Magento\Framework\Exception\LocalizedException
* @return void
*/
protected function _createInvoice()
{
......@@ -1360,12 +1401,16 @@ class Cron
$this->_createInvoice();
}
$status = $this->_getConfigData('payment_authorized', 'adyen_abstract', $this->_order->getStoreId());
$status = $this->_getConfigData(
'payment_authorized', 'adyen_abstract', $this->_order->getStoreId()
);
// virtual order can have different status
if ($this->_order->getIsVirtual()) {
$this->_adyenLogger->addAdyenNotificationCronjob('Product is a virtual product');
$virtualStatus = $this->_getConfigData('payment_authorized_virtual');
$virtualStatus = $this->_getConfigData(
'payment_authorized_virtual', 'adyen_abstract', $this->_order->getStoreId()
);
if ($virtualStatus != "") {
$status = $virtualStatus;
}
......@@ -1389,11 +1434,15 @@ class Cron
$paidAmount = floatval(trim($paidAmount));
if ($paidAmount > $orginalAmount) {
$overpaidStatus = $this->_getConfigData('order_overpaid_status', 'adyen_boleto');
$overpaidStatus = $this->_getConfigData(
'order_overpaid_status', 'adyen_boleto', $this->_order->getStoreId()
);
// check if there is selected a status if not fall back to the default
$status = (!empty($overpaidStatus)) ? $overpaidStatus : $status;
} else {
$underpaidStatus = $this->_getConfigData('order_underpaid_status', 'adyen_boleto');
$underpaidStatus = $this->_getConfigData(
'order_underpaid_status', 'adyen_boleto', $this->_order->getStoreId()
);
// check if there is selected a status if not fall back to the default
$status = (!empty($underpaidStatus)) ? $underpaidStatus : $status;
}
......
# Adyen_Magento2
Adyen Payment plugin for Magento2
## Install with Composer ##
composer require adyen/module-payment
## Installation ##
```
bin/composer require adyen/module-payment
bin/magento module:enable Adyen_Payment
bin/magento setup:upgrade
```
## Manual ##
<a href="https://docs.adyen.com/developers/magento#magento2integration" target="_blank">https://docs.adyen.com/developers/magento#magento2integration</a>
......
......@@ -34,7 +34,6 @@ use Magento\Framework\Setup\SchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
const ADYEN_ORDER_PAYMENT = 'adyen_order_payment';
/**
......@@ -56,11 +55,18 @@ class UpgradeSchema implements UpgradeSchemaInterface
$this->updateSchemaVersion200($setup);
}
if (version_compare($context->getVersion(), '2.0.4', '<')) {
$this->updateSchemaVersion204($setup);
}
$setup->endSetup();
}
/**
* Upgrade to 1.0.0.1
*
* @param SchemaSetupInterface $setup
* @return void
*/
public function updateSchemaVersion1001(SchemaSetupInterface $setup)
{
......@@ -92,7 +98,10 @@ class UpgradeSchema implements UpgradeSchemaInterface
}
/**
* Upgrade to 1.0.0.2
*
* @param SchemaSetupInterface $setup
* @return void
*/
public function updateSchemaVersion1002(SchemaSetupInterface $setup)
{
......@@ -110,7 +119,10 @@ class UpgradeSchema implements UpgradeSchemaInterface
}
/**
* Upgrade to 2.0.0
*
* @param SchemaSetupInterface $setup
* @return void
*/
public function updateSchemaVersion200(SchemaSetupInterface $setup)
{
......@@ -224,4 +236,30 @@ class UpgradeSchema implements UpgradeSchemaInterface
);
}
/**
* Upgrade to 2.0.4
* Update entity_id in notification from smallint to integer
*
* @param SchemaSetupInterface $setup
* @return void
*/
public function updateSchemaVersion204(SchemaSetupInterface $setup)
{
$connection = $setup->getConnection();
$tableName = $setup->getTable('adyen_notification');
$connection->changeColumn(
$tableName,
'entity_id',
'entity_id',
[
'type' => Table::TYPE_INTEGER,
'nullable' => false,
'primary' => true,
'identity' => true,
'unsigned' => true,
'comment' => 'Adyen Notification Entity ID'
]
);
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
"name": "adyen/module-payment",
"description": "Official Magento2 Plugin to connect to Payment Service Provider Adyen.",
"type": "magento2-module",
"version": "2.0.3",
"version": "2.0.4",
"license": [
"OSL-3.0",
"AFL-3.0"
......
......@@ -24,7 +24,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Adyen_Payment" setup_version="2.0.3">
<module name="Adyen_Payment" setup_version="2.0.4">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
......
......@@ -33,7 +33,6 @@ $_info = $this->getInfo();
<dl class="payment-method adyen_hpp">
<?php if($paymentSelectionOnAdyen): ?>
<?php echo $this->escapeHtml($this->getMethod()->getTitle()) ?><br/>
<dt class="title"><?php echo $block->escapeHtml($block->getMethod()->getTitle()) ?></dt>
<?php else: ?>
......
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