Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add save jwt method #14

Merged
merged 1 commit into from
Dec 6, 2023
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
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2023-12-05

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`flutter_google_wallet` - `v0.1.2`](#flutter_google_wallet---v012)

---

#### `flutter_google_wallet` - `v0.1.2`

- **FEAT**(flutter_google_wallet_plugin): add method to add jwt signed wallet.

## 0.1.2

- **FEAT**(flutter_google_wallet_plugin): add method to add jwt signed wallet.


## 2023-06-06

### Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FlutterGoogleWalletPlugin: FlutterPlugin, GoogleWalletApi, ActivityAware,
private lateinit var context: Context
private var activity: Activity? = null
private lateinit var walletClient: PayClient

override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
GoogleWalletApi.setUp(flutterPluginBinding.binaryMessenger, this)
context = flutterPluginBinding.applicationContext
Expand Down Expand Up @@ -44,6 +44,12 @@ class FlutterGoogleWalletPlugin: FlutterPlugin, GoogleWalletApi, ActivityAware,
}
}

override fun savePassesJwt(jsonPass: String, addToGoogleWalletRequestCode: Long) {
if(activity != null){
walletClient.savePassesJwt(jsonPass, activity!!, addToGoogleWalletRequestCode.toInt())
}
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
activity = binding.activity
binding.addActivityResultListener(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface GoogleWalletApi {
fun initWalletClient()
fun getWalletApiAvailabilityStatus(): Boolean
fun savePasses(jsonPass: String, addToGoogleWalletRequestCode: Long)
fun savePassesJwt(jsonPass: String, addToGoogleWalletRequestCode: Long)

companion object {
/** The codec used by GoogleWalletApi. */
Expand Down Expand Up @@ -110,6 +111,26 @@ interface GoogleWalletApi {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.GoogleWalletApi.savePassesJwt", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val jsonPassArg = args[0] as String
val addToGoogleWalletRequestCodeArg = args[1].let { if (it is Int) it.toLong() else it as Long }
var wrapped: List<Any?>
try {
api.savePassesJwt(jsonPassArg, addToGoogleWalletRequestCodeArg)
wrapped = listOf<Any?>(null)
} catch (exception: Throwable) {
wrapped = wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
}
}
}
7 changes: 7 additions & 0 deletions lib/flutter_google_wallet_pigeon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ class PigeonFlutterGoogleWallet extends FlutterGoogleWalletPlatform {
required int addToGoogleWalletRequestCode}) async {
await _api.savePasses(jsonPass, addToGoogleWalletRequestCode);
}

@override
Future<void> savePassesJwt(
{required String jsonPass,
required int addToGoogleWalletRequestCode}) async {
await _api.savePassesJwt(jsonPass, addToGoogleWalletRequestCode);
}
}
6 changes: 6 additions & 0 deletions lib/flutter_google_wallet_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ abstract class FlutterGoogleWalletPlatform extends PlatformInterface {
required int addToGoogleWalletRequestCode}) async {
throw UnimplementedError('savePasses() has not been implemented.');
}

Future<void> savePassesJwt(
{required String jsonPass,
required int addToGoogleWalletRequestCode}) async {
throw UnimplementedError('savePasses() has not been implemented.');
}
}
8 changes: 8 additions & 0 deletions lib/flutter_google_wallet_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ class FlutterGoogleWalletPlugin {
jsonPass: jsonPass,
addToGoogleWalletRequestCode: addToGoogleWalletRequestCode);
}

Future<void> savePassesJwt(
{required String jsonPass,
required int addToGoogleWalletRequestCode}) async {
await FlutterGoogleWalletPlatform.instance.savePassesJwt(
jsonPass: jsonPass,
addToGoogleWalletRequestCode: addToGoogleWalletRequestCode);
}
}
24 changes: 24 additions & 0 deletions lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,28 @@ class GoogleWalletApi {
return;
}
}

Future<void> savePassesJwt(
String arg_jsonPass, int arg_addToGoogleWalletRequestCode) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.GoogleWalletApi.savePassesJwt', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList = await channel
.send(<Object?>[arg_jsonPass, arg_addToGoogleWalletRequestCode])
as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else {
return;
}
}
}
4 changes: 4 additions & 0 deletions pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import 'package:pigeon/pigeon.dart';
@HostApi()
abstract class GoogleWalletApi {
void initWalletClient();

@TaskQueue(type: TaskQueueType.serialBackgroundThread)
bool getWalletApiAvailabilityStatus();

void savePasses(String jsonPass, int addToGoogleWalletRequestCode);

void savePassesJwt(String jsonPass, int addToGoogleWalletRequestCode);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_google_wallet
description: A Flutter Google Wallet Plugin
version: 0.1.1
version: 0.1.2
homepage: https://github.com/voyages-sncf-technologies/flutter_google_wallet

environment:
Expand Down
6 changes: 6 additions & 0 deletions test/flutter_google_wallet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class MockFlutterGoogleWalletPlatform
{required String jsonPass,
required int addToGoogleWalletRequestCode}) =>
Future.value();

@override
Future<void> savePassesJwt(
{required String jsonPass,
required int addToGoogleWalletRequestCode}) =>
Future.value();
}

void main() {
Expand Down
Loading