Skip to content

Instantly share code, notes, and snippets.

@aitor
Last active March 27, 2019 17:41
Show Gist options
  • Save aitor/fe8554f859bc8eb26bb6c3de728f5072 to your computer and use it in GitHub Desktop.
Save aitor/fe8554f859bc8eb26bb6c3de728f5072 to your computer and use it in GitHub Desktop.
// Source at https://developer.paypal.com/js/pages/docs/integration/direct/identity/lipp-button.js
//...
function _getConfig() {
var confObj = {};
var builders = buildForm.querySelectorAll('input, select');
var i = 0;
var el;
for (i; i < builders.length; i++) {
el = builders[i];
if (!/^\s*$/.test(el.value)) {
if (el.type === 'radio') {
if (el.checked) {
confObj[el.name] = el.value;
}
} else if (el.id === 'appid' || el.id === 'containerid') {
confObj[el.id] = el.value.replace(/[^\w\d-]/g, '');
el.value = confObj[el.id];
} else {
confObj[el.id] = el.value.replace(/,/g, '').replace(/(<([^>]+)>)/ig, '');
}
}
}
return confObj;
}
// ...
function init() {
if ('addEventListener' in document && 'getComputedStyle' in window && 'textContent' in document) {
_initLocaleSelect();
// This call to _buildSnippet is generating a BROKEN snippet on initial page load...
_buildSnippet();
// ...because it ignores empty fields (see _getConfig()) and therefore its call
// MUST happen after the initialization of buttonSize OR the management of buttonSize
// at https://www.paypalobjects.com/js/external/connect/login.js MUST be different.
_initButtonType();
_initButtonSize();
buildForm
.addEventListener('change', function () {
_buildSnippet();
});
}
}
// ...
// Source at https://www.paypalobjects.com/js/external/connect/login.js
//...
getTranslation: function(n) {
var t = n || {}
, e = t.text
, a = t.locale
, o = t.buttonSize
, i = "LWP" === t.labelType ? this.logInTranslations : this.connectTranslation;
return e || (a || (a = navigator.language || navigator.userLanguage),
2 === a.length && (a = a + "-" + a),
// If o (buttonSize is undefined getTranslation() return void(0) aka undefined)
// If buttonSize is optional by design and it has not been defined in the config
// i[a].lg_content should be return instead of undefined
i[a = a.replace(/_/, "-").toLowerCase()] ? o ? "lg" === o ? i[a].lg_content : i[a].sm_content : void 0 : i["en-us"].lg_content)
},
//...
//Then in the render function…
var t = "sandbox" === n.authend ? "https://www.sandbox.paypal.com/signin/authorize" : "https://www.paypal.com/signin/authorize"
, e = n.appid || null
, a = n.returnurl || null
, o = n.scopes || "basic"
, i = n.containerid ? document.getElementById(n.containerid) : n.containerelement ? n.containerelement : x
, r = n.responseType || "code"
, l = n.prompt
, c = n.state
, s = (n.openIdUiMode,
// …this shows always the english text if buttonSize has not been provided
// as it's the case on the example snippet provided at
// https://developer.paypal.com/docs/integration/direct/identity/button-js-builder/
f.getTranslation(n) || "Connect with PayPal")
, g = n.theme && "neutral" === n.theme.toLowerCase() ? "" : " PPBlue_V2"
, m = {
flowEntry: "lg" === n.buttonSize ? "CWPP_large" : "CWPP_small",
client_id: e,
response_type: r,
scope: o,
redirect_uri: encodeURIComponent(a),
nonce: f.createRandomNumber(),
newUI: "Y",
prompt: l,
state: c
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment