@salarizadi/capacitor-myket
v1.0.0
Published
A Capacitor plugin for implementing Myket in-app billing
Maintainers
Readme
@salarizadi/capacitor-myket
A zero-config Capacitor plugin for Myket (Iranian Android Market) in-app purchases, powered by the official Myket IAB SDK.
🚀 Features
| | | |-|-| | ✅ Initialize once – auto-reconnects on demand | ✅ Promise + event hybrid API | | ✅ Consumable & non-consumable products | ✅ RSA signature verification | | ✅ Query prices, titles, descriptions | ✅ TypeScript definitions included |
📦 Installation
npm install @salarizadi/capacitor-myket
npx cap sync android🔐 Prerequisites
- Upload your APK to Myket Developer Console (alpha/beta/production).
- Copy your RSA public key from Developer Console → Services & APIs.
🧑💻 Usage
import { Myket } from '@salarizadi/capacitor-myket';
// OR
// const { Myket } = window.Capacitor.Plugins;
// 1️⃣ One-time setup
await Myket.initialize({ rsaPublicKey: 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...' });
// 2️⃣ Listen to purchase life-cycle
Myket.addListener('purchaseStateChanged', ({ state, purchase }) => {
console.log(`State: ${state}`, purchase);
});
// 3️⃣ Fetch product catalog
const { products } = await Myket.getProducts({ skus: ['coin100', 'premium'] });
console.log(products); // [{ sku, title, price, description, type }]
// 4️⃣ Purchase
const { purchase } = await Myket.purchaseProduct({
productId: 'coin100',
type: 'inapp', // 'inapp' | 'subs'
payload: 'user123' // optional developer payload
});
// 5️⃣ Consume (for consumables)
await Myket.consumeProduct({ token: purchase.purchaseToken });📖 API
| Method | Params | Returns | Description |
|--------|--------|---------|-------------|
| initialize | { rsaPublicKey: string } | Promise<{ connected: boolean }> | Must be called first. |
| getConnectionState | — | Promise<{ state: 'CONNECTED' \| 'NOT_INITIALIZED' }> | Diagnostic helper. |
| getProducts | { skus: string[] } | Promise<{ products: SkuDetails[] }> | Load titles, prices, etc. |
| purchaseProduct | PurchaseRequest | Promise<{ purchase: Purchase }> | Launches Myket purchase flow. |
| consumeProduct | { token: string } | Promise<{ consumed: true }> | Marks item as consumed. |
| disconnect | — | Promise<{ disconnected: true }> | Closes helper & frees memory. |
📡 Events
| Event | Payload |
|-------|---------|
| purchaseStateChanged | { state: PurchaseState, purchase?: Purchase } |
Purchase states:PURCHASE_BEGIN, PURCHASED, CANCELLED, FAILED, CONSUMED, FAILED_TO_BEGIN
🧰 Troubleshooting
| Symptom | Fix |
|---------|-----|
| Billing not initialized | Call initialize() before any billing method. |
| -1003: Signature verification failed | Double-check RSA public key. |
| User cancelled | Normal when back button pressed; handle gracefully. |
| Item not found | Product ID must exist in console and be active. |
📄 License
MIT © Salar Izadi
🔗 Links
| | | |-|-| | Repository | github.com/salarizadi/capacitor-myket | | Myket Console | developer.myket.ir | | Capacitor | capacitorjs.com |
