Skip to content

Commit

Permalink
Fix 1912 can add card to wallet (#1932)
Browse files Browse the repository at this point in the history
* fix: #1912 wallet parsing

* chore(release): publish packages

 - [email protected]

---------

Co-authored-by: Remon <[email protected]>
  • Loading branch information
remonh87 and Remon authored Sep 25, 2024
1 parent 1c75fe4 commit 0b4469a
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 14 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## 2024-09-18

### Changes

---

Packages with breaking changes:

- There are no breaking changes in this release.

Packages with other changes:

- [`stripe_platform_interface` - `v11.1.1`](#stripe_platform_interface---v1111)
- [`flutter_stripe` - `v11.1.1`](#flutter_stripe---v1111)
- [`flutter_stripe_web` - `v6.1.1`](#flutter_stripe_web---v611)

Packages with dependency updates only:

> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project.
- `flutter_stripe` - `v11.1.1`
- `flutter_stripe_web` - `v6.1.1`

---

#### `stripe_platform_interface` - `v11.1.1`

- **FIX**: #1912 wallet parsing.


## 2024-09-18

### Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class _CustomerSheetScreenState extends State<CustomerSheetScreen> {
await Stripe.instance.initCustomerSheet(
customerSheetInitParams: CustomerSheetInitParams(
// Main params
setupIntentClientSecret: data['setupIntent'],
// setupIntentClientSecret: data['setupIntent'],
merchantDisplayName: 'Flutter Stripe Store Demo',
allowsRemovalOfLastSavedPaymentMethod: true,
// Customer params
customerId: data['customer'],
customerEphemeralKeySecret: data['ephemeralKeySecret'],
Expand Down
106 changes: 106 additions & 0 deletions example/lib/screens/others/can_add_to_wallet_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import 'package:flutter/material.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:stripe_example/utils.dart';
import 'package:stripe_example/widgets/example_scaffold.dart';
import 'package:stripe_example/widgets/loading_button.dart';
import 'package:stripe_example/widgets/response_card.dart';

class CanAddToWalletScreen extends StatefulWidget {
@override
_CanAddToWalletScreenState createState() => _CanAddToWalletScreenState();
}

class _CanAddToWalletScreenState extends State<CanAddToWalletScreen> {
late TextEditingController _controller;
CanAddCardToWalletResult? canAddCardToWallet;
IsCardInWalletResult? isCardInWallet;

@override
void initState() {
_controller = TextEditingController();
super.initState();
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return ExampleScaffold(
title: 'Can add card to wallet',
tags: ['Provisioning'],
padding: EdgeInsets.all(16),
children: [
TextField(
controller: _controller,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Last4',
),
),
SizedBox(height: 20),
LoadingButton(
onPressed: () async {
final tmp = await _handleCanAddToWallet(_controller.text);
setState(() {
canAddCardToWallet = tmp;
});
},
text: 'Can add card to Wallet',
),
SizedBox(height: 20),
LoadingButton(
onPressed: () async {
final tmp = await _isCardInToWallet(_controller.text);
setState(() {
isCardInWallet = tmp;
});
},
text: 'Is card in Wallet',
),
SizedBox(height: 20),
if (canAddCardToWallet != null || isCardInWallet != null)
ResponseCard(
response: canAddCardToWallet?.toJson().toPrettyString() ??
isCardInWallet?.toJson().toPrettyString() ??
'',
)
],
);
}

Future<CanAddCardToWalletResult> _handleCanAddToWallet(String last4) async {
try {
final result = await Stripe.instance.canAddCardToWallet(
CanAddCardToWalletParams(
cardLastFour: last4,
),
);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Can add card to wallet: ${result}')),
);
return result;
} catch (e) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('Error: $e')));
rethrow;
}
}

Future<IsCardInWalletResult> _isCardInToWallet(String last4) async {
try {
final result = await Stripe.instance.isCardInWallet(last4);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Can add card to wallet: ${result}')),
);
return result;
} catch (e) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('Error: $e')));
rethrow;
}
}
}
9 changes: 9 additions & 0 deletions example/lib/screens/screens.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:stripe_example/screens/customer_sheet/customer_sheet_screen.dart';
import 'package:stripe_example/screens/others/can_add_to_wallet_screen.dart';
import 'package:stripe_example/screens/payment_sheet/payment_element/payment_element.dart';
import 'package:stripe_example/screens/payment_sheet/payment_sheet_deffered_screen.dart';
import 'package:stripe_example/screens/payment_sheet/payment_sheet_screen.dart';
Expand Down Expand Up @@ -368,6 +369,14 @@ class Example extends StatelessWidget {
DevicePlatform.web,
],
),
Example(
title: 'Can add card to wallet',
builder: (context) => CanAddToWalletScreen(),
platformsSupported: [
DevicePlatform.android,
DevicePlatform.ios,
],
),
]),
];
}
2 changes: 1 addition & 1 deletion example/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0920;
LastUpgradeCheck = 1300;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
33CC10EC2044A3C60003C045 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

Check warning on line 1 in example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

View workflow job for this annotation

GitHub Actions / Typo CI

Filename: example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

"xcscheme" in the filename is a typo. Did you mean "scheme"?

Check warning on line 1 in example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

View workflow job for this annotation

GitHub Actions / Typo CI

Filename: example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

"xcschemes" in the filename is a typo. Did you mean "schemes"?

Check warning on line 1 in example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

View workflow job for this annotation

GitHub Actions / Typo CI

Filename: example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

"xcshareddata" in the filename is a typo. Did you mean "sharecropped"?
<Scheme
LastUpgradeVersion = "1300"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion packages/stripe/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies:
meta: ^1.8.0
stripe_android: ^11.1.0
stripe_ios: ^11.1.0
stripe_platform_interface: ^11.1.0
stripe_platform_interface: ^11.1.1
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
4 changes: 4 additions & 0 deletions packages/stripe_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 11.1.1

- #1912 wallet parsing.

## 11.1.0
- Sync with Stripe [0.38.6](https://github.com/stripe/stripe-react-native/releases/tag/v0.38.6).
- Minor fixes and improvements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,24 +636,28 @@ class MethodChannelStripe extends StripePlatform {
@override
Future<CanAddCardToWalletResult> canAddCardToWallet(
CanAddCardToWalletParams params) async {
final result = await _methodChannel.invokeMethod('canAddCardToWallet', {
final result = await _methodChannel
.invokeMapMethod<String, dynamic>('canAddCardToWallet', {
'params': params.toJson(),
});
if (result!['error'] != null) {
throw StripeException.fromJson(result);
}

return ResultParser<CanAddCardToWalletResult>(
parseJson: (json) => CanAddCardToWalletResult.fromJson(json))
.parse(result: result!, successResultKey: 'canAddCardToWalletResult');
return CanAddCardToWalletResult.fromJson(result);
}

@override
Future<IsCardInWalletResult> isCardInWallet(String cardLastFour) async {
final result = await _methodChannel.invokeMethod('canAddCardToWallet', {
final result = await _methodChannel
.invokeMapMethod<String, dynamic>('isCardInWallet', {
'params': {'cardLastFour': cardLastFour},
});
if (result!['error'] != null) {
throw StripeException.fromJson(result);
}

return ResultParser<IsCardInWalletResult>(
parseJson: (json) => IsCardInWalletResult.fromJson(json))
.parse(result: result!, successResultKey: 'canAddCardToWalletResult');
return IsCardInWalletResult.fromJson(result);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stripe_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: stripe_platform_interface
description: Platform interface for stripe sdk
version: 11.1.0
version: 11.1.1
repository: https://github.com/flutter-stripe/flutter_stripe
homepage: https://pub.dev/packages/flutter_stripe

Expand Down
2 changes: 1 addition & 1 deletion packages/stripe_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
freezed_annotation: ^2.0.3
stripe_platform_interface: ^11.1.0
stripe_platform_interface: ^11.1.1
stripe_js: ^6.1.0
web: ^1.0.0

Expand Down

0 comments on commit 0b4469a

Please sign in to comment.