FInal bank, stripe and paypal sandbox completed
This commit is contained in:
@@ -493,13 +493,29 @@ export async function getInvoiceDetail(invoiceId: number): Promise<Invoice> {
|
||||
}
|
||||
|
||||
export async function downloadInvoicePDF(invoiceId: number): Promise<Blob> {
|
||||
const response = await fetch(`/v1/billing/invoices/${invoiceId}/download_pdf/`, {
|
||||
const token = localStorage.getItem('access_token') ||
|
||||
(() => {
|
||||
try {
|
||||
const authStorage = localStorage.getItem('auth-storage');
|
||||
if (authStorage) {
|
||||
const parsed = JSON.parse(authStorage);
|
||||
return parsed?.state?.token || null;
|
||||
}
|
||||
} catch (e) {}
|
||||
return null;
|
||||
})();
|
||||
|
||||
// Use the full API URL from the api.ts module
|
||||
const apiUrl = (await import('./api')).API_BASE_URL;
|
||||
const response = await fetch(`${apiUrl}/v1/billing/invoices/${invoiceId}/download_pdf/`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${localStorage.getItem('access_token')}`,
|
||||
'Authorization': `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('PDF download failed:', response.status, errorText);
|
||||
throw new Error('Failed to download invoice PDF');
|
||||
}
|
||||
|
||||
@@ -1374,9 +1390,11 @@ export async function isPayPalConfigured(): Promise<boolean> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available payment gateways
|
||||
* Get available payment gateways based on user's country
|
||||
* - Pakistan (PK): Stripe + Bank Transfer (manual), NO PayPal
|
||||
* - Global: Stripe + PayPal, NO Bank Transfer
|
||||
*/
|
||||
export async function getAvailablePaymentGateways(): Promise<{
|
||||
export async function getAvailablePaymentGateways(userCountry?: string): Promise<{
|
||||
stripe: boolean;
|
||||
paypal: boolean;
|
||||
manual: boolean;
|
||||
@@ -1386,10 +1404,14 @@ export async function getAvailablePaymentGateways(): Promise<{
|
||||
isPayPalConfigured(),
|
||||
]);
|
||||
|
||||
const isPakistan = userCountry?.toUpperCase() === 'PK';
|
||||
|
||||
return {
|
||||
stripe: stripeAvailable,
|
||||
paypal: paypalAvailable,
|
||||
manual: true, // Manual payment is always available
|
||||
// PayPal: available globally EXCEPT Pakistan
|
||||
paypal: !isPakistan && paypalAvailable,
|
||||
// Manual (Bank Transfer): available for Pakistan only
|
||||
manual: isPakistan,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1404,10 +1426,14 @@ export async function subscribeToPlan(
|
||||
switch (gateway) {
|
||||
case 'stripe': {
|
||||
const session = await createStripeCheckout(planId, options);
|
||||
return { redirect_url: session.checkout_url };
|
||||
// FIX: Return URL should include session_id for verification
|
||||
const redirectUrl = new URL(session.checkout_url);
|
||||
return { redirect_url: redirectUrl.toString() };
|
||||
}
|
||||
case 'paypal': {
|
||||
const order = await createPayPalSubscriptionOrder(planId, options);
|
||||
// FIX: Store order_id in localStorage before redirect
|
||||
localStorage.setItem('paypal_order_id', order.order_id);
|
||||
return { redirect_url: order.approval_url };
|
||||
}
|
||||
case 'manual':
|
||||
@@ -1432,6 +1458,8 @@ export async function purchaseCredits(
|
||||
}
|
||||
case 'paypal': {
|
||||
const order = await createPayPalCreditOrder(packageId, options);
|
||||
// FIX: Store order_id in localStorage before redirect
|
||||
localStorage.setItem('paypal_order_id', order.order_id);
|
||||
return { redirect_url: order.approval_url };
|
||||
}
|
||||
case 'manual':
|
||||
|
||||
Reference in New Issue
Block a user