npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@svton/nestjs-payment

v1.2.0

Published

NestJS payment module with WeChat Pay and Alipay support

Readme

@svton/nestjs-payment

NestJS 支付模块,支持微信支付和支付宝。

安装

pnpm add @svton/nestjs-payment

使用

模块注册

import { Module } from '@nestjs/common';
import { PaymentModule } from '@svton/nestjs-payment';

@Module({
  imports: [
    PaymentModule.forRoot({
      wechat: {
        appId: 'wx...',
        mchId: '商户号',
        privateKey: '-----BEGIN PRIVATE KEY-----\n...',
        serialNo: '证书序列号',
        apiV3Key: 'APIv3密钥',
        notifyUrl: 'https://your-domain.com/pay/wechat/notify',
      },
      alipay: {
        appId: '支付宝应用ID',
        privateKey: '-----BEGIN PRIVATE KEY-----\n...',
        alipayPublicKey: '-----BEGIN PUBLIC KEY-----\n...',
        notifyUrl: 'https://your-domain.com/pay/alipay/notify',
      },
    }),
  ],
})
export class AppModule {}

微信支付

import { Controller, Post, Body } from '@nestjs/common';
import { PaymentService } from '@svton/nestjs-payment';

@Controller('pay')
export class PayController {
  constructor(private readonly paymentService: PaymentService) {}

  // JSAPI 支付 (小程序/公众号)
  @Post('wechat/jsapi')
  async wechatJsapi(@Body() body: { orderId: string; openid: string }) {
    const result = await this.paymentService.wechat.createOrder({
      outTradeNo: body.orderId,
      totalAmount: 100, // 1 元 = 100 分
      description: '商品描述',
      userId: body.openid,
    }, 'jsapi');

    return result.prepayData; // 返回给前端调起支付
  }

  // Native 支付 (扫码)
  @Post('wechat/native')
  async wechatNative(@Body() body: { orderId: string }) {
    const result = await this.paymentService.wechat.createOrder({
      outTradeNo: body.orderId,
      totalAmount: 100,
      description: '商品描述',
    }, 'native');

    return { codeUrl: result.codeUrl }; // 生成二维码
  }
}

支付宝

@Controller('pay')
export class PayController {
  // 电脑网站支付
  @Post('alipay/page')
  async alipayPage(@Body() body: { orderId: string }) {
    const result = await this.paymentService.alipay.createOrder({
      outTradeNo: body.orderId,
      totalAmount: 100,
      description: '商品描述',
    }, 'page');

    return { formHtml: result.formHtml }; // 返回表单 HTML
  }
}

回调通知

@Controller('pay')
export class PayController {
  @Post('wechat/notify')
  async wechatNotify(@Headers() headers: any, @Body() body: string) {
    const notification = this.paymentService.wechat.verifyNotification(headers, body);
    if (!notification) {
      return { code: 'FAIL', message: '签名验证失败' };
    }

    // 处理支付成功逻辑
    await this.orderService.handlePaid(notification.outTradeNo);

    return { code: 'SUCCESS' };
  }

  @Post('alipay/notify')
  async alipayNotify(@Body() body: Record<string, string>) {
    const notification = this.paymentService.alipay.verifyNotification(body);
    if (!notification) {
      return 'fail';
    }

    await this.orderService.handlePaid(notification.outTradeNo);
    return 'success';
  }
}

支付类型

微信支付

| 类型 | 说明 | |------|------| | jsapi | JSAPI 支付 (公众号/小程序) | | native | Native 支付 (扫码) | | app | APP 支付 | | h5 | H5 支付 |

支付宝

| 类型 | 说明 | |------|------| | page | 电脑网站支付 | | wap | 手机网站支付 | | app | APP 支付 |

License

MIT