The PayPal JavaScript SDK button triggers a blank window with a #blocked URL when used in a Django template, but does not have the same issue

I've been grappling with an issue while trying to incorporate PayPal buttons into my Django website. Every time I attempt to do so, the PayPal popup window shows up as about:blank#blocked. In the console, I can see the following error:

popup_open_error_iframe_fallback 
{err: 'n: Can not open popup window - blocked\n    at Ie (…owser=false&allowBillingPayments=true:1342:297830', timestamp: '1644780862712', referer: 'www.sandbox.paypal.com', sdkCorrelationID: 'f12370135a997', sessionID: 'uid_d36969c1b2_mtk6mja6mzy', …}

The puzzling part is that this problem doesn't occur if I simply open the HTML file in a browser on its own... Here's how the script appears:

<!-- Set up a container element for the button -->
<div id="paypal-button-container" class='text-center mt-2'></div>

<!-- Include the PayPal JavaScript SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=blahblahmyid&currency=EUR"></script>

<script>
    // Render the PayPal button into #paypal-button-container
    paypal.Buttons({
        locale: 'it_IT',
        style: {
            color: 'gold',
            shape: 'rect',
            layout: 'vertical',
            label: 'pay'
        },

        // Set up the transaction
        createOrder: function(data, actions) {
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        value: '88.44'
                    }
                }]
            });
        },

        // Finalize the transaction
        onApprove: function(data, actions) {
            return actions.order.capture().then(function(orderData) {
                // Successful capture! For demo purposes:
                console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
                var transaction = orderData.purchase_units[0].payments.captures[0];
                alert('Transaction '+ transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');

                // Replace the above to show a success message within this page, e.g.
                // const element = document.getElementById('paypal-button-container');
                // element.innerHTML = '';
                // element.innerHTML = '<h3>Thank you for your payment!</h3>';
                // Or go to another URL:  actions.redirect('thank_you.html');
            });
        }


    }).render('#paypal-button-container');
</script>

What could be causing this issue? It's perplexing.

Answer №1

A recent update in Django 4.0 introduces a new feature that incorporates the COOP header in modern browsers. This feature aims to prevent remote sites from launching windows within the same browsing context.

By default, the SECURE_CROSS_ORIGIN_OPENER_POLICY setting in Django restricts the browsing context to the current document's origin only. Changing this setting to same-origin-allow-popups enables the Paypal popup to appear within the current context.

For more details, visit https://docs.djangoproject.com/en/4.0/ref/middleware/#cross-origin-opener-policy

In summary, remember to set SECURE_CROSS_ORIGIN_OPENER_POLICY='same-origin-allow-popups'

Answer №2

To include in the django 4.0 settings.py file, insert:

SECURE_CROSS_ORIGIN_OPENER_POLICY='same-origin-allow-popups'

Answer №3

In the case of Joomla! 4, it is essential to configure the System Http-header plugin to have Cross-Origin-Opener-Policy set to 'same-origin-allow-popups'. This step is crucial for ensuring proper functionality of PayPal SDK pop up windows. Failure to do so may result in an error message stating 'popup_open_error_iframe_fallback'.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for transforming a method into a computed property?

Good day, I created a calendar and now I am attempting to showcase events from a JSON file. I understand that in order to display a list with certain conditions, I need to utilize a computed property. However, I am facing difficulties passing parameters to ...

Is "Invalid Date" indicating an incorrect date?

Have you ever wondered why JavaScript returns 'Invalid Date' when setting an (invalid) date? It can be quite confusing and make it difficult to handle errors. So, what is the optimal way to deal with this issue? One approach is to check the date ...

Angular: The Process of Completely Updating a Model Object

Within my application, there is an object named eventData which acts as a singleton and is injected into multiple controllers through a resolve function. This eventData contains various sets of data such as drop down list values along with the main model. ...

Unexpected outcomes arising from using nested arrays with jQuery validation plugin

I have been utilizing the jQuery validation plugin from . I am encountering an issue with validating a nested array "tax_percents[]" that is within another array. The validation seems to only work for the first value in the array, and even for the second f ...

Controller encountering JSON null data

I am currently working on a feature that allows users to send multiple email/SMS messages by selecting checkboxes. However, I am facing an issue where the data is not being passed correctly from my JavaScript function to the action method - all the data sh ...

How can I show a map using AJAX data with jQuery?

Currently, I am working on a project that has specific requirements: Create a button named "city map" on the page. Upon selecting a country and loading the list of cities using an AJAX GET method, click the button to open a new window that displays the ma ...

What is the best way to make a sticky floating sidebar that stays fixed while scrolling?

I'm facing a challenge on my website where I want a sidebar on the left to stay with the user as they scroll. The sidebar should scroll along with the user until it's 5px from the top of the page, at which point it should remain fixed in place. ...

AngularJS Alert: [$injector:unpr] Provider Not Recognized

After setting up the URL routes for the sportsStore app from an AngularJS book to learn, I'm encountering the following errors: Error: [$injector:unpr] Unknown provider: $templateRequestProvider <- $templateRequest <- $route <- ngViewDirect ...

Is it possible to activate the jQuery .click() function for a button with specific text?

Here's a dilemma I'm facing: $('.add_to_cart span:contains("Choose a Size")').click(function() { console.log("it has been clicked") }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></s ...

Preventing commits when encountering build or lint errors

Every git repository contains git hooks within the .git/hooks directory. I have included a npm run lint command in the pre-commit git hook. However, I am unable to prevent the commit if npm run lint returns an error. ...

What is the method for retrieving a specific item within an array object using its index number?

How can I access the object '2016-11-12' inside the $scope.list and display the Order and Balance values? List: $scope.list = { ItemCode:'item1', '2016-11-12':[{Order:'1',Balanace:'2'}], '2016- ...

Irreparable Glitches in Mocha

While developing a blogging platform, everything ran smoothly when tested on a web server. However, I encountered some issues when trying to write unit tests using Mocha and Should.js. Surprisingly, errors kept popping up where they shouldn't have bee ...

Is it better to parse HTML in PHP or JavaScript for an iPhone web application?

I am in the process of creating a web application for iPhone/iPod touch. I need to incorporate an external HTML file and extract specific data from it. One approach is to handle this on the server side by creating a separate page that echoes the desired d ...

The point in the vector data is incorrectly positioned on the map in OpenLayers

I am looking to display a world map using the default OpenLayers WMS, along with a single point on it that will have interactive events like onhover. Below is my code snippet: var options = { projection: ...

Steps for showing an error prompt when input is invalid:

In my Vue 3 application, I have implemented a simple calculator that divides a dividend by a divisor and displays the quotient and remainder. Users can adjust any of the four numbers to perform different calculations. <div id="app"> <inp ...

Displaying Image URLs in a Web Form using AJAX

I have been researching how to accomplish this task. So far, my search has led me to uploading an image and then using AJAX to preview it. Is there a way to do the same for an image URL? For example, when a user submits an image URL, can AJAX provide a ...

What is the best way to have a div gradually glide out (utilizing CSS's transition feature) upon the click of a particular button?

I want the hint-bubble div to smoothly slide out (using 'transition: 0.5s') whenever the hint-btn is clicked. I have successfully implemented it so that the hint-bubble appears when the button is clicked, but it appears instantly and I am struggl ...

Unleashing the Power of Node.js: A Step-by-Step Guide to Crafting

I am developing a console interface that prompts the user with questions and receives input through the console. Some questions require the user to provide a limited number of inputs. I have researched ways to obtain console input in node js, but I haven&a ...

Implementing dynamic element selection with jQuery: combining onClick and onChange events

I am looking to update the appearance of the arrow on a select option. By default, it is styled as caret-down. When a user clicks in the input area, I want to change the style to caret-up. If the select option has been changed or no action has been taken, ...

What is the best way to dynamically resize the content inside a div element based on its dimensions using

My challenge is to create a centered div on the page that resizes with the viewport while maintaining an aspect ratio of 16:9. However, I also need the font and content inside the div to scale proportionally as it resizes. Using vmin works well in most cas ...