Skip to content

Latest commit

 

History

History
147 lines (102 loc) · 3.47 KB

README.md

File metadata and controls

147 lines (102 loc) · 3.47 KB

WeChat Pay Node SDK

WIP

A flexible and lightweight SDK for integrating WeChat Pay with dynamic endpoints, caching, and response transformations.

npm GitHub GitHub issues GitHub pull requests


Features

  • Pre-configured API endpoints for WeChat Pay
  • Support for Redis and in-memory caching
  • Easy extensibility

Table of Contents


Installation

Install the SDK using pnpm or yarn:

pnpm add @nuecms/wepay-sdk
# or
yarn add @nuecms/wepay-sdk

Quick Start

1. Import and Initialize the SDK Builder

import { wxPaySdk } from '@nuecms/wepay-sdk';

const sdk = wxPaySdk({
  appId: string;
  appSecret: string;
  mchId: string;
  publicKey: string;
  privateKey: string;
  secretKey: string;
  cacheProvider: CacheProvider;
});

2. Register API Endpoints

sdk.r('createOrder', '/v3/pay/transactions/jsapi', 'POST');
sdk.r('queryOrder', '/v3/pay/transactions/id/{transaction_id}', 'GET');

3. Make API Calls

const order = await sdk.createOrder({ ...orderDetails });
console.log(order);

4. Signature with API calls

const sdk = wxPaySdk({
  appId: string;
  appSecret: string;
  mchId: string;
  publicKey: string;
  privateKey: string;
  secretKey: string;
});

More

See the testing code in tests folder

Example:


Usage Examples

Registering Endpoints

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');

Making API Calls

Call the registered endpoints dynamically with placeholders and additional options:

const orderDetails = await sdk.createOrder({ ...orderData });

console.log(orderDetails);

Contributing

We welcome contributions to improve this SDK! To get started:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-name).
  3. Commit your changes (git commit -m "Add feature X").
  4. Push to the branch (git push origin feature-name).
  5. Open a pull request.

License

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.