Skip to content

Commit

Permalink
bump to v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Simen Li committed May 16, 2022
1 parent 20df78b commit d27609b
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 85 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A production-ready 綠界全方位金流(ECPay All-In-One, AIO) SDK for Node.js with TypeScript Support

[![build](https://github.com/simenkid/node-ecpay-aio/actions/workflows/build.yml/badge.svg)](https://github.com/simenkid/node-ecpay-aio/actions/workflows/build.yml)
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/simenkid/6cd8ec3f4115bc7b0fc0cb646da2dd77/raw/d473b387740594dc486c5b8032ad8ba7adb7b91b/node-ecpay-aio__heads_main.json)
![Coverage Badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/simenkid/6cd8ec3f4115bc7b0fc0cb646da2dd77/raw/37458fd300efcea7ef2d3adbc4598e47a76a34d9/node-ecpay-aio__heads_main.json)
[![npm](https://img.shields.io/npm/v/node-ecpay-aio.svg?cacheSeconds=3600)](https://www.npmjs.com/package/node-ecpay-aio)
[![npm](https://img.shields.io/npm/l/node-ecpay-aio.svg?cacheSeconds=3600)](https://github.com/simenkid/node-ecpay-aio/blob/main/LICENSE)
[![node version](https://img.shields.io/node/v/node-ecpay-aio)](https://img.shields.io/node/v/node-ecpay-aio)
Expand Down Expand Up @@ -65,3 +65,7 @@ npm install --save node-ecpay-aio
## License

Licensed under [MIT](https://github.com/simenkid/node-ecpay-aio/blob/main/LICENSE).

<br />
<br />
<br />
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-ecpay-aio",
"version": "0.1.9",
"version": "0.2.0",
"description": "A production-ready ECPay AIO SDK for Node.js with TypeScript support.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/Merchant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
TradeV2Query,
FundingReconDetailQuery,
} from '../feature/Query';

import { CreditCardPeriodAction, DoAction } from '../feature/Action';
import { ECPayServiceUrls } from '../config';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from './test_setting';
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/Payment.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ts-nocheck

import { Merchant } from '../feature/Merchant';
import { CreditOneTimePayment } from '../feature/Payment';
import { TEST_MERCHANT_CONFIG } from './test_setting';
Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/payments/ALLPayPayment.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ts-nocheck
import { Merchant } from '../../feature/Merchant';
import { ALLPayment } from '../../feature/Payment';
import { getCurrentTaipeiTimeString } from '../../utils';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from '../test_setting';

describe('AndroidPayment: Check Params Types', () => {
Expand Down Expand Up @@ -119,3 +120,22 @@ describe('AndroidPayment: Check Params Types', () => {
}).toThrowError('must be less than or equal to 999');
});
});

describe('ALLPayment: Redirect Post Form', () => {
const merchant = new Merchant('Test', TEST_MERCHANT_CONFIG);

const baseParams: BasePaymentParams = {
MerchantTradeNo: `nea${getCurrentTaipeiTimeString({ format: 'Serial' })}`,
MerchantTradeDate: getCurrentTaipeiTimeString(),
TotalAmount: 999,
TradeDesc: 'node-ecpay-aio testing order for ALLPayment',
ItemName: 'test item name',
};

test('Checkout with ', async () => {
const payment = merchant.createPayment(ALLPayment, baseParams, {});

const html = await payment.checkout();
expect(html.startsWith('<form id="_form_aio_checkout"')).toBe(true);
});
});
2 changes: 1 addition & 1 deletion src/__tests__/payments/ATMPayment.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@ts-nocheck
import { Merchant } from '../../feature/Merchant';
import { ATMPayment } from '../../feature/Payment';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from '../test_setting';
import { getCurrentTaipeiTimeString } from '../../utils';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from '../test_setting';

const MERCHANT_CONFIG_ASYNC = {
...TEST_MERCHANT_CONFIG,
Expand Down
22 changes: 22 additions & 0 deletions src/__tests__/payments/CreditDividePayment.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ts-nocheck
import { Merchant } from '../../feature/Merchant';
import { CreditDividePayment } from '../../feature/Payment';
import { getCurrentTaipeiTimeString } from '../../utils';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from '../test_setting';

describe('CreditDividePayment: Check Params Types', () => {
Expand All @@ -24,3 +25,24 @@ describe('CreditDividePayment: Check Params Types', () => {
}).toThrowError('must be one of');
});
});

describe('CreditDividePayment: Redirect Post Form', () => {
const merchant = new Merchant('Test', TEST_MERCHANT_CONFIG);

const baseParams: BasePaymentParams = {
MerchantTradeNo: `nea${getCurrentTaipeiTimeString({ format: 'Serial' })}`,
MerchantTradeDate: getCurrentTaipeiTimeString(),
TotalAmount: 999,
TradeDesc: 'node-ecpay-aio testing order for CreditDividePayment',
ItemName: 'test item name',
};

test('Checkout with ', async () => {
const payment = merchant.createPayment(CreditDividePayment, baseParams, {
CreditInstallment: '3',
});

const html = await payment.checkout();
expect(html.startsWith('<form id="_form_aio_checkout"')).toBe(true);
});
});
50 changes: 20 additions & 30 deletions src/__tests__/payments/CreditOneTimePayment.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ts-nocheck
import { Merchant } from '../../feature/Merchant';
import { CreditOneTimePayment } from '../../feature/Payment';
import { getCurrentTaipeiTimeString } from '../../utils';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from '../test_setting';

describe('CreditOneTimePayment: Check Credit Base Params Types', () => {
Expand Down Expand Up @@ -58,36 +59,25 @@ describe('CreditOneTimePayment: Check Credit Base Params Types', () => {
});
});

// describe('CreditOneTimePayment: html', () => {
// const merchant = new Merchant('Test', TEST_MERCHANT_CONFIG);
describe('CreditOneTimePayment: Redirect Post Form', () => {
const merchant = new Merchant('Test', TEST_MERCHANT_CONFIG);

// const baseParams = {
// MerchantTradeNo: 'nodeecpayaio0011',
// MerchantTradeDate: '2021/05/22 11:20:20',
// TotalAmount: 999,
// TradeDesc: 'node-ecpay-aio testing order for CreditOneTimePayment',
// ItemName: 'test item name',
// };
const baseParams: BasePaymentParams = {
MerchantTradeNo: `nea${getCurrentTaipeiTimeString({ format: 'Serial' })}`,
MerchantTradeDate: getCurrentTaipeiTimeString(),
TotalAmount: 999,
TradeDesc: 'node-ecpay-aio testing order for CreditOneTimePayment',
ItemName: 'test item name',
};

// test('Checkout with ', async () => {
// const payment = merchant.createPayment(
// CreditOneTimePayment,
// baseParams,
// {}
// );
test('Checkout with ', async () => {
const payment = merchant.createPayment(
CreditOneTimePayment,
baseParams,
{}
);

// const html = await payment.checkout({
// RelateNumber: 'rl-no',
// TaxType: '1',
// Donation: '0',
// Print: '0',
// InvoiceItemName: 'item1|item2',
// InvoiceItemCount: '2|5',
// InvoiceItemWord: '台|張',
// InvoiceItemPrice: '100|50',
// InvoiceRemark: '測試發票備註',
// CustomerPhone: '0911111111',
// });
// console.log(html);
// });
// });
const html = await payment.checkout();
expect(html.startsWith('<form id="_form_aio_checkout"')).toBe(true);
});
});
22 changes: 6 additions & 16 deletions src/__tests__/payments/CreditPeriodPayment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Merchant } from '../../feature/Merchant';
import { CreditPeriodPayment } from '../../feature/Payment';
import { BasePaymentParamsSchema } from '../../schema';
import { getCurrentTaipeiTimeString } from '../../utils';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from '../test_setting';

const MERCHANT_CONFIG_PERIOD_CREDIT = {
Expand Down Expand Up @@ -336,12 +337,12 @@ describe('PeriodType="Y": Check Params Constraints', () => {
});
});

describe('CreditPeriodPayment: html', () => {
describe('CreditPeriodPayment: Redirect Post Form', () => {
const merchant = new Merchant('Test', TEST_MERCHANT_CONFIG);

const baseParams: BasePaymentParams = {
MerchantTradeNo: 'necacc0001',
MerchantTradeDate: '2022/05/13 15:33:20',
MerchantTradeNo: `nea${getCurrentTaipeiTimeString({ format: 'Serial' })}`,
MerchantTradeDate: getCurrentTaipeiTimeString(),
TotalAmount: 999,
TradeDesc: 'node-ecpay-aio testing order for CreditPeriodPayment',
ItemName: 'test item name',
Expand All @@ -355,19 +356,8 @@ describe('CreditPeriodPayment: html', () => {
ExecTimes: 99,
// PeriodReturnURL: 'https://ap.example.com/api',
});

const html = await payment.checkout();
// const html = await payment.checkout({
// RelateNumber: 'rl-no-1',
// TaxType: '1',
// Donation: '0',
// Print: '0',
// InvoiceItemName: 'item1|item2',
// InvoiceItemCount: '2|5',
// InvoiceItemWord: '台|張',
// InvoiceItemPrice: '100|50',
// InvoiceRemark: '測試發票備註',
// CustomerPhone: '0911111111',
// });
// console.log(html);
expect(html.startsWith('<form id="_form_aio_checkout"')).toBe(true);
});
});
20 changes: 20 additions & 0 deletions src/__tests__/payments/WebATMPayment.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ts-nocheck
import { Merchant } from '../../feature/Merchant';
import { WebATMPayment } from '../../feature/Payment';
import { getCurrentTaipeiTimeString } from '../../utils';
import { TEST_MERCHANT_CONFIG, TEST_BASE_PARAMS } from '../test_setting';

describe('WebATMPayment: Check Params Types', () => {
Expand All @@ -13,3 +14,22 @@ describe('WebATMPayment: Check Params Types', () => {
}).not.toThrowError();
});
});

describe('WebATMPayment: Redirect Post Form', () => {
const merchant = new Merchant('Test', TEST_MERCHANT_CONFIG);

const baseParams: BasePaymentParams = {
MerchantTradeNo: `nea${getCurrentTaipeiTimeString({ format: 'Serial' })}`,
MerchantTradeDate: getCurrentTaipeiTimeString(),
TotalAmount: 999,
TradeDesc: 'node-ecpay-aio testing order for WebATMPayment',
ItemName: 'test item name',
};

test('Checkout with ', async () => {
const payment = merchant.createPayment(WebATMPayment, baseParams, {});

const html = await payment.checkout();
expect(html.startsWith('<form id="_form_aio_checkout"')).toBe(true);
});
});
8 changes: 4 additions & 4 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,26 @@ describe('Query String', () => {
});

describe('getCurrentTaipeiTimeString', () => {
const timestamp = 1652577669234;
const timestamp = 1652693484763;

test('Get datetime string', () => {
const tpeDatetime = getCurrentTaipeiTimeString({ timestamp });
expect(tpeDatetime).toEqual('2022/05/15 09:21:38');
expect(tpeDatetime).toEqual('2022/05/16 17:31:24');
});

test('Get date string', () => {
const tpeDatetime = getCurrentTaipeiTimeString({
timestamp,
format: 'Date',
});
expect(tpeDatetime).toEqual('2022/05/15');
expect(tpeDatetime).toEqual('2022/05/16');
});

test('Get serial time string', () => {
const tpeDatetime = getCurrentTaipeiTimeString({
timestamp,
format: 'Serial',
});
expect(tpeDatetime).toEqual('20220518172109234');
expect(tpeDatetime).toEqual('20220516173124763');
});
});
3 changes: 1 addition & 2 deletions src/feature/Action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Merchant } from './Merchant';
import { ActionError, CheckMacValueError } from './Error';
import {
generateCheckMacValue,
getCurrentUnixTimestampOffset,
Expand All @@ -11,13 +12,11 @@ import {
DoActionParamsSchema,
} from '../schema';
import {
ActionResponseData,
CreditCardPeriodActionParams,
CreditCardPeriodActionResponseData,
DoActionParams,
DoActionResponseData,
} from '../types';
import { ActionError, CheckMacValueError } from './Error';

export class Action<T> {
merchant: Merchant;
Expand Down
5 changes: 1 addition & 4 deletions src/feature/Payment.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { request, get } from 'https';
import { Merchant } from './Merchant';
import { PaymentInfoQuery } from './Query';
import {
generateCheckMacValue,
generateRedirectPostForm,
getEncodedInvoice,
placeOrderRequest,
getQueryStringFromParams,
// PlaceCachedOrderRequest,
} from '../utils';
import {
ALLPaymentParamsSchema,
Expand Down Expand Up @@ -37,7 +35,6 @@ import {
ECPayPaymentType,
PaymentInfoData,
} from '../types';
import { PaymentInfoQuery } from './Query';

export class Payment<T> {
merchant: Merchant;
Expand Down
2 changes: 1 addition & 1 deletion src/feature/Query.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Merchant } from './Merchant';
import { CheckMacValueError, QueryError } from './Error';
import {
generateCheckMacValue,
getCurrentUnixTimestampOffset,
Expand All @@ -24,7 +25,6 @@ import {
TradeInfoData,
TradeV2Data,
} from '../types';
import { CheckMacValueError, QueryError } from './Error';

const QUERY_RESULT_BASE_INT_FIELDS = [
'TradeAmt',
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export {
FundingReconDetailQuery,
} from './feature/Query';

export {
QueryError,
ActionError,
CheckMacValueError,
PlaceOrderError,
} from './feature/Error';

export { CreditCardPeriodAction, DoAction } from './feature/Action';

export { getCurrentTaipeiTimeString } from './utils';
export {
getCurrentTaipeiTimeString,
isValidReceivedCheckMacValue,
} from './utils';
Loading

0 comments on commit d27609b

Please sign in to comment.