@capawesome/capacitor-wallet 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorWallet.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +215 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/Wallet.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/WalletPlugin.java +78 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/classes/CustomExceptions.java +6 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/classes/options/SaveToGoogleWalletOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +157 -0
- package/dist/esm/definitions.d.ts +96 -0
- package/dist/esm/definitions.js +23 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +7 -0
- package/dist/esm/web.js +13 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +50 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +53 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Options/AddPassesOptions.swift +17 -0
- package/ios/Plugin/Classes/Results/CanAddPassesResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +34 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/ios/Plugin/Wallet.swift +53 -0
- package/ios/Plugin/WalletPlugin.swift +80 -0
- package/package.json +91 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapawesomeCapacitorWallet'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robin Genz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapawesomeCapacitorWallet",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapawesomeCapacitorWallet",
|
|
10
|
+
targets: ["WalletPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "WalletPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Plugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "WalletPluginTests",
|
|
25
|
+
dependencies: ["WalletPlugin"],
|
|
26
|
+
path: "ios/PluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# @capawesome/capacitor-wallet
|
|
2
|
+
|
|
3
|
+
Capacitor plugin for adding passes to [Apple Wallet](https://developer.apple.com/documentation/passkit) and [Google Wallet](https://developers.google.com/wallet).
|
|
4
|
+
|
|
5
|
+
<div class="capawesome-z29o10a">
|
|
6
|
+
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
|
+
</a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- 🍎 **Apple Wallet**: Add passes such as tickets, loyalty cards, coupons and boarding passes to Apple Wallet.
|
|
14
|
+
- 🤖 **Google Wallet**: Save passes to Google Wallet using the official "Save to Wallet" flow.
|
|
15
|
+
- ✅ **Availability check**: Check whether passes can be added on the current device before showing the UI.
|
|
16
|
+
- 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
|
|
17
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
18
|
+
|
|
19
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
20
|
+
|
|
21
|
+
## Newsletter
|
|
22
|
+
|
|
23
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
24
|
+
|
|
25
|
+
## Compatibility
|
|
26
|
+
|
|
27
|
+
| Plugin Version | Capacitor Version | Status |
|
|
28
|
+
| -------------- | ----------------- | -------------- |
|
|
29
|
+
| 0.x.x | >=8.x.x | Active support |
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
You can use our **AI-Assisted Setup** to install the plugin.
|
|
34
|
+
Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx skills add capawesome-team/skills --skill capacitor-plugins
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then use the following prompt:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-wallet` plugin in my project.
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npm install @capawesome/capacitor-wallet
|
|
50
|
+
npx cap sync
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
This plugin presents passes only. Passes must be **created and signed on your server**. See [Creating Passes](#creating-passes) below.
|
|
54
|
+
|
|
55
|
+
### iOS
|
|
56
|
+
|
|
57
|
+
Adding passes to Apple Wallet via `PKAddPassesViewController` does not require any special entitlement. The `com.apple.developer.pass-type-identifiers` entitlement is only needed if you want to read or manage passes that your app owns, which is out of scope for this plugin.
|
|
58
|
+
|
|
59
|
+
### Android
|
|
60
|
+
|
|
61
|
+
No additional permissions or Gradle variables are required. The plugin opens the Google Wallet "Save to Wallet" flow, which is handled by the Google Wallet app or the device's browser.
|
|
62
|
+
|
|
63
|
+
## Configuration
|
|
64
|
+
|
|
65
|
+
No configuration required for this plugin.
|
|
66
|
+
|
|
67
|
+
## Usage
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Wallet } from '@capawesome/capacitor-wallet';
|
|
71
|
+
|
|
72
|
+
const canAddPasses = async () => {
|
|
73
|
+
const { canAdd } = await Wallet.canAddPasses();
|
|
74
|
+
return canAdd;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const addPasses = async (passes: string[]) => {
|
|
78
|
+
// `passes` are base64-encoded `.pkpass` files that were signed on your server.
|
|
79
|
+
await Wallet.addPasses({ passes });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const saveToGoogleWallet = async (jwt: string) => {
|
|
83
|
+
// `jwt` is a signed Google Wallet JWT that was created on your server.
|
|
84
|
+
await Wallet.saveToGoogleWallet({ jwt });
|
|
85
|
+
};
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## API
|
|
89
|
+
|
|
90
|
+
<docgen-index>
|
|
91
|
+
|
|
92
|
+
* [`addPasses(...)`](#addpasses)
|
|
93
|
+
* [`canAddPasses()`](#canaddpasses)
|
|
94
|
+
* [`saveToGoogleWallet(...)`](#savetogooglewallet)
|
|
95
|
+
* [Interfaces](#interfaces)
|
|
96
|
+
|
|
97
|
+
</docgen-index>
|
|
98
|
+
|
|
99
|
+
<docgen-api>
|
|
100
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
101
|
+
|
|
102
|
+
### addPasses(...)
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
addPasses(options: AddPassesOptions) => Promise<void>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Add one or more passes to Apple Wallet.
|
|
109
|
+
|
|
110
|
+
The passes must be created and signed on your server. This method only
|
|
111
|
+
presents the system add-pass sheet with the provided passes.
|
|
112
|
+
|
|
113
|
+
Only available on iOS.
|
|
114
|
+
|
|
115
|
+
| Param | Type |
|
|
116
|
+
| ------------- | ------------------------------------------------------------- |
|
|
117
|
+
| **`options`** | <code><a href="#addpassesoptions">AddPassesOptions</a></code> |
|
|
118
|
+
|
|
119
|
+
**Since:** 0.1.0
|
|
120
|
+
|
|
121
|
+
--------------------
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### canAddPasses()
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
canAddPasses() => Promise<CanAddPassesResult>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Check whether passes can be added to Apple Wallet.
|
|
131
|
+
|
|
132
|
+
This may return `false` on some devices (e.g. certain iPads) or when adding
|
|
133
|
+
passes is restricted. Use this to gate the UI that triggers `addPasses`.
|
|
134
|
+
|
|
135
|
+
Only available on iOS.
|
|
136
|
+
|
|
137
|
+
**Returns:** <code>Promise<<a href="#canaddpassesresult">CanAddPassesResult</a>></code>
|
|
138
|
+
|
|
139
|
+
**Since:** 0.1.0
|
|
140
|
+
|
|
141
|
+
--------------------
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
### saveToGoogleWallet(...)
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
saveToGoogleWallet(options: SaveToGoogleWalletOptions) => Promise<void>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Save a pass to Google Wallet.
|
|
151
|
+
|
|
152
|
+
This opens the Google Wallet "Save to Wallet" flow using the provided JWT.
|
|
153
|
+
The JWT must be created and signed on your server.
|
|
154
|
+
|
|
155
|
+
**Note**: With the URL-based flow there is no completion signal, so the
|
|
156
|
+
promise resolves as soon as the flow is launched, not when the pass is
|
|
157
|
+
actually saved.
|
|
158
|
+
|
|
159
|
+
Only available on Android.
|
|
160
|
+
|
|
161
|
+
| Param | Type |
|
|
162
|
+
| ------------- | ------------------------------------------------------------------------------- |
|
|
163
|
+
| **`options`** | <code><a href="#savetogooglewalletoptions">SaveToGoogleWalletOptions</a></code> |
|
|
164
|
+
|
|
165
|
+
**Since:** 0.1.0
|
|
166
|
+
|
|
167
|
+
--------------------
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
### Interfaces
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
#### AddPassesOptions
|
|
174
|
+
|
|
175
|
+
| Prop | Type | Description | Since |
|
|
176
|
+
| ------------ | --------------------- | --------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
177
|
+
| **`passes`** | <code>string[]</code> | The passes to add to Apple Wallet. Each entry must be a base64-encoded `.pkpass` file that was signed on your server. | 0.1.0 |
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
#### CanAddPassesResult
|
|
181
|
+
|
|
182
|
+
| Prop | Type | Description | Since |
|
|
183
|
+
| ------------ | -------------------- | -------------------------------------------- | ----- |
|
|
184
|
+
| **`canAdd`** | <code>boolean</code> | Whether passes can be added to Apple Wallet. | 0.1.0 |
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
#### SaveToGoogleWalletOptions
|
|
188
|
+
|
|
189
|
+
| Prop | Type | Description | Since |
|
|
190
|
+
| --------- | ------------------- | ------------------------------------------------------------- | ----- |
|
|
191
|
+
| **`jwt`** | <code>string</code> | The signed Google Wallet JWT that was created on your server. | 0.1.0 |
|
|
192
|
+
|
|
193
|
+
</docgen-api>
|
|
194
|
+
|
|
195
|
+
## Creating Passes
|
|
196
|
+
|
|
197
|
+
This plugin only **presents** passes to the user. Creating and signing passes must happen on your server, because it requires private keys and certificates that must never be shipped inside your app.
|
|
198
|
+
|
|
199
|
+
### Apple Wallet
|
|
200
|
+
|
|
201
|
+
A pass is a signed `.pkpass` bundle. Build and sign it on your server using your Pass Type ID certificate, then send the resulting file to your app as a base64-encoded string and pass it to `addPasses(...)`. See Apple's [Wallet documentation](https://developer.apple.com/documentation/walletpasses) for details on building and signing passes.
|
|
202
|
+
|
|
203
|
+
### Google Wallet
|
|
204
|
+
|
|
205
|
+
A pass is represented by a signed JWT. Create and sign the JWT on your server using your Google Wallet service account, then send it to your app and pass it to `saveToGoogleWallet(...)`. See Google's [Wallet API documentation](https://developers.google.com/wallet) for details on creating passes and JWTs.
|
|
206
|
+
|
|
207
|
+
**Note**: With the URL-based "Save to Wallet" flow used by this plugin, there is no completion signal, so `saveToGoogleWallet(...)` resolves as soon as the flow is launched, not when the pass is actually saved.
|
|
208
|
+
|
|
209
|
+
## Changelog
|
|
210
|
+
|
|
211
|
+
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/wallet/CHANGELOG.md).
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/wallet/LICENSE).
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.wallet"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError = false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.wallet;
|
|
2
|
+
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
import android.net.Uri;
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.wallet.classes.options.SaveToGoogleWalletOptions;
|
|
7
|
+
import io.capawesome.capacitorjs.plugins.wallet.interfaces.EmptyCallback;
|
|
8
|
+
|
|
9
|
+
public class Wallet {
|
|
10
|
+
|
|
11
|
+
private static final String GOOGLE_WALLET_SAVE_URL = "https://pay.google.com/gp/v/save/";
|
|
12
|
+
|
|
13
|
+
@NonNull
|
|
14
|
+
private final WalletPlugin plugin;
|
|
15
|
+
|
|
16
|
+
public Wallet(@NonNull WalletPlugin plugin) {
|
|
17
|
+
this.plugin = plugin;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public void saveToGoogleWallet(@NonNull SaveToGoogleWalletOptions options, @NonNull EmptyCallback callback) {
|
|
21
|
+
try {
|
|
22
|
+
Uri uri = Uri.parse(GOOGLE_WALLET_SAVE_URL + options.getJwt());
|
|
23
|
+
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
|
24
|
+
plugin.getActivity().startActivity(intent);
|
|
25
|
+
callback.success();
|
|
26
|
+
} catch (Exception exception) {
|
|
27
|
+
callback.error(exception);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.wallet;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.Logger;
|
|
5
|
+
import com.getcapacitor.Plugin;
|
|
6
|
+
import com.getcapacitor.PluginCall;
|
|
7
|
+
import com.getcapacitor.PluginMethod;
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
+
import io.capawesome.capacitorjs.plugins.wallet.classes.CustomException;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.wallet.classes.options.SaveToGoogleWalletOptions;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.wallet.interfaces.EmptyCallback;
|
|
12
|
+
|
|
13
|
+
@CapacitorPlugin(name = "Wallet")
|
|
14
|
+
public class WalletPlugin extends Plugin {
|
|
15
|
+
|
|
16
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
|
|
17
|
+
public static final String TAG = "WalletPlugin";
|
|
18
|
+
|
|
19
|
+
private Wallet implementation;
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public void load() {
|
|
23
|
+
super.load();
|
|
24
|
+
this.implementation = new Wallet(this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@PluginMethod
|
|
28
|
+
public void addPasses(PluginCall call) {
|
|
29
|
+
rejectCallAsUnimplemented(call);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@PluginMethod
|
|
33
|
+
public void canAddPasses(PluginCall call) {
|
|
34
|
+
rejectCallAsUnimplemented(call);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@PluginMethod
|
|
38
|
+
public void saveToGoogleWallet(PluginCall call) {
|
|
39
|
+
try {
|
|
40
|
+
SaveToGoogleWalletOptions options = new SaveToGoogleWalletOptions(call);
|
|
41
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
42
|
+
@Override
|
|
43
|
+
public void success() {
|
|
44
|
+
resolveCall(call);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Override
|
|
48
|
+
public void error(Exception exception) {
|
|
49
|
+
rejectCall(call, exception);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
implementation.saveToGoogleWallet(options, callback);
|
|
53
|
+
} catch (Exception exception) {
|
|
54
|
+
rejectCall(call, exception);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
59
|
+
String message = exception.getMessage();
|
|
60
|
+
if (message == null) {
|
|
61
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
62
|
+
}
|
|
63
|
+
String code = null;
|
|
64
|
+
if (exception instanceof CustomException) {
|
|
65
|
+
code = ((CustomException) exception).getCode();
|
|
66
|
+
}
|
|
67
|
+
Logger.error(TAG, message, exception);
|
|
68
|
+
call.reject(message, code);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private void rejectCallAsUnimplemented(@NonNull PluginCall call) {
|
|
72
|
+
call.unimplemented("This method is not available on this platform.");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private void resolveCall(@NonNull PluginCall call) {
|
|
76
|
+
call.resolve();
|
|
77
|
+
}
|
|
78
|
+
}
|
package/android/src/main/java/io/capawesome/capacitorjs/plugins/wallet/classes/CustomException.java
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.wallet.classes;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
public class CustomException extends Exception {
|
|
7
|
+
|
|
8
|
+
@Nullable
|
|
9
|
+
private final String code;
|
|
10
|
+
|
|
11
|
+
public CustomException(@Nullable String code, @NonNull String message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
public String getCode() {
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.wallet.classes.options;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.PluginCall;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.wallet.classes.CustomExceptions;
|
|
6
|
+
|
|
7
|
+
public class SaveToGoogleWalletOptions {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final String jwt;
|
|
11
|
+
|
|
12
|
+
public SaveToGoogleWalletOptions(@NonNull PluginCall call) throws Exception {
|
|
13
|
+
this.jwt = getJwtFromCall(call);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@NonNull
|
|
17
|
+
public String getJwt() {
|
|
18
|
+
return jwt;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@NonNull
|
|
22
|
+
private static String getJwtFromCall(@NonNull PluginCall call) throws Exception {
|
|
23
|
+
String jwt = call.getString("jwt");
|
|
24
|
+
if (jwt == null || jwt.isEmpty()) {
|
|
25
|
+
throw CustomExceptions.JWT_MISSING;
|
|
26
|
+
}
|
|
27
|
+
return jwt;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
File without changes
|