fixing stripe context
This commit is contained in:
parent
c0b9c6e4f1
commit
d6086829fc
1 changed files with 5 additions and 5 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import React, { createContext, useContext, useEffect, useState } from 'react';
|
import React, { createContext, useContext, useEffect, useState } from 'react';
|
||||||
import { loadStripe } from '@stripe/stripe-js';
|
import { loadStripe } from '@stripe/stripe-js';
|
||||||
import { Elements } from '@stripe/react-stripe-js';
|
import { Elements } from '@stripe/react-stripe-js';
|
||||||
import axios from 'axios';
|
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
import apiClient from '@services/api';
|
||||||
|
|
||||||
// Create the context
|
// Create the context
|
||||||
const StripeContext = createContext();
|
const StripeContext = createContext();
|
||||||
|
|
@ -20,7 +20,7 @@ export const StripeProvider = ({ children }) => {
|
||||||
// If not found, fetch from API
|
// If not found, fetch from API
|
||||||
if (!publicKey) {
|
if (!publicKey) {
|
||||||
// Fetch Stripe public key from backend
|
// Fetch Stripe public key from backend
|
||||||
axios.get('/api/payment/config')
|
apiClient.get('/api/payment/config')
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data.stripePublicKey) {
|
if (response.data.stripePublicKey) {
|
||||||
loadStripeInstance(response.data.stripePublicKey);
|
loadStripeInstance(response.data.stripePublicKey);
|
||||||
|
|
@ -54,7 +54,7 @@ export const StripeProvider = ({ children }) => {
|
||||||
// Create a checkout session
|
// Create a checkout session
|
||||||
const createCheckoutSession = async (cartItems, orderId, shippingAddress, userId) => {
|
const createCheckoutSession = async (cartItems, orderId, shippingAddress, userId) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('/api/payment/create-checkout-session', {
|
const response = await apiClient.post('/api/payment/create-checkout-session', {
|
||||||
cartItems,
|
cartItems,
|
||||||
orderId,
|
orderId,
|
||||||
shippingAddress,
|
shippingAddress,
|
||||||
|
|
@ -71,7 +71,7 @@ export const StripeProvider = ({ children }) => {
|
||||||
// Check session status
|
// Check session status
|
||||||
const checkSessionStatus = async (sessionId) => {
|
const checkSessionStatus = async (sessionId) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/api/payment/session-status/${sessionId}`);
|
const response = await apiClient.get(`/api/payment/session-status/${sessionId}`);
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error checking session status:', err);
|
console.error('Error checking session status:', err);
|
||||||
|
|
@ -82,7 +82,7 @@ export const StripeProvider = ({ children }) => {
|
||||||
// Complete the order after successful payment
|
// Complete the order after successful payment
|
||||||
const completeOrder = async (orderId, sessionId, userId) => {
|
const completeOrder = async (orderId, sessionId, userId) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post('/api/cart/complete-checkout', {
|
const response = await apiClient.post('/api/cart/complete-checkout', {
|
||||||
orderId,
|
orderId,
|
||||||
sessionId,
|
sessionId,
|
||||||
userId
|
userId
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue