Create Pakasir payment edge function to fix CORS issue

- Create create-pakasir-payment edge function to handle payment creation server-side
- Update ConsultingBooking.tsx to use edge function instead of direct API call
- Update Checkout.tsx to use edge function instead of direct API call
- Add config.toml entry for create-pakasir-payment function
- Removes CORS errors when calling Pakasir API from frontend

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
dwindown
2025-12-23 21:20:40 +07:00
parent 94403bd634
commit a9f7c9b07a
4 changed files with 147 additions and 64 deletions

View File

@@ -129,46 +129,37 @@ export default function Checkout() {
setOrderId(order.id);
// Build description from product titles
const productTitles = items.map(item => item.title).join(", ");
// Build description from product titles
const productTitles = items.map(item => item.title).join(", ");
if (paymentMethod === "qris") {
// Call Pakasir API for QRIS
try {
const response = await fetch(`https://app.pakasir.com/api/transactioncreate/qris`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
project: PAKASIR_PROJECT_SLUG,
order_id: order.id,
amount: amountInRupiah,
api_key: getPakasirApiKey(),
description: productTitles,
callback_url: PAKASIR_CALLBACK_URL,
}),
});
if (paymentMethod === "qris") {
// Call edge function to create Pakasir QRIS payment (avoids CORS)
const { data: paymentData, error: paymentError } = await supabase.functions.invoke('create-pakasir-payment', {
body: {
order_id: order.id,
amount: amountInRupiah,
description: productTitles,
},
});
const result = await response.json();
if (result.qr_string || result.qr) {
setPaymentData({
qr_string: result.qr_string || result.qr,
expired_at: result.expired_at,
order_id: order.id,
});
setStep("waiting");
clearCart();
} else {
// Fallback to redirect if API doesn't return QR
const pakasirUrl = `https://app.pakasir.com/pay/${PAKASIR_PROJECT_SLUG}/${amountInRupiah}?order_id=${order.id}`;
clearCart();
window.location.href = pakasirUrl;
}
} catch {
if (paymentError) {
console.error('Payment creation error:', paymentError);
// Fallback to redirect
const pakasirUrl = `https://app.pakasir.com/pay/${PAKASIR_PROJECT_SLUG}/${amountInRupiah}?order_id=${order.id}`;
clearCart();
window.location.href = pakasirUrl;
} else if (paymentData?.data?.qr_string) {
// QRIS available - show QR code
setPaymentData({
qr_string: paymentData.data.qr_string,
expired_at: paymentData.data.expired_at,
order_id: order.id,
});
setStep("waiting");
clearCart();
} else {
// No QR code - redirect to payment page
window.location.href = paymentData.data.payment_url;
}
} else {
// PayPal - redirect to Pakasir PayPal URL