//---------------- // payments // copyright 2010 Slide.com //---------------- if (typeof Slide === "undefined") { Slide = {}; } Slide.Payments = { opened : false, iframe_id : 'vep_payframe', num_calls: 0, // used as an ID for vepcom iframe user_has_oneclick: false, oneclick_txn_failed: false, pending_calls: [], opens : 0, fb_init : false }; Slide.Payments.on_payment = function(receipt) {}; Slide.Payments.on_cancel = function(){}; Slide.Payments.on_open_complete = function(){}; Slide.Payments.on_open = function(){}; Slide.Payments.iframe_height = "0"; Slide.Payments._supported = ""; Slide.Payments.on_oneclick_fail = function(){}; Slide.Payments._open_on_initialized = false; Slide.Payments.log = function(args) { }; /** * Open the initialized (with Slide.Payments.initialize) payment window. * @param userauth authentication object containing 'user', 'app', 'amount', * 'timestamp', 'signature', and 'info' * @param is_express_flow True if this is an express flow, and we should attempt to charge if user has express checkout turned on. * @param amount String amount (ex: "1.00") to attempt to charge the user. * @param subscrip_params Optional object defining a new subscription: * @param subscrip_params.type dbval.UserRecurring.TYPE*; constant identifying the subscription type * @param subscrip_params.sched Cron-like string (MM:HH:DD:mm) defining the recurring payment schedule (see access.bank.subscription_add) * @param subscrip_params.sub_start [optional] Timestamp (GMT -8) that defines the beginning of the subscription window. * @param subscrip_params.sub_end [optional] Timestamp (GMT -8) that defines the end of the subscription and payment windows. * @param subscrip_params.recurdelta [optional] Delay the beginning of the payment schedule for this many seconds (allows for pro-rating) * @param subscrip_params.initamt [optional] Dollar amount to charge on creation of the subscription */ Slide.Payments.open = function(amount, is_express_flow, userauth, subscrip_params) { var is_oneclick_flow = !!is_express_flow; // undefined is boolean false if( !Slide.Payments.initialized ){ Slide.Payments.opens += 1; Slide.Payments._open_on_initialized = [amount, is_oneclick_flow, userauth, subscrip_params, Slide.Payments.opens]; Slide.Payments.log("Slide.Payments.open: called open before initialized, queueing #"+Slide.Payments.opens); return; } Slide.Payments.log("Slide.Payments.open: called open after initialized"); Slide.Payments.on_open(); if( !userauth ){ userauth = Slide.Payments._open_data.auth; }else{ if( userauth.app ){ Slide.Payments._open_data.auth.app = userauth.app; } if( userauth.user ){ Slide.Payments._open_data.auth.user = userauth.user; } if( userauth.signature ){ Slide.Payments._open_data.auth.signature = userauth.signature; } if( userauth.timestamp ){ Slide.Payments._open_data.auth.timestamp = userauth.timestamp; } if( userauth.info ){ Slide.Payments._open_data.auth.info = userauth.info; } } if( is_oneclick_flow && !Slide.Payments.oneclick_txn_failed ){ Slide.Payments.queueCall('Slide.PaymentPopup.showOneclickRemember', false); } // if subscrip_params.(type | sched) is falsy, do not pass any subscrip_params is_subscrip = false; if(subscrip_params && ((subscrip_params['sched'] && subscrip_params['type']) || subscrip_params['change_instr']) ){ is_subscrip = true; Slide.Payments.queueCall('Slide.PaymentPopup.setSubscripParams', subscrip_params); } var open_values = { 'app' : userauth.app, 'user' : userauth.user, 'timestamp' : userauth.timestamp, 'signature' : userauth.signature, 'info' : userauth.info, 'is_oneclick_flow' : is_oneclick_flow, 'amount' : amount, 'is_subscrip': is_subscrip ? '1' : '0' }; if(subscrip_params && subscrip_params['shop_descriptor']) { open_values['shop_descriptor'] = subscrip_params['shop_descriptor']; } Slide.Payments.queueCall('Slide.PaymentPopup.open', open_values); if (Slide.Payments.opened == false) { Slide.Payments.opened = true; } }; Slide.Payments._open_data = {}; /** * Open a zero-dollar card authentication dialog. This exists to save cards into the system, to be used * as stored instruments, without immediately charging to them. * Note that this opens a window that is different from the regular checkout window, and that it must be * closed (by canceling or completing) before a payment window can be opened. */ Slide.Payments.authenticate_card = function(userauth){ Slide.Payments.open("0_auth",false,userauth); }; /** * Initialize the payment form. This can be done in the header or in the body of the * page. If it is done prior to container_id in the document flow, we register * the _initialize function with window.onload and initialize once the window has * finished loading. * * If initialize is invoked after the element referenced by container_id, we simply * invoke the worker _initialize function immediately. * * @param container_id String ID of the container in which to display the payment form * @param userauth Object containing user authentication info * @param callback_url Server-side application callback to which we will send the receipt * @param comm_url Communicator iframe URL * @param buckets Array containing up to four values of in-game currency to purchase * @param conversion_rate Amount (in US cents) that one unit of in-game currency costs */ Slide.Payments.initialize = function(container_id, userauth, callback_url, comm_url, options){ Slide.Payments._adjustHeightInitialDone = false; Slide.Payments.options = options || {}; Slide.Payments.defaults(Slide.Payments.options, { 'buckets': [null], 'conversion_rate': 10, 'shop_descriptor': "", 'buy_phrase': "Select an amount to buy", 'zong_number': '', 'bgcolor': 'FFFFFF', 'hide_labels': false, 'padding': false, 'callback_url': callback_url, '_container_id': container_id, 'buy_button_align': 'right', 'buy_button_url':'' }); var priorOnload = function(){}; if( document.onload ){ priorOnload = window.onload; } var newOnload = function(e){ priorOnload(e); //Execute the previous onload function Slide.Payments._initialize(container_id, userauth, callback_url, comm_url, Slide.Payments.options); }; if( document.getElementById(container_id) ){ Slide.Payments._initialize(container_id, userauth, callback_url, comm_url, Slide.Payments.options); }else{ window.onload = newOnload; } }; /** * After initialization, this function indicates whether the user has stored instruments. */ Slide.Payments.hasStoredInstruments = function(){ return Slide.Payments._hasStoredInstruments; }; Slide.Payments.close = function() { Slide.Payments.log("Slide.Payments.close: closing"); Slide.Payments._on_open_initialized = false; Slide.Payments.initialized = false; Slide.Payments.opened = false; var container = document.getElementById(Slide.Payments.options._container_id); container.style.visibility = 'hidden'; container.style.height = '1px'; container.innerHTML = ''; var od = Slide.Payments._open_data; Slide.Payments._initialize(Slide.Payments.options._container_id, od.auth, od.callback_url, od.comm_url, Slide.Payments.options); }; Slide.Payments._initialize = function(container_id, userauth, callback_url, comm_url, opts){ Slide.Payments._adjustHeightInitialDone = false; if( window.FB && FB.ensureInit ){ FB.ensureInit(function() { FB_RequireFeatures(["Payments"], function() { Slide.Payments._fb_init = true; }); }); } Slide.Payments._open_data = {'amount':0, 'auth':userauth, 'callback_url':callback_url, 'comm_url':comm_url, 'buckets':opts.buckets, 'conversion_rate':opts.conversion_rate}; var initial_height = 0; //Slide.Payments.getViewPortHeight() - 5; var cur_url = window.location + ""; var cur_split = cur_url.split("/"); var cur_host = cur_split[2]; var protocol = 'http'; //cur_split[0].split(':')[0]; if( !comm_url ){ comm_url = protocol + "://" + cur_host + "/vep/vepcast.html"; } else if (!opts.alt_iframe_comm) { var comm_url_parts = comm_url.split("/"); comm_url_parts[2] = cur_host; comm_url = comm_url_parts.join("/"); } var userauth_str = "app="+encodeURIComponent(userauth.app)+ "&user="+encodeURIComponent(userauth.user)+ "×tamp="+encodeURIComponent(userauth.timestamp)+ "&signature="+encodeURIComponent(userauth.signature)+ "&info="+encodeURIComponent(userauth.info); var callback_str = 'callback_url='+encodeURIComponent(callback_url); var comm_str = 'comm_url='+encodeURIComponent(comm_url); var bucket_str = 'buckets='+opts.buckets.join(",")+'&conversion_rate='+opts.conversion_rate; var shop_str = 'shop_descriptor=' + opts.shop_descriptor + '&buy_phrase=' + opts.buy_phrase; var zong_str = 'zong_number=' + opts.zong_number; var bg_str = 'bgcolor=' + opts.bgcolor; var labels_str = 'hide_labels=' + opts.hide_labels; var bb_align_str = 'buy_button_align=' + opts.buy_button_align; var bb_url_str = 'buy_button_url=' + encodeURIComponent(opts.buy_button_url); var hide_store = 'hide_store=' + opts.hide_store; var param_str = userauth_str+'&amount=0&supported='+Slide.Payments._supported+'&'+comm_str+'&'+bucket_str+'&'+shop_str+'&'+zong_str+'&'+bg_str+'&'+labels_str + '&' + bb_align_str + '&' + bb_url_str+'&'+callback_str+'&' + hide_store; var iframe_w = 520; var source = '