/**
* @uses jQuery
* @uses ep
*/
define('de_epages/paypalplus/ui/paypalpluspaymentwall', [
'jquery',
'ep',
'$dict!../dictionary',
'$ready!',
'ep/ajax',
'ep/fn/busy'
], function($, ep, epDict) {
'use strict';
var PaymentWallError = epDict.translate('{PaymentWallError}');
var isMobileGlobal = undefined;
var isErrorShown = false;
return function(isMobile, BasketOrOrderID, PaymentLineItemID) {
isMobileGlobal = isMobile;
showBusyBox();
ep.ajax({
data : {
'ObjectID' : BasketOrOrderID,
'ChangeAction' : 'CreatePaymentPayPalPlus'
},
cache : false,
type : "POST",
dataType : "json"
}).done(function(jsonData) {
if (jsonData.WasCreatePaymentSuccessful) {
buildPaymentWall(PaymentLineItemID);
} else {
showErrorOnStoreFront();
}
}).fail(function(jsonData) {
showErrorOnStoreFront();
});
};
function showBusyBox() {
if (isMobileGlobal) {
ep('#CheckOut').prop('disabled', true);
ep('#CheckOutTop').prop('disabled', true);
}
else {
ep('#ppplus').addClass('ep-busy');
ep('.SubmitButton').prop('disabled', true);
}
};
function hideBusyBox() {
if (isMobileGlobal) {
ep('#CheckOut').prop('disabled', isErrorShown);
ep('#CheckOutTop').prop('disabled', isErrorShown);
}
else {
ep('#ppplus').removeClass('ep-busy');
ep('.SubmitButton').prop('disabled', isErrorShown);
}
};
function showErrorOnStoreFront() {
isErrorShown = true;
hideBusyBox();
ep("#" + "PaymentWallErrorMessage").css({
"display" : "block"
}).html(PaymentWallError);
};
function buildPaymentWall(PaymentLineItemID) {
ep.ajax({
data : {
'ObjectID' : PaymentLineItemID,
'ChangeAction' : 'GetPaymentWallDataPayPalPlus'
},
cache : false,
type : "POST",
dataType : "json"
}).done(function(jsonData) {
if(jsonData.wasSuccessful) {
showPaymentWall(jsonData);
} else {
showErrorOnStoreFront(jsonData.errorCode, jsonData.errorMessage);
}
}).fail(function(jsonData) {
showErrorOnStoreFront(jsonData.status, jsonData.statusText);
});
};
function showPaymentWall(jsonData) {
PAYPAL.apps.PPP({
"approvalUrl" : jsonData.approvalUrl,
"placeholder" : "ppplus",
"mode" : jsonData.mode,
"buttonLocation" : jsonData.buttonLocation,
"language" : jsonData.language,
"country" : jsonData.country,
"enableContinue" : hideBusyBox,
});
};
});