diff --git a/locale.xml b/locale.xml index 42d8e4478e61d9685e58f3427095fd9debb79620..67d8ba0126d98bc1956eef598ce56ba6bf2a8709 100644 --- a/locale.xml +++ b/locale.xml @@ -123,6 +123,14 @@ <de><![CDATA[Sandbox-Modus aktivieren (Zahlungen werden nicht tatsächlich durchgeführt sondern nur über eine Testumgebung; nur aktivieren, wenn der Zahlungsprozess mit Amazon Pay getestet werden soll!)]]></de> <en><![CDATA[Enable sandbox mode (payments are not actually made but only through a test environment, only enable to test the payment process with Amazon Pay!)]]></en> </locale> + <locale name="settings.api.use_ipn_handler.title"> + <de><![CDATA[IPN-Handling]]></de> + <en><![CDATA[IPN Handling]]></en> + </locale> + <locale name="settings.api.use_ipn_handler.description" html="true"> + <de><![CDATA[<b>Aktiviere asnychronen Empfang von Nachrichten seitens Amazon bzgl. des Status von Zahlungsoperationen</b> (notwendig, wenn Anweisung zur Zahlungsdurchführung später als 7 Tage nach Zahlungsautorisierung erfolgt; erfordert Einrichtung einer von außen erreichbaren <a href="https://pay.amazon.com/de/developer/documentation/lpwa/201952050" target="_blank">IPN-URL</a>)]]></de> + <en><![CDATA[<b>Enable asynchronous reception of Amazon messages regarding the status of payment capture requests</b> (necessary if payment capture requests are performed more than 7 days after payment authorization requests; requires an <a href="https://pay.amazon.com/de/developer/documentation/lpwa/201952050" target="_blank">IPN-URL</a> to be set up)]]></en> + </locale> <locale name="settings.category.payment.title"> <de><![CDATA[Zahlungsprozess]]></de> <en><![CDATA[Payment process]]></en> diff --git a/settings.xml b/settings.xml index 75f2ce600bd42b567af0693ce9509c77cbcf0568..34cb75434224c554712a7891a7d0f038a7616c49 100644 --- a/settings.xml +++ b/settings.xml @@ -25,6 +25,10 @@ <type><![CDATA[boolean]]></type> <defaultvalue>1</defaultvalue> </conf> + <conf name="use_ipn_handler"> + <type><![CDATA[boolean]]></type> + <defaultvalue>0</defaultvalue> + </conf> </section> <section name="payment"> @@ -109,6 +113,15 @@ </option> </select> + <input conf="api.use_ipn_handler" type="checkbox"> + <text> + <locale group="quiqqer/payment-amazon" var="settings.api.use_ipn_handler.title"/> + </text> + <description> + <locale group="quiqqer/payment-amazon" var="settings.api.use_ipn_handler.description"/> + </description> + </input> + <input conf="api.sandbox" type="checkbox"> <text> <locale group="quiqqer/payment-amazon" var="settings.api.sandbox.title"/> diff --git a/src/QUI/ERP/Payments/Amazon/Events.php b/src/QUI/ERP/Payments/Amazon/Events.php index b36046bf8c2a1ca4448f25f3d42525f68e027944..795776629915808b3e0875d579ac7fb7db0a2a5b 100644 --- a/src/QUI/ERP/Payments/Amazon/Events.php +++ b/src/QUI/ERP/Payments/Amazon/Events.php @@ -26,6 +26,10 @@ class Events */ public static function onPaymentsGatewayReadRequest(Gateway $Gateway) { + if (!Provider::isIpnHandlingActivated()) { + return; + } + $headers = getallheaders(); $body = file_get_contents('php://input'); @@ -74,8 +78,7 @@ class Events $Gateway->setOrder($Order); $Gateway->enableGatewayPayment(); - // now the Gateway can call executeGatewayPayment() of the - // payment method that is assigned to the Order + // now the Gateway can call \QUI\ERP\Payments\Amazon->executeGatewayPayment() } /** diff --git a/src/QUI/ERP/Payments/Amazon/Payment.php b/src/QUI/ERP/Payments/Amazon/Payment.php index ccd0fc2d92c9cee9acc05ef7b749864700ad6873..b8138731496709bf393337ff59508caa8ef9cc77 100644 --- a/src/QUI/ERP/Payments/Amazon/Payment.php +++ b/src/QUI/ERP/Payments/Amazon/Payment.php @@ -11,6 +11,7 @@ use AmazonPay\ResponseInterface; use QUI; use QUI\ERP\Order\AbstractOrder; use QUI\ERP\Order\Handler as OrderHandler; +use QUI\ERP\Accounting\Payments\Gateway\Gateway; /** * Class Payment @@ -526,9 +527,19 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment $Order->setPaymentData(self::ATTR_ORDER_CAPTURED, true); $Order->update(QUI::getUsers()->getSystemUser()); + + $Gateway = Gateway::getInstance(); + $Gateway->setOrder($Order); + + $this->executeGatewayPayment($Gateway); break; + case 'Pending': // @todo pending status + if (Provider::isIpnHandlingActivated()) { + // etc. + } + break; default: $reason = $status['ReasonCode']; diff --git a/src/QUI/ERP/Payments/Amazon/Provider.php b/src/QUI/ERP/Payments/Amazon/Provider.php index 0531c789c9e5ecc9cba4c4d6657b22acfffbdd24..ad1f8b5038fdb54cce7f8d095dc6e8c7df1cf9a4 100644 --- a/src/QUI/ERP/Payments/Amazon/Provider.php +++ b/src/QUI/ERP/Payments/Amazon/Provider.php @@ -80,6 +80,16 @@ class Provider extends AbstractPaymentProvider return $Conf->get('widgets', $setting); } + /** + * Check if IPN handling is activated in the module settings + * + * @return bool + */ + public static function isIpnHandlingActivated() + { + return boolval(self::getApiSetting('use_ipn_handler')); + } + /** * Check if the Amazon Pay API settings are correct * @@ -94,6 +104,7 @@ class Provider extends AbstractPaymentProvider foreach ($apiSettings as $k => $v) { switch ($k) { case 'sandbox': + case 'use_ipn_handler': continue 2; break; }