# @leaf-x/we-chat-pay

> WeChat payment V3.0.0 API.

Latest version **1.3.3** (published 2021-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @leaf-x/we-chat-pay
pnpm add @leaf-x/we-chat-pay
yarn add @leaf-x/we-chat-pay
bun add @leaf-x/we-chat-pay
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2021-06-01 |
| First published | 2021-04-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=11.0.0 |
| Dependencies | 4 |
| Unpacked size | 51.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | sound shell |
| Maintainers | sound_shell |

## Links

- npm: https://www.npmjs.com/package/@leaf-x/we-chat-pay
- Repository: https://github.com/SoundShell/leaf-x-weChat-pay
- Homepage: https://github.com/SoundShell/leaf-x-weChat-pay#readme
- Issues: https://github.com/SoundShell/leaf-x-weChat-pay/issues
- npm.io page: https://npm.io/package/@leaf-x/we-chat-pay

## Dependencies (4)

- [@fidm/x509](https://npm.io/package/@fidm/x509.md) ^1.2.1
- [@leaf-x/fetch](https://npm.io/package/@leaf-x/fetch.md) ^1.4.9
- [camelcase-keys](https://npm.io/package/camelcase-keys.md) ^6.2.2
- [snakecase-keys](https://npm.io/package/snakecase-keys.md) ^3.2.1

## Recent versions

- 1.3.3 (latest) — 2021-06-01
- 1.3.2 — 2021-05-26
- 1.3.1 — 2021-05-25
- 1.3.0 — 2021-05-21
- 1.2.3 — 2021-05-17
- 1.2.2 — 2021-05-14
- 1.2.1 — 2021-05-13
- 1.2.0 — 2021-05-12
- 1.1.0 — 2021-05-11
- 1.0.6 — 2021-05-11
- 1.0.5 — 2021-05-11
- 1.0.4 — 2021-05-10
- 1.0.3 — 2021-05-10
- 1.0.2 — 2021-05-08
- 1.0.1 — 2021-05-08
- … 15 more at https://npm.io/package/@leaf-x/we-chat-pay/versions

## README

# WeChatPay

WeChat pay V3 API.

## Installation

> npm install @leaf-x/we-chat-pay --save

## Parameters

| Name                  | Type   | Default Value                 | Description                       |
| :-------------------- | :----- | :---------------------------- | :-------------------------------- |
| appId                 | String |                               | WeChat app ID.                    |
| publicAppId           | String |                               | WeChat public ID.                 |
| merchantId            | String | Required                      | Merchant ID.                      |
| merchantKey           | String | Required                      | Merchant key.                     |
| schema                | string | WECHATPAY2-SHA256-RSA2048     | Encryption algorithm mode.        |
| privateKey            | String | Required                      | Private key.                      |
| publicCertificatePath | String |                               | Public key certificate path.      |
| publicCertificateDir  | String |                               | Public key certificate directory. |
| serialNo              | String | Required                      | Certificate number.               |
| url                   | String | https://api.mch.weixin.qq.com | Api url address.                  |
| timeout               | Number | 3000                          | Timeout time, in milliseconds.    |

## Use

```typescript
import {weChat} from '@leaf-x/we-chat-pay';

const pay = weChat({
  appId: 'wx3fb4x113xx8i',
  merchantId: '2362183',
  merchantKey: '123db752cf2c6955122d26d5',
  serialNo: '6D22333S311033394317A3332C444F31112371F',
  privateKey: fs.readFileSync(
    path.join(__dirname, '../public/certificate/private_key.pem'),
    'ascii'
  ),
  publicCertificateDir: path.join(__dirname, '../public/certificate/we_chat'),
});

const result = await pay.getAppPay({
  description: 'test',
  outTradeNo: '2133455555111233567',
  timeExpire: new Date(),
  notifyUrl: 'https://dev.api.leaf-x.com/v3/notifies',
  amount: {total: 1, currency: 'CNY'},
  sceneInfo: {payerClientIp: '127.0.0.0'},
});

console.info(result);
```

---
_Source: https://npm.io/package/@leaf-x/we-chat-pay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
