Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into web_deffered_payment

# Conflicts:
#	packages/stripe_platform_interface/CHANGELOG.md
#	packages/stripe_web/pubspec.yaml
  • Loading branch information
Eduard Dumitrescu committed Sep 30, 2024
2 parents 999e320 + b1fe711 commit 2ac8be2
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 23 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"?>
<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.1
stripe_platform_interface: ^11.2.0
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension type JsPaymentResponse._(JSObject o) {
@JS('complete')
external JSFunction get _complete;
void Function(String) get complete {
return (String val) => _complete.callAsFunction(val.toJS);
return _complete.dartify() as void Function(String);
}
}

Expand Down
6 changes: 5 additions & 1 deletion packages/stripe_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## 11.1.1
## 11.2.0

**Features**
- add methods for deferred payment on web

## 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 @@ -672,24 +672,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.1
version: 11.2.0
repository: https://github.com/flutter-stripe/flutter_stripe
homepage: https://pub.dev/packages/flutter_stripe

Expand Down
4 changes: 2 additions & 2 deletions packages/stripe_web/lib/src/parser/payment_intent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ extension PaymentIntentExtension on js.PaymentIntent {
latestCharge: latestCharge,
//paymentMethodId: payment_method,
captureMethod: CaptureMethodExtension.parse(captureMethod.name),
confirmationMethod:
ConfirmationMethodExtension.parse(confirmationMethod.name),
confirmationMethod: ConfirmationMethodExtension.parse(confirmationMethod.name),
//
description: description,
// receiptEmail: receipt_email,
Expand Down Expand Up @@ -75,6 +74,7 @@ extension CaptureMethodExtension on CaptureMethod {
case 'automatic':
return CaptureMethod.Automatic;
case 'AutomaticAsync':
case 'automaticAsync':
case 'automatic_async':
return CaptureMethod.AutomaticAsync;
case 'Manual':
Expand Down
6 changes: 2 additions & 4 deletions packages/stripe_web/lib/src/widgets/platform_pay_button.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import 'dart:js_interop';

import 'package:web/web.dart' as web;
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter_stripe_web/flutter_stripe_web.dart';
import 'package:flutter_stripe_web/src/parser/payment_request.dart';

import 'package:stripe_js/stripe_js.dart';
import 'package:web/web.dart' as web;

const kPlatformPayButtonDefaultHeight = 40.0;

Expand Down Expand Up @@ -76,7 +74,7 @@ class _WebPlatformPayButtonState extends State<WebPlatformPayButton> {
height: '${constraints.maxHeight}px',
))))
..on('click', (event) {
//callMethod(event, 'preventDefault', []);
event.toDart['preventDefault']();
widget.onPressed();
})
..mount('#platform-pay-button'.toJS);
Expand Down
4 changes: 2 additions & 2 deletions packages/stripe_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_stripe_web
description: Stripe sdk bindings for the Flutter web platform. This package contains the implementation of the platform interface for web.
version: 6.1.1
version: 6.1.0
homepage: https://github.com/flutter-stripe/flutter_stripe

environment:
Expand All @@ -13,7 +13,7 @@ dependencies:
flutter_web_plugins:
sdk: flutter
freezed_annotation: ^2.0.3
stripe_platform_interface: ^11.1.1
stripe_platform_interface: ^11.2.0
stripe_js: ^6.1.1
web: ^1.0.0

Expand Down

0 comments on commit 2ac8be2

Please sign in to comment.