Skip to content

Commit

Permalink
fix #1886 and #1862 by adding missing params to payment element
Browse files Browse the repository at this point in the history
  • Loading branch information
Remon committed Aug 19, 2024
1 parent fffe097 commit 115a1f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ extension type JsElementsCreateOptions._(JSObject o) {
String? locale,
String? clientSecret,
JsElementAppearance? appearance,
String? customerSessionClientSecret,
String loader,
});

external JSArray<Font> fonts;
external String locale;
external String clientSecret;
external String customerSessionClientSecret;
external JsElementAppearance appearance;
}

Expand Down
39 changes: 34 additions & 5 deletions packages/stripe_web/lib/src/widgets/payment_element.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import 'dart:js_interop';

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

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import '../../flutter_stripe_web.dart';
import 'package:stripe_js/stripe_api.dart' as js;
import 'package:stripe_js/stripe_js.dart' as js;
import 'package:web/web.dart' as web;

import '../../flutter_stripe_web.dart';

export 'package:stripe_js/stripe_api.dart' show PaymentElementLayout;

typedef PaymentElementTheme = js.ElementTheme;

class PaymentElement extends StatefulWidget {
final String clientSecret;
final String? customerSessionClientSecret;
final double? width;
final double? height;
final CardStyle? style;
Expand All @@ -26,10 +27,19 @@ class PaymentElement extends StatefulWidget {
final CardChangedCallback onCardChanged;
final PaymentElementLayout layout;
final js.ElementAppearance? appearance;
final js.PaymentElementDefaultValues? defaultValues;
final js.PaymentElementBusiness? business;
final dynamic paymentMethodOrder;
final js.PaymentElementFields? fields;
final bool? readOnly;
final js.PaymentElementOptionsTerms? terms;
final js.PaymentElementWalletOptions? wallets;
final js.PaymentElementApplePayOptions? applePay;

PaymentElement({
super.key,
required this.clientSecret,
this.customerSessionClientSecret,
this.width,
this.height,
this.style,
Expand All @@ -41,6 +51,14 @@ class PaymentElement extends StatefulWidget {
required this.onCardChanged,
this.layout = PaymentElementLayout.accordion,
this.appearance,
this.defaultValues,
this.business,
this.paymentMethodOrder,
this.fields,
this.readOnly,
this.terms,
this.wallets,
this.applePay,
});

@override
Expand Down Expand Up @@ -169,12 +187,23 @@ class PaymentElementState extends State<PaymentElement> {
final appearance = widget.appearance ?? js.ElementAppearance();
return js.JsElementsCreateOptions(
clientSecret: widget.clientSecret,
customerSessionClientSecret: widget.customerSessionClientSecret,
appearance: appearance.toJson().jsify() as js.JsElementAppearance,
);
}

js.PaymentElementOptions elementOptions() {
return js.PaymentElementOptions(layout: widget.layout);
return js.PaymentElementOptions(
layout: widget.layout,
defaultValues: widget.defaultValues,
business: widget.business,
paymentMethodOrder: widget.paymentMethodOrder,
fields: widget.fields,
readOnly: widget.readOnly,
terms: widget.terms,
wallets: widget.wallets,
applePay: widget.applePay,
);
}

@override
Expand Down

0 comments on commit 115a1f2

Please sign in to comment.