Skip to content

Commit 9e8e970

Browse files
authored
Merge pull request #1 from cybersource-tpi/main
Initial Commit
2 parents 01d1e07 + d6310e7 commit 9e8e970

File tree

403 files changed

+50452
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

403 files changed

+50452
-2
lines changed

README.md

+166-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,166 @@
1-
# cybersource-plugins-oraclecxcommerce
2-
This repository contains the Cybersource plugins for Oracle
1+
# ISV OCC Payment
2+
3+
## Documentation
4+
5+
Please refer to the [official documentation](documentation/occ.md) to get all details about payment integration and installation steps.
6+
7+
## Local development
8+
9+
## Prerequisites
10+
11+
- Yarn version: [1.22.4](https://classic.yarnpkg.com/en/docs/install/#mac-stable)
12+
- NodeJS version: 10.18.0, You could use [NVM](https://github.com/nvm-sh/nvm) to manage multiple versions locally
13+
14+
Please make sure you familiarize yourself with Typescript v3.9.5 as it is being used for both widget and server side extension development.
15+
16+
## Install dependencies
17+
18+
From your project's root run
19+
20+
```bash
21+
yarn install
22+
```
23+
24+
## Building code
25+
26+
Running `build` script from project's root will build code for all the packages
27+
28+
```bash
29+
yarn build
30+
```
31+
32+
To build packages individually make sure you switch to respective package directory as shown below
33+
34+
```bash
35+
cd packages/<package_name>
36+
yarn build
37+
yarn start
38+
```
39+
40+
## Local development servers
41+
42+
To quickly start all servers from project's root directory run
43+
44+
- Start OCC Mock Server: `yarn start:mock-server`
45+
- Start Server Side extension: `yarn start:server`
46+
- Start Payment Widget: `yarn start:widget`
47+
48+
If all servers above have successfully started you should be able to test payment integrations
49+
50+
### Configuration
51+
52+
Before starting local dev servers make sure you provide gateway settings in `packages/payment-gateway/settings.json`. More details about available settings can be found in the [Payment Gateway Package](documentation/occ.md#payment-gateway-package-payment-gateway) section
53+
54+
### OCC Mock Server (packages/occ-mock-server)
55+
56+
`packages/occ-mock-server` package acts as REST API mocks in order to abstract away dependencies on certain OCC endpoints. Endpoints are defined in the following file `packages/occ-mock-server/src/routes/index.ts`.
57+
58+
The package is used only for local development and is not deployed to OCC
59+
60+
| **Endpoint** | **Description** |
61+
|------------------------------------------------|------------------------------------------------------------------------------------------------------|
62+
| `/ccadmin/v1/sitesettings/isv-occ-gateway` | Stubs gateway settings manage in `packages/payment-gateway/settings.json` |
63+
| `/ccadmin/v1/login` | Stubs OCC login API |
64+
| `/ccstore/v1/orders` | Stubs OCC order API. Does the minimum required 'order to webhook' and 'webhook to order' conversions |
65+
| `/ccstore/v1/profiles/current/creditCards` | Stubs the list of saved cards. Helps with testing saved cards locally. |
66+
| `/ccstore/v1/profiles/current/creditCards/:id` | Stubs saved cards CRUD API |
67+
68+
To start server run the following:
69+
70+
```bash
71+
cd packages/occ-mock-server
72+
yarn start:watch
73+
```
74+
75+
By default server will listen on port 5000 (HTTP) and 5001 (HTTPS)
76+
77+
### Server Side Extension (packages/server-extension)
78+
79+
You can start SSE locally by running
80+
81+
```bash
82+
cd packages/server-extension
83+
yarn start:watch
84+
```
85+
86+
Server startup script and setup is located at `packages/server-extension/src/server.ts` By default server will listen on port 3000 (HTTP) and 3001 (HTTPS).
87+
88+
For local development `packages/server-extension/config/app.local.json` configuration file is loaded.
89+
90+
`server-extension` consumes endpoints from `occ-mock-server` so make sure both are running locally
91+
92+
### OCC Mock Storefront (packages/occ-mock-storefront)
93+
94+
Both `packages/payment-widget` and `packages/saved-cards-widget` packages depend on `packages/occ-mock-storefront`.
95+
96+
`occ-mock-storefront` acts as storefront stub for OCC view models. It mimics OCC storefront behavior without need to deploy payment widget to see it in action. It can help you avoid setting up [Design Code Utility](https://docs.oracle.com/en/cloud/saas/commerce-cloud/20a/occ-developer/use-design-code-utility.html) to develop payment widget locally.
97+
98+
`occ-mock-storefront` also provides Typescript friendly environment and type declarations as OCC does not support it out of the box.
99+
100+
### Payment widget (packages/payment-widget)
101+
102+
Payment Widget can be started locally using webpack dev server with configuration located at `packages/payment-widget/webpack.dev.config.js`
103+
104+
You can start the widget locally by running
105+
106+
```bash
107+
cd packages/payment-widget
108+
yarn start
109+
```
110+
111+
Make sure both `occ-mock-server` and `server -extension` have been also started.
112+
113+
In case you would like to start dev server using secure connection (HTTPS) run the following:
114+
115+
```bash
116+
NODE_HTTPS=true yarn start
117+
```
118+
119+
`NODE_HTTPS` env variable will instruct dev server to start using HTTPS.
120+
121+
All local development steps being prepared in `packages/payment-widget/widget/isv-occ-payment/js/dev`
122+
123+
```text
124+
.
125+
├── webpack.dev.config.js
126+
└── widget
127+
└── isv-occ-payment
128+
└── js
129+
   └── dev
130+
      ├── client-main.ts // Instantiate payment widget component and initialize it
131+
       ├── controls.ts // Helper tools to control test data and logging output
132+
      └── index.html // HTML template injecting payment widget for rendering
133+
```
134+
135+
### Saved Cards widget (packages/saved-cards-widget)
136+
137+
Saved Cards widget can be started locally using webpack dev server with configuration located at `packages/saved-cards-widget/webpack.dev.config.js`
138+
139+
You can start the widget locally by running
140+
141+
```bash
142+
cd packages/saved-cards-widget
143+
yarn start
144+
```
145+
146+
Make sure both `occ-mock-server` and `server -extension` have been also started.
147+
148+
All local development steps being prepared in `packages/saved-cards-widget/widget/saved-cards/js/dev`
149+
150+
```text
151+
.
152+
├── webpack.dev.config.js
153+
└── widget
154+
└── saved-cards
155+
└── js
156+
   └── dev
157+
      ├── client-main.ts // Instantiate saved cards widget component and initialize it
158+
       ├── controls.ts // Helper tools to control test data and logging output
159+
      └── index.html // HTML template injecting saved cards widget for rendering
160+
```
161+
162+
## Extension management CLI
163+
164+
Solution include CLI tool to deploy and manage both server side extensions and widgets.
165+
166+
Run `yarn occ` from project's root to see all available commands. You will need to provide credentials to be able to execute commands. Credentials in some cases are username and password for OCC Admin, in other cases [Application Key](https://docs.oracle.com/en/cloud/saas/commerce-cloud/20a/occ-developer/register-applications.html) should be provided.

bin/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
const program = require('commander');
4+
5+
require('./widget/commands');
6+
require('./sse/commands');
7+
8+
// Allow commander to parse `process.argv`
9+
program.parse(process.argv);

bin/sse/commands.js

+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
'use strict';
2+
3+
const program = require('commander');
4+
const cmd = require('../../lib/sse/cmd');
5+
6+
// List server-side extension custom apps on CX Commerce server
7+
// $ occ list-apps --url <host> --appKey <appKey>
8+
// $ occ ls -u <host> -k <appKey>
9+
program
10+
.command('list-apps') // sub-command name
11+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
12+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
13+
.description('List server-side extension custom apps on CX Commerce server') // command description
14+
// function to execute when command invoked
15+
.action(async (options) => {
16+
const response = await cmd.listApps(options);
17+
console.log(JSON.stringify(response));
18+
});
19+
20+
// Create server-side extension archive
21+
// $ occ package-app <appName>
22+
program
23+
.command('package-app <appName>') // sub-command name
24+
.description('Create server-side extension archive') // command description
25+
// function to execute when command invoked
26+
.action(async (appName) => {
27+
const response = await cmd.packageApp(appName);
28+
console.log(JSON.stringify(response));
29+
});
30+
31+
// Upload server-side extension custom app to CX Commerce server
32+
// $ occ upload-app <appName> --url <host> --appKey <appKey>
33+
// $ occ ls -u <host> -k <appKey> --a <appName>
34+
program
35+
.command('upload-app <appName>') // sub-command name
36+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
37+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
38+
.option(
39+
'-x, --exclude <items>',
40+
'List of directories excluded from zip package',
41+
(value) => value.split(','),
42+
[]
43+
)
44+
.description('Upload server-side extension custom app to CX Commerce server') // command description
45+
// function to execute when command invoked
46+
.action(async (appName, options) => {
47+
const response = await cmd.uploadApp(appName, options);
48+
console.log(response);
49+
});
50+
51+
// Get server-side extension log
52+
// $ occ server-log --url <host> --appKey <appKey>
53+
// $ occ server-log -u <host> -k <appKey>
54+
program
55+
.command('server-log') // sub-command name
56+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
57+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
58+
.option(
59+
'-d, --date [date]',
60+
'The date of the log file to return. Will default to the current day if not supplied.'
61+
)
62+
.option(
63+
'-l, --loggingLevel [loggingLevel]',
64+
'The level of the log file to return. must be one of the following; debug, info, warning, error.',
65+
'debug'
66+
)
67+
.description('Get server-side extension logs') // command description
68+
// function to execute when command invoked
69+
.action(async (options) => {
70+
const response = await cmd.getServerLogs(options);
71+
console.log(response);
72+
});
73+
74+
// Returns the tail logs from the extension server for the given logging level and date.
75+
// $ occ tail-log --url <host> --appKey <appKey>
76+
// $ occ tail-log -u <host> -k <appKey>
77+
program
78+
.command('tail-log') // sub-command name
79+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
80+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
81+
.option(
82+
'-d, --date [date]',
83+
'The date of the log file to return. Will default to the current day if not supplied.'
84+
)
85+
.option(
86+
'-l, --loggingLevel [loggingLevel]',
87+
'The level of the log file to return. must be one of the following; debug, info, warning, error.',
88+
'debug'
89+
)
90+
.description('Tail server-side extension logs') // command description
91+
// function to execute when command invoked
92+
.action(async (options) => {
93+
const response = await cmd.getServerLogTail(options);
94+
console.log(response);
95+
});
96+
97+
// Download server-side extension custom app files
98+
// $ occ download-app <appName> --url <host> --appKey <appKey>
99+
// $ occ download-app <appName> -u <host> -k <appKey>
100+
program
101+
.command('download-app <appName>') // sub-command name
102+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
103+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
104+
.description('Download server-side custom app files') // command description
105+
// function to execute when command invoked
106+
.action(async (appName, options) => {
107+
const response = await cmd.downloadApp(appName, options);
108+
console.log(response);
109+
});
110+
111+
// List custom app routes
112+
// $ occ list-routes [appName] --url <host> --appKey <appKey>
113+
program
114+
.command('list-routes [appName]') // sub-command name
115+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
116+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
117+
.description('List custom app routes') // command description
118+
// function to execute when command invoked
119+
.action(async (appName, options) => {
120+
const response = await cmd.listRoutes(appName, options);
121+
console.log(response);
122+
});
123+
124+
// List environment variables
125+
// $ occ config:list --url <host> --appKey <appKey>
126+
program
127+
.command('config:list') // sub-command name
128+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
129+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
130+
.description('List environment variables') // command description
131+
// function to execute when command invoked
132+
.action(async (options) => {
133+
const response = await cmd.getEnvironmentVariables(options);
134+
console.log(JSON.stringify(response));
135+
});
136+
137+
// Set environment variables
138+
// $ occ config:set --url <host> --appKey <appKey> <var> [otherVars]
139+
program
140+
.command('config:set <envVar> [otherEnvVars...]') // sub-command name
141+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
142+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
143+
.description('Set environment variables') // command description
144+
// function to execute when command invoked
145+
.action(async (envVar, otherEnvVars, options) => {
146+
const response = await cmd.setEnvironmentVariables(envVar, otherEnvVars, options);
147+
console.log(JSON.stringify(response));
148+
});
149+
150+
// Unset environment variables
151+
// $ occ config:unset --url <host> --appKey <appKey> <var> [otherVars]
152+
program
153+
.command('config:unset <envVar> [otherEnvVars...]') // sub-command name
154+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
155+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
156+
.description('Set environment variables') // command description
157+
// function to execute when command invoked
158+
.action(async (envVar, otherEnvVars, options) => {
159+
const response = await cmd.deleteEnvironmentVariables(envVar, otherEnvVars, options);
160+
console.log(JSON.stringify(response));
161+
});
162+
163+
// Run tests
164+
// $ occ run-tests <appName> --url <host> --appKey <appKey>
165+
program
166+
.command('run-tests <appName>') // sub-command name
167+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
168+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
169+
.option('-i, --interval [interval]', 'Interval to wait between polling for results.', 10)
170+
.option('-t, --maxAttempts [maxAttempts]', 'Total number of attempts.', 5)
171+
.description('Run tests') // command description
172+
// function to execute when command invoked
173+
.action(async (appName, options) => {
174+
const response = await cmd.runTests(appName, options);
175+
console.log(JSON.stringify(response));
176+
});
177+
178+
// Upload Apple Pay domain association file
179+
// $ occ upload-apple-domain-association <file>
180+
program
181+
.command('upload-apple-domain-association <filePath>')
182+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
183+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
184+
.description('Upload Apple Pay domain association file')
185+
.action(async (filePath, options) => {
186+
const response = await cmd.uploadAppleDomainAssociation(filePath, options);
187+
console.log(JSON.stringify(response));
188+
});
189+
190+
// Get Custom Site Settings Config Data
191+
// $ occ settings:list <gatewayId>
192+
program
193+
.command('settings:list <gatewayId>')
194+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
195+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
196+
.description('Get Custom Site Settings. Get site settings by ID.')
197+
.action(async (gatewayId, options) => {
198+
const response = await cmd.getSiteSettings(gatewayId, options);
199+
console.log(JSON.stringify(response));
200+
});
201+
202+
// Set Site Setting Config Data
203+
// $ occ settings:set <gatewayId>
204+
program
205+
.command('settings:set <gatewayId> <payload>')
206+
.requiredOption('-u, --url <url>', 'The url to your CX Commerce host.')
207+
.requiredOption('-k, --appKey <appKey>', 'The application key.')
208+
.description('Update a Site Settings based on ID and request parameters.')
209+
.action(async (gatewayId, payload, options) => {
210+
const response = await cmd.setSiteSettings(gatewayId, payload, options);
211+
console.log(JSON.stringify(response));
212+
});

0 commit comments

Comments
 (0)