Refactor: Rename create-pakasir-payment to create-payment
- Rename function to abstract payment provider details - Add support for both QRIS and PayPal methods - Update frontend to use generic create-payment function - Remove provider-specific naming from UI/UX - Payment provider (Pakasir) is now an implementation detail Response format: - QRIS: returns qr_string for in-app display, payment_url as fallback - PayPal: returns payment_url for redirect 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -132,24 +132,28 @@ export default function Checkout() {
|
||||
// Build description from product titles
|
||||
const productTitles = items.map(item => item.title).join(", ");
|
||||
|
||||
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,
|
||||
},
|
||||
});
|
||||
// Call edge function to create payment (avoids CORS)
|
||||
const { data: paymentData, error: paymentError } = await supabase.functions.invoke('create-payment', {
|
||||
body: {
|
||||
order_id: order.id,
|
||||
amount: amountInRupiah,
|
||||
description: productTitles,
|
||||
method: paymentMethod, // 'qris' or 'paypal'
|
||||
},
|
||||
});
|
||||
|
||||
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}`;
|
||||
if (paymentError) {
|
||||
console.error('Payment creation error:', paymentError);
|
||||
throw new Error(paymentError.message || 'Gagal membuat pembayaran');
|
||||
}
|
||||
|
||||
if (paymentData?.success) {
|
||||
if (paymentData.data.method === 'paypal') {
|
||||
// PayPal - redirect to payment URL
|
||||
clearCart();
|
||||
window.location.href = pakasirUrl;
|
||||
} else if (paymentData?.data?.qr_string) {
|
||||
// QRIS available - show QR code
|
||||
window.location.href = paymentData.data.payment_url;
|
||||
} else if (paymentData.data.qr_string) {
|
||||
// QRIS available - show QR code in app
|
||||
setPaymentData({
|
||||
qr_string: paymentData.data.qr_string,
|
||||
expired_at: paymentData.data.expired_at,
|
||||
@@ -159,13 +163,11 @@ export default function Checkout() {
|
||||
clearCart();
|
||||
} else {
|
||||
// No QR code - redirect to payment page
|
||||
clearCart();
|
||||
window.location.href = paymentData.data.payment_url;
|
||||
}
|
||||
} else {
|
||||
// PayPal - redirect to Pakasir PayPal URL
|
||||
clearCart();
|
||||
const paypalUrl = `https://app.pakasir.com/paypal/${PAKASIR_PROJECT_SLUG}/${amountInRupiah}?order_id=${order.id}`;
|
||||
window.location.href = paypalUrl;
|
||||
throw new Error('Gagal membuat pembayaran');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Checkout error:", error);
|
||||
|
||||
Reference in New Issue
Block a user