Skip to content
Snippets Groups Projects
Commit b55dd0ca authored by srosse's avatar srosse
Browse files

OO-5059: wait a little before drawing paypal smart buttons

parent 6d5dcb44
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ import org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem; ...@@ -28,6 +28,7 @@ import org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem;
import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event; import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl; import org.olat.core.gui.control.WindowControl;
import org.olat.core.util.Formatter;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
import org.olat.resource.accesscontrol.OfferAccess; import org.olat.resource.accesscontrol.OfferAccess;
import org.olat.resource.accesscontrol.Price; import org.olat.resource.accesscontrol.Price;
...@@ -71,9 +72,11 @@ public class PaypalSmartButtonAccessController extends FormBasicController imple ...@@ -71,9 +72,11 @@ public class PaypalSmartButtonAccessController extends FormBasicController imple
layoutCont.contextPut("currency", currency); layoutCont.contextPut("currency", currency);
String excludeFundings = paypalModule.getExcludeFundings(); String excludeFundings = paypalModule.getExcludeFundings();
layoutCont.contextPut("excludeFundings", excludeFundings == null ? "" : excludeFundings); layoutCont.contextPut("excludeFundings", excludeFundings == null ? "" : excludeFundings);
layoutCont.contextPut("csrfToken", ureq.getUserSession().getCsrfToken());
String description = link.getOffer().getDescription(); String description = link.getOffer().getDescription();
if(StringHelper.containsNonWhitespace(description)) { if(StringHelper.containsNonWhitespace(description)) {
description = Formatter.escWithBR(description).toString();
description = StringHelper.xssScan(description); description = StringHelper.xssScan(description);
layoutCont.contextPut("description", description); layoutCont.contextPut("description", description);
} }
......
...@@ -18,26 +18,33 @@ ...@@ -18,26 +18,33 @@
</div> </div>
<div id="paypal_buttons_${r.getCId()}"> <div id="paypal_buttons_${r.getCId()}">
<script defer> <script defer data-csp-nonce="${csrfToken}">
jQuery(function() { jQuery(function() {
jQuery.ajax({ jQuery.ajax({
url: 'https://www.paypal.com/sdk/js?client-id=$clientId&currency=${currency}&intent=authorize&commit=true&disable-funding=${excludeFundings}', url: 'https://www.paypal.com/sdk/js?client-id=$clientId&currency=${currency}&intent=authorize&commit=true&disable-funding=${excludeFundings}',
cache: true, cache: true,//paypal don't like the anti-cache parameter
dataType: "script", dataType: "script",
success: loadButtons, success: loadButtons,
error: errorButtons, error: errorButtons,
}); });
function errorButtons() { function errorButtons() {
location.reload(); if(window.console) console.log('Errors');
} }
function loadButtons() { function loadButtons() {
try { try {
internalLoadButtons(); setTimeout(function() {
internalLoadButtons();
var numOfPayPal = jQuery('#paypal_buttons_${r.getCId()} iframe').length;
if(numOfPayPal == 0) {
setTimeout(function() {
internalLoadButtons();
}, 100);
}
}, 100);
} catch(e) { } catch(e) {
if(window.console) console.log(e); if(window.console) console.log(e);
location.reload();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment