var PaymentScreenPay=function(container,settings_purchase){var pane,page,header_title,footer,area_contact,area_select,area_store,report_error,report_notice,input_email,radioboxes_payment,cbox_remember,but_process,but_process_label,but_process_icon,but_loadform,but_loadform_label,but_loadform_icon,but_close,icon_loading,currency,logged_in,payment,timeout_order_validated,INSTANCE=new VSModule,PADDLE_FORM_TYPE="overlay",URL_PURCHASE_SETUP="/api/purchases/setup",URL_INVOICE_PPI="/api/invoice/ppi",URL_INVOICE_CUSTOMIZATION="/api/invoice/customization",REGEX_EMAIL=/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,monitor_email=!1;function setup(){var but_close;input_email=new VectorStock.FieldInput($('input[name="email"]',area_contact)),radioboxes_payment=new VectorStock.FieldRadioboxes($("ul.radiobuttons li",area_select)),cbox_remember=new VectorStock.FieldCheckbox($("#pay-remember-payment",area_store)),but_process=$("#pbox-but-process-card",footer),but_process_label=$(".label",but_process),but_loadform=$("#pbox-but-load-form",footer),but_loadform_label=$(".label",but_loadform),but_close=$('button[data-action="close"]',container),icon_loading&&icon_loading.remove(),radioboxes_payment.on("change",onPaymentSelect),but_process.on("click",payWithStoredCard),but_loadform.on("click",validateForm),but_close.on("click",close),INSTANCE.show()}function onPaymentSelect(type){container.attr("data-payment",type)}function displayLoadingState(){report_error&&(report_error.remove(),report_error=null),container.addClass("disabled"),input_email.disable(),radioboxes_payment.disable(),cbox_remember.disable(),but_process.prop("disabled",!0),but_process_label.data("label",but_process_label.html()).html("Processing…"),but_process_icon=$(".icon",but_process).loadingIcon(),but_loadform.prop("disabled",!0),but_loadform_label.data("label",but_loadform_label.html()).html("Loading…"),but_loadform_icon=$(".icon",but_loadform).loadingIcon(),but_close.hide(),INSTANCE.dispatchEvent("disable")}function revertLoadingState(){container.removeClass("disabled"),input_email.enable(),cbox_remember.enable(),radioboxes_payment.enable(),but_process.prop("disabled",!1),but_process_label.html(but_process_label.data("label")),but_process_icon.remove(),but_loadform.prop("disabled",!1),but_loadform_label.html(but_loadform_label.data("label")),but_loadform_icon.remove(),but_close.show(),INSTANCE.dispatchEvent("enable")}function validateEmail(value){return value.match(REGEX_EMAIL)?(input_email.clearError(),!0):(input_email.showError("Enter a valid email"),input_email.focus(),monitor_email||(input_email.on("change",validateEmail),monitor_email=!0),!1)}function validateForm(){var is_validated=!0;(is_validated=logged_in?is_validated:validateEmail(input_email.value))&&function(){displayLoadingState();var invoice_url=settings_purchase.customization?URL_INVOICE_CUSTOMIZATION:URL_INVOICE_PPI,invoice_params=getFormParams();invoice_params.store_card=cbox_remember.checked?1:0,$.post(invoice_url,invoice_params).done(function(response){var url;response.success?(url=response.url,"inline"===PADDLE_FORM_TYPE?Paddle.Checkout.open({method:"inline",allowQuantity:!1,override:url,frameTarget:"pbox_paddle_form",frameInitialHeight:"100%",frameStyle:"width:100%; min-width:312px; background-color: transparent; border: none;",loadCallback:function(){}}):Paddle.Checkout.open({method:"overlay",allowQuantity:!1,override:url,loadCallback:function(){}})):(displayError("Failed to initiate payment","We could not connect with our payment provider - please try again."),revertLoadingState(),VectorStock.log({source:"PaymentBox",issue:"Failed to setup Paddle invoice",detail:{params:invoice_params,response:response}}))}).fail(function(event){displayError("Failed to load payment","We could not load our payment provider - please try again."),revertLoadingState(),VectorStock.log({source:"PaymentBox",issue:"Paddle invoice setup failed to load",detail:{params:invoice_params,event:event}})})}()}function displayError(title,description){report_error&&report_error.remove(),report_error=$('
').prependTo(page),$(""+description+"
").appendTo(report_error)}function getFormParams(){var invoice_params={vector:settings_purchase.image.id,license:settings_purchase.image.license};return logged_in||(invoice_params.email=input_email.value),settings_purchase.customization&&(invoice_params.asset_method=settings_purchase.image.payment||"existing"),invoice_params}function payWithStoredCard(){displayLoadingState();var invoice_url=settings_purchase.customization?URL_INVOICE_CUSTOMIZATION:URL_INVOICE_PPI,invoice_params=getFormParams();invoice_params.use_token=1,$.post(invoice_url,invoice_params).done(function(response){response.success?INSTANCE.validateOrder(response.order_id):(displayError("Payment Declined","We could not complete payment using your stored card. Please try entering a new card instead."),revertLoadingState(),VectorStock.log({source:"PaymentBox",issue:"Stored card declined",detail:{params:invoice_params,response:response}}))}).fail(function(event){displayError("Failed to Process","We could not connect to the payment server. Please try entering a new card instead."),revertLoadingState(),VectorStock.log({source:"PaymentBox",issue:"Stored card failed to process",detail:{params:invoice_params,event:event}})})}function validateOrder(order_id,attempt_counter){attempt_counter=attempt_counter||0,clearValidationTimeout(),$.post("/api/invoice/check-validated",{order_id:order_id}).done(function(description){var params,title;description.success?(revertLoadingState(),params=[description],settings_purchase.image&¶ms.push(settings_purchase.image.license),INSTANCE.dispatchEvent("purchase",params)):(5==++attempt_counter&&(title="Your payment is taking longer than usual.",description="If you wish, you can close this popup and continue browsing images. We will email you with a download link once your payment has been validated.",report_notice&&report_notice.remove(),report_notice=$('').prependTo(page),$(""+description+"
").appendTo(report_notice),but_close.show(),INSTANCE.dispatchEvent("enable")),timeout_order_validated=setTimeout(function(){validateOrder(order_id,attempt_counter)},2e3))}).fail(function(event){var log_detail={order_id:order_id,order:purchase_order,event:event};VectorStock.log({source:"PaymentBox",issue:"Failed to load purchase order validation",detail:log_detail})})}function clearValidationTimeout(){timeout_order_validated&&(clearTimeout(timeout_order_validated),timeout_order_validated=null)}function close(){INSTANCE.close(),INSTANCE.dispatchEvent("close")}return INSTANCE.show=function(){container.addClass("show")},INSTANCE.hide=function(){container.removeClass("show")},INSTANCE.updateTotalPrice=function(total_cost,currency_type){0We have emailed you the invoice and download link
We have emailed you the invoice and download link
Your designer is waiting to begin!
').appendTo(picture)}function onClickOverlay(event){$(event.target)[0]==overlay[0]&&INSTANCE.close()}function onPurchase(response,image_license){screen_pay.hide();var url_customization,next_step,url_download=response.url;"zip"!==settings_purchase.filetype&&response.file_urls&&response.file_urls[settings_purchase.filetype]&&(url_download=response.file_urls[settings_purchase.filetype]),settings_customization&&response.customization&&(url_customization=response.customization.url,next_step=response.customization.status),(screen_success=new PaymentScreenSuccess($('.pb-screen[data-screen="success"]',screens),url_download,url_customization,next_step,image_license,response.transaction)).on("view_options",function(){INSTANCE.dispatchEvent("view_options"),INSTANCE.close()}),screen_success.on("close",function(){INSTANCE.close()}),images?EventTracker.track(EventTrackerLogger.ID_LOG,{source:"Cart Popup",event:"Purchased"}):EventTracker.track(EventTrackerLogger.ID_LOG,{source:"Purchase Popup",event:"Purchased"}),INSTANCE.dispatchEvent("purchase",[response,image_license,settings_purchase.total_cost])}return INSTANCE.close=function(){screen_pay&&screen_pay.close(),container&&container.remove(),overlay&&overlay.remove(),timeout_session_expiry&&clearTimeout(timeout_session_expiry),INSTANCE.dispatchEvent("close")},INSTANCE.updateTotalPrice=function(total,currency){var sb_total=$("li.total",sidebar_points);$(".dd em",sb_total).html(total),$(".dd abbr",sb_total).html(currency),screen_pay.updateTotalPrice(total,currency)},INSTANCE.validateOrder=function(order_id){screen_pay.validateOrder(order_id)},INSTANCE.revertLoadingState=function(){screen_pay.revertLoadingState()},function(){if(!window.Paddle)return alert("The payment processor is unavilable at this time. Please reload the page and try again or contact our support team."),INSTANCE.close();var image_snapshot;PaymentBox.paddle_setup||(Paddle.Setup({vendor:136127,eventCallback:function(data){switch(data.event){case"Checkout.Complete":var price_currency=JSON.parse(data.eventData.checkout.passthrough);PaymentBox.instance.validateOrder(price_currency.invoice_id);break;case"Checkout.Close":PaymentBox.instance.revertLoadingState();break;case"Checkout.Location.Submit":break;case"Checkout.Loaded":var price_total=data.eventData.checkout.prices.customer.total,price_currency=data.eventData.checkout.prices.customer.currency;PaymentBox.instance.updateTotalPrice(price_total,price_currency)}}}),PaymentBox.paddle_setup=!0),overlay=$('').css({height:$(document).height()}).appendTo("body").on("click",onClickOverlay),setTimeout(function(){overlay.addClass("reveal")}),function(){var pb_content,banner;if(container=$(HTML_TEMPLATE).appendTo(overlay),pb_content=$(".pb-sidebar",container),total_previews=$(".pb-screen",pb_content).show(),pb_content=$(".pb-content",total_previews),sidebar_points=$("ul",pb_content),screens=$(".pb-screens",container),images){var total_previews=Math.min(5,images.length);imageset=$(".imageset",pb_content).attr("data-images",total_previews);for(var i=total_previews;i--;)addImage(images[i])}else imageset=$(".imageset",pb_content).attr("data-images",1),addImage(image.id,image.title);screen_pay=new PaymentScreenPay($('.pb-screen[data-screen="pay"]',screens),images?{total_cost:settings_purchase.total_cost}:{image:image,customization:settings_customization,total_cost:settings_purchase.total_cost,upgrade:settings_purchase.upgrade});settings_customization||(container.addClass("upsell").append(HTML_BANNER),banner=$(".pb-banner button",container));screen_pay.on("load_currency",updateSidebar),screen_pay.on("disable",disableBox),screen_pay.on("enable",enableBox),screen_pay.on("purchase",onPurchase),screen_pay.on("close",INSTANCE.close),settings_purchase.upgrade?banner.parent().remove():banner&&banner.on("click",function(event){var min_cost;VectorStock.isLoggedIn()?(min_cost=Math.max(30,5*Math.ceil(Math.round(settings_purchase.total_cost)/5)),images?VectorStock.goToURL("/purchase/credits/"+min_cost):VectorStock.goToURL("/purchase/credits/"+min_cost+"?id="+image.id)):(INSTANCE.close(),VectorStock.goToURL("/signup"))});$(window).height()