-//Helper Functions\r
-function showDom(id) {\r
- let arr;\r
- if (!Array.isArray(id)) {\r
- arr = [id];\r
- } else {\r
- arr = id;\r
- }\r
- arr.forEach(function (domId) {\r
- document.getElementById(domId).style.display = "block";\r
- });\r
-}\r
-\r
-function hideDom(id) {\r
- let arr;\r
- if (!Array.isArray(id)) {\r
- arr = [id];\r
- } else {\r
- arr = id;\r
- }\r
- arr.forEach(function (domId) {\r
- document.getElementById(domId).style.display = "none";\r
- });\r
-}\r
-\r
-function getUrlParams(prop) {\r
- let params = {},\r
- search = decodeURIComponent(window.location.href.slice(window.location.href.indexOf("?") + 1)),\r
- definitions = search.split("&");\r
-\r
- definitions.forEach(function (val) {\r
- let parts = val.split("=", 2);\r
- params[parts[0]] = parts[1];\r
- });\r
-\r
- return (prop && prop in params) ? params[prop] : params;\r
-}\r
-\r
-document.addEventListener("input", function (event) {\r
- if ((event.target.id === "countrySelect") && event.target.id !== null) {\r
- window.location.href =\r
- window.location.pathname +\r
- "?buyer-country=" +\r
- event.target.options[event.target.selectedIndex].value;\r
- }\r
-});\r
-\r
-ready = function (fn) {\r
- if (document.readyState != "loading") {\r
- fn();\r
- } else {\r
- document.addEventListener("DOMContentLoaded", fn);\r
- }\r
-}\r
-\r
-select_country_dropdown = function () {\r
- const queryString = window.location.search;\r
- const urlParams = new URLSearchParams(queryString);\r
- const buyer_country = urlParams.get("buyer-country")\r
- //If this param exists in URL\r
- if (buyer_country) {\r
- //Build script tag for head based on buyer country\r
- let head = document.getElementsByTagName("head")[0];\r
- let paypal_sdk_script = document.createElement("script");\r
- paypal_sdk_script.type = "text/javascript"; \r
- paypal_sdk_script.setAttribute("async", "");\r
- paypal_sdk_script.src = "https://www.paypal.com/sdk/js?intent=capture&vault=false&client-id=Aa2IfcoEvHnfJRnVQLSFrSs3SmTTkv5N1weMEL66ysqYIeHfAqXpDVkjOv3vLhkhbP4eKB6MpRlQIcJw&buyer-country=" + buyer_country;\r
- paypal_sdk_script.onload = init_smart_buttons; \r
- head.appendChild(paypal_sdk_script);\r
- //Pre-populate fields\r
- for (let i = 0; i < document.getElementById("countrySelect").options.length; i++) {\r
- if (document.getElementById("countrySelect").options[i].value == buyer_country) {\r
- document.getElementById("countrySelect").options[i].selected = true;\r
- }\r
- }\r
- apm_country_list = [\r
- {\r
- country: "DE", address: {\r
- address_line_1: "Bayreuther Straße 42",\r
- address_line_2: "",\r
- city: "Gmindersdorf",\r
- state: "Reutlingen",\r
- postal_code: "72760",\r
- }, recipient_name: "Jane Doe"\r
- },\r
- {\r
- country: "US", address: {\r
- address_line_1: "2211 North Street",\r
- address_line_2: "",\r
- city: "San Jose",\r
- state: "CA",\r
- postal_code: "95123"\r
- }, recipient_name: "Jane Doe"\r
- },\r
- {\r
- country: "BE", address: {\r
- address_line_1: "Putstraat 478",\r
- address_line_2: "",\r
- city: "Sint-Pauwels",\r
- state: "",\r
- postal_code: "9170"\r
- }, recipient_name: "Marina Beich"\r
- },\r
- {\r
- country: "PL", address: {\r
- address_line_1: "ul. Królewska 78",\r
- address_line_2: "",\r
- city: "Kraków",\r
- state: "",\r
- postal_code: "30-081"\r
- }, recipient_name: "August Pedersen"\r
- },\r
- {\r
- country: "AT", address: {\r
- address_line_1: "Hauptstrasse 85",\r
- address_line_2: "",\r
- city: "PULGARN",\r
- state: "",\r
- postal_code: "4221"\r
- }, recipient_name: "Berrie Hulstein"\r
- },\r
- {\r
- country: "NL", address: {\r
- address_line_1: "Asterstraat 135",\r
- address_line_2: "",\r
- city: "Almelo",\r
- state: "",\r
- postal_code: "7601 AK"\r
- }, recipient_name: "Joos Voorham"\r
- },\r
- {\r
- country: "IT", address: {\r
- address_line_1: "Via Longhena, 132",\r
- address_line_2: "",\r
- city: "Galloro RM",\r
- state: "",\r
- postal_code: "00040"\r
- }, recipient_name: "Colette Jalbert"\r
- },\r
- {\r
- country: "ES", address: {\r
- address_line_1: "Calle Alcalá 22",\r
- address_line_2: "",\r
- city: "Madrid",\r
- state: "",\r
- postal_code: "28055"\r
- }, recipient_name: "Ana García López"\r
- },\r
- {\r
- country: "AU", address: {\r
- address_line_1: "15 Mary Street",\r
- address_line_2: "",\r
- city: "North Sydney",\r
- state: "NSW",\r
- postal_code: "2001"\r
- }, recipient_name: "Jane Doe"\r
- },\r
- {\r
- country: "MX", address: {\r
- address_line_1: "Av. Caudillo del Sur 1234, Edificio B-5",\r
- address_line_2: "11560, Col. Municipio Libre, D.F.",\r
- city: "Mexico City",\r
- state: "Morelos",\r
- postal_code: "11560"\r
- }, recipient_name: "Raúl Uriarte, Jr."\r
- },\r
- {\r
- country: "BR", address: {\r
- address_line_1: "Rua da Matriz 123",\r
- address_line_2: "apto 25 Centro",\r
- city: "Rio de Janeiro",\r
- state: "Paraná",\r
- postal_code: "01000-001"\r
- }, recipient_name: "João da Silva"\r
- },\r
- {\r
- country: "JP", address: {\r
- address_line_1: "123-4567 東京都港区",\r
- address_line_2: "青山 1-1-1 ペイパルビル 1037",\r
- city: "港区",\r
- state: "東京都",\r
- postal_code: "104-0051"\r
- }, recipient_name: "山田 花子"\r
- },\r
- {\r
- country: "GB", address: {\r
- address_line_1: "1 Main Terrace",\r
- address_line_2: "",\r
- city: "Wolverhampton",\r
- state: "West Midlands",\r
- postal_code: "W12 4LQ"\r
- }, recipient_name: "Jane Doe"\r
- }\r
- ];\r
- apm_country_check = false;\r
- apm_country_list.forEach(function (country_object) {\r
- if (country_object.country === buyer_country) {\r
- apm_country_check = true;\r
- document.getElementById("recipient_name").value = country_object.recipient_name;\r
- document.getElementById("line1").value = country_object.address.address_line_1;\r
- document.getElementById("line2").value = country_object.address.address_line_2;\r
- document.getElementById("city").value = country_object.address.city;\r
- document.getElementById("state").value = country_object.address.state;\r
- document.getElementById("zip").value = country_object.address.postal_code;\r
- }\r
- });\r
- if (apm_country_check === false && buyer_country !== null) {\r
- document.getElementById("recipient_name").value = "Jane Doe";\r
- document.getElementById("line1").value =\r
- document.getElementById("line2").value =\r
- document.getElementById("city").value =\r
- document.getElementById("state").value =\r
- document.getElementById("zip").value = "";\r
- }\r
- } else {\r
- //Build script tag with no particular buyer country\r
- let head = document.getElementsByTagName("head")[0];\r
- let paypal_sdk_script = document.createElement("script");\r
- paypal_sdk_script.type = "text/javascript"; \r
- paypal_sdk_script.setAttribute("async", "");\r
- paypal_sdk_script.src = "https://www.paypal.com/sdk/js?intent=capture&vault=false&client-id=Aa2IfcoEvHnfJRnVQLSFrSs3SmTTkv5N1weMEL66ysqYIeHfAqXpDVkjOv3vLhkhbP4eKB6MpRlQIcJw";\r
- paypal_sdk_script.onload = init_smart_buttons; \r
- head.appendChild(paypal_sdk_script);\r
- }\r
-}\r
-\r
-ready(select_country_dropdown);\r
-\r
-let serialize = function (form) {\r
-\r
- // Setup our serialized data\r
- let serialized = [];\r
-\r
- // Loop through each field in the form\r
- for (let i = 0; i < form.elements.length; i++) {\r
-\r
- let field = form.elements[i];\r
-\r
- // Don't serialize fields without a name, submits, buttons, file and reset inputs, and disabled fields\r
- if (!field.name || field.disabled || field.type === "file" || field.type === "reset" || field.type === "submit" || field.type === "button") continue;\r
-\r
- // If a multi-select, get all selections\r
- if (field.type === "select-multiple") {\r
- for (let n = 0; n < field.options.length; n++) {\r
- if (!field.options[n].selected) continue;\r
- serialized.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.options[n].value));\r
- }\r
- }\r
-\r
- // Convert field data to a query string\r
- else if ((field.type !== "checkbox" && field.type !== "radio") || field.checked) {\r
- serialized.push(encodeURIComponent(field.name) + "=" + encodeURIComponent(field.value));\r
- }\r
- }\r
-\r
- return serialized.join("&");\r
-\r
-};
\ No newline at end of file