Wrapply logoWrapply Tutorials
💳 Store payments

In-App-Käufe integrieren: von Website zu Flutter-App

Diese Anleitung erklärt native In-App-Käufe in einer Wrapply-App: Store-Produkte, Product IDs, Kaufaufrufe, Wiederherstellung und serverseitige Belegprüfung.

Bridge-Befehle für In-App-Käufe

Wenn das In-App-Kauf-Modul aktiviert ist, stellt die generierte App echte JavaScript-Befehle in der WebView bereit. Die Website ruft sie auf, danach sollte das Backend den Kauf prüfen und die bezahlte Funktion freischalten.

BefehlVerwendungPayloadTypische Antwort
window.Wrapply.iap.getProducts(payload)Liest Produkte aus Google Play oder App Store{ productIds: ['premium_monthly'] }{ ok, available, products, notFoundIds }
window.Wrapply.iap.purchase(payload)Startet den nativen Kaufablauf{ productId, consumable, applicationUserName }{ ok, purchaseStarted, product }
window.Wrapply.iap.restorePurchases(payload)Stellt nicht konsumierbare Käufe oder Abos wieder her{ applicationUserName }{ ok, restoreStarted, latestPurchases }
window.Wrapply.iap.getStatus(payload)Prüft Store-Billing-Verfügbarkeit und letzte Ereignisse{}{ ok, available, latestPurchases }

Erforderliche Store-Konfiguration

Erstellen Sie die Produkte in Google Play Console und App Store Connect mit denselben Product IDs wie auf der Website. Testen Sie auf echten Geräten und validieren Sie Belege serverseitig, bevor Abos, Credits oder Premium-Inhalte freigeschaltet werden.

function onWrapplyReady(callback) {
if (window.Wrapply?.__nativeBridgeReady) return callback(window.Wrapply);
window.addEventListener('wrapplyNativeBridgeReady', () => callback(window.Wrapply), { once: true });
}

onWrapplyReady(async (Wrapply) => {
if (!Wrapply.iap) return;
const products = await Wrapply.iap.getProducts({ productIds: ['premium_monthly', 'credits_10'] });
console.log(products);
});
async function buyPremium(currentUser) {
if (!window.Wrapply?.iap) return showWebCheckoutFallback();
const result = await window.Wrapply.iap.purchase({
productId: 'premium_monthly',
consumable: false,
applicationUserName: currentUser.id
});
await fetch('/api/iap/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(result)
});
}
async function restoreNativePurchases(currentUser) {
if (!window.Wrapply?.iap) return;
const restored = await window.Wrapply.iap.restorePurchases({
applicationUserName: currentUser.id
});
await fetch('/api/iap/restore', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(restored)
});
}

Integrationsbeispiele

Das gleiche Bridge-Muster funktioniert in JavaScript, React, Vue, Angular, PHP/Laravel, WordPress oder jQuery. Wichtig ist, auf die native Bridge zu warten.

JavaScript

async function runNativeFeature(currentUser) {
if (!window.Wrapply?.iap) return;
const result = await window.Wrapply.iap.purchase({
productId: 'premium_monthly',
consumable: false,
applicationUserName: currentUser.id
});
await fetch('/api/wrapply-event', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(result)
});
}

React Hook

import { useEffect, useState } from 'react';
export function useWrapplyBridge() {
const [ready, setReady] = useState(false);
useEffect(() => {
if (window.Wrapply?.__nativeBridgeReady) return setReady(true);
const onReady = () => setReady(true);
window.addEventListener('wrapplyNativeBridgeReady', onReady);
return () => window.removeEventListener('wrapplyNativeBridgeReady', onReady);
}, []);
return { ready, Wrapply: ready ? window.Wrapply : null };
}

Vue Composable

import { ref, onMounted } from 'vue';
export function useWrapplyBridge() {
const ready = ref(false);
onMounted(() => {
if (window.Wrapply?.__nativeBridgeReady) ready.value = true;
else window.addEventListener('wrapplyNativeBridgeReady', () => ready.value = true, { once: true });
});
return { ready };
}

Angular Service

@Injectable({ providedIn: 'root' })
export class WrapplyBridgeService {
async callNative(payload = {}) {
if (!window.Wrapply?.iap) return { ok: false, error: 'Bridge unavailable' };
return window.Wrapply.iap.getStatus(payload);
}
}

jQuery

$('#wrapply-action').on('click', async function () {
if (!window.Wrapply?.iap) return;
const result = await window.Wrapply.iap.getStatus({});
$('#wrapply-output').text(JSON.stringify(result, null, 2));
});

CMS / Backend Template

<button onclick="runNativeFeature(window.currentUser)">Open app feature</button>
<script>
window.addEventListener('wrapplyNativeBridgeReady', function () {
document.body.classList.add('wrapply-native-app');
});
</script>
Wichtig: Die Bridge funktioniert in der WebView der generierten App, nicht in der öffentlichen Website im Browser.
Wenn native Funktionen aktiviert sind, enthält das ZIP zusätzlich WRAPPLY_NATIVE_BRIDGE_GUIDE.pdf mit aktiven Modulen, exakten Aufrufen und Implementierungshinweisen.