Skip to content

Commit

Permalink
Lib updates (#5)
Browse files Browse the repository at this point in the history
* Libs update + prettier formating

* Libs update + prettier formating

* Using new payment api

* Payment model updates

* CI updates
  • Loading branch information
edolganov authored Aug 22, 2024
1 parent e59fc82 commit 5c26808
Show file tree
Hide file tree
Showing 30 changed files with 8,551 additions and 10,253 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build.js
jest.config.js
88 changes: 80 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,88 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
sourceType: 'module',
ecmaVersion: 15,
},
plugins: ['@typescript-eslint', 'unused-imports'],
extends: [
'eslint:recommended',
'airbnb-base',
'airbnb-typescript/base',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/stylistic-type-checked',
'prettier',
],
rules: {
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'no-restricted-syntax': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/ban-tslint-comment': 'off', // caused by no way to remove this from generated code
'object-property-newline': [
'error',
{
allowAllPropertiesOnSameLine: true,
// allowMultiplePropertiesPerLine is deprecated property, but is used by Webstorm
allowMultiplePropertiesPerLine: true,
},
],
'no-multiple-empty-lines': 'error',
'@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: false }],
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/prefer-nullish-coalescing': ['error', { ignorePrimitives: { string: true, boolean: true } }],
'unused-imports/no-unused-imports': 'error',
'import/no-unresolved': 'error',
'max-classes-per-file': 'off',
'no-underscore-dangle': 'off',
'no-useless-constructor': 'off',
'import/prefer-default-export': 'off',
'class-methods-use-this': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/explicit-module-boundary-types': "off",
'@typescript-eslint/no-non-null-assertion': 'off',
}
'no-console': ['error', { allow: ['warn', 'error', 'info', 'log'] }],
'import/order': [
'error',
{
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
pathGroups: [
{
pattern: '@/**',
group: 'internal',
position: 'after',
},
],
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'type'],
'newlines-between': 'always',
},
],
'operator-linebreak': [
'error',
'before',
{
overrides: {
'=': 'ignore',
':': 'before',
'||': 'before',
'&&': 'before',
'??': 'before',
},
},
],
},
ignorePatterns: ['.eslintrc.js'],
settings: {
'import/resolver': {
typescript: {},
},
},
};
2 changes: 1 addition & 1 deletion .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '20'
cache: 'npm'
- run: npm install
- run: npm run docs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '20'

- run: npm install
- run: npm run test
Expand Down
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"trailingComma": "all",
"printWidth": 120,
"arrowParens": "always",
"endOfLine": "auto"
}
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SMARTy Pay Node SDK
Simple library for creating invoices on backend side
Simple library for creating payments on backend side

## Installation
```shell
Expand All @@ -8,50 +8,50 @@ npm i smartypay-node-sdk

## Usage

### Create invoice
### Create payment

[See docs](https://docs.smartypay.io/general/authentication#signing-requests)

```typescript
import {SmartyPayAPI} from 'smartypay-node-sdk';
import { SmartyPayAPI } from 'smartypay-node-sdk';

async function createInvoice() {
async function createPayment() {

// call API
const api = new SmartyPayAPI({
secretKey: 'YOUR_SECRET_KEY',
publicKey: 'YOUR_API_KEY',
});

const invoice = await api.invoices.createInvoice({
expiresAt: new Date(Date.now() + 1000 * 60 * 60), // after 1 hour from now
amount: '1.99',
token: 'bUSDT',
metadata: 'YOUR_PURCHASE_ID' // optional
const payment = await api.payments.createPayment({
amount: {
value: '1',
currency: 'bUSDT',
},
expiresAt: new Date(Date.now() + 1000 * 60 * 60), // optional: after 1 hour from now
metadata: { orderId: 'YOUR_PURCHASE_ID' } // optional: any metadata
});

// result invoice id
const invoiceId = invoice.id;

// params to open invoice
const params = new URLSearchParams();
params.set('invoice-id', invoiceId);

// result payment id
const paymentId = payment.id;

// additional params:
const params = new URLSearchParams();
// params.set('name', 'Item Name to Buy');
// params.set('success-url', 'https://...');
// params.set('fail-url', 'https://...');

// final url be like "https://checkout.smartypay.io/invoice?invoice-id=XXXXXXX"
const urlToRedirect = 'https://checkout.smartypay.io/invoice?' + params.toString();
// final url be like "https://checkout.smartypay.io/XXXXXXX?..."
const urlToRedirect = 'https://checkout.smartypay.io/' + paymentId + '?' + params.toString();
}
```
- **expiresAt** - date before invoice is active
- **amount** - amount for invoice (example 0.99)
- **token** - see valid tokens here: https://docs.smartypay.io/general/supported-tokens
- **metadata** - optional field for any custom metadata (usually it's your own purchase id for success webhook)
- **secretKey** - you can get it here: https://dashboard.smartypay.io/
- **publicKey** - you can get it here: https://dashboard.smartypay.io/
- **amount** - Amount for a payment (value and currency token). See valid tokens here: https://docs.smartypay.io/general/supported-tokens
- **expiresAt** - Optional: date before payment is active
- **metadata** - Optional: key-value for any custom metadata (usually it's your own purchase id for success webhook)

Api common config:
- **secretKey** - You can get it here: https://dashboard.smartypay.io/
- **publicKey** - You can get it here: https://dashboard.smartypay.io/


### Create client's recharge address
Expand All @@ -78,10 +78,12 @@ async function createRechargeAddress(customerId: string) {
const rechargeAddress = resp.address;
}
```
- **token** - see valid tokens here: https://docs.smartypay.io/general/supported-tokens
- **customerId** - customer's id from your own system
- **secretKey** - you can get it here: https://dashboard.smartypay.io/
- **publicKey** - you can get it here: https://dashboard.smartypay.io/
- **token** - See valid tokens here: https://docs.smartypay.io/general/supported-tokens
- **customerId** - Customer's id from your own system

Api common config:
- **secretKey** - You can get it here: https://dashboard.smartypay.io/
- **publicKey** - You can get it here: https://dashboard.smartypay.io/

### Check webhook signature

Expand Down
15 changes: 4 additions & 11 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const esbuild = require('esbuild');
const { dtsPlugin } = require("esbuild-plugin-d.ts");
const { dtsPlugin } = require('esbuild-plugin-d.ts');

const libDest = 'dist/esbuild/smartypay-node-sdk.js';
const cliDest = 'dist/esbuild/smartypay-cli.js';

async function build(){

async function build() {
// lib
await esbuild.build({
logLevel: 'info',
Expand All @@ -15,12 +14,9 @@ async function build(){
sourcemap: 'external',
platform: 'node',
outfile: libDest,
plugins: [
dtsPlugin()
]
plugins: [dtsPlugin()],
});


// cli
await esbuild.build({
logLevel: 'info',
Expand All @@ -31,12 +27,9 @@ async function build(){
platform: 'node',
outfile: cliDest,
});

}


build().catch((e) => {
console.error('build error', e);
process.exit(1)
process.exit(1);
});

Loading

0 comments on commit 5c26808

Please sign in to comment.