-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a265b9b
commit 1182915
Showing
3 changed files
with
148 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// @ts-check | ||
|
||
/** @typedef {any} Paddle */ | ||
|
||
let didInitializePaddle = false; | ||
|
||
/** | ||
* @param {{plusButton?: Element | null; feeButton?: Element | null; corpButton?: Element | null}} options | ||
*/ | ||
export async function initPaddle(options) { | ||
/** @type {any} */ | ||
let Paddle; | ||
if (!didInitializePaddle) { | ||
// @ts-ignore | ||
await import('https://cdn.paddle.com/paddle/v2/paddle.js'); | ||
Paddle = /** @type {any} */(window).Paddle; | ||
Paddle.Initialize({ | ||
token: 'live_b32a4d21e35479ee3ea2b849be9', | ||
}); | ||
} | ||
|
||
/** | ||
* @param {Element} element | ||
* @param {string} priceId | ||
*/ | ||
const initClick = (element, priceId) => { | ||
element.addEventListener('click', () => { | ||
Paddle.Checkout.open({ | ||
settings: { | ||
displayMode: 'overlay', | ||
theme: 'dark', | ||
variant: 'one-page', | ||
}, | ||
items: [ | ||
{ | ||
priceId, | ||
quantity: 1, | ||
}, | ||
], | ||
}); | ||
}); | ||
}; | ||
|
||
if (options.plusButton) { | ||
initClick(options.plusButton, 'pri_01je4ebmn474jsee5eh2gmfan9'); | ||
} | ||
if (options.feeButton) { | ||
initClick(options.feeButton, 'pri_01jf039mt65me4f2exbgpg3p9m'); | ||
} | ||
if (options.corpButton) { | ||
initClick(options.corpButton, 'pri_01jf03sd119pqskcgmj48e0zq2'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters