Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A module built with [Expo Modules](https://docs.expo.dev/modules/overview/) that provides wallet features for iOS and Android.

Uses [PassKit](https://developer.apple.com/documentation/passkit/wallet) on iOS, [Google Wallet API](https://developers.google.com/wallet/generic) on Android.
Uses [PassKit](https://developer.apple.com/documentation/passkit/wallet) on iOS, [Google Wallet API](https://developers.google.com/wallet/generic) on Android. This now supports both signed and unsigned JWTs for Android.

<img src="https://github.com/premieroctet/react-native-wallet/assets/11079152/ef45634f-a671-403d-b7dd-211af2d612b8" width="300" height="auto" />
<img src="https://github.com/premieroctet/react-native-wallet/assets/11079152/5c27516d-37b8-434e-b8e9-7731cca0a5ee" width="300" height="auto" />
Expand Down Expand Up @@ -88,7 +88,8 @@ export default function App() {
#### Methods

- `canAddPasses(): boolean`: Check if the device can add passes.
- `addPass(urlOrToken: string): Promise<boolean>`: Add a pass to the wallet. Returns `true` if the pass was added or if its already added. Returns `false` if the user cancelled the operation. `urlOrToken` should be the pkpass URL for iOS, and the pass JWT for Android.
- `addPass(urlOrToken: string): Promise<boolean>`: Add a pass to the wallet. Returns `true` if the pass was added or if its already added. Returns `false` if the user cancelled the operation. `urlOrToken` should be the pkpass URL for iOS, and the **unsigned** pass JWT for Android. [Read more here](https://developers.google.com/wallet/generic/android#add-a-pass)
- `addPassWithSignedJwt(signedJwt: string): Promise<boolean>`: Add a pass to the wallet using a signed JWT. Returns `true` if the pass was added or if its already added. Returns `false` if the user cancelled the operation. This is for Android only. [Read more here](https://developers.google.com/wallet/generic/android#add-a-pass)
- `hasPass(urlOrToken: string): Promise<boolean>`: Check if a pass exists in the wallet. Returns `true` if the pass exists, `false` otherwise. On Android, this always returns `false`.
- `removePass(urlOrToken: string): Promise<void>`: Remove a pass from the wallet. On Android, this is no-op. On iOS, make sure you have the correct entitlements. See [documentation](https://developer.apple.com/documentation/passkit/pkpasslibrary/1617083-removepass#discussion).

Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ android {
compileSdkVersion safeExtGet("compileSdkVersion", 33)

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.majorVersion
jvmTarget = JavaVersion.VERSION_17.majorVersion
}

namespace "com.premieroctet.wallet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ class RNWalletModule : Module() {
addPassPromise = promise
}

AsyncFunction("addPassWithSignedJwt") { jwt: String, promise: Promise ->
if (appContext.currentActivity == null) {
promise.reject(CodedException("Current activity not found"))
return@AsyncFunction
}
walletClient.savePassesJwt(jwt, appContext.currentActivity!!, addToGoogleWalletRequestCode)
addPassPromise = promise
}

OnCreate {
if (appContext.reactContext != null) {
walletClient = Pay.getClient(appContext.reactContext!!.applicationContext)
Expand Down
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ export function addPass(urlOrToken: string): Promise<boolean> {
return RNWalletModule.addPass(urlOrToken);
}

/**
* @param signedJwt The signed JWT
* @returns boolean indicating if the pass was added
*
* @platform android
*/
export function addPassWithSignedJwt(signedJwt: string): Promise<boolean> {
if (Platform.OS !== "android") {
console.warn("RNWallet.addPassWithSignedJwt is only available on Android");
return Promise.resolve(false);
}

return RNWalletModule.addPassWithSignedJwt(signedJwt);
}

/**
* @param url The pkpass file url
* @returns boolean indicating if the pass exists in the wallet
Expand Down
Loading