Skip to content

Commit

Permalink
fix web example
Browse files Browse the repository at this point in the history
  • Loading branch information
cedvandenbosch committed Nov 7, 2024
1 parent a9650ef commit a2e24ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Future<SetupKeys> createSetupIntent() async {
'Content-Type': 'application/json',
},
body: json.encode({
'payment_method_types': ['cards', 'sepa_debit'],
'payment_method_types': ['card', 'sepa_debit'],
}),
);
final body = json.decode(response.body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter_stripe_web/flutter_stripe_web.dart';
import '_create_setup_intent.dart';

extension ToHex on Color {
String toRgb() => 'rgb($r, $g, $b)';
String toRgb() => 'rgb($red, $green, $blue)';
}

class AddPaymentMethodScreenLoader {
Expand Down Expand Up @@ -64,13 +64,16 @@ class _AddPaymentMethodScreenPlatformState
),
body: Column(
children: [
PaymentElement(
clientSecret: widget.setupKeys.clientSecret,
onCardChanged: (c) {
setState(() => isComplete = c?.complete ?? false);
},
layout: PaymentElementLayout.tabs,
appearance: buildAppearance(context),
Padding(
padding: const EdgeInsets.all(24),
child: PaymentElement(
clientSecret: widget.setupKeys.clientSecret,
onCardChanged: (c) {
setState(() => isComplete = c?.complete ?? false);
},
layout: PaymentElementLayout.tabs,
appearance: buildAppearance(context),
),
),
const SizedBox(height: 8),
ElevatedButton(
Expand All @@ -86,8 +89,10 @@ class _AddPaymentMethodScreenPlatformState
final theme = Theme.of(context);
final isDark = theme.brightness == Brightness.dark;

print(theme.colorScheme.surface.toRgb());

return ElementAppearance(
theme: isDark ? ElementTheme.night : ElementTheme.none,
theme: isDark ? ElementTheme.night : ElementTheme.stripe,
variables: {
'fontFamily': 'roboto, system-ui, sans-serif',
'colorBackground': theme.colorScheme.surface.toRgb(),
Expand Down
8 changes: 3 additions & 5 deletions example/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,9 @@ app.post('/create-setup-intent', async (req, res) => {

//@ts-ignore
const setupIntent = await stripe.setupIntents.create({
...{
customerId: customer.id,
payment_method_types,
usage: ['off_session'],
},
customer: customer.id,
payment_method_types,
usage: 'off_session',
...(payment_method_types?.includes('paypal') ? payPalIntentPayload : {}),
});

Expand Down

0 comments on commit a2e24ff

Please sign in to comment.