WIP
A flexible and lightweight SDK for integrating WeChat Pay with dynamic endpoints, caching, and response transformations.
- Pre-configured API endpoints for WeChat Pay
- Support for Redis and in-memory caching
- Easy extensibility
Install the SDK using pnpm
or yarn
:
pnpm add @nuecms/wepay-sdk
# or
yarn add @nuecms/wepay-sdk
import { wxPaySdk } from '@nuecms/wepay-sdk';
const sdk = wxPaySdk({
appId: string;
appSecret: string;
mchId: string;
publicKey: string;
privateKey: string;
secretKey: string;
cacheProvider: CacheProvider;
});
sdk.r('createOrder', '/v3/pay/transactions/jsapi', 'POST');
sdk.r('queryOrder', '/v3/pay/transactions/id/{transaction_id}', 'GET');
const order = await sdk.createOrder({ ...orderDetails });
console.log(order);
const sdk = wxPaySdk({
appId: string;
appSecret: string;
mchId: string;
publicKey: string;
privateKey: string;
secretKey: string;
});
See the testing code in tests
folder
Example:
Register endpoints with their HTTP method, path, and dynamic placeholders (e.g., {transaction_id}
):
sdk.r('createOrder', '/v3/pay/transactions/jsapi', 'POST');
sdk.r('queryOrder', '/v3/pay/transactions/id/{transaction_id}', 'GET');
Call the registered endpoints dynamically with placeholders and additional options:
const orderDetails = await sdk.createOrder({ ...orderData });
console.log(orderDetails);
We welcome contributions to improve this SDK! To get started:
- Fork the repository.
- Create a new branch (
git checkout -b feature-name
). - Commit your changes (
git commit -m "Add feature X"
). - Push to the branch (
git push origin feature-name
). - Open a pull request.
This SDK is released under the MIT License. You’re free to use, modify, and distribute this project. See the LICENSE
file for more details.