diff --git a/README.md b/README.md index e1bde45..b1b00a6 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,37 @@ ## PayPal Payment Buttons [![Build Status](https://travis-ci.org/paypal/JavaScriptButtons.png?branch=master)](https://travis-ci.org/paypal/JavaScriptButtons) -Unofficial PayPal HTML payment buttons that are as easy as including a snippet of code. [Try it out and configure your own](http://paypal.github.com/JavaScriptButtons/). +Unofficial PayPal JavaScript payment buttons that are as easy as including a snippet of code. [Try it out and configure your own](http://paypal.github.com/JavaScriptButtons/). +### PayPal Button SDK +To use any of the buttons below, paste this snippet into your page. At the top of the snippet, replace "YOUR_MERCHANT_ID" with your Merchant ID. This will load the PayPal Button SDK asynchronously so it does not block loading other elements on your page. + +```html + +``` + We have a few flavors of buttons for you to use: ### Buy Now Buy Now buttons are for single item purchases. ```html - + data-amount="1.00" +> ``` @@ -20,21 +39,21 @@ Buy Now buttons are for single item purchases. Add To Cart buttons lets users add multiple items to their PayPal cart. ```html - +> ``` ### Hosted Hosted buttons help tamper-proof your button's data. ```html - +> ``` *Note: Hosted buttons IDs must be created on PayPal.com or via the Button Manager APIs using your credentials.* @@ -43,14 +62,12 @@ Hosted buttons help tamper-proof your button's data. QR codes which can be scanned with a smart phone can also be easily generated. ```html - +> ``` - ## Button variables All of PayPal's [HTML button variables](https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_Appx_websitestandard_htmlvariables) are supported by prefixing their name with "data-". Here are the most commonly used: @@ -107,7 +124,7 @@ The JavaScript buttons have been tested and work in all modern browsers includin ## Getting your Merchant ID -Your merchant ID needs to be added to the URL of the referenced script. This ID can either be your Secure Merchant ID, which can be found by logging into your PayPal account and visiting your profile, or your email address. +Your merchant ID needs to be added to the top of the referenced script. This ID can either be your Secure Merchant ID, which can be found by logging into your PayPal account and visiting your profile, or your email address. ## Contributing diff --git a/dist/paypal-button-minicart.min.js b/dist/paypal-button-minicart.min.js index 0c12237..7235deb 100644 --- a/dist/paypal-button-minicart.min.js +++ b/dist/paypal-button-minicart.min.js @@ -1,7 +1,7 @@ /*! * PayPalJSButtons * JavaScript integration for PayPal's payment buttons - * @version 1.0.0 - 2013-01-24, 5:42:15 PM + * @version 1.0.0 - 2013-02-18, 8:09:56 PM * @author Jeff Harrell */ -if(typeof PAYPAL=="undefined"||!PAYPAL)var PAYPAL={};PAYPAL.apps=PAYPAL.apps||{},function(){"use strict";var config={parent:document.body,displayEdge:"right",edgeDistance:"50px",formTarget:null,cookiePath:"/",strings:{button:"",subtotal:"",discount:"",shipping:"",processing:""},name:"PPMiniCart",peekEnabled:!0,paypalURL:"https://www.paypal.com/cgi-bin/webscr",assetURL:"http://www.minicartjs.com/build/",events:{onRender:null,afterRender:null,onHide:null,afterHide:null,onShow:null,afterShow:null,onAddToCart:null,afterAddToCart:null,onRemoveFromCart:null,afterRemoveFromCart:null,onCheckout:null,onReset:null,afterReset:null}};PAYPAL.apps.MiniCart=function(){var e={},t=!1,n=!1,r={_cart:!0,_xclick:!0},i="MiniCart_AddToCart_WPS_US",s=/^(?:business|currency_code|lc|paymentaction|no_shipping|cn|no_note|invoice|handling_cart|weight_cart|weight_unit|tax_cart|page_style|image_url|cpp_|cs|cbt|return|cancel_return|notify_url|rm|custom|charset)/,o=function(){var e=config.name,t=[],n,r;t.push("#"+e+" form { position:fixed; float:none; top:-250px; "+config.displayEdge+":"+config.edgeDistance+"; width:265px; margin:0; padding:50px 10px 0; min-height:170px; background:#fff url("+config.assetURL+"images/minicart_sprite.png) no-repeat -125px -60px; border:1px solid #999; border-top:0; font:13px/normal arial, helvetica; color:#333; text-align:left; -moz-border-radius:0 0 8px 8px; -webkit-border-radius:0 0 8px 8px; border-radius:0 0 8px 8px; -moz-box-shadow:1px 1px 1px rgba(0, 0, 0, 0.1); -webkit-box-shadow:1px 1px 1px rgba(0, 0, 0, 0.1); box-shadow:1px 1px 1px rgba(0, 0, 0, 0.1); } "),t.push("#"+e+" ul { position:relative; overflow-x:hidden; overflow-y:auto; height:130px; margin:0 0 7px; padding:0; list-style-type:none; border-top:1px solid #ccc; border-bottom:1px solid #ccc; } "),t.push("#"+e+" li { position:relative; margin:-1px 0 0; padding:6px 5px 6px 0; border-top:1px solid #f2f2f2; } "),t.push("#"+e+" li a { display: block; width: 155px; color:#333; text-decoration:none; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; } "),t.push("#"+e+" li a span { color:#999; font-size:10px; } "),t.push("#"+e+" li .quantity { position:absolute; top:.5em; right:78px; width:22px; padding:1px; border:1px solid #83a8cc; text-align:right; } "),t.push("#"+e+" li .price { position:absolute; top:.5em; right:4px; } "),t.push("#"+e+" li .remove { position:absolute; top:9px; right:60px; width:14px; height:14px; background:url("+config.assetURL+"images/minicart_sprite.png) no-repeat -134px -4px; border:0; cursor:pointer; } "),t.push("#"+e+" p { margin:0; padding:0 0 0 20px; background:url("+config.assetURL+"images/minicart_sprite.png) no-repeat; font-size:13px; font-weight:bold; } "),t.push("#"+e+" p:hover { cursor:pointer; } "),t.push("#"+e+" p input { float:right; margin:4px 0 0; padding:1px 4px; text-decoration:none; font-weight:normal; color:#333; background:#ffa822 url("+config.assetURL+"images/minicart_sprite.png) repeat-x left center; border:1px solid #d5bd98; border-right-color:#935e0d; border-bottom-color:#935e0d; -moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px; } "),t.push("#"+e+" p .shipping { display:block; font-size:10px; font-weight:normal; color:#999; } "),n=document.createElement("style"),n.type="text/css",n.styleSheet?n.styleSheet.cssText=t.join(""):n.appendChild(document.createTextNode(t.join(""))),r=document.getElementsByTagName("head")[0],r.appendChild(n)},u=function(){var t=e.UI,n,r,s,o,u;t.wrapper=document.createElement("div"),t.wrapper.id=config.name,n=document.createElement("input"),n.type="hidden",n.name="cmd",n.value="_cart",r=n.cloneNode(!1),r.name="upload",r.value="1",s=n.cloneNode(!1),s.name="bn",s.value=i,t.cart=document.createElement("form"),t.cart.method="post",t.cart.action=config.paypalURL,config.formTarget&&(t.cart.target=config.formTarget),t.cart.appendChild(n),t.cart.appendChild(r),t.cart.appendChild(s),t.wrapper.appendChild(t.cart),t.itemList=document.createElement("ul"),t.cart.appendChild(t.itemList),t.summary=document.createElement("p"),t.cart.appendChild(t.summary),t.button=document.createElement("input"),t.button.type="submit",t.button.value=config.strings.button||"Checkout",t.summary.appendChild(t.button),t.subtotal=document.createElement("span"),t.subtotal.innerHTML=config.strings.subtotal||"Subtotal: ",t.subtotalAmount=document.createElement("span"),t.subtotalAmount.innerHTML="0.00",t.subtotal.appendChild(t.subtotalAmount),t.summary.appendChild(t.subtotal),t.shipping=document.createElement("span"),t.shipping.className="shipping",t.shipping.innerHTML=config.strings.shipping||"does not include shipping & tax",t.summary.appendChild(t.shipping);if(window.attachEvent&&!window.opera){u=navigator.userAgent.match(/MSIE\s([^;]*)/);if(u){u=parseFloat(u[1]);if(u<7||u>=7&&document.compatMode==="BackCompat")t.cart.style.position="absolute",t.wrapper.style[config.displayEdge]="0",t.wrapper.style.setExpression("top","x = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop")}}o=typeof config.parent=="string"?document.getElementById(config.parent):config.parent,o.appendChild(t.wrapper)},a=function(){var n=e.UI,i,s,o;i=document.getElementsByTagName("form");for(o=0;o=15){r.style.backgroundColor="transparent",i==="0.00"&&e.hide(null,!0);return}setTimeout(c,30)}()},e.show=function(n){var r=parseInt(e.UI.cart.offsetTop,10),i=0,s=config.events,o=s.onShow,u=s.afterShow;n&&n.preventDefault&&n.preventDefault();if(typeof o=="function"&&o.call(e,n)===!1)return;$.util.animate(e.UI.cart,"top",{from:r,to:i},function(){typeof u=="function"&&u.call(e,n)}),e.UI.summary.style.backgroundPosition="-195px 2px",t=!0},e.hide=function(n,r){var i=e.UI,s=i.cart,o=i.summary,u=s.offsetHeight?s.offsetHeight:document.defaultView.getComputedStyle(s,"").getPropertyValue("height"),a=o.offsetHeight?o.offsetHeight:document.defaultView.getComputedStyle(o,"").getPropertyValue("height"),f=parseInt(s.offsetTop,10),l=config.events,c=l.onHide,h=l.afterHide,p;r||e.products.length===0||!config.peekEnabled?p=u*-1:p=(u-a-8)*-1,n&&n.preventDefault&&n.preventDefault();if(typeof c=="function"&&c.call(e,n)===!1)return;$.util.animate(s,"top",{from:f,to:p},function(){typeof h=="function"&&h.call(e,n)}),o.style.backgroundPosition="-195px -32px",t=!1},e.toggle=function(n){t?e.hide(n):e.show(n)},e.reset=function(){var n=e.UI,r=config.events,i=r.onReset,s=r.afterReset;if(typeof i=="function"&&i.call(e)===!1)return;e.products=[],t&&(n.itemList.innerHTML="",n.subtotalAmount.innerHTML="",e.hide(null,!0)),$.storage.remove(),typeof s=="function"&&s.call(e)},e}();var ProductNode=function(e,t){this._view(e,t)};ProductNode.prototype={_view:function(e,t){var n,r,i,s,o,u,a;this.product=e.product,this.settings=e.settings,this.liNode=document.createElement("li"),this.nameNode=document.createElement("a"),this.metaNode=document.createElement("span"),this.discountNode=document.createElement("span"),this.discountInput=document.createElement("input"),this.priceNode=document.createElement("span"),this.quantityInput=document.createElement("input"),this.removeInput=document.createElement("input");if(!this.product||!this.product.item_name&&!this.product.item_number){this.isPlaceholder=!0;return}this.product.item_name&&(n=this.product.item_name),this.nameNode.innerHTML=n,this.nameNode.title=n,this.nameNode.href=this.product.href,this.nameNode.appendChild(this.metaNode),this.product.item_number&&(this.metaNode.innerHTML="
#"+this.product.item_number),o=this.getOptions();for(a in o)this.metaNode.innerHTML+="
"+a+": "+o[a];s=this.getDiscount(),this.discountInput.type="hidden",this.discountInput.name="discount_amount_"+t,this.discountInput.value=s,this.metaNode.appendChild(this.discountNode),r=this.getPrice(),this.priceNode.className="price",i=this.getQuantity(),this.quantityInput.name="quantity_"+t,this.quantityInput.className="quantity",this.quantityInput.setAttribute("autocomplete","off"),this.setQuantity(i),this.removeInput.type="button",this.removeInput.className="remove",this.liNode.appendChild(this.nameNode),this.liNode.appendChild(this.quantityInput),this.liNode.appendChild(this.discountInput),this.liNode.appendChild(this.removeInput),this.liNode.appendChild(this.priceNode);for(a in this.product)a!=="quantity"&&a.indexOf("discount_")===-1&&(u=document.createElement("input"),u.type="hidden",u.name=a+"_"+t,u.value=this.product[a],this.liNode.appendChild(u))},getDiscount:function(){var e=0,t=this.product.discount_num||-1,n;return this.product.discount_amount?(e=parseFloat(this.product.discount_amount),this.product.discount_amount2&&(n=this.getQuantity(),n>1&&(e+=Math.max(n-1,t)*parseFloat(this.product.discount_amount2)))):this.product.discount_rate&&(e=this.product.amount*parseFloat(this.product.discount_rate)/100,this.product.discount_rate2&&(n=this.getQuantity(),n>1&&(e+=Math.max(n-1,t)*this.product.amount*parseFloat(this.product.discount_amount2)/100))),e&&e.toFixed(2)},getOptions:function(){var e={},t=0;while(typeof this.product["on"+t]!="undefined")e[this.product["on"+t]]=this.product["os"+t],t++;return e},setQuantity:function(e){var t;e=parseInt(e,10),this.product.quantity=e;if(this.quantityInput.value!==e){this.quantityInput.value=e;if(t=this.getDiscount())this.discountInput.value=t,this.discountNode.innerHTML="
",this.discountNode.innerHTML+=config.strings.discount||"Discount: ",this.discountNode.innerHTML+=$.util.formatCurrency(t,this.settings.currency_code)}this.setPrice(this.product.amount*e)},getQuantity:function(){return typeof this.product.quantity!==undefined?this.product.quantity:1},setPrice:function(e){e=parseFloat(e,10),this.priceNode.innerHTML=$.util.formatCurrency(e.toFixed(2),this.settings.currency_code)},getPrice:function(){return(this.product.amount*this.getQuantity()).toFixed(2)}};var $={};$.storage=function(){var e=config.name;return window.localStorage?{load:function(){var t=localStorage.getItem(e);return t&&(t=JSON.parse(decodeURIComponent(t))),t},save:function(t){var n=[],r,i,s;if(t){for(s=0,i=t.length;s0&&s>n.to||i<0&&s=7&&document.compatMode==="BackCompat")t.cart.style.position="absolute",t.wrapper.style[config.displayEdge]="0",t.wrapper.style.setExpression("top","x = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop")}}o=typeof config.parent=="string"?document.getElementById(config.parent):config.parent,o.appendChild(t.wrapper)},a=function(){var n=e.UI,i,s,o;i=document.getElementsByTagName("form");for(o=0;o=15){r.style.backgroundColor="transparent",i==="0.00"&&e.hide(null,!0);return}setTimeout(c,30)}()},e.show=function(n){var r=parseInt(e.UI.cart.offsetTop,10),i=0,s=config.events,o=s.onShow,u=s.afterShow;n&&n.preventDefault&&n.preventDefault();if(typeof o=="function"&&o.call(e,n)===!1)return;$.util.animate(e.UI.cart,"top",{from:r,to:i},function(){typeof u=="function"&&u.call(e,n)}),e.UI.summary.style.backgroundPosition="-195px 2px",t=!0},e.hide=function(n,r){var i=e.UI,s=i.cart,o=i.summary,u=s.offsetHeight?s.offsetHeight:document.defaultView.getComputedStyle(s,"").getPropertyValue("height"),a=o.offsetHeight?o.offsetHeight:document.defaultView.getComputedStyle(o,"").getPropertyValue("height"),f=parseInt(s.offsetTop,10),l=config.events,c=l.onHide,h=l.afterHide,p;r||e.products.length===0||!config.peekEnabled?p=u*-1:p=(u-a-8)*-1,n&&n.preventDefault&&n.preventDefault();if(typeof c=="function"&&c.call(e,n)===!1)return;$.util.animate(s,"top",{from:f,to:p},function(){typeof h=="function"&&h.call(e,n)}),o.style.backgroundPosition="-195px -32px",t=!1},e.toggle=function(n){t?e.hide(n):e.show(n)},e.reset=function(){var n=e.UI,r=config.events,i=r.onReset,s=r.afterReset;if(typeof i=="function"&&i.call(e)===!1)return;e.products=[],t&&(n.itemList.innerHTML="",n.subtotalAmount.innerHTML="",e.hide(null,!0)),$.storage.remove(),typeof s=="function"&&s.call(e)},e}();var ProductNode=function(e,t){this._view(e,t)};ProductNode.prototype={_view:function(e,t){var n,r,i,s,o,u,a;this.product=e.product,this.settings=e.settings,this.liNode=document.createElement("li"),this.nameNode=document.createElement("a"),this.metaNode=document.createElement("span"),this.discountNode=document.createElement("span"),this.discountInput=document.createElement("input"),this.priceNode=document.createElement("span"),this.quantityInput=document.createElement("input"),this.removeInput=document.createElement("input");if(!this.product||!this.product.item_name&&!this.product.item_number){this.isPlaceholder=!0;return}this.product.item_name&&(n=this.product.item_name),this.nameNode.innerHTML=n,this.nameNode.title=n,this.nameNode.href=this.product.href,this.nameNode.appendChild(this.metaNode),this.product.item_number&&(this.metaNode.innerHTML="
#"+this.product.item_number),o=this.getOptions();for(a in o)this.metaNode.innerHTML+="
"+a+": "+o[a];s=this.getDiscount(),this.discountInput.type="hidden",this.discountInput.name="discount_amount_"+t,this.discountInput.value=s,this.metaNode.appendChild(this.discountNode),r=this.getPrice(),this.priceNode.className="price",i=this.getQuantity(),this.quantityInput.name="quantity_"+t,this.quantityInput.className="quantity",this.quantityInput.setAttribute("autocomplete","off"),this.setQuantity(i),this.removeInput.type="button",this.removeInput.className="remove",this.liNode.appendChild(this.nameNode),this.liNode.appendChild(this.quantityInput),this.liNode.appendChild(this.discountInput),this.liNode.appendChild(this.removeInput),this.liNode.appendChild(this.priceNode);for(a in this.product)a!=="quantity"&&a.indexOf("discount_")===-1&&(u=document.createElement("input"),u.type="hidden",u.name=a+"_"+t,u.value=this.product[a],this.liNode.appendChild(u))},getDiscount:function(){var e=0,t=this.product.discount_num||-1,n;return this.product.discount_amount?(e=parseFloat(this.product.discount_amount),this.product.discount_amount2&&(n=this.getQuantity(),n>1&&(e+=Math.max(n-1,t)*parseFloat(this.product.discount_amount2)))):this.product.discount_rate&&(e=this.product.amount*parseFloat(this.product.discount_rate)/100,this.product.discount_rate2&&(n=this.getQuantity(),n>1&&(e+=Math.max(n-1,t)*this.product.amount*parseFloat(this.product.discount_amount2)/100))),e&&e.toFixed(2)},getOptions:function(){var e={},t=0;while(typeof this.product["on"+t]!="undefined")e[this.product["on"+t]]=this.product["os"+t],t++;return e},setQuantity:function(e){var t;e=parseInt(e,10),this.product.quantity=e;if(this.quantityInput.value!==e){this.quantityInput.value=e;if(t=this.getDiscount())this.discountInput.value=t,this.discountNode.innerHTML="
",this.discountNode.innerHTML+=config.strings.discount||"Discount: ",this.discountNode.innerHTML+=$.util.formatCurrency(t,this.settings.currency_code)}this.setPrice(this.product.amount*e)},getQuantity:function(){return typeof this.product.quantity!==undefined?this.product.quantity:1},setPrice:function(e){e=parseFloat(e,10),this.priceNode.innerHTML=$.util.formatCurrency(e.toFixed(2),this.settings.currency_code)},getPrice:function(){return(this.product.amount*this.getQuantity()).toFixed(2)}};var $={};$.storage=function(){var e=config.name;return window.localStorage?{load:function(){var t=localStorage.getItem(e);return t&&(t=JSON.parse(decodeURIComponent(t))),t},save:function(t){var n=[],r,i,s;if(t){for(s=0,i=t.length;s0&&s>n.to||i<0&&s-1;i--)r=t[i],r.getAttribute(e)&&n.push(t);return n}}function v(e){function i(e,t){t(e),e=e.firstChild;while(e)i(e,t),e=e.nextSibling}var t=[],n="data-paypal",r;return i(document.body,function(i){i.nodeType===1&&(r=i.getAttribute(n))&&r===e&&t.push(i)}),t}function m(){var e=document.getElementsByTagName("script"),t,n,r,i,s,o;for(s=0,o=e.length;s */ -if(typeof PAYPAL=="undefined"||!PAYPAL)var PAYPAL={};PAYPAL.apps=PAYPAL.apps||{},function(){"use strict";function u(n,r){var i=document.createElement("form"),s=document.createElement("input"),o=document.createElement("input"),u=n.items,a,l,c,h,p,d,v;s.type="image",o.type="hidden",i.method="post",i.action=t,i.className="paypal-button",i.target="_top";for(p in u)a=u[p],a.isEditable?(h=document.createElement("input"),h.type="text",h.className="paypal-input",h.name=a.key,h.value=a.value,c=document.createElement("label"),c.className="paypal-label",c.appendChild(document.createTextNode(e.config.labels[a.key]+" "||"")),c.appendChild(h),l=document.createElement("p"),l.className="paypal-group",l.appendChild(c)):(h=l=o.cloneNode(!0),h.name=a.key,h.value=a.value),i.appendChild(l);d=u.size&&u.size.value,v=u.lc&&u.lc.value,i.appendChild(s),s.src=f(r,d,v);if(PAYPAL.apps.MiniCart&&n.cmd==="_cart"){var m=PAYPAL.apps.MiniCart;m.UI.itemList||m.render(),m.bindForm(i)}return i}function a(e,r,i){var s=document.createElement("img"),o=t+"?",u=13,a=e.items,f,l;r=r.value||250;for(l in a)f=a[l],o+=f.key+"="+encodeURIComponent(f.value)+"&";return o=encodeURIComponent(o),s.src=n.replace("{url}",o).replace("{pattern}",u).replace("{size}",r),s}function f(e,t,n){var r=o[e]||o.buynow;return n=n||"en_US",t=t==="small"?"SM":"LG",r.replace(/\{locale\}/,n).replace(/\{size\}/,t)}function l(e){var t={},n,r,i,s,o;if(n=e.attributes)for(o=0,s=n.length;o-1;i--)r=t[i],r.getAttribute(e)&&n.push(t);return n}}function v(e){function i(e,t){t(e),e=e.firstChild;while(e)i(e,t),e=e.nextSibling}var t=[],n="data-paypal",r;return i(document.body,function(i){i.nodeType===1&&(r=i.getAttribute(n))&&r===e&&t.push(i)}),t}function m(){var e=document.getElementsByTagName("script"),t,n,r,i,s,o;for(s=0,o=e.length;s