@gizwits/react-native-wechat-lib-harmony
v0.1.0
Published
HarmonyOS payment implementation for react-native-wechat-lib (RNOH 0.82)
Keywords
Readme
@gizwits/react-native-wechat-lib-harmony
Payment-only HarmonyOS companion for react-native-wechat-lib. Version 0.1.0 targets RN 0.82 / RNOH 0.82.30 and HarmonyOS API 13+. Uses the pinned official @tencent/[email protected] OHPM dependency.
Integration
Install this package alongside the original npm dependency. Keep createHarmonyMetroConfig enabled; harmony.alias redirects the original import only on HarmonyOS. Do not replace the Android/iOS dependency or add a global Metro alias.
import * as WeChat from 'react-native-wechat-lib';
await WeChat.registerApp(appId, universalLink);
const installed = await WeChat.isWXAppInstalled();
const response = await WeChat.pay(serverPaymentParameters);
// response.errCode === 0 is an SDK hint, NOT proof that the server credited an order.Run RNOH autolinking and ohpm install. Both ArkTS and C++ registrations are provided. Add weixin and wxopensdk to the entry module's querySchemes (retain https). Forward both EntryAbility.onCreate and onNewWant to WechatBridge.handleWant(want) after calling their super implementations:
import { WechatBridge } from '@gizwits/react-native-wechat-lib-harmony';
// Inside BOTH lifecycle methods:
WechatBridge.handleWant(want);The callback ability must be exported and match pay({ callbackAbility }), default EntryAbility. Configure the mobile AppID's Harmony bundle name and app Identifier on WeChat Open Platform; Android package/signature configuration is not a substitute. universalLink is accepted for compatibility but unused on HarmonyOS.
Contract and limitations
- Implemented:
registerApp,isWXAppInstalled,pay,WechatError. - Payment accepts camelCase and legacy lowercase keys, including
paySign; timestamp becomes a string andpackagedefaults toSign=WXPay. payresolves only for SDKerrCode: 0; otherwise rejectsWechatErrorwith numeric.code(including-2cancellation). Plugin errors use string codes such asE_BUSY,E_TIMEOUT,E_NOT_INSTALLED,E_APP_ID_MISMATCH.timeoutis seconds, 1–600, default 120. After timeout, the native session stays busy until the old SDK callback arrives. If no callback ever arrives, check the server order and restart the app before another payment. This avoids assigning a late result to a newer payment.- Matching callback transaction/prepay IDs are checked when supplied. Callbacks without a live request are not reported as successful payments. After process death, reconcile the order with the backend; a JS Promise cannot survive process death.
- Sharing, login, mini programs and event-listener APIs are not implemented in 0.1.0. They explicitly report
E_UNSUPPORTED; this is not a full API parity release. - No merchant private keys or signing logic belong in this package. Require consent/privacy disclosure before SDK use; include the vendor SDK's privacy requirements in the host app.
Development and packaging
npm run build:har packages a source HAR: the consuming app compiles ArkTS and C++. It is not a precompiled native binary. Vendor SDKs are downloaded by OHPM, not republished in this npm package. npm pack runs the same build automatically. This repository uses yarn payments:sync to refresh the two local file: dependencies after edits, followed by ohpm install in harmony.
The package has not been published. UNLICENSED is intentional pending the owner's release/license decision. Confirm namespace rights, license and real-device acceptance before publishing.
Sources: official SDK package, WeChat APP SDK integration, APP payment.
