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 38699823 authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #290 from Adyen/PW-514

PW-514 Invoice on shipment option for openinvoice payment methods
parents dee1944e ad542767
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2017 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\Observer\Adminhtml;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
/**
* Class DataAssignObserver
*/
class BeforeShipmentObserver extends AbstractDataAssignObserver
{
private $_adyenHelper;
/**
* BeforeShipmentObserver constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
)
{
$this->_adyenHelper = $adyenHelper;
}
/**
* @param Observer $observer
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute(Observer $observer)
{
$shipment = $observer->getEvent()->getShipment();
$order = $shipment->getOrder();
$captureOnShipment = $this->_adyenHelper->getConfigData('capture_on_shipment', 'adyen_abstract', $order->getStoreId());
if ($this->isPaymentMethodAdyen($order) && $captureOnShipment) {
$payment = $order->getPayment();
$brandCode = $payment->getAdditionalInformation(
\Adyen\Payment\Observer\AdyenHppDataAssignObserver::BRAND_CODE
);
if ($this->_adyenHelper->isPaymentMethodOpenInvoiceMethod($brandCode)) {
if ($order->canInvoice()) {
try {
$invoice = $order->prepareInvoice();
$invoice->getOrder()->setIsInProcess(true);
// set transaction id so you can do a online refund from credit memo
$pspReference = $order->getPayment()->getAdyenPspReference();
$invoice->setTransactionId($pspReference);
$invoice->register()->pay();
$invoice->save();
} catch (Exception $e) {
throw new Exception(sprintf('Error saving invoice. The error message is:', $e->getMessage()));
}
}
}
}
}
/**
* Determine if the payment method is Adyen
*/
public function isPaymentMethodAdyen($order)
{
return strpos($order->getPayment()->getMethod(), 'adyen') !== false;
}
}
<?xml version="1.0"?>
<!--
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_shipment_save_before">
<observer name="adyen_shipment_save_before" instance="Adyen\Payment\Observer\Adminhtml\BeforeShipmentObserver" />
</event>
</config>
...@@ -32,6 +32,12 @@ ...@@ -32,6 +32,12 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model> <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_abstract/paypal_capture_mode</config_path> <config_path>payment/adyen_abstract/paypal_capture_mode</config_path>
</field> </field>
<field id="capture_on_shipment" translate="label" type="select" sortOrder="15" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Capture on shipment for OpenInvoice Methods (Klarna, Ratepay and Afterpay)</label>
<tooltip>If you enable this function it will do a capture request to Adyen if you do a shipment for openinvoice payment methods.</tooltip>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/adyen_abstract/capture_on_shipment</config_path>
</field>
<field id="auto_capture_openinvoice" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1"> <field id="auto_capture_openinvoice" translate="label" type="select" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use auto-capture for OpenInvoice payments</label> <label>Use auto-capture for OpenInvoice payments</label>
<tooltip>Applicable for Klarna and AfterPay only. By default OpenInvoice is set to manual capture. If you want auto capture you need to contact magento@adyen.com. After approval has been given, then you can set this option to 'Yes'.</tooltip> <tooltip>Applicable for Klarna and AfterPay only. By default OpenInvoice is set to manual capture. If you want auto capture you need to contact magento@adyen.com. After approval has been given, then you can set this option to 'Yes'.</tooltip>
......
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