-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 1912 can add card to wallet (#1932)
* fix: #1912 wallet parsing * chore(release): publish packages - [email protected] --------- Co-authored-by: Remon <[email protected]>
- Loading branch information
Showing
11 changed files
with
168 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
example/lib/screens/others/can_add_to_wallet_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters