Skip to content

Commit

Permalink
chore(gc): update payment sdk (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonogwuru authored Jan 28, 2025
1 parent 283892b commit e3b4790
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
35 changes: 35 additions & 0 deletions processor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions processor/src/libs/fastify/context/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Authentication, SessionAuthentication } from '@commercetools/connect-payments-sdk';
import * as paymentSdk from '@commercetools/connect-payments-sdk';
import { fastifyRequestContext, requestContext } from '@fastify/request-context';
import { randomUUID } from 'crypto';
import { FastifyInstance, FastifyRequest } from 'fastify';
Expand All @@ -15,7 +15,7 @@ export type ContextData = {
query?: any;
correlationId: string;
requestId: string;
authentication?: Authentication;
authentication?: paymentSdk.Authentication;
};

export const getRequestContext = (): Partial<ContextData> => {
Expand All @@ -35,38 +35,38 @@ export const updateRequestContext = (ctx: Partial<ContextData>) => {
};

export const getCtSessionIdFromContext = (): string => {
const authentication = getRequestContext().authentication as SessionAuthentication;
return authentication?.getCredentials();
const contextData = getRequestContext() as ContextData;
return paymentSdk.getCtSessionIdFromContext(contextData) as string;
};

export const getCartIdFromContext = (): string => {
const authentication = getRequestContext().authentication as SessionAuthentication;
return authentication?.getPrincipal().cartId;
const contextData = getRequestContext() as ContextData;
return paymentSdk.getCartIdFromContext(contextData) as string;
};

export const getAllowedPaymentMethodsFromContext = (): string[] => {
const authentication = getRequestContext().authentication as SessionAuthentication;
return authentication?.getPrincipal().allowedPaymentMethods;
const contextData = getRequestContext() as ContextData;
return paymentSdk.getAllowedPaymentMethodsFromContext(contextData) as string[];
};

export const getPaymentInterfaceFromContext = (): string | undefined => {
const authentication = getRequestContext().authentication as SessionAuthentication;
return authentication?.getPrincipal().paymentInterface;
const contextData = getRequestContext() as ContextData;
return paymentSdk.getPaymentInterfaceFromContext(contextData);
};

export const getProcessorUrlFromContext = (): string => {
const authentication = getRequestContext().authentication as SessionAuthentication;
return authentication?.getPrincipal().processorUrl;
const contextData = getRequestContext() as ContextData;
return paymentSdk.getProcessorUrlFromContext(contextData) as string;
};

export const getMerchantReturnUrlFromContext = (): string | undefined => {
const authentication = getRequestContext().authentication as SessionAuthentication;
return authentication?.getPrincipal().merchantReturnUrl;
const contextData = getRequestContext() as ContextData;
return paymentSdk.getMerchantReturnUrlFromContext(contextData);
};

export const getFutureOrderNumberFromContext = (): string | undefined => {
const authentication = getRequestContext().authentication as SessionAuthentication;
return authentication?.getPrincipal().futureOrderNumber;
const contextData = getRequestContext() as ContextData;
return paymentSdk.getFutureOrderNumberFromContext(contextData);
};

export const requestContextPlugin = fp(async (fastify: FastifyInstance) => {
Expand Down

0 comments on commit e3b4790

Please sign in to comment.