diff --git a/src/interfaces/Payments.ts b/src/interfaces/Payments.ts index c05a3bef5..cdebbc4b7 100644 --- a/src/interfaces/Payments.ts +++ b/src/interfaces/Payments.ts @@ -23,6 +23,11 @@ export interface Payment { method_id: UUID // PaymentMethod.id status: PaymentStatus amount: number + date: string + orders: { + id: UUID + amount: number + }[] } export interface PaymentCreateDto { diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 4f12044b8..012c46d49 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -21,6 +21,7 @@ export * from './PackagesTemplate' export * from './Page' export * from './Payments' export * from './PaymentMethods' +export * from './Payments' export { Permission, PermissionEntry, PermissionsTree } from './Permissions' export * from './Product' export * from './ProductSet' diff --git a/src/services/api/modules/orders.ts b/src/services/api/modules/orders.ts index 98931c0b5..678e6e2ba 100644 --- a/src/services/api/modules/orders.ts +++ b/src/services/api/modules/orders.ts @@ -39,6 +39,7 @@ import { createEntityAuditsService, EntityAuditsService } from './audits' import { createOrderDocumentsService, OrderDocumentsService } from './ordersDocuments' import { stringifyQueryParams } from '../../../utils' import { FieldSort } from '../../../interfaces/Sort' +import { Payment } from '../../../interfaces/Payments' export interface OrdersListParams extends SearchParam, PaginationParams, MetadataParams { /** @@ -60,7 +61,7 @@ export interface OrdersService extends EntityMetadataService, EntityAuditsServic * Creates new payment for the given order * @returns The payment URL to redirect the user to */ - pay(orderCode: string, paymentMethodId: UUID, continueUrl: string): Promise + pay(orderIds: UUID[], paymentMethodId: string, continueUrl: string): Promise /** * Creates payment that is paid for the given order @@ -126,15 +127,13 @@ export const createOrdersService: ServiceFactory = (axios) => { const paymentMethodsService = createPaymentMethodsService(axios) return { - async pay(code, paymentMethodId, continueUrl) { + async pay(orderIds, paymentMethodId, continueUrl) { const { data: { data }, - } = await axios.post>( - `${route}/${code}/pay/id:${paymentMethodId}`, - { - continue_url: continueUrl, - }, - ) + } = await axios.post>(`${route}/pay/id:${paymentMethodId}`, { + continue_url: continueUrl, + orders: orderIds.map((id) => ({ id })), + }) return data.redirect_url }, diff --git a/src/services/api/modules/tests/orders.test.ts b/src/services/api/modules/tests/orders.test.ts index 156b55abd..0c2168c03 100644 --- a/src/services/api/modules/tests/orders.test.ts +++ b/src/services/api/modules/tests/orders.test.ts @@ -19,7 +19,6 @@ import { createOrdersService } from '../orders' const dummyOrdersResponse: HeseyaResponse = { data: { id: '1', - external_id: '1', method: 'payu', method_id: null, status: PaymentStatus.Successful, @@ -27,6 +26,7 @@ const dummyOrdersResponse: HeseyaResponse = { redirect_url: '/redirect', continue_url: '/continue', date: '2020-01-01', + external_id: 'XN-2137', }, meta: { currency: { name: 'pln', symbol: 'pln', decimals: 2 }, @@ -129,11 +129,11 @@ afterEach(() => { describe('orders service test', () => { it('should make a request to create new payment for the given order', async () => { const service = createOrdersService(axios) - const expectedUrl = `orders/2137/pay/id:payment-id` + const expectedUrl = `orders/pay/id:payment-id` mock.onPost(expectedUrl).reply(200, dummyOrdersResponse) - const result = await service.pay('2137', 'payment-id', dummyOrdersResponse.data.continue_url) + const result = await service.pay(['2137'], 'payment-id', dummyOrdersResponse.data.continue_url) expect(mock.history.post[0]?.url).toEqual(expectedUrl) expect(result).toEqual(dummyOrdersResponse.data.redirect_url) })