Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .eslintrc.json

This file was deleted.

17 changes: 11 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
node-version: 16
version: 10
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/
- run: yarn --frozen-lockfile
- run: yarn test
- run: npm publish
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test
- run: pnpm publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
15 changes: 10 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '14', '16', '18', '20']
node: ['22', '24']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10
- name: Setup node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: yarn --frozen-lockfile
- run: yarn test
cache: 'pnpm'
- run: pnpm install --frozen-lockfile
- run: pnpm test
3 changes: 3 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json"
}
9 changes: 9 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["typescript"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"no-unused-vars": ["warn", { "caughtErrorsIgnorePattern": "^_", "argsIgnorePattern": "^_" }]
},
"ignorePatterns": ["node_modules", "built", "pnpm-lock.yaml"]
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ const payjp = new Payjp('sk_live_xxx', {maxRetry: 5, retryInitialDelay: 1000, re
```

A delay of retry is calculated based on [Exponential backoff with equal jitter](https://aws.amazon.com/jp/blogs/architecture/exponential-backoff-and-jitter/) algorithm.
Each delay is randomly choiced between "`retryInitialDelay` * 2 ** `retryCount`" and "`retryInitialDelay` * 2 ** `retryCount` / 2" but doesn't exceed `retryMaxDelay`.
Each delay is randomly choiced between "`retryInitialDelay` * 2 ** `retryCount`" and "`retryInitialDelay` * 2 ** `retryCount` / 2" but doesn't exceed `retryMaxDelay`.

## Contributors

See the [list of contributors](https://github.com/payjp/payjp-node/graphs/contributors) who participated in this project.
78 changes: 78 additions & 0 deletions example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import Payjp = require("./built");

const PAYJP_SECRET_KEY = process.env.PAYJP_SECRET_KEY;
if (!PAYJP_SECRET_KEY) {
console.error("Please set the PAYJP_SECRET_KEY environment variable");
console.error("Usage: PAYJP_SECRET_KEY=sk_test_xxx npx ts-node example.ts");
process.exit(1);
}

const payjp = Payjp(PAYJP_SECRET_KEY);

async function main() {
console.log("=== PAY.JP SDK Example ===\n");

// 1. Retrieve account information
console.log("1. Retrieving account information...");
const account = await payjp.accounts.retrieve();
console.log(` Account ID: ${account.id}`);
console.log(` Email: ${account.email}\n`);

// 2. Create customer
console.log("2. Creating customer...");
const customer = await payjp.customers.create({
email: "test@example.com",
description: "Test customer for SDK verification",
});
console.log(` Customer ID: ${customer.id}`);
console.log(` Email: ${customer.email}`);
console.log(` Description: ${customer.description}\n`);

// 3. Retrieve customer
console.log("3. Retrieving customer...");
const retrievedCustomer = await payjp.customers.retrieve(customer.id);
console.log(` Customer ID: ${retrievedCustomer.id}`);
console.log(` Created at: ${new Date(retrievedCustomer.created * 1000).toLocaleString()}\n`);

// 4. List customers
console.log("4. Listing customers...");
const customerList = await payjp.customers.list({ limit: 3 });
console.log(` Retrieved: ${customerList.data.length}`);
console.log(` Total count: ${customerList.count}\n`);

// 5. Create plan
console.log("5. Creating plan...");
const plan = await payjp.plans.create({
amount: 500,
currency: "jpy",
interval: "month",
name: "Test plan for SDK verification",
});
console.log(` Plan ID: ${plan.id}`);
console.log(` Amount: ${plan.amount} JPY/${plan.interval}\n`);

// 6. List charges
console.log("6. Listing charges...");
const chargeList = await payjp.charges.list({ limit: 3 });
console.log(` Retrieved: ${chargeList.data.length}`);
console.log(` Total count: ${chargeList.count}\n`);

// 7. Cleanup
console.log("7. Cleaning up...");
const deletedPlan = await payjp.plans.delete(plan.id);
console.log(` Plan deleted: ${deletedPlan.deleted ? "success" : "failed"}`);
const deletedCustomer = await payjp.customers.delete(customer.id);
console.log(` Customer deleted: ${deletedCustomer.deleted ? "success" : "failed"}\n`);

console.log("=== Example completed ===");
}

main().catch((error) => {
console.error("An error occurred:");
if (error.response?.body) {
console.error(JSON.stringify(error.response.body, null, 2));
} else {
console.error(error.message);
}
process.exit(1);
});
30 changes: 10 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "payjp",
"version": "2.3.0",
"version": "3.0.0",
"description": "PAY.JP node.js bindings",
"main": "built/index.js",
"types": "built/index.d.ts",
Expand All @@ -16,36 +16,26 @@
"test:debug": "mocha --inspect-brk",
"test:typescript": "tsc --noEmit --target esnext --module commonjs test/types/*.ts",
"build": "tsc",
"lint": "npm run lint:base -- .",
"lint:base": "eslint --ignore-path .gitignore --ext .js,.ts",
"lint:fix": "npm run lint -- --fix",
"lint": "oxlint .",
"lint:fix": "oxlint --fix .",
"format": "oxfmt .",
"format:check": "oxfmt --check .",
"prepublish": "npm run build"
},
"repository": {
"type": "git",
"url": "git://github.com/payjp/payjp-node.git"
},
"author": "PAY.JP <support@pay.jp> (https://pay.jp)",
"contributors": [
"Daiki Arai <darai0512@yahoo.co.jp>",
"Yoichi Fujimoto <wozozo@gmail.com>"
],
"license": "MIT",
"engines": {
"node": ">=12"
"node": ">=22"
},
"devDependencies": {
"@types/superagent": "3.8.3",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@types/prettier": "1.16.1",
"@typescript-eslint/parser": "^5.17.0",
"eslint": "^8.0.0",
"eslint-config-prettier": "4.1.0",
"@types/node": "^22.19.1",
"mocha": "^6.0.2",
"typescript": "^4.6.3",
"prettier": "1.17.1"
},
"dependencies": {
"superagent": "3.8.3"
"oxfmt": "^0.16.0",
"oxlint": "^1.31.0",
"typescript": "^5.7.2"
}
}
Loading