Skip to content

Commit

Permalink
Fix invoice lang
Browse files Browse the repository at this point in the history
  • Loading branch information
myslaf committed Mar 29, 2024
1 parent bbf40e2 commit b0cc953
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 50 deletions.
5 changes: 3 additions & 2 deletions src/react/context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ import {
} from "./studentDetails";
import { ChallengesContext, ChallengesContextProvider } from "./challenges";
import { getFlatTopics } from "../../utils/course";
import { RequestOptionsInit } from "umi-request";

export const SCORMPlayer: React.FC<{
uuid: string;
Expand Down Expand Up @@ -1261,9 +1262,9 @@ const EscolaLMSContextProviderInner: FunctionComponent<
);

const fetchOrderInvoice = useCallback(
(id: number) => {
(id: number, options?: RequestOptionsInit) => {

Check warning on line 1265 in src/react/context/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/react/context/index.tsx#L1265

Added line #L1265 was not covered by tests
return token
? orderInvoice.bind(null, apiUrl)(token, id)
? orderInvoice.bind(null, apiUrl)(token, id, options)
: Promise.reject("noToken");
},
[token]
Expand Down
12 changes: 8 additions & 4 deletions src/react/context/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as API from "./../../types/api";
import { RequestOptionsInit } from 'umi-request';
import * as API from './../../types/api';

export interface ContextState<T> {
loading: boolean;
Expand Down Expand Up @@ -325,7 +326,7 @@ export interface EscolaLMSContextAPIConfig {
filter: API.PageParams &
API.PaginationParams & {
type?: string;
"tags[]"?: string;
'tags[]'?: string;
name?: string;
productable_type?: string;
}
Expand All @@ -334,7 +335,7 @@ export interface EscolaLMSContextAPIConfig {
filter: API.PageParams &
API.PaginationParams & {
type?: string;
"tags[]"?: string;
'tags[]'?: string;
name?: string;
productable_type?: string;
}
Expand Down Expand Up @@ -428,7 +429,10 @@ export interface EscolaLMSContextAPIConfig {
| API.DefaultResponse<API.StationaryEvent>
| API.DefaultMetaResponse<API.StationaryEvent>
>;
fetchOrderInvoice: (id: number) => Promise<Blob>;
fetchOrderInvoice: (
id: number,
options?: RequestOptionsInit
) => Promise<Blob>;
changeConsultationTerm: (
termId: number,
newDate: string
Expand Down
89 changes: 45 additions & 44 deletions src/services/cart.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import request, { RequestOptionsInit } from "umi-request";
import * as API from "../types/api";
import { currentTimezone } from "../utils";
import request, { RequestOptionsInit } from 'umi-request';
import * as API from '../types/api';
import { currentTimezone } from '../utils';

export async function addToCart(
apiUrl: string,
Expand All @@ -10,11 +10,11 @@ export async function addToCart(
options?: RequestOptionsInit
) {
return request<API.AddProductResponse>(`${apiUrl}/api/cart/products`, {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
data: {
id: productId,
Expand All @@ -31,11 +31,11 @@ export async function removeFromCart(
options?: RequestOptionsInit
) {
return request<API.SuccessResponse>(`${apiUrl}/api/cart/products/${itemId}`, {
method: "DELETE",
method: 'DELETE',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
...(options || {}),
});
Expand All @@ -47,10 +47,10 @@ export async function cart(
options?: RequestOptionsInit
) {
return request<API.DefaultResponseSuccess<API.Cart>>(`${apiUrl}/api/cart`, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
"Current-timezone": currentTimezone(),
'Content-Type': 'application/json',
'Current-timezone': currentTimezone(),
Authorization: `Bearer ${token}`,
},
...(options || {}),
Expand All @@ -65,11 +65,11 @@ export async function addMissingProducts(
return request<API.DefaultResponseSuccess<API.Cart>>(
`${apiUrl}/api/cart/missing`,
{
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
data: {
products: products,
Expand All @@ -85,14 +85,14 @@ export async function payWithStripe(
token: string
) {
return request<API.SuccessResponse>(`${apiUrl}/api/cart/pay`, {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
data: {
gateway: "stripe",
gateway: 'stripe',
payment_method,
return_url,
},
Expand All @@ -107,11 +107,11 @@ export async function payWithP24(
data?: API.InvoiceData
) {
return request<API.P24Response>(`${apiUrl}/api/cart/pay`, {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
data: { email, return_url, ...data },
});
Expand All @@ -126,11 +126,11 @@ export async function subscriptionPayWithP24(
data?: API.InvoiceData
) {
return request<API.P24Response>(`${apiUrl}/api/product/${subId}/pay`, {
method: "POST",
method: 'POST',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
data: { email, return_url, ...data },
});
Expand All @@ -143,11 +143,11 @@ export async function orders(
options?: RequestOptionsInit
) {
return request<API.OrderList>(`${apiUrl}/api/orders`, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
params,
...(options || {}),
Expand All @@ -160,11 +160,11 @@ export async function payments(
options?: RequestOptionsInit
) {
return request<API.PaymentList>(`${apiUrl}/api/payments`, {
method: "GET",
method: 'GET',
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
...(options || {}),
});
Expand All @@ -176,27 +176,27 @@ export async function addVoucher(
token: string
) {
return request<API.AuthResponse>(`${apiUrl}/api/cart/voucher`, {
method: "POST",
method: 'POST',
data: {
code: voucher,
},
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
});
}

export async function removeVoucher(apiUrl: string, token: string) {
return request<API.AuthResponse>(`${apiUrl}/api/cart/voucher`, {
method: "DELETE",
method: 'DELETE',
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
},
});
}
Expand All @@ -208,13 +208,14 @@ export async function orderInvoice(
options?: RequestOptionsInit
) {
return request<Blob>(`${apiUrl}/api/order-invoices/${id}`, {
method: "GET",
...(options || {}),
method: 'GET',
headers: {
"Content-Type": "application/pdf",
'Content-Type': 'application/pdf',
Authorization: `Bearer ${token}`,
"Current-timezone": currentTimezone(),
'Current-timezone': currentTimezone(),
...(options?.headers ?? {}),
},
responseType: "blob",
...(options || {}),
responseType: 'blob',
});
}

0 comments on commit b0cc953

Please sign in to comment.