@anycade/sdk
v1.0.1
Published
Anycade SDK
Readme
@anycade/sdk
Web SDK for Anycade Games
Installation
# npm
npm i @anycade/sdk
# yarn
yarn add @anycade/sdk
# pnpm
pnpm add @anycade/sdkInstallation using CDN
Warning
The script must be inserted before your main game script!
<script src="https://unpkg.com/@anycade/sdk/dist/browser/index.min.js"></script>Getting started
import { SDK } from '@anycade/sdk';
const sdk = new SDK({
gameId: '123456'
});Using the CDN version, the
SDKclass is accessible throughAnycade.
const sdk = new Anycade.SDK({
gameId: '123456'
});SDK options
debug- Debug modegameId- Game ID
initialize
SDK initialization with the platform.
const sdk = new SDK({
gameId: '123456',
});
try {
await sdk.initialize();
// Ok
} catch (error) {
// Error
}Payments
purchase
Show the payment window.
try {
const result = await sdk.payments.purchase({
meta: {
// Custom fields to retrieve
foo: 'bar',
},
productId: '123456', // Id of the product from the platform
});
// Handle the result.
switch (result.status) {
case 'cancel':
// Cancel the payment process.
case 'fail':
// Failed to pay.
case 'success':
// Paid successfully.
}
// Access custom fields.
result.meta;
} catch (error) {
// Error
}