// Returns binary .pkpass — save directly to disk or send to user
const res = await fetch("https://your-worker.workers.dev/api/passes/receipt", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "wpk_your_key",
},
body: JSON.stringify({
platform: "apple", // "apple" | "google" | "both"
receipt: {
orderId: "ORD-2025-001",
merchantName: "Acme Coffee Co.",
purchaseDate: "Jan 15, 2025",
total: 24.99,
currency: "USD",
lineItems: [
{ description: "Oat Latte", quantity: 2, total: 12.00 },
{ description: "Croissant", quantity: 1, total: 4.50 },
],
paymentMethod: "Visa",
cardLast4: "4242",
pointsEarned: 25,
backgroundColor: "rgb(15, 23, 42)",
foregroundColor: "rgb(255, 255, 255)",
},
}),
});
// Save the .pkpass file (iOS opens it → Add to Apple Wallet)
const blob = await res.blob();
const url = URL.createObjectURL(blob);
window.location.href = url; // triggers wallet sheet on iOS