Skip to content

Commit

Permalink
BREAKING: rename ApplePayShippingContact to Platformpayshipping contact
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Dec 11, 2023
1 parent 9eb7985 commit cfd1567
Show file tree
Hide file tree
Showing 13 changed files with 572 additions and 309 deletions.
12 changes: 11 additions & 1 deletion example/lib/screens/wallets/apple_pay_create_payment_method.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import 'package:flutter/material.dart';
import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:stripe_example/widgets/example_scaffold.dart';
import 'package:stripe_example/widgets/response_card.dart';

class ApplePayCreatePaymentMethodScreen extends StatefulWidget {
@override
_ApplePayScreenState createState() => _ApplePayScreenState();
}

class _ApplePayScreenState extends State<ApplePayCreatePaymentMethodScreen> {
PlatformPayPaymentMethod? response;
@override
void initState() {
Stripe.instance.isPlatformPaySupportedListenable.addListener(update);
Expand Down Expand Up @@ -37,6 +39,10 @@ class _ApplePayScreenState extends State<ApplePayCreatePaymentMethodScreen> {
)
else
Text('Apple Pay is not available in this device'),
SizedBox(
height: 50,
),
ResponseCard(response: response?.toString() ?? ''),
],
);
}
Expand Down Expand Up @@ -76,8 +82,12 @@ class _ApplePayScreenState extends State<ApplePayCreatePaymentMethodScreen> {
),
);

setState(() {
response = paymentMethod;
});

ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
'Success!: The payment method with id: ${paymentMethod.id} was created successfully,')));
'Success!: The payment method with id: ${paymentMethod.paymentMethod.id} was created successfully,')));
}
}
2 changes: 1 addition & 1 deletion packages/stripe/lib/src/stripe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Stripe {
/// Creating payment method does not return a token by default. Use `usesDeprecatedTokenFlow` instead.
///
/// throws [StripeError] in case creating payment method is failing.
Future<PaymentMethod> createPlatformPayPaymentMethod({
Future<PlatformPayPaymentMethod> createPlatformPayPaymentMethod({
required PlatformPayPaymentMethodParams params,
bool usesDeprecatedTokenFlow = false,
}) async {
Expand Down
6 changes: 3 additions & 3 deletions packages/stripe/lib/src/widgets/apple_pay_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApplePayButton extends StatelessWidget {
Key? key,
this.style = PlatformButtonStyle.automatic,
this.type = PlatformButtonType.plain,
this.cornerRadius=4,
this.cornerRadius = 4,
this.onPressed,
double? width,
double? height = _kApplePayButtonDefaultHeight,
Expand Down Expand Up @@ -242,8 +242,8 @@ class _UiKitApplePayButtonState extends State<_UiKitApplePayButton> {
}

// For some reason json serializable cannot be cast
ApplePayShippingContact _convertShippingContact(dynamic json) =>
ApplePayShippingContact(
PlatformPayShippingContact _convertShippingContact(dynamic json) =>
PlatformPayShippingContact(
phoneNumber: json['phoneNumber'],
name: ApplePayContactName(
familyName: json['name']['familyName'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ class MethodChannelStripe extends StripePlatform {
}

@override
Future<PaymentMethod> platformPayCreatePaymentMethod({
Future<PlatformPayPaymentMethod> platformPayCreatePaymentMethod({
required PlatformPayPaymentMethodParams params,
bool usesDeprecatedTokenFlow = false,
}) async {
Expand Down Expand Up @@ -596,9 +596,11 @@ class MethodChannelStripe extends StripePlatform {
'usesDeprecatedTokenFlow': usesDeprecatedTokenFlow,
});

return ResultParser<PaymentMethod>(
parseJson: (json) => PaymentMethod.fromJson(json))
.parse(result: result!, successResultKey: 'paymentMethod');
if (result!.containsKey('error')) {
throw ResultParser<void>(parseJson: (json) => {}).parseError(result);
}

return PlatformPayPaymentMethod.fromJson(result);
}

@override
Expand Down
24 changes: 2 additions & 22 deletions packages/stripe_platform_interface/lib/src/models/apple_pay.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:stripe_platform_interface/src/models/platform_pay.dart';

part 'apple_pay.freezed.dart';
part 'apple_pay.g.dart';
Expand Down Expand Up @@ -202,28 +203,7 @@ class ApplePayErrorAddressField with _$ApplePayErrorAddressField {
_$ApplePayErrorAddressFieldFromJson(json);
}

@freezed

/// Entered Shipping contact data
class ApplePayShippingContact with _$ApplePayShippingContact {
@JsonSerializable(explicitToJson: true)
const factory ApplePayShippingContact({
/// Email address of the shipping contact
String? emailAddress,

/// Name of shipping contact
required ApplePayContactName name,

/// Postal address of shipping contact
required ApplePayPostalAddress postalAddress,

///Phone Number of the shipping contact
String? phoneNumber,
}) = _ApplePayShippingContact;

factory ApplePayShippingContact.fromJson(Map<String, dynamic> json) =>
_$ApplePayShippingContactFromJson(json);
}

@freezed

Expand Down Expand Up @@ -264,7 +244,7 @@ class ApplePayPostalAddress with _$ApplePayPostalAddress {
}

typedef OnDidSetShippingContact = FutureOr<void> Function(
ApplePayShippingContact contact);
PlatformPayShippingContact contact);
typedef OnDidSetShippingMethod = FutureOr<void> Function(
ApplePayShippingMethod method);
typedef OnCouponCodeEntered = FutureOr<void> Function(String couponCode);
Expand Down
Loading

0 comments on commit cfd1567

Please sign in to comment.