Skip to content

Commit

Permalink
Add existing implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenkumarct committed Jan 22, 2024
1 parent cc5c72a commit 628f63c
Show file tree
Hide file tree
Showing 68 changed files with 2,459 additions and 2 deletions.
2 changes: 1 addition & 1 deletion enabler/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<body>
<div id="app"></div>
<script type="module">
import { Connector } from '/lib/main.ts';
import { Connector } from '/enabler/src/main.ts';

const sessionId = await getSessionId();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion enabler/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["lib", "decs.d.ts"]
"include": [
"src", "decs.d.ts"]
}
3 changes: 3 additions & 0 deletions processor/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules
.env
/dist
29 changes: 29 additions & 0 deletions processor/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Server configuration
NODE_ENV=development
SERVER_HOST=0.0.0.0
SERVER_PORT=8080

# Adyen credentials
ADYEN_ENVIRONMENT=TEST
ADYEN_API_KEY=[Adyen-api-key]
ADYEN_LIVE_URL_PREFIX=
ADYEN_NOTIFICATION_HMAC_KEY=[Adyen-hmac-key]
ADYEN_MERCHANT_ACCOUNT=[Adyen-merchant-account]
ADYEN_RETURN_URL=[Adyen-return-url-connector]

#Adyen config options
SUPPORTED_UI_ELEMENTS=[dropin,components]
ENABLE_STORE_DETAILS=[true/false]

# CoCo credentials
CTP_AUTH_URL=https://auth.[region].commercetools.com
CTP_API_URL=https://api.[region].commercetools.com
CTP_CLIENT_ID=[CoCo-client-id]
CTP_CLIENT_SECRET=[CoCo-client-secret]
CTP_PROJECT_KEY=[CoCo-project-key]
CTP_SESSION_URL=[CoCo-session-url]

# Merchant website
SELLER_RETURN_URL=[Merchant-website-return-url]
SELLER_SEND_NOTIFICATION_ENABLED=[true/false]
SELLER_NOTIFICATION_URL=[Merchant-website-return-url]
37 changes: 37 additions & 0 deletions processor/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"root": true,
"env": {
"node": true,
"jest": true
},
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript",
"prettier",
"plugin:prettier/recommended"
],
"plugins": ["@typescript-eslint", "import", "jest", "prettier", "unused-imports"],
"rules": {
"no-redeclare": ["warn"],
"no-console": ["error"],
"no-unused-vars": "off",
"no-irregular-whitespace": "warn",
"no-duplicate-imports": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
{
"vars": "all",
"varsIgnorePattern": "^_",
"args": "after-used",
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/no-unused-vars": ["warn"],
"import/no-duplicates": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off"
}
}
24 changes: 24 additions & 0 deletions processor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
4 changes: 4 additions & 0 deletions processor/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
coverage
node_modules
pnpm-lock.yaml
10 changes: 10 additions & 0 deletions processor/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
arrowParens: 'always',
bracketSameLine: true,
bracketSpacing: true,
printWidth: 120,
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
useTabs: false,
};
8 changes: 8 additions & 0 deletions processor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:18

COPY . /app
WORKDIR /app
RUN npm ci
RUN npm run build

ENTRYPOINT [ "npm", "run", "start" ]
15 changes: 15 additions & 0 deletions processor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Adyen advanced flow

[Official documentation](https://docs.adyen.com/online-payments/build-your-integration/additional-use-cases/advanced-flow-integration/?platform=Web&integration=Drop-in&version=5.51.0){:target="_blank"}


## Get payment methods


## Make a payment


## Submit additional payment details


## Get the payment outcome
6 changes: 6 additions & 0 deletions processor/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
14 changes: 14 additions & 0 deletions processor/src/clients/adyen/adyen.client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Client, CheckoutAPI } from '@adyen/api-library';
import { config } from '../../config/config';

export const AdyenAPI = (): CheckoutAPI => {
const apiClient = new Client({
apiKey: config.adyenApiKey,
environment: config.adyenEnvironment.toUpperCase() as Environment,
...(config.adyenLiveUrlPrefix && {
liveEndpointUrlPrefix: config.adyenLiveUrlPrefix,
}),
});

return new CheckoutAPI(apiClient);
};
39 changes: 39 additions & 0 deletions processor/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const convertStringCommaSeparatedValuesToArray = (supportedUIElements?: string): string[] => {
if (supportedUIElements) {
return supportedUIElements.split(',');
}
return [];
};

export const config = {
// Required by Payment SDK
projectKey: process.env.CTP_PROJECT_KEY || 'test',
clientId: process.env.CTP_CLIENT_ID || 'clientId',
clientSecret: process.env.CTP_CLIENT_SECRET || 'clientSecret',
authUrl: process.env.CTP_AUTH_URL || 'http://auth.test.com',
apiUrl: process.env.CTP_API_URL || 'http://api.test.com',
sessionUrl: process.env.CTP_SESSION_URL || 'http://session.test.com',

// Required by logger
loggerLevel: process.env.LOGGER_LEVEL || 'info',

// Required to setup fastify server
serverPort: process.env.SERVER_PORT ? parseInt(process.env.SERVER_PORT) : 8080,
serverHost: process.env.SERVER_HOST || '0.0.0.0',

// Adyen specific configuration
adyenEnvironment: process.env.ADYEN_ENVIRONMENT || '',
adyenClientKey: process.env.ADYEN_CLIENT_KEY || '',
adyenApiKey: process.env.ADYEN_API_KEY || '',
adyenHMACKey: process.env.ADYEN_NOTIFICATION_HMAC_KEY || '',
adyenLiveUrlPrefix: process.env.ADYEN_LIVE_URL_PREFIX || '',
adyenMerchantAccount: process.env.ADYEN_MERCHANT_ACCOUNT || '',
adyenReturnUrl: process.env.ADYEN_RETURN_URL || '',

// TODO review these configurations
supportedUIElements: convertStringCommaSeparatedValuesToArray(process.env.SUPPORTED_UI_ELEMENTS),
enableStoreDetails: process.env.ENABLE_STORE_DETAILS === 'true' ? true : false,
sellerReturnUrl: process.env.SELLER_RETURN_URL || '',
sellerNotificationUrl: process.env.SELLER_NOTIFICATION_URL || '',
sellerSendNotiticationEnabled: process.env.SELLER_SEND_NOTIFICATION_ENABLED === 'true' ? true : false,
};
3 changes: 3 additions & 0 deletions processor/src/dtos/notification.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Notification } from '@adyen/api-library/lib/src/typings/notification/notification';

export type PaymentNotificationData = Notification;
13 changes: 13 additions & 0 deletions processor/src/dtos/payment-methods.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Static, Type } from '@sinclair/typebox';

export const SupportedPaymentMethodDTO = Type.Object({
type: Type.String(),
});

export const SupportedPaymentMethodsSchema = Type.Object({
dropin: Type.Optional(Type.Array(SupportedPaymentMethodDTO)),
components: Type.Optional(Type.Array(SupportedPaymentMethodDTO)),
hostedPage: Type.Optional(Type.Array(SupportedPaymentMethodDTO)),
});

export type SupportedPaymentMethodsDTO = Static<typeof SupportedPaymentMethodsSchema>;
93 changes: 93 additions & 0 deletions processor/src/dtos/payment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { Static, Type } from '@sinclair/typebox';
import { CreateCheckoutSessionRequest } from '@adyen/api-library/lib/src/typings/checkout/createCheckoutSessionRequest';
import { CreateCheckoutSessionResponse } from '@adyen/api-library/lib/src/typings/checkout/createCheckoutSessionResponse';
import { PaymentDetailsRequest } from '@adyen/api-library/lib/src/typings/checkout/paymentDetailsRequest';
import { PaymentDetailsResponse } from '@adyen/api-library/lib/src/typings/checkout/paymentDetailsResponse';
import { PaymentMethodsRequest } from '@adyen/api-library/lib/src/typings/checkout/paymentMethodsRequest';
import { PaymentMethodsResponse } from '@adyen/api-library/lib/src/typings/checkout/paymentMethodsResponse';
import { PaymentRequest } from '@adyen/api-library/lib/src/typings/checkout/paymentRequest';
import { PaymentResponse } from '@adyen/api-library/lib/src/typings/checkout/paymentResponse';

export type GetPaymentMethodsData = Omit<PaymentMethodsRequest, 'amount' | 'merchantAccount' | 'countryCode'>;
export type PaymentMethodsData = PaymentMethodsResponse;

export type CreateSessionData = Omit<
CreateCheckoutSessionRequest,
| 'amount'
| 'merchantAccount'
| 'countryCode'
| 'returnUrl'
| 'reference'
| 'storePaymentMethod'
| 'shopperReference'
| 'recurringProcessingModel'
| 'storePaymentMethodMode'
>;

export type SessionData = {
sessionData: CreateCheckoutSessionResponse;
paymentReference: string;
};

export type CreatePaymentData = Omit<
PaymentRequest,
| 'amount'
| 'additionalAmount'
| 'merchantAccount'
| 'countryCode'
| 'returnUrl'
| 'lineItems'
| 'reference'
| 'shopperReference'
| 'recurringProcessingModel'
> & {
paymentReference?: string;
};
export type PaymentData = Pick<
PaymentResponse,
'action' | 'resultCode' | 'threeDS2ResponseData' | 'threeDS2Result' | 'threeDSPaymentData'
> & {
paymentReference: string;
};

export type PaymentConfirmationData = Pick<
PaymentDetailsResponse,
'resultCode' | 'threeDS2ResponseData' | 'threeDS2Result' | 'threeDSPaymentData'
> & {
paymentReference: string;
};

export type ConfirmPaymentData = PaymentDetailsRequest & {
paymentReference: string;
};

export const CapturePaymentRequestSchema = Type.Object({
amount: Type.Object({
centAmount: Type.Number(),
currencyCode: Type.String(),
}),
});

export const RefundPaymentRequestSchema = Type.Object({
amount: Type.Object({
centAmount: Type.Number(),
currencyCode: Type.String(),
}),
});

export enum PaymentModificationStatus {
RECEIVED = 'received',
}
const PaymentModificationSchema = Type.Enum(PaymentModificationStatus);

export const PaymentModificationResponseSchema = Type.Object({
status: PaymentModificationSchema,
});

export type DeleteStoredPaymentMethodData = {
customerId: string;
};

export type CapturePaymentRequestDTO = Static<typeof CapturePaymentRequestSchema>;
export type RefundPaymentRequestDTO = Static<typeof RefundPaymentRequestSchema>;
export type PaymentModificationResponseDTO = Static<typeof PaymentModificationResponseSchema>;
19 changes: 19 additions & 0 deletions processor/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '@fastify/request-context';
import { ContextData, SessionContextData } from './libs/fastify/context/context';

declare module '@fastify/request-context' {
interface RequestContextData {
request: ContextData;
session?: SessionContextData;
}
}

declare module 'fastify' {
interface FastifyInstance {
vite: any;
}

export interface FastifyRequest {
correlationId?: string;
}
}
Loading

0 comments on commit 628f63c

Please sign in to comment.