Skip to content

Instantly share code, notes, and snippets.

@jookyboi
Last active March 22, 2018 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jookyboi/9c8ac23afbc3d23b33958007d19e388a to your computer and use it in GitHub Desktop.
Save jookyboi/9c8ac23afbc3d23b33958007d19e388a to your computer and use it in GitHub Desktop.
The following is a hack to get around the issue posed by https://github.com/paypal/paypal-checkout/issues/323. It uses Electron to close the BrowserWindow when the popup fails to load. In the latest version of `checkout.js`, Paypal will fall back to

From Electron's main.ts:

import { BrowserWindow, ipcMain } from 'electron';
...
ipcMain.on(
    'close-paypal',
    () => {
        BrowserWindow.getAllWindows().forEach((win) => {
            // The Paypal window would fail to load contents due to security 
            // restrictions and return an empty URL
            if (!win.webContents.getURL()) {
                win.close();
            }
        });
    }
);

From your content script (I'm using TypeScript):

const { ipcRenderer } = require('electron');
...
paypal.Button.render({
  ...
  payment: () => {
      ipcRenderer.send('close-paypal', '');
      // Other logic to trigger payment flow
  }
  ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment