diff --git a/processor/src/dtos/payment-methods.dto.ts b/processor/src/dtos/payment-methods.dto.ts index 74d6456..666b3da 100644 --- a/processor/src/dtos/payment-methods.dto.ts +++ b/processor/src/dtos/payment-methods.dto.ts @@ -1,7 +1,11 @@ import { Static, Type } from '@sinclair/typebox'; -export const SupportedPaymentMethodData = Type.String(); +export const SupportedPaymentComponentsData = Type.Object({ + type: Type.String(), +}); -export const SupportedPaymentMethodsSchema = Type.Array(SupportedPaymentMethodData); +export const SupportedPaymentComponentsSchema = Type.Object({ + components: Type.Array(SupportedPaymentComponentsData), +}); -export type SupportedPaymentMethodsDTO = Static; +export type SupportedPaymentComponentsSchemaDTO = Static; diff --git a/processor/src/routes/payment-components.route.ts b/processor/src/routes/payment-components.route.ts index 58e9f15..0512810 100644 --- a/processor/src/routes/payment-components.route.ts +++ b/processor/src/routes/payment-components.route.ts @@ -10,8 +10,12 @@ export const paymentComponentsRoute = async ( fastify: FastifyInstance, options: FastifyPluginOptions & PaymentComponentsRoutesOptions, ) => { - fastify.get('/payment-components', async (request, reply) => { - const result = await options.paymentService.getSupportedPaymentComponents(); - reply.code(200).send(result); - }); + fastify.get( + '/payment-components', + + async (request, reply) => { + const result = await options.paymentService.getSupportedPaymentComponents(); + reply.code(200).send(result); + }, + ); }; diff --git a/processor/src/routes/payment.route.ts b/processor/src/routes/payment.route.ts index 5a0454c..4d9dc23 100644 --- a/processor/src/routes/payment.route.ts +++ b/processor/src/routes/payment.route.ts @@ -1,4 +1,3 @@ - import { SessionAuthenticationHook } from '@commercetools/connect-payments-sdk'; import { FastifyInstance, FastifyPluginOptions } from 'fastify'; import { diff --git a/processor/src/services/payment.service.ts b/processor/src/services/payment.service.ts index 87cfdba..7dc3222 100644 --- a/processor/src/services/payment.service.ts +++ b/processor/src/services/payment.service.ts @@ -1,8 +1,9 @@ import { CommercetoolsCartService, CommercetoolsPaymentService } from '@commercetools/connect-payments-sdk'; import { paymentProviderApi } from '../clients/mockPaymentAPI'; -import { CreatePayment, PaymentService, PaymentServiceOptions, SupportedPaymentComponents } from './types/payment.type'; +import { CreatePayment, PaymentService, PaymentServiceOptions } from './types/payment.type'; import { PaymentOutcome, PaymentResponseSchemaDTO } from '../dtos/payment.dto'; import { getCartIdFromContext } from '../libs/fastify/context/context'; +import { SupportedPaymentComponentsSchemaDTO } from '../dtos/payment-methods.dto'; export class DefaultPaymentService implements PaymentService { private ctCartService: CommercetoolsCartService; @@ -13,10 +14,14 @@ export class DefaultPaymentService implements PaymentService { this.ctPaymentService = opts.ctPaymentService; } - public async getSupportedPaymentComponents(): Promise { + public async getSupportedPaymentComponents(): Promise { // TODO : Implement actual API call to payment service provider return { - supportedPaymentComponents: ['dropin', 'card', 'applepay'], + components: [ + { + type: 'card', + }, + ], }; } diff --git a/processor/src/services/types/payment.type.ts b/processor/src/services/types/payment.type.ts index 0315026..81a55fd 100644 --- a/processor/src/services/types/payment.type.ts +++ b/processor/src/services/types/payment.type.ts @@ -1,7 +1,7 @@ import { Cart, Payment } from '@commercetools/platform-sdk'; import { CommercetoolsCartService, CommercetoolsPaymentService } from '@commercetools/connect-payments-sdk'; import { PaymentOutcome, PaymentRequestSchemaDTO, PaymentResponseSchemaDTO } from '../../dtos/payment.dto'; -import { SupportedPaymentMethodsDTO } from '../../dtos/payment-methods.dto'; +import { SupportedPaymentComponentsSchemaDTO } from '../../dtos/payment-methods.dto'; export type CreatePayment = { data: PaymentRequestSchemaDTO; @@ -19,13 +19,9 @@ export type MockPaymentProviderResponse = { paymentMethodType: string; }; -export type SupportedPaymentComponents = { - supportedPaymentComponents: SupportedPaymentMethodsDTO; -}; - export interface PaymentService { createPayment(opts: CreatePayment): Promise; - getSupportedPaymentComponents(): Promise; + getSupportedPaymentComponents(): Promise; } export type PaymentServiceOptions = {