Skip to content
Code-Schnipsel Gruppen Projekte
Commit f8773a36 erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

temp comit

Übergeordneter fde1cd56
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -22,17 +22,6 @@ QUI::$Ajax->registerFunction(
try {
$Order = Handler::getInstance()->getOrderByHash($orderHash);
if (!$orderReferenceId) {
$orderReferenceId = $Order->getPaymentDataEntry(Payment::ATTR_AMAZON_ORDER_REFERENCE_ID);
if (!$orderReferenceId) {
// OrderReferenceId has not yet been set to the Order
// and must be (re-)generated by loading the Amazon Pay
// Wallet and/or Address widget(s)
return false;
}
}
$Payment = new Payment();
$Payment->authorizePayment($orderReferenceId, $Order);
} catch (AmazonPayException $Exception) {
......
......@@ -28,7 +28,8 @@ define('package/quiqqer/payment-amazon/bin/controls/PaymentDisplay', [
'$showAmazonPayBtn',
'$onAmazonLoginReady',
'$showAmazonWallet',
'$showErrorMsg'
'$showErrorMsg',
'$onPayBtnClick'
],
options: {
......@@ -192,13 +193,19 @@ define('package/quiqqer/payment-amazon/bin/controls/PaymentDisplay', [
/**
* Show Amazon Pay Wallet widget
*
* @param {Boolean} [showInfoMessage] - Show info message
*/
$showAmazonWallet: function () {
$showAmazonWallet: function (showInfoMessage) {
var self = this;
this.$showMsg(
QUILocale.get(pkg, 'controls.PaymentDisplay.wallet_info')
);
if (showInfoMessage) {
this.$showMsg(
QUILocale.get(pkg, 'controls.PaymentDisplay.wallet_info')
);
}
this.$WalletElm.set('html', '');
var Options = {
sellerId : this.getAttribute('sellerid'),
......@@ -229,6 +236,7 @@ define('package/quiqqer/payment-amazon/bin/controls/PaymentDisplay', [
case 'PaymentMethodNotModifiable':
case 'StaleOrderReference':
self.$AuthBtnElm.removeClass('quiqqer-payment-amazon__hidden');
self.$orderReferenceId = false;
self.$showErrorMsg(Error.getErrorMessage());
break;
......@@ -254,38 +262,76 @@ define('package/quiqqer/payment-amazon/bin/controls/PaymentDisplay', [
text : QUILocale.get(pkg, 'controls.PaymentDisplay.btn_pay.text'),
texticon: 'fa fa-amazon',
events : {
onClick: function () {
self.$OrderProcess.Loader.show();
self.$authorizePayment().then(function (success) {
self.$OrderProcess.Loader.hide();
if (!success) {
self.$showErrorMsg(
QUILocale.get(pkg, 'controls.PaymentDisplay.processing_error')
);
return;
}
console.log("payment is authorized -> OrderProcess->next()");
self.$OrderProcess.next();
}, function (error) {
self.$OrderProcess.Loader.hide();
self.$showErrorMsg(error.getMessage());
if (error.getAttribute('reRenderWallet')) {
self.$showAmazonWallet();
}
});
}
onClick: this.$onPayBtnClick
}
}).inject(this.getElm().getElement('#quiqqer-payment-amazon-btn-pay'));
}
// rendet wallet widget
new OffAmazonPayments.Widgets.Wallet(Options).bind('quiqqer-payment-amazon-wallet');
},
/**
* Start payment process
*
* @param {Object} Btn
*/
$onPayBtnClick: function (Btn) {
var self = this;
Btn.disable();
Btn.setAttribute('texticon', 'fa fa-spinner fa-spin');
self.$WalletElm.addClass('quiqqer-payment-amazon__hidden');
self.$OrderProcess.Loader.show(
QUILocale.get(pkg, 'controls.PaymentDisplay.authorize_payment')
);
self.$authorizePayment().then(function (success) {
if (success) {
self.$OrderProcess.next();
return;
}
self.$OrderProcess.Loader.hide();
self.$showErrorMsg(
QUILocale.get(pkg, 'controls.PaymentDisplay.processing_error')
);
self.$showAmazonWallet(false);
Btn.enable();
Btn.setAttribute('texticon', 'fa fa-amazon');
}, function (error) {
self.$OrderProcess.Loader.hide();
self.$showErrorMsg(error.getMessage());
if (error.getAttribute('orderCancelled')) {
self.$orderReferenceId = false;
}
if (error.getAttribute('reRenderWallet')) {
self.$WalletElm.removeClass('quiqqer-payment-amazon__hidden');
self.$showAmazonWallet(false);
Btn.enable();
Btn.setAttribute('texticon', 'fa fa-amazon');
return;
}
// sign out
amazon.Login.logout();
Btn.destroy();
self.$showErrorMsg(
QUILocale.get(pkg, 'controls.PaymentDisplay.fatal_error')
);
});
},
/**
* Start the payment process
*
......@@ -299,7 +345,6 @@ define('package/quiqqer/payment-amazon/bin/controls/PaymentDisplay', [
'package' : pkg,
orderHash : self.getAttribute('orderhash'),
orderReferenceId: self.$orderReferenceId,
accessToken : self.$accessToken,
onError : reject
})
});
......
......@@ -31,15 +31,23 @@
</locale>
<locale name="payment.error_msg.InvalidPaymentMethod">
<de><![CDATA[Die Zahlung mit Amazon Pay konnte nicht durchgeführt werden, da die von Ihnen gewählte Zahlungsmethode von Amazon abgelehnt wurde. Bitte wiederholen Sie den Vorgang und wählen Sie eine andere Zahlungsmethode bei Amazon.]]></de>
<en><![CDATA[Payment with Amazon Pay could not be made because your chosen payment method was disapproved by Amazon. Please try again and choose another payment method on Amazon.]]></en>
<en><![CDATA[Payment with Amazon Pay could not be made because your chosen payment method was disapproved by Amazon. Please try again or choose another payment method on Amazon.]]></en>
</locale>
<locale name="payment.error_msg.AmazonRejected">
<locale name="payment.error_msg.PaymentMethodNotAllowed">
<de><![CDATA[Die Zahlung mit Amazon Pay konnte nicht durchgeführt werden, da die von Ihnen gewählte Zahlungsmethode von Amazon abgelehnt wurde. Bitte wiederholen Sie den Vorgang und wählen Sie eine andere Zahlungsmethode bei Amazon.]]></de>
<en><![CDATA[Payment with Amazon Pay could not be made because your chosen payment method was disapproved by Amazon. Please try again and choose another payment method on Amazon.]]></en>
<en><![CDATA[Payment with Amazon Pay could not be made because your chosen payment method was disapproved by Amazon. Please try again or choose another payment method on Amazon.]]></en>
</locale>
<locale name="payment.error_msg.AmazonRejected">
<de><![CDATA[Die Zahlung mit Amazon Pay konnte nicht durchgeführt werden, da der Zahlungsvorgang von Amazon abgelehnt wurde. Bitte wiederholen Sie den Vorgang und wählen Sie eine andere Zahlungsmethode bei Amazon.]]></de>
<en><![CDATA[Payment with Amazon Pay could not be made because the payment process was declined by Amazon. Please try again or choose another payment method on Amazon.]]></en>
</locale>
<locale name="payment.error_msg.ProcessingFailure">
<de><![CDATA[Die Zahlung mit Amazon Pay konnte nicht durchgeführt werden, da der Zahlungsvorgang von Amazon abgelehnt wurde. Bitte wiederholen Sie den Vorgang und wählen Sie eine andere Zahlungsmethode bei Amazon.]]></de>
<en><![CDATA[Payment with Amazon Pay could not be made because the payment process was declined by Amazon. Please try again or choose another payment method on Amazon.]]></en>
</locale>
<locale name="payment.error_msg.TransactionTimedOut">
<de><![CDATA[Die Zahlung mit Amazon Pay konnte nicht durchgeführt werden, da der Zahlungsvorgang zu lange gebraucht hat. Bitte wiederholen Sie den Vorgang.]]></de>
<en><![CDATA[Payment with Amazon Pay could not be made because the payment process took too long. Please repeat the process.]]></en>
<de><![CDATA[Die Zahlung mit Amazon Pay konnte nicht durchgeführt werden, da die Autorisierung des Zahlungsvorgangs zu lange gebraucht hat. Bitte wiederholen Sie den Vorgang oder wählen Sie eine andere Zahlungsweise.]]></de>
<en><![CDATA[Payment with Amazon Pay could not be made because the authorization of the payment process took too long. Please repeat the process or choose a different payment method.]]></en>
</locale>
<locale name="payment.error_msg.MaxCapturesProcessed">
<de><![CDATA[Die Zahlung mit Amazon Pay konnte nicht durchgeführt werden, da der Zahlungsvorgang bereits abgeschlossen ist.]]></de>
......@@ -49,6 +57,10 @@
<de><![CDATA[Der Zahlungsfluss von Bestellung #[orderHash] kann nicht initialisiert werden, da er noch nicht durch Amazon autorisiert ist.]]></de>
<en><![CDATA[The payment capture of order # [orderHash] can not be initialized because it is not yet authorized by Amazon.]]></en>
</locale>
<locale name="payment.error_msg.fatal_error">
<de><![CDATA[Beim Bezahlungsvorgang mit Amazon Pay ist ein Fehler aufgetreten. Die Zahlung konnte nicht durchgeführt werden. Ihre ausgewählte Zahlungsweise wurde nicht belastet. Bitte wählen Sie eine andere Zahlungsweise.]]></de>
<en><![CDATA[An error occurred while paying with Amazon Pay. The payment could not be processed. Your selected payment method has not been charged. Please choose a different payment method.]]></en>
</locale>
<!-- Settings -->
<locale name="settings.menu.title">
......@@ -179,6 +191,10 @@
<de><![CDATA[Bitte wählen Sie die Zahlungsweise aus, über die Amazon den Betrag der Bestellung einzieht.]]></de>
<en><![CDATA[Please select the method of payment through which Amazon collects the order amount.]]></en>
</locale>
<locale name="controls.PaymentDisplay.authorize_payment">
<de><![CDATA[Autorisiere Zahlung bei Amazon]]></de>
<en><![CDATA[Authorize payment with Amazon]]></en>
</locale>
</groups>
</locales>
......@@ -11,7 +11,6 @@ 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
......@@ -26,6 +25,9 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
const ATTR_AMAZON_CAPTURE_ID = 'amazon-AmazonCaptureId';
const ATTR_AMAZON_ORDER_REFERENCE_ID = 'amazon-OrderReferenceId';
const ATTR_CAPTURE_REFERENCE_IDS = 'amazon-CaptureReferenceIds';
const ATTR_ORDER_AUTHORIZED = 'amazon-OrderAuthorized';
const ATTR_ORDER_REFERENCE_SET = 'amazon-OrderReferenceSet';
const ATTR_RECONFIRM_ORDER = 'amazon-ReconfirmOrder';
/**
* Setting options
......@@ -73,8 +75,6 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
*/
public function isSuccessful($hash)
{
\QUI\System\Log::writeRecursive("check sucess $hash");
try {
$Order = OrderHandler::getInstance()->getOrderByHash($hash);
} catch (\Exception $Exception) {
......@@ -86,6 +86,10 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
return false;
}
if ($Order->getPaymentDataEntry(self::ATTR_ORDER_AUTHORIZED)) {
return true;
}
$orderReferenceId = $Order->getPaymentDataEntry(self::ATTR_AMAZON_ORDER_REFERENCE_ID);
if (empty($orderReferenceId)) {
......@@ -101,8 +105,10 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
return false;
}
\QUI\System\Log::writeRecursive("IS SUCCESSFUl");
// If payment is authorized everyhting is fine
$Order->setPaymentData(self::ATTR_ORDER_AUTHORIZED, true);
$Order->update(QUI::getUsers()->getSystemUser());
return true;
}
......@@ -128,13 +134,17 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
* Execute the request from the payment provider
*
* @param QUI\ERP\Accounting\Payments\Gateway\Gateway $Gateway
* @return void
*
* @throws QUI\ERP\Accounting\Payments\Exception
* @throws QUI\ERP\Accounting\Payments\Transactions\Exception
* @throws QUI\Exception
*/
public function executeGatewayPayment(QUI\ERP\Accounting\Payments\Gateway\Gateway $Gateway)
{
$AmazonPay = $this->getAmazonPayClient();
$Order = $Gateway->getOrder();
$AmazonPay = $this->getAmazonPayClient();
$Order = $Gateway->getOrder();
$this->Order = $Order;
$Order->addHistory('Amazon Pay :: Check if payment from Amazon was successful');
......@@ -147,18 +157,21 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
$response = $this->getResponseData($Response);
// check the amount that has already been captured
$calculations = $Order->getArticles()->getCalculations();
$targetSum = $calculations['sum'];
$currencyCode = $Order->getCurrency()->getCode();
$calculations = $Order->getArticles()->getCalculations();
$targetSum = $calculations['sum'];
$targetCurrencyCode = $Order->getCurrency()->getCode();
$captureData = $response['GetCaptureDetailsResult']['CaptureDetails'];
$actualSum = $captureData['CaptureAmount']['Amount'];
$actualCurrencyCode = $captureData['CaptureAmount']['CurrencyCode'];
$captureData = $response['GetCaptureDetailsResult']['CaptureDetails'];
$actualSum = $captureData['CaptureAmount']['Amount'];
\QUI\System\Log::writeRecursive("COMPARE sums QUIQQER: $actualSum <> AMAZON: $targetSum");
if ($actualSum < $targetSum) {
$Order->addHistory(
'Amazon Pay :: The amount that was captured from Amazon was less than the'
. ' total sum of the order. Total sum: ' . $targetSum . ' ' . $currencyCode
. ' | Actual sum captured by Amazon: ' . $actualSum . ' ' . $currencyCode
. ' total sum of the order. Total sum: ' . $targetSum . ' ' . $targetCurrencyCode
. ' | Actual sum captured by Amazon: ' . $actualSum . ' ' . $actualCurrencyCode
);
return;
......@@ -167,10 +180,12 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
// book payment in QUIQQER ERP
$Gateway->purchase(
$actualSum,
new QUI\ERP\Currency\Currency($currencyCode),
new QUI\ERP\Currency\Currency($actualCurrencyCode),
$Order,
$this
);
$this->closeOrderReference();
}
/**
......@@ -221,56 +236,87 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
*/
public function authorizePayment($orderReferenceId, AbstractOrder $Order)
{
$Order->addHistory('Amazon Pay :: Authorize payment');
if ($Order->getPaymentDataEntry(self::ATTR_ORDER_AUTHORIZED)) {
$Order->addHistory('Amazon Pay :: Authorization already exist');
return;
}
$AmazonPay = $this->getAmazonPayClient();
$this->Order = $Order;
$Order->addHistory('Amazon Pay :: Authorize payment');
$calculations = $Order->getArticles()->getCalculations();
$reconfirmOrder = $Order->getPaymentDataEntry(self::ATTR_RECONFIRM_ORDER);
// $Order->setPaymentData(self::ATTR_AMAZON_AUTHORIZATION_ID, null);
// Re-confirm Order after previously declined Authorization because of "InvalidPaymentMethod"
if ($reconfirmOrder) {
$Order->addHistory(
'Amazon Pay :: Re-confirm Order after declined Authorization because of "InvalidPaymentMethod"'
);
$calculations = $Order->getArticles()->getCalculations();
$amazonAuthorizationId = $Order->getPaymentDataEntry(self::ATTR_AMAZON_AUTHORIZATION_ID);
$orderReferenceId = $Order->getPaymentDataEntry(self::ATTR_AMAZON_ORDER_REFERENCE_ID);
if (!empty($amazonAuthorizationId)) {
$Order->addHistory('Amazon Pay :: Authorization already exist');
$Response = $AmazonPay->confirmOrderReference(array(
'amazon_order_reference_id' => $orderReferenceId
));
// check if an Authorization already exists and is in state OPEN
$Response = $AmazonPay->getAuthorizationDetails(array(
'amazon_authorization_id' => $amazonAuthorizationId
$this->getResponseData($Response); // check response data
$Order->setPaymentData(self::ATTR_RECONFIRM_ORDER, false);
$Order->addHistory('Amazon Pay :: OrderReference re-confirmed');
} elseif (!$Order->getPaymentDataEntry(self::ATTR_ORDER_REFERENCE_SET)) {
$Order->addHistory(
'Amazon Pay :: Setting details of the Order to Amazon Pay API'
);
$Response = $AmazonPay->setOrderReferenceDetails(array(
'amazon_order_reference_id' => $orderReferenceId,
'amount' => $calculations['sum'],
'currency_code' => $Order->getCurrency()->getCode(),
'seller_order_id' => $Order->getId()
));
$response = $this->getResponseData($Response);
$this->checkAuthorizationStatus($response['GetAuthorizationDetailsResult']['AuthorizationDetails']);
$response = $this->getResponseData($Response);
$orderReferenceDetails = $response['SetOrderReferenceDetailsResult']['OrderReferenceDetails'];
return;
if (isset($orderReferenceDetails['Constraints']['Constraint']['ConstraintID'])) {
$Order->addHistory(
'Amazon Pay :: An error occurred while setting the details of the Order: "'
. $orderReferenceDetails['Constraints']['Constraint']['ConstraintID'] . '""'
);
$this->throwAmazonPayException(
$orderReferenceDetails['Constraints']['Constraint']['ConstraintID'],
array(
'reRenderWallet' => 1
)
);
}
$AmazonPay->confirmOrderReference(array(
'amazon_order_reference_id' => $orderReferenceId
));
$Order->setPaymentData(self::ATTR_ORDER_REFERENCE_SET, true);
$Order->update(QUI::getUsers()->getSystemUser());
}
$Order->addHistory('Amazon Pay :: Authorization does not exist. Requesting new Authorization.');
$Order->addHistory('Amazon Pay :: Requesting new Authorization');
$authorizationReferenceId = $this->getNewAuthorizationReferenceId($Order);
$Response = $AmazonPay->charge(array(
'amazon_reference_id' => $orderReferenceId,
'charge_amount' => $calculations['sum'],
$Response = $AmazonPay->authorize(array(
'amazon_order_reference_id' => $orderReferenceId,
'authorization_amount' => $calculations['sum'],
'currency_code' => $Order->getCurrency()->getCode(),
'authorization_reference_id' => $authorizationReferenceId,
'charge_order_id' => $Order->getId(),
'transaction_timeout' => 0 // get authorization status synchronously
));
$response = $this->getResponseData($Response);
if (isset($response['SetOrderReferenceDetailsResult']['OrderReferenceDetails']['Constraints']['Constraint']['ConstraintID'])) {
$Order->addHistory(
'Amazon Pay :: An error occurred while requesting the Authorization: "'
. $response['SetOrderReferenceDetailsResult']['OrderReferenceDetails']['Constraints']['Constraint']['ConstraintID'] . '""'
);
$this->throwAmazonPayException(
$response['SetOrderReferenceDetailsResult']['OrderReferenceDetails']['Constraints']['Constraint']['ConstraintID']
);
}
// save reference ids in $Order
$authorizationDetails = $response['AuthorizeResult']['AuthorizationDetails'];
$amazonAuthorizationId = $authorizationDetails['AmazonAuthorizationId'];
......@@ -281,9 +327,97 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
$Order->update(QUI::getUsers()->getSystemUser());
$this->checkAuthorizationStatus($authorizationDetails);
// check Authorization
$Order->addHistory('Amazon Pay :: Checking Authorization status');
$status = $authorizationDetails['AuthorizationStatus'];
$state = $status['State'];
switch ($state) {
case 'Open':
// everything is fine
$Order->addHistory(
'Amazon Pay :: Authorization is OPEN an can be used for capturing'
);
$Order->setPaymentData(self::ATTR_ORDER_AUTHORIZED, true);
$Order->update(QUI::getUsers()->getSystemUser());
break;
case 'Declined':
$reason = $status['ReasonCode'];
switch ($reason) {
case 'InvalidPaymentMethod':
$Order->addHistory(
'Amazon Pay :: Authorization was DECLINED. User has to choose another payment method.'
. ' ReasonCode: "' . $reason . '"'
);
$Order->setPaymentData(self::ATTR_ORDER_REFERENCE_SET, true);
$Order->update(QUI::getUsers()->getSystemUser());
$this->throwAmazonPayException($reason, array(
'reRenderWallet' => 1
));
break;
case 'TransactionTimedOut':
$Order->addHistory(
'Amazon Pay :: Authorization was DECLINED. User has to choose another payment method.'
. ' ReasonCode: "' . $reason . '"'
);
$AmazonPay->cancelOrderReference(array(
'amazon_order_reference_id' => $orderReferenceId,
'cancelation_reason' => 'Order #' . $Order->getHash() . ' could not be authorized :: TransactionTimedOut'
));
$Order->setPaymentData(self::ATTR_ORDER_REFERENCE_SET, false);
$Order->update(QUI::getUsers()->getSystemUser());
$this->throwAmazonPayException($reason, array(
'reRenderWallet' => 1,
'orderCancelled' => 1
));
break;
default:
$Order->addHistory(
'Amazon Pay :: Authorization was DECLINED. OrderReference has to be closed. Cannot use Amazon Pay for this Order.'
. ' ReasonCode: "' . $reason . '"'
);
$Response = $AmazonPay->getOrderReferenceDetails(array(
'amazon_order_reference_id' => $orderReferenceId
));
$response = $Response->toArray();
$orderReferenceDetails = $response['GetOrderReferenceDetailsResult']['OrderReferenceDetails'];
$orderReferenceStatus = $orderReferenceDetails['OrderReferenceStatus']['State'];
if ($orderReferenceStatus === 'Open') {
$AmazonPay->cancelOrderReference(array(
'amazon_order_reference_id' => $orderReferenceId,
'cancelation_reason' => 'Order #' . $Order->getHash() . ' could not be authorized'
));
$Order->setPaymentData(self::ATTR_AMAZON_ORDER_REFERENCE_ID, false);
$Order->update(QUI::getUsers()->getSystemUser());
}
}
break;
default:
$reason = $status['ReasonCode'];
$Order->addHistory(
'Amazon Pay :: Authorization cannot be used because it is in state "' . $state . '".'
. ' ReasonCode: "' . $reason . '"'
);
$Order->addHistory('Amazon Pay :: Authorization request successful');
$this->throwAmazonPayException($reason);
}
}
/**
......@@ -320,7 +454,7 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
$this->authorizePayment($orderReferenceId, $Order);
} catch (AmazonPayException $Exception) {
$Order->addHistory(
'Amazon Pay :: Capture failed because the Order has no Authorization'
'Amazon Pay :: Capture failed because the Order has no OPEN Authorization'
);
throw new AmazonPayException(array(
......@@ -387,50 +521,19 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
/**
* Set the Amazon Pay OrderReference to status CLOSED
*
* @param AbstractOrder $Order
* @param string $reason (optional) - Close reason [default: "Order #hash completed"]
* @return void
*/
protected function closeOrderReference()
protected function closeOrderReference(AbstractOrder $Order, $reason = null)
{
$AmazonPay = $this->getAmazonPayClient();
$orderReferenceId = $this->Order->getPaymentDataEntry(self::ATTR_AMAZON_ORDER_REFERENCE_ID);
}
/**
* Check AuthorizationDetails of an Amazon Pay Authorization
*
* If "State" is "Open" everything is fine and the payment can be captured
*
* @param array $authorizationDetails
* @return void
* @throws AmazonPayException
*/
public function checkAuthorizationStatus($authorizationDetails)
{
$this->Order->addHistory('Amazon Pay :: Checking Authorization status');
$status = $authorizationDetails['AuthorizationStatus'];
$state = $status['State'];
switch ($state) {
case 'Open':
$this->Order->addHistory(
'Amazon Pay :: Authorization is OPEN an can be used for charging'
);
return; // everything is fine
break;
default:
$this->Order->addHistory(
'Amazon Pay :: Authorization cannot be used because it is in state "' . $state . '".'
. ' ReasonCode: "' . $status['ReasonCode'] . '"'
);
$orderReferenceId = $Order->getPaymentDataEntry(self::ATTR_AMAZON_ORDER_REFERENCE_ID);
$this->throwAmazonPayException($status['ReasonCode']);
break;
}
$AmazonPay->closeOrderReference(array(
'amazon_order_reference_id' => $orderReferenceId,
'closure_reason' => $reason ?: 'Order #' . $Order->getHash() . ' completed'
));
}
/**
......@@ -480,6 +583,8 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
{
$response = $Response->toArray();
\QUI\System\Log::writeRecursive($response);
if (!empty($response['Error']['Code'])) {
$this->throwAmazonPayException($response['Error']['Code']);
}
......@@ -491,30 +596,30 @@ class Payment extends QUI\ERP\Accounting\Payments\Api\AbstractPayment
* Throw AmazonPayException for specific Amazon API Error
*
* @param string $errorCode
* @param array $exceptionAttributes (optional) - Additional Exception attributes that may be relevant for the Frontend
* @return string
*
* @throws AmazonPayException
*/
protected function throwAmazonPayException($errorCode)
protected function throwAmazonPayException($errorCode, $exceptionAttributes = array())
{
$L = $this->getLocale();
$lg = 'quiqqer/payment-amazon';
$msg = $L->get($lg, 'payment.error_msg.general_error');
$reRenderWallet = false;
$L = $this->getLocale();
$lg = 'quiqqer/payment-amazon';
$msg = $L->get($lg, 'payment.error_msg.general_error');
switch ($errorCode) {
case 'InvalidPaymentMethod':
case 'PaymentMethodNotAllowed':
case 'TransactionTimedOut':
case 'AmazonRejected':
case 'ProcessingFailure':
case 'MaxCapturesProcessed':
$msg = $L->get($lg, 'payment.error_msg.' . $errorCode);
break;
default:
}
$Exception = new AmazonPayException($msg);
$Exception->setAttribute('reRenderWallet', $reRenderWallet);
$Exception->setAttributes($exceptionAttributes);
throw $Exception;
}
......
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren