@moonpay/platform-sdk-web
v1.39.0
Published
MoonPay Developer Platform SDK for web browsers
Downloads
44,531
Keywords
Readme
@moonpay/platform-sdk-web
Browser SDK for the MoonPay Developer Platform. Connect customers to MoonPay, fetch quotes and payment methods, and render MoonPay frames (widget, Apple Pay, Google Pay, buy, add-card, challenge) as iframes in your web app.
Installation
npm install @moonpay/platform-sdk-webQuick start
Create a session server-side with @moonpay/platform-sdk-node, pass the session token to the browser, then create a client:
import { createClient } from '@moonpay/platform-sdk-web';
const client = createClient({ sessionToken });
// Check whether the customer already has an active MoonPay connection
const connection = await client.getConnection();
if (!connection.ok) {
console.error(connection.error);
return;
}
if (connection.value.status === 'connectionRequired') {
// Render the connect frame so the customer can sign in to MoonPay
await client.connect({
container: document.getElementById('moonpay-container'),
onEvent: (event) => console.log(event.kind),
});
}All client methods return a Result<T, E> discriminated union instead of throwing — check result.ok before using result.value.
Pass an optional theme to style every visible MoonPay frame:
appearance—'light'or'dark'. Omit it to follow the customer's system preference.brandColor— your brand color (for example'FF6B00'). The frame derives its whole palette from it.customTheme— border radius, color scheme and palette overrides. See Theming.
Only the auth frame applies brandColor and customTheme for now. Other frames ignore them, so you can set them once on the client. The widget frame also ignores appearance.
const client = createClient({
sessionToken,
theme: {
appearance: 'dark',
brandColor: 'FF6B00',
customTheme: { borderRadius: 'l' },
},
});
// The connect flow can override any option per call:
await client.connect({ container, theme: { appearance: 'light' } });What the client provides
- Connection —
getConnection(),connect(),setupAuth(),resetConnection() - Payments data —
getQuote(),getPaymentMethods(),deletePaymentMethod(),listTransactions(),getTransaction() - Frames —
setupWidget(),setupBuyButton(),setupAddCard(),setupChallenge(),setupCustomerExport() - Frames (deprecated, use
setupBuyButton()above) —setupApplePay(),setupGooglePay(),setupBuy() - Customer —
getCustomer(),submitCustomerKyc(),getCustomerUploadUrl(),submitCustomerFiles()for headless integrations - Identity (deprecated, use Customer above) —
createIdentity(),getIdentity(),updateIdentity(),verifyIdentity()and file upload helpers
Related packages
| Package | Use it for |
|---------|------------|
| @moonpay/platform-sdk-node | Server-side session creation |
| @moonpay/platform-sdk-react-native | React Native apps |
| @moonpay/platform-protocol | Shared protocol and API types |
Documentation
Full guides and API reference: dev.moonpay.com
License
MIT
