Skip to content

Commit

Permalink
Fix type of supported payment components
Browse files Browse the repository at this point in the history
  • Loading branch information
leungkinghin-ct committed Feb 7, 2024
1 parent edf78de commit 2d586c2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
10 changes: 7 additions & 3 deletions processor/src/dtos/payment-methods.dto.ts
Original file line number Diff line number Diff line change
@@ -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<typeof SupportedPaymentMethodsSchema>;
export type SupportedPaymentComponentsSchemaDTO = Static<typeof SupportedPaymentComponentsSchema>;
12 changes: 8 additions & 4 deletions processor/src/routes/payment-components.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
);
};
1 change: 0 additions & 1 deletion processor/src/routes/payment.route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { SessionAuthenticationHook } from '@commercetools/connect-payments-sdk';
import { FastifyInstance, FastifyPluginOptions } from 'fastify';
import {
Expand Down
11 changes: 8 additions & 3 deletions processor/src/services/payment.service.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,10 +14,14 @@ export class DefaultPaymentService implements PaymentService {
this.ctPaymentService = opts.ctPaymentService;
}

public async getSupportedPaymentComponents(): Promise<SupportedPaymentComponents> {
public async getSupportedPaymentComponents(): Promise<SupportedPaymentComponentsSchemaDTO> {
// TODO : Implement actual API call to payment service provider
return {
supportedPaymentComponents: ['dropin', 'card', 'applepay'],
components: [
{
type: 'card',
},
],
};
}

Expand Down
8 changes: 2 additions & 6 deletions processor/src/services/types/payment.type.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,13 +19,9 @@ export type MockPaymentProviderResponse = {
paymentMethodType: string;
};

export type SupportedPaymentComponents = {
supportedPaymentComponents: SupportedPaymentMethodsDTO;
};

export interface PaymentService {
createPayment(opts: CreatePayment): Promise<PaymentResponseSchemaDTO>;
getSupportedPaymentComponents(): Promise<SupportedPaymentComponents>;
getSupportedPaymentComponents(): Promise<SupportedPaymentComponentsSchemaDTO>;
}

export type PaymentServiceOptions = {
Expand Down

0 comments on commit 2d586c2

Please sign in to comment.