Skip to content

Commit

Permalink
chore(gc): update payment sdk (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonogwuru authored Jan 16, 2025
1 parent 27c06f7 commit a0814e8
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 147 deletions.
183 changes: 53 additions & 130 deletions processor/package-lock.json

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

2 changes: 1 addition & 1 deletion processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@adyen/api-library": "22.1.0",
"@commercetools-backend/loggers": "22.38.1",
"@commercetools/connect-payments-sdk": "0.14.0",
"@commercetools/connect-payments-sdk": "0.15.0",
"@fastify/autoload": "6.0.3",
"@fastify/cors": "10.0.2",
"@fastify/formbody": "8.0.2",
Expand Down
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 a0814e8

Please sign in to comment.