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

feat: payment process (temp commit)

Übergeordneter 66e396ba
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -35,11 +35,13 @@ define('package/quiqqer/payment-amazon/bin/controls/recurring/PaymentDisplay', [
],
options: {
sandbox : true,
sellerid : '',
clientid : '',
orderhash : '',
successful: false
sandbox : true,
sellerid : '',
clientid : '',
orderhash : '',
successful : false,
displayprice : '',
displayinterval: ''
},
initialize: function (options) {
......@@ -238,7 +240,10 @@ define('package/quiqqer/payment-amazon/bin/controls/recurring/PaymentDisplay', [
if (showInfoMessage) {
this.$showMsg(
QUILocale.get(pkg, 'controls.PaymentDisplay.wallet_info')
QUILocale.get(pkg, 'controls.recurring.PaymentDisplay.wallet_info', {
price : this.getAttribute('displayprice'),
interval: this.getAttribute('displayinterval')
})
);
}
......@@ -252,13 +257,11 @@ define('package/quiqqer/payment-amazon/bin/controls/recurring/PaymentDisplay', [
},
agreementType : 'BillingAgreement',
onReady : function (billingAgreement) {
self.$billingAgreementId = billingAgreement.getAmazonBillingAgreementId();
console.log("billingAgreementId", self.$billingAgreementId);
if (!self.$billingAgreementId) {
self.$billingAgreementId = billingAgreement.getAmazonBillingAgreementId();
}
self.$OrderProcess.resize();
//self.$PayBtn.enable();
},
onPaymentSelect: function (billingAgreement) {
self.$showRecurringPaymentConsent();
......@@ -309,26 +312,6 @@ define('package/quiqqer/payment-amazon/bin/controls/recurring/PaymentDisplay', [
var PayBtnElm = this.getElm().getElement('#quiqqer-payment-amazon-btn-pay');
if (!this.$PayBtn) {
this.$PayBtn = new QUIButton({
'class' : 'btn-primary',
disabled : true,
text : QUILocale.get(pkg, 'controls.PaymentDisplay.btn_pay.text', {
display_price: PayBtnElm.get('data-price')
}),
alt : QUILocale.get(pkg, 'controls.PaymentDisplay.btn_pay.title', {
display_price: PayBtnElm.get('data-price')
}),
title : QUILocale.get(pkg, 'controls.PaymentDisplay.btn_pay.title', {
display_price: PayBtnElm.get('data-price')
}),
textimage: 'fa fa-amazon',
events : {
onClick: this.$onPayBtnClick
}
}).inject(PayBtnElm);
}
// rendet wallet widget
var WalletWidget = new OffAmazonPayments.Widgets.Wallet(Options);
WalletWidget.setPresentmentCurrency(PayBtnElm.get('data-currencycode'));
......@@ -337,22 +320,14 @@ define('package/quiqqer/payment-amazon/bin/controls/recurring/PaymentDisplay', [
/**
* Show Amazon Pay consent widget for recurring payment
*
* @param {Boolean} [showInfoMessage] - Show info message
*/
$showRecurringPaymentConsent: function (showInfoMessage) {
$showRecurringPaymentConsent: function () {
if (this.$consentBoxShown) {
return;
}
var self = this;
if (showInfoMessage) {
this.$showMsg(
QUILocale.get(pkg, 'controls.PaymentDisplay.wallet_info')
);
}
this.$ConsentElm.set('html', '');
this.$ConsentElm.removeClass('quiqqer-payment-amazon__hidden');
......@@ -369,23 +344,20 @@ define('package/quiqqer/payment-amazon/bin/controls/recurring/PaymentDisplay', [
onConsent: function (billingAgreementConsentStatus) {
var buyerBillingAgreementConsentStatus = billingAgreementConsentStatus.getConsentStatus();
if (!buyerBillingAgreementConsentStatus) {
if (!buyerBillingAgreementConsentStatus || buyerBillingAgreementConsentStatus !== 'true') {
self.$showErrorMsg(
QUILocale.get(pkg, 'controls.recurring.PaymentDisplay.consent_denied')
);
self.fireEvent('processingError', [self]);
self.$PayBtn.disable();
return;
}
self.$OrderProcess.Loader.show();
self.$createBillingAgreement().then(function () {
self.$OrderProcess.Loader.hide();
console.log("billing agreement created!");
})
self.$PayBtn.enable();
},
onError : function (Error) {
console.log(Error);
switch (Error.getErrorCode()) {
// handle errors on the shop side (most likely misconfiguration)
case 'InvalidAccountStatus':
......@@ -435,123 +407,36 @@ define('package/quiqqer/payment-amazon/bin/controls/recurring/PaymentDisplay', [
ConsentWidget.bind('quiqqer-payment-amazon-consent');
this.$consentBoxShown = true;
if (!this.$PayBtn) {
this.$PayBtn = new QUIButton({
'class' : 'btn-primary',
disabled : true,
text : QUILocale.get(pkg, 'controls.recurring.PaymentDisplay.btn_pay.text'),
title : QUILocale.get(pkg, 'controls.recurring.PaymentDisplay.btn_pay.title'),
textimage: 'fa fa-amazon',
events : {
onClick: this.$onPayBtnClick
}
}).inject(this.getElm().getElement('#quiqqer-payment-amazon-btn-pay'));
}
},
///**
// * 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.$initConfirmationFlow().then(function () {
// return self.$confirmOrder();
// }).then(function (success) {
// if (success) {
// self.$confirmationFlow.success();
// return;
// }
//
// self.$OrderProcess.Loader.hide();
//
// self.$showErrorMsg(
// QUILocale.get(pkg, 'controls.PaymentDisplay.processing_error')
// );
//
// self.$showAmazonWallet(false);
//
// Btn.enable();
// Btn.setAttribute('textimage', 'fa fa-amazon');
// }, function (error) {
// self.$OrderProcess.Loader.hide();
// self.$showErrorMsg(error.getMessage());
//
// if (error.getAttribute('orderCancelled')) {
// self.$orderReferenceId = false;
// }
//
// // abort Amazon Pay initConfirmationFlow
// self.$confirmationFlow.error();
//
// if (error.getAttribute('reRenderWallet')) {
// self.$WalletElm.removeClass('quiqqer-payment-amazon__hidden');
// self.$showAmazonWallet(false);
//
// Btn.enable();
// Btn.setAttribute('textimage', 'fa fa-amazon');
//
// self.fireEvent('processingError', [self]);
// return;
// }
//
// // sign out
// amazon.Login.logout();
// Btn.destroy();
//
// self.$showErrorMsg(
// QUILocale.get(pkg, 'controls.PaymentDisplay.fatal_error')
// );
//
// new QUIButton({
// text : QUILocale.get(pkg, 'controls.PaymentDisplay.btn_reselect_payment.text'),
// texticon: 'fa fa-credit-card',
// events : {
// onClick: function () {
// window.location.reload();
// }
// }
// }).inject(self.getElm().getElement('#quiqqer-payment-amazon-btn-pay'));
// });
//},
//
///**
// * Init SCA-compatible confirmation flow
// *
// * @return {Promise}
// */
//$initConfirmationFlow: function () {
// var self = this;
//
// return new Promise(function (resolve, reject) {
// OffAmazonPayments.initConfirmationFlow(
// self.getAttribute('sellerid'),
// self.$orderReferenceId,
// function (confirmationFlow) {
// self.$confirmationFlow = confirmationFlow;
// resolve();
// },
// reject
// );
// });
//},
//
///**
// * Confirm order with Amazon Pay
// *
// * @return {Promise}
// */
//$confirmOrder: function () {
// var self = this;
//
// return new Promise(function (resolve, reject) {
// QUIAjax.post('package_quiqqer_payment-amazon_ajax_confirmOrder', resolve, {
// 'package' : pkg,
// orderHash : self.getAttribute('orderhash'),
// orderReferenceId: self.$orderReferenceId,
// onError : reject
// })
// });
//},
/**
* Event: on pay btn click
*/
$onPayBtnClick: function () {
var self = this;
this.$OrderProcess.Loader.show();
this.$createBillingAgreement().then(function () {
self.$OrderProcess.Loader.hide();
}, function (e) {
self.$showError(e.getMessage());
self.$showAmazonWallet(false);
});
},
/**
* Create / set up a BillingAgreement
......
......@@ -324,6 +324,18 @@
<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.recurring.PaymentDisplay.wallet_info" html="true">
<de><![CDATA[Bitte wählen Sie die Zahlungsweise aus, über die Amazon den Betrag Ihres Abonnements <b>[interval]</b> i.H.v. <b>[price]</b> einzieht.]]></de>
<en><![CDATA[Please select the payment method that Amazon uses to collect the amount of your subscription of <b>[price]</b> in a <b>[interval]</b> interval.]]></en>
</locale>
<locale name="controls.recurring.PaymentDisplay.btn_pay.text">
<de><![CDATA[Regelmäßige Zahlung jetzt einrichten]]></de>
<en><![CDATA[Set up regular payment now]]></en>
</locale>
<locale name="controls.recurring.PaymentDisplay.btn_pay.title">
<de><![CDATA[Hier klicken, um die regelmäßige Zahlung Ihres Abonnements über Ihr Amazon-Konto einzurichten]]></de>
<en><![CDATA[Click here to set up regular payment of your subscription through your Amazon account]]></en>
</locale>
<locale name="controls.PaymentDisplay.authorize_payment">
<de><![CDATA[Autorisiere Zahlung bei Amazon]]></de>
<en><![CDATA[Authorize payment with Amazon]]></en>
......
......@@ -21,15 +21,15 @@ class BillingAgreements
const TBL_BILLING_AGREEMENTS = 'amazon_billing_agreements';
const TBL_BILLING_AGREEMENT_TRANSACTIONS = 'amazon_billing_agreement_transactions';
const BILLING_AGREEMENT_STATE_ACTIVE = 'Active';
const BILLING_AGREEMENT_STATE_OPEN = 'Open';
const BILLING_AGREEMENT_STATE_ACTIVE = 'Active';
const BILLING_AGREEMENT_STATE_OPEN = 'Open';
const BILLING_AGREEMENT_VALIDATION_SUCCESS = 'Success';
const BILLING_AGREEMENT_VALIDATION_FAILURE = 'Failure';
const TRANSACTION_STATE_COMPLETED = 'Completed';
const TRANSACTION_STATE_DENIED = 'Denied';
const EXCEPTION_CODE_BILLING_AGREEMENT_VALIDATION_ERROR = 630001;
/**
* Runtime cache that knows then a transaction history
* for a Billing Agreement has been freshly fetched from Amazon.
......@@ -106,11 +106,10 @@ class BillingAgreements
]);
$details = $Response->toArray();
$details = $details['GetBillingAgreementDetailsResult']['BillingAgreementDetails'];
\QUI\System\Log::writeRecursive($details);
if (empty($details['BillingAgreementStatus'] ||
$details['BillingAgreementStatus'] !== self::BILLING_AGREEMENT_STATE_OPEN)) {
if (empty($details['BillingAgreementStatus']['State'] ||
$details['BillingAgreementStatus']['State'] !== self::BILLING_AGREEMENT_STATE_OPEN)) {
$Order->addHistory(Utils::getHistoryText(
'BillingAgreement.confirm_billing_agreement_error'
));
......@@ -142,6 +141,7 @@ class BillingAgreements
* @return void
*
* @throws AmazonPayException
* @throws QUI\Exception
*/
public static function validateBillingAgreement(AbstractOrder $Order)
{
......@@ -156,8 +156,7 @@ class BillingAgreements
]);
$result = $Response->toArray();
\QUI\System\Log::writeRecursive($result);
$result = $result['ValidateBillingAgreementResult'];
if (empty($result['ValidationResult']) || $result['ValidationResult'] !== self::BILLING_AGREEMENT_VALIDATION_SUCCESS) {
$Order->addHistory(Utils::getHistoryText(
......@@ -166,10 +165,13 @@ class BillingAgreements
Utils::saveOrder($Order);
throw new AmazonPayException([
'quiqqer/payment-amazon',
'exception.BillingAgreements.billing_agreement_not_validated'
]);
throw new AmazonPayException(
[
'quiqqer/payment-amazon',
'exception.BillingAgreements.billing_agreement_not_validated'
],
self::EXCEPTION_CODE_BILLING_AGREEMENT_VALIDATION_ERROR
);
}
$Order->addHistory(Utils::getHistoryText(
......@@ -179,6 +181,19 @@ class BillingAgreements
$Order->setAttribute(Payment::ATTR_AMAZON_BILLING_AGREEMENT_VALIDATED, true);
Utils::saveOrder($Order);
// Save billing agreement data in database
$Customer = $Order->getCustomer();
QUI::getDataBase()->insert(
self::getBillingAgreementsTable(),
[
'amazon_agreement_id' => $Order->getAttribute(Payment::ATTR_AMAZON_BILLING_AGREEMENT_ID),
'customer' => $Customer->getName().' ('.$Customer->getId().')',
'global_process_id' => $Order->getHash(),
'active' => 1
]
);
}
/**
......
......@@ -25,9 +25,7 @@
margin: 35px auto 0 auto;
min-width: 300px;
max-width: 600px;
min-height: 228px;
height: 240px;
max-height: 400px;
height: 150px;
}
#quiqqer-payment-amazon-btn-pay {
......
......@@ -12,10 +12,6 @@
<div id="quiqqer-payment-amazon-btn" class="quiqqer-payment-amazon-btn-elm" data-size="{$btn_size}" data-color="{$btn_color}"></div>
<div id="quiqqer-payment-amazon-wallet" class="quiqqer-payment-amazon__hidden"></div>
<div id="quiqqer-payment-amazon-consent" class="quiqqer-payment-amazon__hidden"></div>
<div id="quiqqer-payment-amazon-btn-pay"
data-price="{$display_price}"
data-currencycode="{$currency_code}"
>
</div>
<div id="quiqqer-payment-amazon-btn-pay"></div>
</div>
{/if}
\ No newline at end of file
......@@ -4,6 +4,8 @@ namespace QUI\ERP\Payments\Amazon\Recurring;
use QUI;
use QUI\ERP\Payments\Amazon\Provider;
use QUI\ERP\Plans\Utils as ERPPlansUtils;
use QUI\ERP\Plans\Handler as ERPPlansHandler;
/**
* Class PaymentDisplay
......@@ -55,6 +57,22 @@ class PaymentDisplay extends QUI\Control
]);
$this->setJavaScriptControlOption('orderhash', $Order->getHash());
$this->setJavaScriptControlOption('displayprice', $PriceCalculation->getSum()->formatted());
$planDetails = ERPPlansUtils::getPlanDetailsFromOrder($Order);
if (!empty($planDetails['invoice_interval'])) {
try {
$InvoiceInterval = ERPPlansUtils::parseIntervalFromDuration($planDetails['invoice_interval']);
$this->setJavaScriptControlOption(
'displayinterval',
ERPPlansUtils::intervalToIntervalText($InvoiceInterval)
);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
// Check if an Amazon Pay authorization already exists (i.e. Order is successful / can be processed)
$this->setJavaScriptControlOption('successful', $Order->isSuccessful());
......
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