Skip to content

Commit

Permalink
chore: android code integrity
Browse files Browse the repository at this point in the history
  • Loading branch information
BreX900 committed Nov 19, 2023
1 parent 142c1f9 commit 35b140f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/stripe_terminal_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
distribution: 'zulu'
- run: ./gradlew spotlessCheck
working-directory: stripe_terminal/android
- run: ./gradlew :mek_stripe_terminal:assemble
working-directory: stripe_terminal/example/android

integration-example:
runs-on: macos-latest
Expand Down
1 change: 0 additions & 1 deletion stripe_terminal/android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
# org.gradle.parallel=true
#Fri Jul 21 11:00:59 CEST 2023
android.enableJetifier=true
android.enableR8=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536M
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.stripe.stripeterminal.external.models.PaymentMethodDetails
import mek.stripeterminal.api.ChargeApi
import mek.stripeterminal.api.ChargeStatusApi
import mek.stripeterminal.api.PaymentMethodDetailsApi
import mek.stripeterminal.api.toApi
import mek.stripeterminal.toHashMap

fun Charge.toApi(): ChargeApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import mek.stripeterminal.api.PaymentIntentUsageApi
import mek.stripeterminal.api.PaymentMethodOptionsParametersApi
import mek.stripeterminal.api.PaymentMethodTypeApi
import mek.stripeterminal.api.PaymentStatusApi
import mek.stripeterminal.api.toHost
import mek.stripeterminal.toHashMap

fun PaymentIntent.toApi(): PaymentIntentApi {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mek.stripeterminal.mappings

import com.stripe.stripeterminal.external.models.PaymentMethod
import mek.stripeterminal.api.PaymentMethodApi
import mek.stripeterminal.api.toApi
import mek.stripeterminal.toHashMap

fun PaymentMethod.toApi(): PaymentMethodApi {
Expand Down
89 changes: 58 additions & 31 deletions stripe_terminal/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:io';
import 'package:example/models/discovery_method.dart';
import 'package:example/models/k.dart';
import 'package:example/stripe_api.dart';
import 'package:example/utils/permission_utils.dart';
import 'package:flutter/material.dart';
import 'package:mek_stripe_terminal/mek_stripe_terminal.dart';
import 'package:permission_handler/permission_handler.dart';
Expand All @@ -15,19 +16,35 @@ void main() async {

print('Stripe Secret Key: ${StripeApi.secretKey.isNotEmpty}');

runApp(const MaterialApp(
home: MyApp(),
));
runApp(const App());
}

class MyApp extends StatefulWidget {
const MyApp({super.key});
class App extends StatelessWidget {
const App({super.key});

@override
State<MyApp> createState() => _MyAppState();
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.from(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
brightness: Brightness.dark,
seedColor: Colors.amber,
),
),
home: const HomeScreen(),
);
}
}

class _MyAppState extends State<MyApp> {
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});

@override
State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
final _api = StripeApi();
Terminal? _terminal;

Expand Down Expand Up @@ -71,10 +88,23 @@ class _MyAppState extends State<MyApp> {
];

for (final permission in permissions) {
final result = await permission.request();
print('$permission: $result');
final status = await permission.request();
print('$permission: $status');

if (result == PermissionStatus.denied || result == PermissionStatus.permanentlyDenied) return;
if (status == PermissionStatus.denied || status == PermissionStatus.permanentlyDenied) {
_showSnackBar('Please grant ${permission.name} permission.');
return;
}
}

for (final service in permissions.whereType<PermissionWithService>()) {
final status = await service.serviceStatus;
print('$service: $status');

if (status != ServiceStatus.enabled) {
_showSnackBar('Please enable ${service.name} service.');
return;
}
}

final terminal = await Terminal.getInstance(
Expand Down Expand Up @@ -286,6 +316,8 @@ class _MyAppState extends State<MyApp> {

@override
Widget build(BuildContext context) {
final viewPadding = MediaQuery.viewPaddingOf(context);

final terminal = _terminal;
final paymentIntent = _paymentIntent;
final collectingPaymentMethod = _collectingPaymentMethod;
Expand Down Expand Up @@ -452,29 +484,24 @@ class _MyAppState extends State<MyApp> {
return DefaultTabController(
length: tabs.length,
child: Scaffold(
body: Column(
children: [
Material(
color: Theme.of(context).colorScheme.primary,
child: SafeArea(
child: TabBar(
isScrollable: true,
tabs: tabs.keys.toList(),
),
),
appBar: PreferredSize(
preferredSize: Size.fromHeight(64.0 + viewPadding.top),
child: Padding(
padding: EdgeInsets.only(top: viewPadding.top),
child: TabBar(
isScrollable: true,
tabs: tabs.keys.toList(),
),
Expanded(
child: TabBarView(
children: tabs.values.map((e) {
return SingleChildScrollView(
child: Column(
children: e,
),
);
}).toList(),
),
),
body: TabBarView(
children: tabs.values.map((e) {
return SingleChildScrollView(
child: Column(
children: e,
),
),
],
);
}).toList(),
),
),
);
Expand Down
5 changes: 5 additions & 0 deletions stripe_terminal/example/lib/utils/permission_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:permission_handler/permission_handler.dart';

extension PermissionName on Permission {
String get name => toString().split('.').last;
}

0 comments on commit 35b140f

Please sign in to comment.