Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/hosted platform views #67

Merged
merged 50 commits into from
Dec 5, 2023
Merged

Conversation

Robert-SD
Copy link
Contributor

Summary

Added card component

diff --git a/example/lib/main.dart b/example/lib/main.dart
index cf7a81b..60e1f30 100644
--- a/example/lib/main.dart
+++ b/example/lib/main.dart
@@ -88,11 +88,57 @@ class _MyAppState extends State<MyApp> {
                     MaterialPageRoute(
                         builder: (context) => FirstRoute(
                               repository: _adyenSessionRepository,
-
                             )),
                   );
                 },
-                child: const Text("Card component")),
+                child: const Text("Card component scroll view")),
+            TextButton(
+                onPressed: () {
+                  showModalBottomSheet(
+                      context: context,
+                      isScrollControlled: true,
+                      backgroundColor: Colors.white,
+                      shape: RoundedRectangleBorder(
+                        borderRadius: BorderRadius.circular(10.0),
+                      ),
+                      builder: (BuildContext context) {
+                        return SingleChildScrollView(
+                            child: Column(
+                          children: [
+                            Container(height: 8),
+                            Container(
+                              width: 48,
+                              height: 6,
+                              decoration: BoxDecoration(
+                                  borderRadius: BorderRadius.circular(10),
+                                  color: Colors.grey),
+                            ),
+                            Container(height: 8),
+                            Container(
+                              padding: EdgeInsets.only(
+                                  bottom:
+                                      MediaQuery.of(context).viewInsets.bottom),
+                              child: FutureBuilder<String>(
+                                future: _adyenSessionRepository
+                                    .fetchPaymentMethods(),
+                                builder: (BuildContext context,
+                                    AsyncSnapshot<String> snapshot) {
+                                  if (snapshot.data == null) {
+                                    return const Center(
+                                      child: CircularProgressIndicator(),
+                                    );
+                                  } else {
+                                    return buildCardWidget(snapshot, context,
+                                        _adyenSessionRepository);
+                                  }
+                                },
+                              ),
+                            ),
+                          ],
+                        ));
+                      });
+                },
+                child: const Text("Card component sheet")),
           ],
         ),
       ),
diff --git a/example/lib/navigation/routes.dart b/example/lib/navigation/routes.dart
index 2f48364..1f7c146 100644
--- a/example/lib/navigation/routes.dart
+++ b/example/lib/navigation/routes.dart
@@ -29,7 +29,7 @@ class FirstRoute extends StatelessWidget {
                   child: Column(
                     children: [
                       const FlutterLogo(size: 128),
-                      buildCardWidget(snapshot, context),
+                      buildCardWidget(snapshot, context, repository),
                       Container(height: 50),
                       Container(height: 280, color: Colors.blue),
                       const Text(
@@ -43,55 +43,60 @@ class FirstRoute extends StatelessWidget {
           ),
         ));
   }
+}

-  Widget buildCardWidget(AsyncSnapshot<String> snapshot, BuildContext context) {
-    return AdyenCardWidget(
-      paymentMethods: snapshot.data!,
-      clientKey: Config.clientKey,
-      onSubmit: repository.postPayments,
-      onResult: (event) async {
-        _dialogBuilder(context, event);
-      },
-    );
-  }

-  _dialogBuilder(BuildContext context, PaymentResult paymentResult) {
-    String title = "";
-    String message = "";
-    switch (paymentResult) {
-      case PaymentAdvancedFlowFinished():
-        title = "Finished";
-        message = "Result code: ${paymentResult.resultCode}";
-      case PaymentSessionFinished():
-        title = "Finished";
-        message = "Result code: ${paymentResult.resultCode}";
-      case PaymentCancelledByUser():
-        title = "Cancelled by user";
-        message = "Drop-in cancelled by user";
-      case PaymentError():
-        title = "Error occurred";
-        message = "${paymentResult.reason}";
-    }
+Widget buildCardWidget(
+  AsyncSnapshot<String> snapshot,
+  BuildContext context,
+  AdyenSessionsRepository repository,
+) {
+  return AdyenCardWidget(
+    paymentMethods: snapshot.data!,
+    clientKey: Config.clientKey,
+    onSubmit: repository.postPayments,
+    onResult: (event) async {
+      _dialogBuilder(context, event);
+    },
+  );
+}

-    return showDialog(
-      context: context,
-      builder: (BuildContext context) {
-        return AlertDialog(
-          title: Text(title),
-          content: Text(message),
-          actions: <Widget>[
-            TextButton(
-              style: TextButton.styleFrom(
-                textStyle: Theme.of(context).textTheme.labelLarge,
-              ),
-              child: const Text('Close'),
-              onPressed: () {
-                Navigator.of(context).pop();
-              },
-            ),
-          ],
-        );
-      },
-    );
+_dialogBuilder(BuildContext context, PaymentResult paymentResult) {
+  String title = "";
+  String message = "";
+  switch (paymentResult) {
+    case PaymentAdvancedFlowFinished():
+      title = "Finished";
+      message = "Result code: ${paymentResult.resultCode}";
+    case PaymentSessionFinished():
+      title = "Finished";
+      message = "Result code: ${paymentResult.resultCode}";
+    case PaymentCancelledByUser():
+      title = "Cancelled by user";
+      message = "Drop-in cancelled by user";
+    case PaymentError():
+      title = "Error occurred";
+      message = "${paymentResult.reason}";
   }
+
+  return showDialog(
+    context: context,
+    builder: (BuildContext context) {
+      return AlertDialog(
+        title: Text(title),
+        content: Text(message),
+        actions: <Widget>[
+          TextButton(
+            style: TextButton.styleFrom(
+              textStyle: Theme.of(context).textTheme.labelLarge,
+            ),
+            child: const Text('Close'),
+            onPressed: () {
+              Navigator.of(context).pop();
+            },
+          ),
+        ],
+      );
+    },
+  );
 }
diff --git a/example/lib/network/models/session_request_network_model.dart b/example/lib/network/models/session_request_network_model.dart
index 232e31f..22d6f9f 100644
--- a/example/lib/network/models/session_request_network_model.dart
+++ b/example/lib/network/models/session_request_network_model.dart
@@ -47,6 +47,29 @@ class SessionRequestNetworkModel {
   String toRawJson() => json.encode(toJson());

   Map<String, dynamic> toJson() {
+    Map<String, dynamic> installmentOptions = json.decode("""{
+        "visa": {
+                "plans": [
+                    "regular"
+                ],
+                "values": [
+                    2,
+                    4
+                ]
+            },
+        "mc": {
+            "values": [
+                2,
+                3,
+                5
+            ],
+            "plans": [
+                "regular",
+                "revolving"
+            ]
+        }
+    }""");
+
     final Map<String, dynamic> data = <String, dynamic>{};
     data['merchantAccount'] = merchantAccount;
     data['amount'] = amount.toJson();
@@ -66,6 +89,7 @@ class SessionRequestNetworkModel {
     data['deliveryAddress'] = deliveryAddress?.toJson();
     data['lineItems'] =
         lineItems?.map((lineItem) => lineItem.toJson()).toList();
+    data['installmentOptions'] = installmentOptions;
     return data;
   }
 }
diff --git a/ios/Classes/components/CardComponent.swift b/ios/Classes/components/CardComponent.swift
index 9607bd5..703763a 100644
--- a/ios/Classes/components/CardComponent.swift
+++ b/ios/Classes/components/CardComponent.swift
@@ -79,7 +79,6 @@ class FLNativeView: NSObject, FlutterPlatformView, PaymentComponentDelegate {
     }

     func createNativeView(view _view: TestView, args: NSDictionary){
-        _view.backgroundColor = UIColor.blue

         _view.handler = {
             let height = self.cardComponent?.viewController.preferredContentSize.height
@@ -97,6 +96,7 @@ class FLNativeView: NSObject, FlutterPlatformView, PaymentComponentDelegate {
             self.cardComponent = component
             let componentViewController = component.viewController

+
             rootViewController = getViewController()
             rootViewController?.addChild(componentViewController)

@@ -104,6 +104,7 @@ class FLNativeView: NSObject, FlutterPlatformView, PaymentComponentDelegate {
             componentViewController.view.frame = CGRect(x:0.0, y:0.0, width: 0, height:0)
             (componentViewController.view.subviews[0].subviews[0] as? UIScrollView)?.bounces = false
             (componentViewController.view.subviews[0].subviews[0] as? UIScrollView)?.isScrollEnabled = false
+            (componentViewController.view.subviews[0].subviews[0] as? UIScrollView)?.alwaysBounceVertical = false

             //let formViewController = componentViewController.children[0]
@@ -154,8 +155,11 @@ class FLNativeView: NSObject, FlutterPlatformView, PaymentComponentDelegate {
             throw PlatformError(errorDescription: "error")
         }

+        var style = FormComponentStyle()
+        style.backgroundColor = UIColor.clear
         let component = CardComponent(paymentMethod: paymentMethod,
-                                      context: adyenContext
+                                      context: adyenContext,
+                                      configuration: .init(style: style)
                                 )
         component.cardComponentDelegate = self
         return component
diff --git a/ios/Classes/components/TestView.swift b/ios/Classes/components/TestView.swift
index 15c5850..f8de610 100644
--- a/ios/Classes/components/TestView.swift
+++ b/ios/Classes/components/TestView.swift
@@ -25,9 +25,5 @@ class TestView : UIStackView {
         super.layoutSubviews()

         handler()
-
-        print("Layout custom view")
-        print(bounds.height)
-        print(subviews.first?.systemLayoutSizeFitting(.init(width: bounds.width, height: .greatestFiniteMagnitude)))
     }
 }
diff --git a/lib/src/components/card_widget.dart b/lib/src/components/card_widget.dart
index 65b390a..58c75dc 100644
--- a/lib/src/components/card_widget.dart
+++ b/lib/src/components/card_widget.dart
@@ -65,15 +65,10 @@ class AdyenCardWidget extends StatelessWidget {
         builder: (BuildContext context, AsyncSnapshot<double> snapshot) {
           print("value is: $snapshot");
           return SizedBox(
-            height: snapshot.data ?? 500,
+            height: (snapshot.data ?? 300) + 40,
             child: cardView,
           );
         });
-
-    // return SizedBox(
-    //   height: 500,
-    //   child: cardView,
-    // );
   }

   Widget buildCardView(String viewType, Map<String, dynamic> creationParams) {
…mViews

# Conflicts:
#	android/src/main/kotlin/com/adyen/adyen_checkout/PlatformApi.kt
#	ios/Classes/PlatformApi.swift
#	lib/src/generated/platform_api.g.dart
#	pigeons/platform_api.dart
@Robert-SD Robert-SD merged commit 0889ab3 into main Dec 5, 2023
1 check passed
@Robert-SD Robert-SD deleted the feature/hostedPlatformViews branch December 5, 2023 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants