Skip to content

Commit

Permalink
chore: migration codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyingchun committed May 15, 2024
1 parent 108ac9d commit 2c70501
Show file tree
Hide file tree
Showing 70 changed files with 1,456 additions and 1,832 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-jars-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperse-io/paypal-node-sdk": patch
---

refactor codes
8 changes: 4 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ module.exports = {
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
},
ignorePatterns: [
...getDefaultIgnorePatterns(),
'src/custom-admin-ui/admin-ui',
],
ignorePatterns: [...getDefaultIgnorePatterns()],
extends: [
'@armit/eslint-config-bases/typescript',
'@armit/eslint-config-bases/sonar',
'@armit/eslint-config-bases/regexp',
'@armit/eslint-config-bases/vitest',
// Apply prettier and disable incompatible rules
'@armit/eslint-config-bases/prettier',
],
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release-or-version-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
- name: Install Dependencies
run: yarn --frozen-lockfile

- name: Unit tests
run: |
yarn test
# - name: Unit tests
# run: |
# yarn test

# @link https://github.com/changesets/action
- name: Create Release Pull Request or Publish to npm
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# and https://github.com/github/gitignore for examples

# local env files (followinf dotenv-flow / nextjs convention)

.env
.env.local
.env.*.local

Expand Down
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.preferences.importModuleSpecifier": "relative",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
"source.fixAll": "explicit",
"source.organizeImports": "never"
},
"files.associations": {
"*.css": "tailwindcss"
},
// Disable vscode formatting for js,jsx,ts,tsx files
// to allow dbaeumer.vscode-eslint to format them
"[javascript]": {
"editor.formatOnSave": false
}
}
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@
},
"types": "./dist/index.d.ts",
"files": [
"./dist/",
"./index.js"
"./dist/"
],
"scripts": {
"build": "rimraf dist && tsc -p ./tsconfig.build.json ",
"clean": "rimraf --no-glob ./dist ./coverage ./.eslintcache ./tsconfig.tsbuildinfo",
"test": "vitest run --dir tests/",
"test-task": "vitest run",
"test-unit": "vitest run --dir src/",
"test-e2e": "vitest run --dir e2e/",
"lint": "eslint . --ext .ts,.mts,.tsx,.js,.jsx,.cjs,.mjs --cache --cache-location .cache/eslint/hyperse-main.eslintcache",
"typecheck": "tsc --project ./tsconfig.json --noEmit",
"lint-staged-files": "lint-staged --allow-empty",
Expand All @@ -48,35 +46,40 @@
"cz": "cz",
"husky": "is-ci || husky"
},
"workspaces": [
".",
"samples"
],
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"dependencies": {
"@paypal/paypalhttp": "^1.0.0",
"@paypal/paypalhttp": "^1.0.1",
"@types/paypal__paypalhttp": "^1.0.3"
},
"devDependencies": {
"@armit/eslint-config-bases": "0.1.5",
"@armit/eslint-config-bases": "0.1.6",
"@changesets/changelog-git": "0.2.0",
"@changesets/cli": "2.27.1",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@swc/core": "1.5.5",
"@types/node": "20.12.11",
"@swc/core": "1.5.7",
"@types/node": "20.12.12",
"@types/prettier": "3.0.0",
"@types/shell-quote": "1.7.5",
"commitizen": "4.3.0",
"cz-conventional-changelog": "3.3.0",
"dotenv": "16.4.5",
"eslint": "8.x",
"husky": "9.0.11",
"is-ci": "3.0.1",
"lint-staged": "15.2.2",
"minimist": "1.2.8",
"npm-run-all": "4.1.5",
"prettier": "3.2.5",
"rimraf": "5.0.6",
"rimraf": "5.0.7",
"shell-quote": "1.8.1",
"swc-unplugin-ts": "1.0.3",
"terser": "5.31.0",
Expand Down
80 changes: 0 additions & 80 deletions samples/AuthorizeIntentExamples/authorizeOrder.js

This file was deleted.

50 changes: 50 additions & 0 deletions samples/AuthorizeIntentExamples/authorizeOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { OrdersAuthorizeRequest } from '@hyperse-io/paypal-node-sdk';
import { createClient } from 'samples/Common/payPalClient.js';

/**
* This function can be used to perform authorization on the approved order.
* An valid approved order id should be passed as an argument to this function.
*
* @param orderId
* @param debug
* @returns
*/
export async function authorizeOrder(orderId, debug = false) {
try {
const request = new OrdersAuthorizeRequest(orderId);
request.requestBody({});
const response = await createClient().execute(request);
if (debug) {
console.log('Status Code: ' + response.statusCode);
console.log('Status: ' + response.result.status);
console.log(
'Authorization ID: ',
response.result.purchase_units[0].payments.authorizations[0].id
);
console.log('Order ID: ' + response.result.id);
console.log('Links: ');
response.result.links.forEach((item) => {
const rel = item.rel;
const href = item.href;
const method = item.method;
const message = `\t${rel}: ${href}\tCall Type: ${method}`;
console.log(message);
});
console.log('Authorization Links:');
response.result.purchase_units[0].payments.authorizations[0].links.forEach(
(item) => {
const rel = item.rel;
const href = item.href;
const method = item.method;
const message = `\t${rel}: ${href}\tCall Type: ${method}`;
console.log(message);
}
);
// To toggle print the whole body comment/uncomment the below line
console.log(JSON.stringify(response.result, null, 4));
}
return response;
} catch (e) {
console.log(e);
}
}
66 changes: 0 additions & 66 deletions samples/AuthorizeIntentExamples/captureOrder.js

This file was deleted.

36 changes: 36 additions & 0 deletions samples/AuthorizeIntentExamples/captureOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { AuthorizationsCaptureRequest } from '@hyperse-io/paypal-node-sdk';
import { createClient } from 'samples/Common/payPalClient.js';

/**
* This function can be used to capture the payment on an authorized Order.
* An Valid authorization Id should be passed as an argument to this method.
*
* @param authId
* @param debug
* @returns
*/
export async function captureOrder(authId, debug = false) {
try {
const request = new AuthorizationsCaptureRequest(authId);
request.requestBody({});
const response = await createClient().execute(request);
if (debug) {
console.log('Status Code: ' + response.statusCode);
console.log('Status: ' + response.result.status);
console.log('Capture ID: ' + response.result.id);
console.log('Links:');
response.result.links.forEach((item) => {
const rel = item.rel;
const href = item.href;
const method = item.method;
const message = `\t${rel}: ${href}\tCall Type: ${method}`;
console.log(message);
});
// To toggle print the whole body comment/uncomment the below line
console.log(JSON.stringify(response.result, null, 4));
}
return response;
} catch (e) {
console.log(e);
}
}
Loading

0 comments on commit 2c70501

Please sign in to comment.