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

jupiter-payment

v1.0.0

Published

React Native 原生支付库:微信支付与 Apple Pay

Readme

jupiter-payment

React Native 原生支付库,支持 微信支付Apple Pay,两种支付方式均在 iOS/Android 原生层实现,可发布至 npm 供业务 App 集成。

功能

| 能力 | iOS | Android | |----------------|-----|---------| | 微信支付 | ✅ | ✅ | | Apple Pay | ✅ | ❌(仅 iOS) |

与后端对接说明

本库不包含任何后端请求,只负责调起原生支付界面并返回支付结果。以下必须由你们的后端完成:

  • 微信支付:后端调用微信「统一下单」拿到 prepayId、签名等参数,下发给 App;用户支付后,前端把结果(或订单号)回传后端,由后端查单 / 验签确认支付是否成功。
  • Apple Pay:用户在本库调起的界面内授权后,会得到 paymentToken;该 token 必须发给后端,由后端与支付渠道(如 Apple Pay、银联等)通信完成实际扣款与校验。

建议流程(以微信为例):先请求后端预下单 → 拿到参数 → 调本库调起支付 → 收到结果后再请求后端查单/确认。下面示例里用 yourBackendApi 表示需要你自己实现的接口。

安装

npm install jupiter-payment
# 或
yarn add jupiter-payment

链接原生依赖

iOS

  1. 在项目根目录执行:
cd ios && pod install && cd ..
  1. 集成微信 SDK
    ios/Podfile 中增加(或使用 微信开放平台 官方集成方式):
pod 'WechatOpenSDK'
  1. 微信支付回调
    在 AppDelegate 的 application:openURL:options: 中调用:
#import <React/RCTLinkingManager.h>

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
  // 微信支付 / 微信登录 回调
  if ([url.scheme hasPrefix:@"wx"]) {
    return [RCTLinkingManager application:app openURL:url options:options];
  }
  return NO;
}

并在合适位置(例如在 RCTLinkingManager 处理前或后)通知本库处理微信 URL,例如通过 RCTBridge 取到 JupiterPayment 模块并调用 handleWeChatOpenURL。若你使用 RCTLinkingManager 处理 wx scheme,需确保本库能收到同一 URL(例如在 AppDelegate 里先调本库再调 RCTLinkingManager,具体以你现有微信回调逻辑为准)。

  1. Apple Pay
    • 在 Apple Developer 后台创建 Merchant ID、配置 Apple Pay。
    • Xcode 中为 App 勾选 Apple Pay 能力并选择该 Merchant ID。

Android

  1. 集成微信 SDK
    在宿主 App 的 android/build.gradleapp/build.gradledependencies 中增加:
implementation 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.0'
  1. 注册包
    MainApplicationgetPackages() 中已通过 react-native link 自动添加本库;若未自动链接,请手动加入:
import com.jupiterpayment.JupiterPaymentPackage;

// 在 getPackages() 中:
packages.add(new JupiterPaymentPackage());
  1. 微信支付回调
    微信会回调到你在微信开放平台配置的包名+类名(如 WXPayEntryActivity)。在该 Activity 的 onResp 中,任选一种方式回传结果给本库:

    • 方式 A:发 Broadcast(推荐)
// 在 WXPayEntryActivity 收到微信 onResp 后:
val intent = Intent("com.jupiterpayment.WECHAT_PAY_RESULT")
intent.putExtra("errCode", resp.errCode)
intent.putExtra("errStr", resp.errStr)
sendBroadcast(intent)
  • 方式 B:直接调 Module
    若能从当前 Context 拿到 ReactApplicationContext,可获取 JupiterPaymentModule 并调用 deliverWeChatPayResult(errCode, errStr)

使用示例

微信支付(含与后端配合的完整流程)

import { isWeChatInstalled, payWithWeChat } from 'jupiter-payment';

async function doWeChatPay(orderId: string, amount: number) {
  const installed = await isWeChatInstalled();
  if (!installed) {
    alert('请先安装微信');
    return;
  }

  // 1. 请求后端:预下单,拿到微信支付参数(后端调微信统一下单 API)
  const { payParams } = await yourBackendApi.createWeChatOrder({ orderId, amount });
  // payParams: { appId, partnerId, prepayId, nonceStr, timeStamp, package, sign }

  // 2. 调起微信支付(本库只做这一步,不请求后端)
  const result = await payWithWeChat(payParams);

  // 3. 根据结果再请求后端:查单 / 确认支付(后端查单或验签,再更新订单状态)
  if (result.errCode === 0) {
    await yourBackendApi.confirmWeChatOrder({ orderId });
    // 或后端用 orderId 主动查单
  } else {
    // 用户取消或失败,可通知后端或仅做 UI 提示
  }
}

仅调起微信支付(参数由后端下发)

import { isWeChatInstalled, payWithWeChat } from 'jupiter-payment';

// 1. 可选:检查是否安装微信
const installed = await isWeChatInstalled();

// 2. 由服务端预下单后拿到以下参数,再调起支付
const result = await payWithWeChat({
  appId: 'wx...',
  partnerId: '...',
  prepayId: '...',
  nonceStr: '...',
  timeStamp: '...',
  package: 'Sign=WXPay',
  sign: '...',
});

// result: { errCode: number; errStr?: string }
// errCode 0 表示用户支付成功;其余为取消或失败,见微信文档。
// 注意:拿到 result 后仍需请求后端查单/确认,不要仅凭 errCode 就认为已到账。

Apple Pay(仅 iOS)

import { isApplePaySupported, payWithApplePay } from 'jupiter-payment';

const supported = await isApplePaySupported();
if (!supported) return;

const result = await payWithApplePay({
  merchantId: 'merchant.com.yourapp',
  countryCode: 'CN',
  currencyCode: 'CNY',
  paymentItems: [
    { label: '商品名称', amount: '0.01' },
    { label: '小费', amount: '0.00', isPending: true },
  ],
  supportedNetworks: ['visa', 'masterCard', 'chinaUnionPay'],
});

if (result.success && result.paymentToken) {
  // 将 paymentToken 发给服务端完成扣款与验证(必须由后端调支付渠道)
  await yourBackendApi.completeApplePay({ paymentToken: result.paymentToken });
}

iOS 微信回调(AppDelegate)

若你在 JS 侧或原生侧统一处理链接,需要把微信 URL 交给本库时,可调用:

import { handleWeChatOpenURL } from 'jupiter-payment';

// 在 AppDelegate 收到 URL 后,从 JS 侧调用(需能拿到该 URL):
handleWeChatOpenURL(url.toString());

通常更推荐在 AppDelegate 中直接使用原生模块 JupiterPayment.handleWeChatOpenURL(urlString),确保从系统回调到本库只走原生,避免依赖 JS 已就绪。

API 概览

  • isWeChatInstalled(): Promise<boolean>
  • payWithWeChat(params: WeChatPayParams): Promise<WeChatPayResult>
  • isApplePaySupported(): Promise<boolean>(iOS only)
  • payWithApplePay(params: ApplePayParams): Promise<ApplePayResult>(iOS only)
  • handleWeChatOpenURL(url: string): void(iOS,用于 AppDelegate 回调)

类型定义见 src/types.ts 或包导出类型。

发布到 npm

npm run build
npm login
npm publish

如需作用域包:npm publish --access public(如 @your-org/jupiter-payment)。

许可

MIT