(function() {
var sdkId = 'wpecpp-paypal-sdk-0b5f40275bf8407a282338f458937a61';
var sdkUrl = 'https://www.paypal.com/sdk/js?client-id=Advx1wc_4Se6ICsYnMXTqWntyS0F1VdRHIeWnT2Qgv0nFi6sD86KEM9DSxcG79rq_weHqfs1uClL1xDy&merchant-id=WTQMTAVGKTEZJ¤cy=EUR&intent=capture&components=buttons,funding-eligibility&locale=es_ES';
// Check if SDK script already exists in DOM or is being loaded
if (!document.getElementById(sdkId)) {
var script = document.createElement('script');
script.id = sdkId;
script.src = sdkUrl;
script.setAttribute('data-partner-attribution-id', 'WPPlugin_STP_CP');
document.head.appendChild(script);
}
})();
.wpecpp-paypal-button-container > *,
.wpecpp-paypal-hosted-fields-container .wpecpp-paypal-btn {
max-width: 300px;
}
.wpecpp-paypal-hosted-fields-container .wpecpp-paypal-btn {
height: 40px;
}
const wpecppPaypalFunding_r0d5aa13be5f8e19724c20b0b505e29d3 = ["paypal"];
(function() {
const message_r0d5aa13be5f8e19724c20b0b505e29d3 = document.getElementById('wpecpp-paypal-message-r0d5aa13be5f8e19724c20b0b505e29d3');
// Wait for SDK to be fully loaded with polling
function initPayPalButton_r0d5aa13be5f8e19724c20b0b505e29d3() {
// Check if PayPal SDK is fully loaded with all required methods
if ( typeof paypal === 'undefined' ||
typeof paypal.getFundingSources !== 'function' ||
typeof paypal.Buttons !== 'function' ) {
// SDK not loaded yet, wait and try again
setTimeout(initPayPalButton_r0d5aa13be5f8e19724c20b0b505e29d3, 100);
return;
}
paypal.getFundingSources().forEach(function (fundingSource) {
if ( wpecppPaypalFunding_r0d5aa13be5f8e19724c20b0b505e29d3.indexOf(fundingSource) > -1 ) {
const style = {
shape: 'rect',
label: 'buynow',
height: 40 };
if ( fundingSource !== 'card' ) {
let color = 'gold';
if (fundingSource === 'venmo' && color === 'gold') {
color = 'blue';
} else if (['ideal', 'bancontact', 'giropay', 'eps', 'sofort', 'mybank', 'p24'].indexOf(fundingSource) > -1 && ['gold', 'blue'].indexOf(color) > -1) {
color = 'default';
}
style.color = color;
}
const button = paypal.Buttons({
fundingSource: fundingSource,
style: style,
createOrder: function() {
message_r0d5aa13be5f8e19724c20b0b505e29d3.innerHTML = '';
const form = document.getElementById('r0d5aa13be5f8e19724c20b0b505e29d3'),
formData = new FormData(),
nameInput = form.querySelector('[name="item_name"]'),
priceInput = form.querySelector('[name="amount"]'),
quantityInput = form.querySelector('[name="quantity"]');
formData.append('action', 'wpecpp-ppcp-order-create');
formData.append('nonce', wpecpp.nonce);
formData.append('name', nameInput ? nameInput.value : '');
formData.append('price', priceInput ? priceInput.value : 0);
if (quantityInput) {
formData.append('quantity', quantityInput.value);
}
return fetch(wpecpp.ajaxUrl, {
method: 'post',
body: formData
}).then(function(response) {
return response.json();
}).then(function(data) {
let orderID = false;
if (data.success && data.data.order_id) {
orderID = data.data.order_id;
} else {
throw data.data && data.data.message ? data.data.message : 'An unknown error occurred while creating the order. Please reload the page and try again.';
}
return orderID;
});
},
onApprove: function(data) {
const formData = new FormData();
formData.append('action', 'wpecpp-ppcp-order-finalize');
formData.append('nonce', wpecpp.nonce);
formData.append('order_id', data.orderID);
return fetch(wpecpp.ajaxUrl, {
method: 'post',
body: formData
}).then(function(response) {
return response.json();
}).then(function(data) {
if (data.success) {
if (wpecpp.return.length) {
window.location.href = wpecpp.return;
} else {
message_r0d5aa13be5f8e19724c20b0b505e29d3.innerHTML = '
' + data.data.message + '';
}
} else {
throw data.data.message;
}
});
},
onCancel: function() {
if (wpecpp.cancel.length) {
window.location.href = wpecpp.cancel;
} else {
message_r0d5aa13be5f8e19724c20b0b505e29d3.innerHTML = '
The payment was cancelled.';
}
},
onError: function (error) {
message_r0d5aa13be5f8e19724c20b0b505e29d3.innerHTML = '
' + (error ? error : 'Site admin, an error was detected in the plugin settings.Please check the PayPal connection and product settings (price, name, etc.)') + '';
}
});
if (button.isEligible()) {
button.render('#wpecpp-paypal-button-container-r0d5aa13be5f8e19724c20b0b505e29d3');
}
}
});
} // End initPayPalButton function
// Start initialization (will poll until SDK is ready)
initPayPalButton_r0d5aa13be5f8e19724c20b0b505e29d3();
})(); // End IIFE
.wpecpp-stripe-button-container > * {max-width: 300px;}