├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── documentation.md │ ├── feature_request.md │ └── question.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── main.yml │ └── publish.yml ├── .gitignore ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── analysis_options.yaml ├── android ├── .gitignore ├── build.gradle ├── gradle.properties ├── settings.gradle └── src │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── squareup │ └── sdk │ └── reader │ └── flutter │ ├── AuthorizeModule.java │ ├── CheckoutModule.java │ ├── ReaderSettingsModule.java │ ├── SquareReaderSdkFlutterPlugin.java │ ├── StoreCustomerCardModule.java │ └── internal │ ├── DateFormatUtils.java │ ├── ErrorHandlerUtils.java │ └── converter │ ├── CardConverter.java │ ├── CheckoutResultConverter.java │ ├── LocationConverter.java │ ├── MoneyConverter.java │ ├── TenderCardDetailsConverter.java │ ├── TenderCashDetailsConverter.java │ └── TenderConverter.java ├── doc ├── get-started.md ├── reference.md └── troubleshooting.md ├── example ├── .gitignore ├── .metadata ├── README.md ├── analysis_options.yaml ├── android │ ├── .gitignore │ ├── app │ │ ├── build.gradle │ │ └── src │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── flutter │ │ │ │ └── squareup │ │ │ │ └── sdk │ │ │ │ └── reader │ │ │ │ ├── MainActivity.java │ │ │ │ └── MainApplication.java │ │ │ └── res │ │ │ ├── drawable-hdpi │ │ │ └── ic_jewel.png │ │ │ ├── drawable-mdpi │ │ │ └── ic_jewel.png │ │ │ ├── drawable-xhdpi │ │ │ └── ic_jewel.png │ │ │ ├── drawable-xxhdpi │ │ │ └── ic_jewel.png │ │ │ ├── drawable-xxxhdpi │ │ │ └── ic_jewel.png │ │ │ ├── drawable │ │ │ ├── ic_launcher_foreground.xml │ │ │ ├── launch_background.xml │ │ │ ├── launcher_screen.xml │ │ │ └── window_background.xml │ │ │ ├── mipmap-anydpi │ │ │ └── ic_launcher.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle.properties.enc │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── icons │ └── ic_jewel.png ├── ios │ ├── .gitignore │ ├── Flutter │ │ ├── AppFrameworkInfo.plist │ │ ├── Debug.xcconfig │ │ └── Release.xcconfig │ ├── Podfile │ ├── Podfile.lock │ ├── Runner.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── Runner.xcscheme │ ├── Runner.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── WorkspaceSettings.xcsettings │ └── Runner │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ ├── Contents.json │ │ │ ├── Icon-20@2x.png │ │ │ ├── Icon-20@3x.png │ │ │ ├── Icon-29@2x.png │ │ │ ├── Icon-29@3x.png │ │ │ ├── Icon-40@2x.png │ │ │ ├── Icon-40@3x.png │ │ │ ├── Icon-60@2x.png │ │ │ ├── Icon-60@3x.png │ │ │ └── iTunesArtwork@2x.png │ │ ├── Contents.json │ │ └── Logo.imageset │ │ │ ├── Contents.json │ │ │ └── Logo.pdf │ │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ │ ├── Info.plist │ │ └── Runner-Bridging-Header.h ├── lib │ ├── generated_plugin_registrant.dart │ ├── main.dart │ └── screens │ │ ├── authorize_screen.dart │ │ ├── checkout_screen.dart │ │ ├── manual_authorize_screen.dart │ │ ├── splash_screen.dart │ │ └── widgets │ │ ├── animated_square_logo.dart │ │ ├── buttons.dart │ │ ├── dialog_modal.dart │ │ ├── loading.dart │ │ └── square_logo.dart └── pubspec.yaml ├── ios ├── .gitignore ├── Assets │ └── .gitkeep ├── Classes │ ├── Converters │ │ ├── FlutterReaderSDKDateFormatter.h │ │ ├── FlutterReaderSDKDateFormatter.m │ │ ├── SQRDCard+FlutterReaderSDKAdditions.h │ │ ├── SQRDCard+FlutterReaderSDKAdditions.m │ │ ├── SQRDCheckoutResult+FlutterReaderSDKAdditions.h │ │ ├── SQRDCheckoutResult+FlutterReaderSDKAdditions.m │ │ ├── SQRDLocation+FlutterReaderSDKAdditions.h │ │ ├── SQRDLocation+FlutterReaderSDKAdditions.m │ │ ├── SQRDMoney+FlutterReaderSDKAdditions.h │ │ ├── SQRDMoney+FlutterReaderSDKAdditions.m │ │ ├── SQRDTender+FlutterReaderSDKAdditions.h │ │ ├── SQRDTender+FlutterReaderSDKAdditions.m │ │ ├── SQRDTenderCardDetails+FlutterReaderSDKAdditions.h │ │ ├── SQRDTenderCardDetails+FlutterReaderSDKAdditions.m │ │ ├── SQRDTenderCashDetails+FlutterReaderSDKAdditions.h │ │ └── SQRDTenderCashDetails+FlutterReaderSDKAdditions.m │ ├── FlutterReaderSDKAuthorization.h │ ├── FlutterReaderSDKAuthorization.m │ ├── FlutterReaderSDKCheckout.h │ ├── FlutterReaderSDKCheckout.m │ ├── FlutterReaderSDKErrorUtilities.h │ ├── FlutterReaderSDKErrorUtilities.m │ ├── FlutterReaderSDKReaderSettings.h │ ├── FlutterReaderSDKReaderSettings.m │ ├── FlutterReaderSDKStoreCustomerCard.h │ ├── FlutterReaderSDKStoreCustomerCard.m │ ├── SquareReaderSdkFlutterPlugin.h │ └── SquareReaderSdkFlutterPlugin.m └── square_reader_sdk.podspec ├── lib ├── models.dart ├── models.g.dart ├── reader_sdk.dart └── src │ ├── serializers.dart │ └── serializers.g.dart └── pubspec.yaml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41B Issue report" 3 | about: I hit an error when I tried to use this plugin. 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe the issue 11 | 23 | 24 | ### To Reproduce 25 | 53 | 54 | ### Expected behavior 55 | 60 | 61 | 62 | **Environment (please complete the following information):** 63 | 71 | 72 | ### Screenshots 73 | 74 | 75 | ### Additional context 76 | 77 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F4C3 Documentation Feedback" 3 | about: You want to suggest improvements or report something that is wrong or missing 4 | from the documentation. 5 | title: '' 6 | labels: documentation 7 | assignees: '' 8 | 9 | --- 10 | 11 | ### Describe the change you would like to see 12 | 14 | 15 | ### How would the suggested change make the documentation more useful? 16 | 18 | 19 | ### Additional context 20 | 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F680 Feature request" 3 | about: You have an idea that could make this plugin better 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe the functionality you would like to see 11 | 13 | 14 | ### How would this feature make the plugin more useful? 15 | 17 | 18 | ### Additional context 19 | 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F914 Questions and Help" 3 | about: You have a quetion or need help using this plugin. 4 | title: '' 5 | labels: question 6 | assignees: '' 7 | 8 | --- 9 | 10 | ### Describe your question 11 | 13 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 8 | 9 | ## Summary 10 | 11 | 12 | 13 | ## Related issues 14 | 15 | Fix # 16 | 17 | ## Changelog 18 | 19 | 20 | 21 | * message 22 | 23 | ## Test Plan 24 | 25 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: reader-sdk-flutter-plugin 2 | on: [push] 3 | jobs: 4 | install-and-test: 5 | runs-on: macos-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - uses: actions/setup-java@v3 9 | with: 10 | java-version: '17' 11 | distribution: 'temurin' 12 | - uses: subosito/flutter-action@v1 13 | with: 14 | channel: 'stable' # or: 'beta', 'dev' or 'master' 15 | - run: flutter pub get 16 | # Android 17 | - run: | 18 | cd example 19 | flutter pub get 20 | cd android 21 | ./gradlew clean build -PSQUARE_READER_SDK_APPLICATION_ID=${{secrets.SQUARE_READER_SDK_APPLICATION_ID}} -PSQUARE_READER_SDK_REPOSITORY_PASSWORD=${{secrets.SQUARE_READER_SDK_REPOSITORY_PASSWORD}} 22 | # #IOS 23 | - run: | 24 | cd example 25 | flutter pub get 26 | cd ios 27 | ruby <(curl https://connect.squareup.com/readersdk-installer) install --app-id ${{secrets.SQUARE_READER_SDK_APPLICATION_ID}} --repo-password ${{secrets.SQUARE_READER_SDK_REPOSITORY_PASSWORD}} --version 1.6.1 > /dev/null 28 | flutter clean 29 | rm Pods && rm Podfile.lock 30 | flutter pub get 31 | pod update Firebase/CoreOnly 32 | pod install --repo-update 33 | xcodebuild -workspace Runner.xcworkspace -configuration Debug -scheme Runner -destination "platform=iOS Simulator,OS=16.2,name=iPhone 14" -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to pub.dev 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v[0-9]+.[0-9]+.[0-9]+*' 7 | 8 | jobs: 9 | publish: 10 | permissions: 11 | id-token: write # Required for authentication using OIDC 12 | uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 13 | # with: 14 | # working-directory: path/to/package/within/repository -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | pubspec.lock 7 | 8 | build/ 9 | android/.project 10 | .vscode/settings.json 11 | android/.classpath 12 | android/.settings/org.eclipse.buildship.core.prefs 13 | .clang-format 14 | android/bin 15 | .vscode/launch.json 16 | 17 | .idea/ 18 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Changelog 2 | 3 | ### v4.0.1 Aug 29st, 2024 4 | 5 | * Upgrade to Reader SDK 1.7.5 on Android. 6 | * Support CompileSDK and targetSDK 34 on Android 7 | * Fixed the [issue](https://github.com/square/reader-sdk-flutter-plugin/pull/116) with resuming the app after process is killed on Android. 8 | 9 | ### v4.0.0 Sep 1st, 2022 10 | 11 | * Update package dependencies to latest versions for Null Safety support. 12 | * Update example UI 13 | * Support Flutter 3 14 | * Upgrade to Reader SDK 1.6.0 on iOS and 1.6.1 on Android. 15 | * Support CompileSDK and targetSDK 30+ on Android 16 | 17 | ### v3.0.0 July 23rd, 2021 18 | 19 | * Update package dependencies to latest versions for Null Safety support. 20 | * Plugin and Example code migration to null safety. 21 | * Dart version : 2.12 22 | 23 | ### v2.3.0 April 20, 2021 24 | 25 | * Adding support for Reader SDK 1.4.4+ on both Android and iOS. 26 | * On iOS, in Reader SDK 1.4.7+, the plugin now correctly handles the `SquareReaderSDK.xcframework` being downloaded 27 | 28 | ### v2.2.0 June 24, 2020 29 | 30 | * Added support for v2 flutter embeddings (flutter 1.12+). 31 | 32 | ### v2.1.0 Oct 22, 2019 33 | 34 | * Update Square Reader SDK minimum supported version to 1.3.3 in order to support iOS 13 35 | * Now requires Xcode 10.2+ 36 | 37 | ### v2.0.3 Sep 16, 2019 38 | * add support for isAuthorizationInProgress 39 | 40 | ### v2.0.2 Aug 25, 2019 41 | 42 | * Update Square Reader SDK minimum supported version to 1.3.1 43 | * Add delay capture support 44 | 45 | ### v2.0.1 Mar 29, 2019 46 | 47 | * Fix the bug on Android default Reader SDK version setting 48 | 49 | ### v2.0.0 Mar 29, 2019 50 | 51 | * Support AndroidX. 52 | * Upgrade to Square Reader SDK 1.2.1 (Android Only) 53 | 54 | ### v1.1.1 Mar 13, 2019 55 | 56 | * add **store customer card** suport. 57 | 58 | ### v1.1.0 Mar 5, 2019 59 | 60 | * remove `alwaysRequireSignature` and add `collectSignature` to checkout configuration. 61 | * bump the minimum dependency to Reader SDK 1.1.1(iOS)/1.1.3(Android). 62 | * this change **does NOT** include all new features introduced in Reader SDK 1.1.* such as **Store customer card**, see reader SDK [Change Log](https://docs.connect.squareup.com/changelog/mobile-logs/2019-02-13) for details. 63 | 64 | ### v1.0.3 Dec 5, 2018 65 | 66 | * Documentation update. 67 | 68 | ### v1.0.2 Dec 4, 2018 69 | 70 | * Initial release. 71 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | If you would like to contribute code to this project you must sign the 5 | [Individual Contributor License Agreement (CLA)]. Your code cannot be accepted 6 | into the project until you sign the agreement. 7 | 8 | **DO NOT SUBMIT CHANGES THAT BREAK THE QUICK START SAMPLE APP**. If you are 9 | adding new features, confirm the functionality is compatible with the sample app 10 | (at minimum) or consider adding to the sample code to demonstrate the new 11 | feature (recommended). 12 | 13 | To contribute: 14 | 15 | 1. Fork this repository. 16 | 1. Follow existing coding conventions and styles to keep the code as readable 17 | as possible. 18 | 1. Comment your code so others can understand it easily. 19 | 1. Update the associated docs (README, reference, etc.) to reflect your changes 20 | as needed. If appropriate, you can add a new markdown page to the `doc` 21 | folder to document your changes. 22 | 1. Submit a pull request with your changes. 23 | 24 | 25 | [//]: # "Link anchor definitions" 26 | [Individual Contributor License Agreement (CLA)]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Flutter plugin for Reader SDK 2 | 3 | [![build](https://github.com/square/reader-sdk-flutter-plugin/actions/workflows/build.yml/badge.svg)](https://github.com/square/reader-sdk-flutter-plugin/actions/workflows/build.yml) 4 | [![Pub](https://img.shields.io/pub/v/square_reader_sdk)](https://pub.dev/packages/square_reader_sdk) 5 | 6 | Square [Reader SDK] lets developers embed the [Square] checkout flow and accept 7 | in-person payments in custom apps using Square Readers. The SDK supports 8 | authorization, transaction processing, and Reader management. 9 | 10 | Use Square's official Flutter plugin for Reader SDK to build in-person payment 11 | solutions on Android and iOS. 12 | 13 | ## Migration from 3.x to 4.x 14 | 15 | Remove initialize method from `onCreate` method in your application class in Android portion 16 | 17 | ```diff 18 | package ; 19 | 20 | - import com.squareup.sdk.reader.ReaderSdk; 21 | import io.flutter.app.FlutterApplication; 22 | 23 | public class MainApplication extends FlutterApplication { 24 | 25 | @Override 26 | public void onCreate() { 27 | super.onCreate(); 28 | - ReaderSdk.initialize(this); 29 | } 30 | } 31 | ``` 32 | 33 | ### If you targeting SDK 31 and above 34 | Go to your app and add code to request `BLUETOOTH_SCAN` and `BLUETOOTH_CONNECT` permissions before 35 | you invoke any of Reader plugin method. 36 | 37 | ## How to use 38 | 39 | The Flutter plugin for Reader SDK acts as a wrapper on the native SDKs and is 40 | currently compatible with the following native Reader SDK versions: 41 | 42 | * iOS: 1.6.0 and above 43 | * Android: 1.7.5 and above 44 | 45 | Try the [sample app] to see the plugin in action or follow the instructions in 46 | the [getting started guide] to build a custom solution from scratch. 47 | 48 | 49 | ### Additional documentation 50 | 51 | In addition to this README, the following is available in the 52 | [flutter plugin GitHub repo]: 53 | 54 | * [Getting Started] 55 | * [Technical Reference] 56 | * [Troubleshooting] 57 | * [`doc`] - Root directory for all documentation 58 | * [`example`] - Root directory of the Flutter sample app (with walkthrough). 59 | 60 | 61 | ## Build requirements 62 | 63 | ### Flutter 64 | 65 | * Flutter version 2.0 or higher 66 | * Dart version 2.12 or higher 67 | 68 | ### Android 69 | 70 | * minSdkVersion is API 24 or higher. 71 | * Android SDK platform: API 31. 72 | * Android SDK build tools: 28.0.2 73 | * Android Gradle Plugin: 3.0.0 or greater. 74 | * Support library: 26.0.2 75 | * Google Play Services: 16.0.1 76 | * Google APIs Intel x86 Atom_64 System Image 77 | 78 | ### iOS 79 | 80 | * Xcode version: 10.2 or greater. 81 | * iOS Base SDK: 11.1 or greater. 82 | * Deployment target: iOS 11.0 or greater. 83 | 84 | 85 | ## Reader SDK requirements and limitations 86 | 87 | * Reader SDK is only available for accounts based in the United States. 88 | Authorization requests for accounts based outside the United States return an 89 | error. 90 | * Reader SDK may not be used for unattended terminals. Using Reader SDK to 91 | implement payment solutions in unattended terminals or kiosks (for example, 92 | vending machines) is strictly prohibited. 93 | * Reader SDK requires an authorization token from the [Mobile Authorization API] 94 | to connect Square Readers and accept payments. 95 | * Reader SDK only supports on-screen tipping. Digital receipts and tips can be 96 | configured in Reader SDK. Tipping on printed receipts is not supported at this 97 | time. 98 | * Reader SDK cannot issue refunds. Refunds can be issued programmatically using 99 | the Refunds API or manually in the [Square Dashboard]. 100 | * Reader SDK is not supported in the Square sandbox. See [Testing Mobile Apps] 101 | for testing recommendations. 102 | * Your version of Reader SDK must adhere to the Square SDK update policy. To 103 | limit risk to developers and their users, Square enforces an 104 | [update policy for Reader SDK] that requires developers to keep their version 105 | of Reader SDK current. 106 | 107 | 108 | ## License 109 | 110 | ``` 111 | Copyright 2022 Square Inc. 112 | 113 | Licensed under the Apache License, Version 2.0 (the "License"); 114 | you may not use this file except in compliance with the License. 115 | You may obtain a copy of the License at 116 | 117 | http://www.apache.org/licenses/LICENSE-2.0 118 | 119 | Unless required by applicable law or agreed to in writing, software 120 | distributed under the License is distributed on an "AS IS" BASIS, 121 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122 | See the License for the specific language governing permissions and 123 | limitations under the License. 124 | ``` 125 | 126 | 127 | [//]: # "Link anchor definitions" 128 | [Mobile Authorization API]: https://developer.squareup.com/docs/mobile-authz/build-with-mobile-authz 129 | [Reader SDK]: https://developer.squareup.com/docs/reader-sdk/what-it-does 130 | [Square Dashboard]: https://squareup.com/dashboard/ 131 | [Square]: https://squareup.com 132 | [update policy for Reader SDK]: https://developer.squareup.com/docs/reader-sdk/what-it-does#reader-sdk-update-policy 133 | [Testing Mobile Apps]: https://developer.squareup.com/docs/testing/mobile 134 | [`doc`]: https://github.com/square/reader-sdk-flutter-plugin/tree/master/doc 135 | [`example`]: https://github.com/square/reader-sdk-flutter-plugin/tree/master/example 136 | [Getting Started]: https://github.com/square/reader-sdk-flutter-plugin/tree/master/doc/get-started.md 137 | [Technical Reference]: https://github.com/square/reader-sdk-flutter-plugin/tree/master/doc/reference.md 138 | [Troubleshooting]: https://github.com/square/reader-sdk-flutter-plugin/tree/master/doc/troubleshooting.md 139 | [sample app]: https://github.com/square/reader-sdk-flutter-plugin/tree/master/example/README.md 140 | [getting started guide]: https://github.com/square/reader-sdk-flutter-plugin/tree/master/doc/get-started.md 141 | [flutter plugin GitHub repo]: https://github.com/square/reader-sdk-flutter-plugin/tree/master 142 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | linter: 2 | rules: 3 | # --- STYLE 4 | # identifiers 5 | - camel_case_types 6 | - library_names 7 | - file_names 8 | - library_prefixes 9 | - non_constant_identifier_names 10 | - constant_identifier_names # prefer 11 | # ordering 12 | - directives_ordering 13 | # formating 14 | - curly_braces_in_flow_control_structures 15 | # --- DOCUMENTATION 16 | # comments 17 | # doc comments 18 | - slash_for_doc_comments 19 | - comment_references 20 | # markdown 21 | # writing 22 | # --- USAGE 23 | # libraries 24 | - implementation_imports 25 | - avoid_relative_lib_imports 26 | # strings 27 | - prefer_adjacent_string_concatenation 28 | - prefer_interpolation_to_compose_strings # prefer 29 | - unnecessary_brace_in_string_interps # avoid 30 | # collections 31 | - prefer_collection_literals 32 | - avoid_function_literals_in_foreach_calls # avoid 33 | - prefer_iterable_whereType 34 | # functions 35 | - prefer_function_declarations_over_variables 36 | - unnecessary_lambdas 37 | # parameters 38 | - prefer_equal_for_default_values 39 | # variables 40 | - avoid_init_to_null 41 | # members 42 | - unnecessary_getters_setters 43 | - prefer_final_fields 44 | - prefer_expression_function_bodies # consider 45 | - unnecessary_this 46 | - prefer_typing_uninitialized_variables 47 | # constructors 48 | - prefer_initializing_formals 49 | - type_init_formals 50 | - empty_constructor_bodies 51 | - unnecessary_new 52 | - unnecessary_const 53 | # error handling 54 | - avoid_catches_without_on_clauses # avoid 55 | - use_rethrow_when_possible 56 | # asynchrony 57 | # --- DESIGN 58 | # names 59 | - use_to_and_as_if_applicable 60 | # libraries 61 | # classes 62 | - one_member_abstracts # avoid 63 | - avoid_classes_with_only_static_members # avoid 64 | # constructors 65 | - prefer_constructors_over_static_methods 66 | # members 67 | - use_setters_to_change_properties 68 | - avoid_setters_without_getters 69 | - avoid_returning_null # avoid 70 | - avoid_returning_this # avoid 71 | # types 72 | - type_annotate_public_apis # prefer 73 | - omit_local_variable_types # avoid 74 | - avoid_types_on_closure_parameters # avoid 75 | - avoid_return_types_on_setters 76 | - prefer_generic_function_type_aliases 77 | - avoid_private_typedef_functions # prefer 78 | # parameters 79 | - avoid_positional_boolean_parameters # avoid 80 | # equality 81 | - hash_and_equals 82 | - avoid_null_checks_in_equality_operators -------------------------------------------------------------------------------- /android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | group 'com.squareup.readersdkflutterplugin' 17 | version '2.0-SNAPSHOT' 18 | 19 | buildscript { 20 | repositories { 21 | google() 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | classpath 'com.android.tools.build:gradle:8.5.2' 27 | } 28 | } 29 | 30 | rootProject.allprojects { 31 | repositories { 32 | google() 33 | mavenCentral() 34 | maven { 35 | url "https://sdk.squareup.com/android" 36 | credentials { 37 | username SQUARE_READER_SDK_APPLICATION_ID 38 | password SQUARE_READER_SDK_REPOSITORY_PASSWORD 39 | } 40 | } 41 | } 42 | } 43 | 44 | apply plugin: 'com.android.library' 45 | 46 | def DEFAULT_PLAY_SERVICES_BASE_VERSION = '16.0.1' 47 | def READER_SDK_VERSION = '1.7.5' 48 | 49 | android { 50 | compileSdkVersion 34 51 | namespace 'com.squareup.readersdkflutterplugin' 52 | defaultConfig { 53 | minSdkVersion 24 54 | targetSdkVersion 34 55 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 56 | multiDexEnabled true 57 | } 58 | lintOptions { 59 | disable 'InvalidPackage' 60 | } 61 | dexOptions { 62 | // Ensures incremental builds remain fast 63 | preDexLibraries true 64 | // Required to build with Reader SDK 65 | jumboMode true 66 | // Required to build with Reader SDK 67 | keepRuntimeAnnotatedClasses false 68 | } 69 | } 70 | 71 | dependencies { 72 | def readerSdkVersion = rootProject.hasProperty('readerSdkVersion') ? rootProject.readerSdkVersion : READER_SDK_VERSION 73 | def playServicesBaseVersion = rootProject.hasProperty('googlePlayServiceVersion') ? rootProject.googlePlayServiceVersion : DEFAULT_PLAY_SERVICES_BASE_VERSION 74 | implementation "com.google.android.gms:play-services-base:$playServicesBaseVersion" 75 | api "com.squareup.sdk.reader:reader-sdk-$SQUARE_READER_SDK_APPLICATION_ID:$readerSdkVersion" 76 | runtimeOnly "com.squareup.sdk.reader:reader-sdk-internals:$readerSdkVersion" 77 | } 78 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Square Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | org.gradle.jvmargs=-Xmx4g 16 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'square_reader_sdk' 2 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/ReaderSettingsModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter; 17 | 18 | import android.app.Activity; 19 | import android.content.Context; 20 | 21 | import com.squareup.sdk.reader.ReaderSdk; 22 | import com.squareup.sdk.reader.core.CallbackReference; 23 | import com.squareup.sdk.reader.core.ResultError; 24 | import com.squareup.sdk.reader.flutter.internal.ErrorHandlerUtils; 25 | import com.squareup.sdk.reader.hardware.ReaderSettingsActivityCallback; 26 | import com.squareup.sdk.reader.hardware.ReaderSettingsErrorCode; 27 | import io.flutter.plugin.common.MethodChannel.Result; 28 | 29 | final class ReaderSettingsModule { 30 | // Define all the reader settings debug codes and messages below 31 | // These error codes and messages **MUST** align with iOS error codes and dart error codes 32 | // Search KEEP_IN_SYNC_READER_SETTINGS_ERROR to update all places 33 | 34 | // flutter plugin debug error codes 35 | private static final String FL_READER_SETTINGS_ALREADY_IN_PROGRESS = "fl_reader_settings_already_in_progress"; 36 | 37 | // flutter plugin debug messages 38 | private static final String FL_MESSAGE_READER_SETTINGS_ALREADY_IN_PROGRESS = "A reader settings operation is already in progress. Ensure that the in-progress reader settings is completed before calling startReaderSettingsAsync again."; 39 | 40 | private volatile CallbackReference readerSettingCallbackRef; 41 | private Context currentContext; 42 | 43 | public ReaderSettingsModule(Context context) { 44 | currentContext = context; 45 | } 46 | 47 | public void startReaderSettings(final Result flutterResult) { 48 | if (readerSettingCallbackRef != null) { 49 | flutterResult.error( 50 | ErrorHandlerUtils.USAGE_ERROR, 51 | ErrorHandlerUtils.getNativeModuleErrorMessage(FL_READER_SETTINGS_ALREADY_IN_PROGRESS), 52 | ErrorHandlerUtils.getDebugErrorObject(FL_READER_SETTINGS_ALREADY_IN_PROGRESS, FL_MESSAGE_READER_SETTINGS_ALREADY_IN_PROGRESS)); 53 | return; 54 | } 55 | ReaderSettingsActivityCallback readerSettingsCallback = new ReaderSettingsActivityCallback() { 56 | @Override 57 | public void onResult(com.squareup.sdk.reader.core.Result> result) { 58 | readerSettingCallbackRef.clear(); 59 | readerSettingCallbackRef = null; 60 | if (result.isError()) { 61 | ResultError error = result.getError(); 62 | flutterResult.error( 63 | ErrorHandlerUtils.getErrorCode(error.getCode()), 64 | error.getMessage(), 65 | ErrorHandlerUtils.getDebugErrorObject(error.getDebugCode(), error.getDebugMessage())); 66 | return; 67 | } 68 | flutterResult.success(null); 69 | } 70 | }; 71 | readerSettingCallbackRef = ReaderSdk.readerManager() 72 | .addReaderSettingsActivityCallback(readerSettingsCallback); 73 | 74 | ReaderSdk.readerManager().startReaderSettingsActivity(currentContext); 75 | } 76 | 77 | public void setContext(Context context) { 78 | this.currentContext = context; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/SquareReaderSdkFlutterPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter; 17 | 18 | import android.app.Activity; 19 | import android.content.Context; 20 | 21 | import androidx.annotation.NonNull; 22 | 23 | import io.flutter.embedding.engine.plugins.FlutterPlugin; 24 | import io.flutter.embedding.engine.plugins.activity.ActivityAware; 25 | import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; 26 | import io.flutter.plugin.common.BinaryMessenger; 27 | import io.flutter.plugin.common.MethodCall; 28 | import io.flutter.plugin.common.MethodChannel; 29 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler; 30 | import io.flutter.plugin.common.MethodChannel.Result; 31 | import io.flutter.plugin.common.PluginRegistry.Registrar; 32 | import java.util.HashMap; 33 | 34 | import com.squareup.sdk.reader.ReaderSdk; 35 | 36 | public class SquareReaderSdkFlutterPlugin implements MethodCallHandler, FlutterPlugin, ActivityAware { 37 | 38 | private static MethodChannel methodChannel; 39 | private AuthorizeModule authorizeModule; 40 | private CheckoutModule checkoutModule; 41 | private ReaderSettingsModule readerSettingsModule; 42 | private StoreCustomerCardModule storeCustomerCardModule; 43 | private Activity currentActivity; 44 | private static boolean sdkInitialized = false; 45 | 46 | public static void registerWith(Registrar registrar) { 47 | SquareReaderSdkFlutterPlugin instance = new SquareReaderSdkFlutterPlugin(registrar.activity()); 48 | instance.onAttachedToEngine(registrar.activity(), registrar.messenger()); 49 | methodChannel.setMethodCallHandler(instance); 50 | 51 | } 52 | 53 | private SquareReaderSdkFlutterPlugin(Context context) { 54 | init(context); 55 | } 56 | 57 | /** 58 | * Needed by GeneratedPluginRegistrant to be able to construct the plugin and call onAttachedToEngine. 59 | */ 60 | public SquareReaderSdkFlutterPlugin() { 61 | } 62 | 63 | private void init(Context context) { 64 | authorizeModule = new AuthorizeModule(); 65 | checkoutModule = new CheckoutModule(context); 66 | readerSettingsModule = new ReaderSettingsModule(context); 67 | storeCustomerCardModule = new StoreCustomerCardModule(context); 68 | } 69 | 70 | private void setContextForModules(final Activity activity) { 71 | currentActivity = activity; 72 | checkoutModule.setContext(activity); 73 | readerSettingsModule.setContext(activity); 74 | storeCustomerCardModule.setContext(activity); 75 | } 76 | 77 | @Override 78 | public void onMethodCall(MethodCall call, @NonNull Result result) { 79 | initializeReaderSdk(); 80 | 81 | String methodName = call.method; 82 | switch (methodName) { 83 | case "isAuthorized": 84 | authorizeModule.isAuthorized(result); 85 | break; 86 | case "isAuthorizationInProgress": 87 | authorizeModule.isAuthorizationInProgress(result); 88 | break; 89 | case "authorizedLocation": 90 | authorizeModule.authorizedLocation(result); 91 | break; 92 | case "authorize": 93 | String authCode = call.argument("authCode"); 94 | authorizeModule.authorize(authCode, result); 95 | break; 96 | case "canDeauthorize": 97 | authorizeModule.canDeauthorize(result); 98 | break; 99 | case "deauthorize": 100 | authorizeModule.deauthorize(result); 101 | break; 102 | case "startCheckout": 103 | HashMap checkoutParams = call.argument("checkoutParams"); 104 | checkoutModule.startCheckout(checkoutParams, result); 105 | break; 106 | case "startReaderSettings": 107 | readerSettingsModule.startReaderSettings(result); 108 | break; 109 | case "startStoreCard": 110 | String customerId = call.argument("customerId"); 111 | storeCustomerCardModule.startStoreCard(customerId, result); 112 | break; 113 | default: 114 | result.notImplemented(); 115 | break; 116 | } 117 | } 118 | 119 | @Override 120 | public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { 121 | onAttachedToEngine(flutterPluginBinding.getApplicationContext(), flutterPluginBinding.getBinaryMessenger()); 122 | methodChannel.setMethodCallHandler(this); 123 | } 124 | 125 | private void onAttachedToEngine(Context context, BinaryMessenger messenger) { 126 | methodChannel = new MethodChannel(messenger, "square_reader_sdk"); 127 | init(context); 128 | } 129 | 130 | 131 | @Override 132 | public void onDetachedFromEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { 133 | methodChannel = null; 134 | } 135 | 136 | @Override 137 | public void onAttachedToActivity(@NonNull ActivityPluginBinding activityPluginBinding) { 138 | setContextForModules(activityPluginBinding.getActivity()); 139 | } 140 | 141 | @Override 142 | public void onDetachedFromActivityForConfigChanges() { 143 | } 144 | 145 | @Override 146 | public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding activityPluginBinding) { 147 | setContextForModules(activityPluginBinding.getActivity()); 148 | } 149 | 150 | @Override 151 | public void onDetachedFromActivity() { 152 | 153 | } 154 | 155 | private void initializeReaderSdk() { 156 | if (sdkInitialized) { 157 | return; 158 | } 159 | 160 | try { 161 | ReaderSdk.initialize(currentActivity.getApplication()); 162 | sdkInitialized = true; 163 | } catch (IllegalStateException e) { 164 | // allow double-initialization; devs _should_ init in Application.onCreate, 165 | // but to be non-breaking we try here also in case they didn't. 166 | } 167 | } 168 | } -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/StoreCustomerCardModule.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter; 17 | 18 | import android.app.Activity; 19 | import android.content.Context; 20 | 21 | import com.squareup.sdk.reader.ReaderSdk; 22 | import com.squareup.sdk.reader.checkout.Card; 23 | import com.squareup.sdk.reader.core.CallbackReference; 24 | import com.squareup.sdk.reader.core.ResultError; 25 | import com.squareup.sdk.reader.crm.StoreCardActivityCallback; 26 | import com.squareup.sdk.reader.crm.StoreCustomerCardErrorCode; 27 | import com.squareup.sdk.reader.flutter.internal.ErrorHandlerUtils; 28 | import com.squareup.sdk.reader.flutter.internal.converter.CardConverter; 29 | import io.flutter.plugin.common.MethodChannel.Result; 30 | 31 | final class StoreCustomerCardModule { 32 | // Define all the checkout debug codes and messages below 33 | // These error codes and messages **MUST** align with iOS error codes and dart error codes 34 | // Search KEEP_IN_SYNC_STORE_CUSTOMER_CARD_ERROR to update all places 35 | 36 | // flutter plugin debug error codes 37 | private static final String FL_STORE_CUSTOMER_CARD_ALREADY_IN_PROGRESS = "fl_store_customer_card_already_in_progress"; 38 | 39 | // flutter plugin debug messages 40 | private static final String FL_MESSAGE_STORE_CUSTOMER_CARD_ALREADY_IN_PROGRESS = "A store customer card operation is already in progress. Ensure that the in-progress store customer card is completed before calling startStoreCardAsync again."; 41 | 42 | private Context currentContext; 43 | private final CardConverter cardConverter; 44 | private volatile CallbackReference storeCustomerCardCallbackRef; 45 | 46 | 47 | public StoreCustomerCardModule(Context context) { 48 | currentContext = context; 49 | cardConverter = new CardConverter(); 50 | } 51 | 52 | public void startStoreCard(String customerId, final Result flutterResult) { 53 | if (storeCustomerCardCallbackRef != null) { 54 | flutterResult.error( 55 | ErrorHandlerUtils.USAGE_ERROR, 56 | ErrorHandlerUtils.getNativeModuleErrorMessage(FL_STORE_CUSTOMER_CARD_ALREADY_IN_PROGRESS), 57 | ErrorHandlerUtils.getDebugErrorObject(FL_STORE_CUSTOMER_CARD_ALREADY_IN_PROGRESS, FL_MESSAGE_STORE_CUSTOMER_CARD_ALREADY_IN_PROGRESS)); 58 | return; 59 | } 60 | 61 | StoreCardActivityCallback storeCardActivityCallback = new StoreCardActivityCallback() { 62 | @Override 63 | public void onResult(com.squareup.sdk.reader.core.Result> result) { 64 | storeCustomerCardCallbackRef.clear(); 65 | storeCustomerCardCallbackRef = null; 66 | if (result.isError()) { 67 | ResultError error = result.getError(); 68 | flutterResult.error( 69 | ErrorHandlerUtils.getErrorCode(error.getCode()), 70 | error.getMessage(), 71 | ErrorHandlerUtils.getDebugErrorObject(error.getDebugCode(), error.getDebugMessage())); 72 | return; 73 | } 74 | 75 | Card card = result.getSuccessValue(); 76 | flutterResult.success(cardConverter.toMapObject(card)); 77 | } 78 | }; 79 | 80 | storeCustomerCardCallbackRef = ReaderSdk.customerCardManager().addStoreCardActivityCallback(storeCardActivityCallback); 81 | ReaderSdk.customerCardManager().startStoreCardActivity(currentContext, customerId); 82 | } 83 | 84 | public void setContext(Context context) { 85 | this.currentContext = context; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/DateFormatUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal; 17 | 18 | import java.text.DateFormat; 19 | import java.text.SimpleDateFormat; 20 | import java.util.Date; 21 | 22 | public class DateFormatUtils { 23 | 24 | private static final ThreadLocal ISO_8601 = new ThreadLocal() { 25 | @Override protected DateFormat initialValue() { 26 | return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); 27 | } 28 | }; 29 | 30 | public static String formatISO8601UTC(Date date) { 31 | return ISO_8601.get().format(date); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/converter/CardConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal.converter; 17 | 18 | import com.squareup.sdk.reader.checkout.Card; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | public class CardConverter { 23 | private static final Map brandStringMap; 24 | 25 | static { 26 | brandStringMap = new HashMap<>(); 27 | for (Card.Brand brand : Card.Brand.values()) { 28 | switch(brand) { 29 | case OTHER_BRAND: 30 | brandStringMap.put(brand, "OTHER_BRAND"); 31 | break; 32 | case VISA: 33 | brandStringMap.put(brand, "VISA"); 34 | break; 35 | case MASTERCARD: 36 | brandStringMap.put(brand, "MASTERCARD"); 37 | break; 38 | case AMERICAN_EXPRESS: 39 | brandStringMap.put(brand, "AMERICAN_EXPRESS"); 40 | break; 41 | case DISCOVER: 42 | brandStringMap.put(brand, "DISCOVER"); 43 | break; 44 | case DISCOVER_DINERS: 45 | brandStringMap.put(brand, "DISCOVER_DINERS"); 46 | break; 47 | case INTERAC: 48 | brandStringMap.put(brand, "INTERAC"); 49 | break; 50 | case JCB: 51 | brandStringMap.put(brand, "JCB"); 52 | break; 53 | case CHINA_UNIONPAY: 54 | brandStringMap.put(brand, "CHINA_UNIONPAY"); 55 | break; 56 | case SQUARE_GIFT_CARD: 57 | brandStringMap.put(brand, "SQUARE_GIFT_CARD"); 58 | break; 59 | case EFTPOS: 60 | brandStringMap.put(brand, "EFTPOS"); 61 | break; 62 | case FELICA: 63 | brandStringMap.put(brand, "FELICA"); 64 | default: 65 | // UNKNOWN should never happen if the right Reader SDK version is loaded with plugin 66 | // But we choose not break plugin if the type isn't important 67 | brandStringMap.put(brand, "UNKNOWN"); 68 | } 69 | } 70 | } 71 | 72 | public HashMap toMapObject(Card card) { 73 | HashMap mapToReturn = new HashMap<>(); 74 | mapToReturn.put("brand", brandStringMap.get(card.getBrand())); 75 | mapToReturn.put("lastFourDigits", card.getLastFourDigits()); 76 | mapToReturn.put("expirationMonth", card.getExpirationMonth()); 77 | mapToReturn.put("expirationYear", card.getExpirationYear()); 78 | mapToReturn.put("id", card.getId()); 79 | mapToReturn.put("cardholderName", card.getCardholderName()); 80 | return mapToReturn; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/converter/CheckoutResultConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal.converter; 17 | 18 | import com.squareup.sdk.reader.flutter.internal.DateFormatUtils; 19 | import com.squareup.sdk.reader.checkout.CheckoutResult; 20 | import com.squareup.sdk.reader.checkout.Money; 21 | import com.squareup.sdk.reader.checkout.Tender; 22 | import java.util.ArrayList; 23 | import java.util.HashMap; 24 | 25 | public class CheckoutResultConverter { 26 | private final MoneyConverter moneyConverter; 27 | private final TenderConverter tenderConverter; 28 | 29 | public CheckoutResultConverter() { 30 | moneyConverter = new MoneyConverter(); 31 | tenderConverter = new TenderConverter(); 32 | } 33 | 34 | public HashMap toMapObject(CheckoutResult result) { 35 | HashMap mapToReturn = new HashMap<>(); 36 | if (result.getTransactionId() != null) { 37 | mapToReturn.put("transactionId", result.getTransactionId()); 38 | } 39 | mapToReturn.put("transactionClientId", result.getTransactionClientId()); 40 | mapToReturn.put("locationId", result.getLocationId()); 41 | mapToReturn.put("createdAt", DateFormatUtils.formatISO8601UTC(result.getCreatedAt())); 42 | Money totalMoney = result.getTotalMoney(); 43 | mapToReturn.put("totalMoney", moneyConverter.toMapObject(totalMoney)); 44 | Money totalTipMoney = result.getTotalTipMoney(); 45 | mapToReturn.put("totalTipMoney", moneyConverter.toMapObject(totalTipMoney)); 46 | 47 | ArrayList> tenders = new ArrayList<>(); 48 | for (Tender tender : result.getTenders()) { 49 | tenders.add(tenderConverter.toMapObject(tender)); 50 | } 51 | mapToReturn.put("tenders", tenders); 52 | 53 | return mapToReturn; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/converter/LocationConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal.converter; 17 | 18 | import com.squareup.sdk.reader.authorization.Location; 19 | import java.util.HashMap; 20 | 21 | public final class LocationConverter { 22 | private final MoneyConverter moneyConverter; 23 | 24 | public LocationConverter() { 25 | moneyConverter = new MoneyConverter(); 26 | } 27 | 28 | public HashMap toMapObject(Location location) { 29 | HashMap mapToReturn = new HashMap<>(); 30 | mapToReturn.put("locationId", location.getLocationId()); 31 | mapToReturn.put("name", location.getName()); 32 | mapToReturn.put("businessName", location.getBusinessName()); 33 | mapToReturn.put("isCardProcessingActivated", location.isCardProcessingActivated()); 34 | mapToReturn.put("minimumCardPaymentAmountMoney", moneyConverter.toMapObject(location.getMinimumCardPaymentAmountMoney())); 35 | mapToReturn.put("maximumCardPaymentAmountMoney", moneyConverter.toMapObject(location.getMaximumCardPaymentAmountMoney())); 36 | mapToReturn.put("currencyCode", location.getCurrencyCode().name()); 37 | 38 | return mapToReturn; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/converter/MoneyConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal.converter; 17 | 18 | import com.squareup.sdk.reader.checkout.Money; 19 | import java.util.HashMap; 20 | 21 | class MoneyConverter { 22 | public HashMap toMapObject(Money money) { 23 | HashMap mapToReturn = new HashMap<>(); 24 | mapToReturn.put("amount", money.getAmount()); 25 | mapToReturn.put("currencyCode", money.getCurrencyCode().name()); 26 | 27 | return mapToReturn; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/converter/TenderCardDetailsConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal.converter; 17 | 18 | import com.squareup.sdk.reader.checkout.TenderCardDetails; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | class TenderCardDetailsConverter { 23 | private static final Map entryMethodStringMap; 24 | 25 | static { 26 | entryMethodStringMap = new HashMap<>(); 27 | for (TenderCardDetails.EntryMethod method : TenderCardDetails.EntryMethod.values()) { 28 | switch (method) { 29 | case MANUALLY_ENTERED: 30 | entryMethodStringMap.put(method, "MANUALLY_ENTERED"); 31 | break; 32 | case SWIPE: 33 | entryMethodStringMap.put(method, "SWIPE"); 34 | break; 35 | case CHIP: 36 | entryMethodStringMap.put(method, "CHIP"); 37 | break; 38 | case CONTACTLESS: 39 | entryMethodStringMap.put(method, "CONTACTLESS"); 40 | break; 41 | default: 42 | // UNKNOWN should never happen if the right Reader SDK version is loaded with plugin 43 | // But we choose not break plugin if the type isn't important 44 | entryMethodStringMap.put(method, "UNKNOWN"); 45 | } 46 | } 47 | 48 | } 49 | private final CardConverter cardConverter; 50 | 51 | public TenderCardDetailsConverter(){ 52 | cardConverter = new CardConverter(); 53 | } 54 | 55 | public HashMap toMapObject(TenderCardDetails tenderCardDetails) { 56 | HashMap mapToReturn = new HashMap<>(); 57 | mapToReturn.put("entryMethod", entryMethodStringMap.get(tenderCardDetails.getEntryMethod())); 58 | mapToReturn.put("card", cardConverter.toMapObject(tenderCardDetails.getCard())); 59 | return mapToReturn; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/converter/TenderCashDetailsConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal.converter; 17 | 18 | import com.squareup.sdk.reader.checkout.TenderCashDetails; 19 | import java.util.HashMap; 20 | 21 | class TenderCashDetailsConverter { 22 | private final MoneyConverter moneyConverter; 23 | 24 | public TenderCashDetailsConverter(){ 25 | moneyConverter = new MoneyConverter(); 26 | } 27 | 28 | public HashMap toJSObject(TenderCashDetails tenderCashDetails) { 29 | HashMap mapToReturn = new HashMap<>(); 30 | mapToReturn.put("buyerTenderedMoney", moneyConverter.toMapObject(tenderCashDetails.getBuyerTenderedMoney())); 31 | mapToReturn.put("changeBackMoney", moneyConverter.toMapObject(tenderCashDetails.getChangeBackMoney())); 32 | return mapToReturn; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /android/src/main/java/com/squareup/sdk/reader/flutter/internal/converter/TenderConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.squareup.sdk.reader.flutter.internal.converter; 17 | 18 | import com.squareup.sdk.reader.flutter.internal.DateFormatUtils; 19 | import com.squareup.sdk.reader.checkout.Tender; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | class TenderConverter { 24 | private static final Map tenderTypeMap; 25 | 26 | static { 27 | tenderTypeMap = new HashMap<>(); 28 | for (Tender.Type type : Tender.Type.values()) { 29 | switch (type) { 30 | case CARD: 31 | tenderTypeMap.put(type, "card"); 32 | break; 33 | case CASH: 34 | tenderTypeMap.put(type, "cash"); 35 | break; 36 | case OTHER: 37 | tenderTypeMap.put(type, "other"); 38 | break; 39 | default: 40 | // unknown should never happen if the right Reader SDK version is loaded with plugin 41 | // But we choose not break plugin if the type isn't important 42 | tenderTypeMap.put(type, "unknown"); 43 | } 44 | } 45 | 46 | } 47 | 48 | private final MoneyConverter moneyConverter; 49 | private final TenderCardDetailsConverter tenderCardDetailsConverter; 50 | private final TenderCashDetailsConverter tenderCashDetailsConverter; 51 | 52 | public TenderConverter(){ 53 | moneyConverter = new MoneyConverter(); 54 | tenderCardDetailsConverter = new TenderCardDetailsConverter(); 55 | tenderCashDetailsConverter = new TenderCashDetailsConverter(); 56 | } 57 | 58 | public HashMap toMapObject(Tender tender) { 59 | HashMap mapToReturn = new HashMap<> (); 60 | mapToReturn.put("createdAt", DateFormatUtils.formatISO8601UTC(tender.getCreatedAt())); 61 | mapToReturn.put("tipMoney", moneyConverter.toMapObject(tender.getTipMoney())); 62 | mapToReturn.put("totalMoney", moneyConverter.toMapObject(tender.getTotalMoney())); 63 | Tender.Type tenderType = tender.getType(); 64 | mapToReturn.put("type", tenderTypeMap.get(tenderType)); 65 | 66 | if (tenderType == Tender.Type.CARD) { 67 | mapToReturn.put("tenderId", tender.getTenderId()); 68 | mapToReturn.put("cardDetails", tenderCardDetailsConverter.toMapObject(tender.getCardDetails())); 69 | } else if (tenderType == Tender.Type.CASH) { 70 | mapToReturn.put("cashDetails", tenderCashDetailsConverter.toJSObject(tender.getCashDetails())); 71 | } 72 | 73 | return mapToReturn; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .dart_tool/ 3 | 4 | .packages 5 | .pub/ 6 | 7 | build/ 8 | 9 | .flutter-plugins 10 | .flutter-plugins-dependencies 11 | 12 | android/.project 13 | android/.settings/org.eclipse.buildship.core.prefs 14 | android/app/.classpath 15 | android/app/.project 16 | android/app/.settings/org.eclipse.buildship.core.prefs 17 | android/app/bin/ 18 | ios/flutter 19 | ios/SquareReaderSDK.xcframework 20 | ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist 21 | .vscode -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 9299c02cf708497d6f72edda8efae0bb8340660e 8 | channel: beta 9 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Flutter Plugin for Reader SDK Quick Start 2 | 3 | 4 | 5 | ## Assumptions and prerequisites 6 | 7 | This quick start guide makes the following assumptions: 8 | 9 | * You have read the [Reader SDK Overview]. This quick start focuses on getting 10 | the sample app installed and running to demonstrate how the Flutter 11 | plugin works. 12 | * You have a Square account enabled for payment processing. If you have not 13 | enabled payment processing on your account (or you are not sure), visit 14 | [squareup.com/activate]. 15 | * You are familiar with basic Flutter development. 16 | 17 | ## Before you start 18 | 19 | * Follow the **Install** instructions in the [Flutter Getting Started] guide to 20 | setup your Flutter development environment. 21 | * Confirm your environment meets the Reader SDK build requirements listed in the 22 | [root README] for this repo. 23 | * Clone this repo (if you have not already): 24 | `git clone https://github.com/square/reader-sdk-flutter-plugin.git` 25 | 26 | ## Step 1: Request Reader SDK credentials 27 | 28 | 1. Open the [Square Application Dashboard]. 29 | 2. Create a new Square application. 30 | 3. Click on the new application to bring up the Square application settings 31 | pages. 32 | 4. Open the **Reader SDK** page and click "Request Credentials" to generate your 33 | Reader SDK repository password. 34 | 5. You will need the **Application ID** and **Repository password** from the 35 | **Reader SDK** settings page to configure Reader SDK in the next steps. 36 | 37 | 38 | ## Step 2: Run the Flutter example app for Android 39 | 40 | 1. Open `/example/android/gradle.properties`. 41 | 2. Set the Reader SDK variables with your Reader SDK credentials: 42 | ```yaml 43 | # Set the variables below with your Reader SDK credentials 44 | SQUARE_READER_SDK_APPLICATION_ID=YOUR_SQUARE_READER_APP_ID 45 | SQUARE_READER_SDK_REPOSITORY_PASSWORD=YOUR_SQUARE_READER_REPOSITORY_PASSWORD 46 | ``` 47 | 3. Confirm you have installed the required Android SDK elements. If you are 48 | unsure, the Reader SDK build requirements are listed in the [root README] for 49 | this repo. 50 | 4. Configure an Android emulator that runs Android API 27 (Oreo, 8.1), 51 | and launch the emulator **or** connect your dev machine to an Android device 52 | running Android API 27 with development mode enabled. 53 | 5. Run the sample app from the `example` folder: 54 | ```bash 55 | cd /example 56 | flutter run 57 | ``` 58 | 6. Go to the **Reader SDK** settings page in your [Square Application Dashboard] 59 | and generate a new mobile authorization code by clicking 60 | "Generate Mobile Auth Code". 61 | 7. Copy the mobile authorization code string from the Square application 62 | settings page. 63 | 8. Tap "Enter Code Manually" in the sample app and paste the mobile 64 | authorization code into the field provided. 65 | 66 | You can view the [transaction details in Square Dashboard]. 67 | 68 | 69 | ## Step 3: Run the Flutter example app for iOS 70 | 71 | 1. Change to the `ios` folder under `example`. 72 | 2. Install ReaderSDK, replacing `YOUR_SQUARE_READER_APP_ID` and 73 | `YOUR_SQUARE_READER_REPOSITORY_PASSWORD` with your Reader SDK credentials. 74 | 75 | The command below will download the framework into the current directory. **The framework must be in either the `ios` directory or the `ios/Frameworks` directory of your Flutter project.** 76 | ```bash 77 | ruby <(curl https://connect.squareup.com/readersdk-installer) install \ 78 | --app-id YOUR_SQUARE_READER_APP_ID \ 79 | --repo-password YOUR_SQUARE_READER_REPOSITORY_PASSWORD 80 | ``` 81 | 3. Launch the iOS emulator or connect to an iOS device with development mode 82 | enabled. 83 | 4. Run the sample app from the `example` folder: 84 | ```bash 85 | cd /example 86 | flutter run 87 | ``` 88 | 5. Go to the **Reader SDK** settings page in your [Square Application Dashboard] 89 | and generate a new mobile authorization code by clicking 90 | "Generate Mobile Auth Code". 91 | 6. Copy the mobile authorization code string from the Square application 92 | settings page. 93 | 7. Tap "Enter Code Manually" in the sample app and paste the mobile 94 | authorization code into the field provided. 95 | 96 | You can view the [transaction details in Square Dashboard]. 97 | 98 | 99 | 100 | [//]: # "Link anchor definitions" 101 | [Reader SDK Overview]: https://developer.squareup.com/docs/reader-sdk/what-it-does 102 | [squareup.com/activate]: https://squareup.com/activate 103 | [Square Application Dashboard]: https://connect.squareup.com/apps/ 104 | [Flutter Getting Started]: https://flutter.io/docs/get-started/install 105 | [root README]: ../README.md 106 | [transaction details in Square Dashboard]: https://squareup.com/dashboard/sales/transactions 107 | 108 | ## Feedback 109 | Rate this sample app [here](https://delighted.com/t/Z1xmKSqy)! 110 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | analyzer: 2 | errors: 3 | # treat missing required parameters as a warning (not a hint) 4 | missing_required_param: warning 5 | 6 | linter: 7 | rules: 8 | # --- STYLE 9 | # identifiers 10 | - camel_case_types 11 | - library_names 12 | - file_names 13 | - library_prefixes 14 | - non_constant_identifier_names 15 | - constant_identifier_names # prefer 16 | # ordering 17 | - directives_ordering 18 | # formating 19 | - curly_braces_in_flow_control_structures 20 | # --- DOCUMENTATION 21 | # comments 22 | # doc comments 23 | - slash_for_doc_comments 24 | - comment_references 25 | # markdown 26 | # writing 27 | # --- USAGE 28 | # libraries 29 | - implementation_imports 30 | - avoid_relative_lib_imports 31 | # strings 32 | - prefer_adjacent_string_concatenation 33 | - prefer_interpolation_to_compose_strings # prefer 34 | - unnecessary_brace_in_string_interps # avoid 35 | # collections 36 | - prefer_collection_literals 37 | - avoid_function_literals_in_foreach_calls # avoid 38 | - prefer_iterable_whereType 39 | # functions 40 | - prefer_function_declarations_over_variables 41 | - unnecessary_lambdas 42 | # parameters 43 | - prefer_equal_for_default_values 44 | # variables 45 | - avoid_init_to_null 46 | # members 47 | - unnecessary_getters_setters 48 | - prefer_final_fields 49 | - prefer_expression_function_bodies # consider 50 | - unnecessary_this 51 | - prefer_typing_uninitialized_variables 52 | # constructors 53 | - prefer_initializing_formals 54 | - type_init_formals 55 | - empty_constructor_bodies 56 | - unnecessary_new 57 | - unnecessary_const 58 | # error handling 59 | - avoid_catches_without_on_clauses # avoid 60 | - use_rethrow_when_possible 61 | # asynchrony 62 | # --- DESIGN 63 | # names 64 | - use_to_and_as_if_applicable 65 | # libraries 66 | # classes 67 | - one_member_abstracts # avoid 68 | - avoid_classes_with_only_static_members # avoid 69 | - public_member_api_docs 70 | # constructors 71 | - prefer_constructors_over_static_methods 72 | # members 73 | - use_setters_to_change_properties 74 | - avoid_setters_without_getters 75 | - avoid_returning_null # avoid 76 | - avoid_returning_this # avoid 77 | # types 78 | - type_annotate_public_apis # prefer 79 | - omit_local_variable_types # avoid 80 | - avoid_types_on_closure_parameters # avoid 81 | - avoid_return_types_on_setters 82 | - prefer_generic_function_type_aliases 83 | - avoid_private_typedef_functions # prefer 84 | # parameters 85 | - avoid_positional_boolean_parameters # avoid 86 | # equality 87 | - hash_and_equals 88 | - avoid_null_checks_in_equality_operators -------------------------------------------------------------------------------- /example/android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.class 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | GeneratedPluginRegistrant.java 11 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | def localProperties = new Properties() 2 | def localPropertiesFile = rootProject.file('local.properties') 3 | if (localPropertiesFile.exists()) { 4 | localPropertiesFile.withReader('UTF-8') { reader -> 5 | localProperties.load(reader) 6 | } 7 | } 8 | 9 | def flutterRoot = localProperties.getProperty('flutter.sdk') 10 | if (flutterRoot == null) { 11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 12 | } 13 | 14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode') 15 | if (flutterVersionCode == null) { 16 | flutterVersionCode = '1' 17 | } 18 | 19 | def flutterVersionName = localProperties.getProperty('flutter.versionName') 20 | if (flutterVersionName == null) { 21 | flutterVersionName = '1.0' 22 | } 23 | 24 | apply plugin: 'com.android.application' 25 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" 26 | apply plugin: 'kotlin-android' 27 | 28 | android { 29 | namespace 'com.example.flutter.squareup.sdk.reader' 30 | compileSdkVersion 34 31 | ndkVersion = "26.1.10909125" 32 | 33 | sourceSets { 34 | main.java.srcDirs += 'src/main/kotlin' 35 | } 36 | 37 | defaultConfig { 38 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). 39 | applicationId "com.example.flutter.squareup.sdk.reader" 40 | minSdkVersion 26 41 | targetSdkVersion 34 42 | versionCode flutterVersionCode.toInteger() 43 | versionName flutterVersionName 44 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 45 | multiDexEnabled true 46 | } 47 | 48 | compileOptions { 49 | sourceCompatibility JavaVersion.VERSION_1_8 50 | targetCompatibility JavaVersion.VERSION_1_8 51 | } 52 | 53 | kotlinOptions { 54 | jvmTarget = "1.8" 55 | } 56 | 57 | java { 58 | toolchain { 59 | languageVersion = JavaLanguageVersion.of(17) 60 | } 61 | } 62 | 63 | buildTypes { 64 | release { 65 | // TODO: Add your own signing config for the release build. 66 | // Signing with the debug keys for now, so `flutter run --release` works. 67 | signingConfig signingConfigs.debug 68 | minifyEnabled false 69 | shrinkResources false } 70 | } 71 | packagingOptions { 72 | resources { 73 | excludes += ['META-INF/*.kotlin_module'] 74 | } 75 | } 76 | 77 | 78 | dexOptions { 79 | preDexLibraries true 80 | jumboMode true 81 | keepRuntimeAnnotatedClasses false 82 | } 83 | lint { 84 | checkReleaseBuilds false 85 | disable 'InvalidPackage' 86 | } 87 | } 88 | 89 | flutter { 90 | source '../..' 91 | } 92 | 93 | dependencies { 94 | configurations.all { 95 | resolutionStrategy { 96 | force 'com.android.support:support-v4:27.1.0' 97 | }} 98 | implementation "androidx.multidex:multidex:2.0.1" 99 | implementation 'com.google.android.gms:play-services-safetynet:15.0.1' 100 | implementation 'com.google.android.gms:play-services-ads-identifier:15.0.1' 101 | testImplementation 'junit:junit:4.12' 102 | androidTestImplementation 'androidx.test:runner:1.1.0-alpha4' 103 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4' 104 | } 105 | 106 | configurations.all { 107 | resolutionStrategy { 108 | eachDependency { details -> 109 | // Force all primary support libraries to the same version 110 | if (details.requested.group == 'com.android.support' 111 | && details.requested.name != 'multidex' 112 | && details.requested.name != 'multidex-instrumentation') { 113 | // Force the version that works for you. 114 | // Square has tested ReaderSDK with 26.0.2 115 | details.useVersion '26.0.2' 116 | } 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 21 | 25 | 33 | 37 | 40 | 41 | 42 | 43 | 44 | 45 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/flutter/squareup/sdk/reader/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.example.flutter.squareup.sdk.reader; 17 | 18 | import androidx.annotation.NonNull; 19 | 20 | import io.flutter.embedding.android.FlutterActivity; 21 | 22 | public class MainActivity extends FlutterActivity { 23 | } 24 | 25 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/flutter/squareup/sdk/reader/MainApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | package com.example.flutter.squareup.sdk.reader; 17 | 18 | import com.squareup.sdk.reader.ReaderSdk; 19 | import io.flutter.app.FlutterApplication; 20 | 21 | import io.flutter.view.FlutterMain; 22 | 23 | 24 | public class MainApplication extends FlutterApplication { 25 | 26 | @Override 27 | public void onCreate() { 28 | super.onCreate(); 29 | ReaderSdk.initialize(this); 30 | FlutterMain.startInitialization(this); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-hdpi/ic_jewel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/drawable-hdpi/ic_jewel.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-mdpi/ic_jewel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/drawable-mdpi/ic_jewel.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-xhdpi/ic_jewel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/drawable-xhdpi/ic_jewel.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-xxhdpi/ic_jewel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/drawable-xxhdpi/ic_jewel.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable-xxxhdpi/ic_jewel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/drawable-xxxhdpi/ic_jewel.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | 10 | 14 | 17 | 20 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launch_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/launcher_screen.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/window_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | @color/blue 19 | @color/dark_blue 20 | @color/white 21 | #4087E1 22 | 23 | #b34A90E2 24 | #FFFFFF 25 | 26 | #b3FFFFFF 27 | 28 | #80FFFFFF 29 | #3A71B0 30 | 31 | #803A71B0 32 | #757575 33 | #FF3B30 34 | 35 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | RNReaderSDKSample 19 | 20 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 27 | 28 | 31 | 32 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | ext.kotlin_version = '1.8.0' 3 | 4 | repositories { 5 | google() 6 | mavenCentral() 7 | maven { 8 | url "https://maven.google.com" 9 | } 10 | } 11 | 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:8.5.2' 14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 15 | classpath 'com.dipien:bye-bye-jetifier:1.2.1' 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | mavenCentral() 23 | maven { url 'https://www.jitpack.io' } 24 | maven { 25 | url "https://maven.google.com" 26 | } 27 | } 28 | } 29 | 30 | ext { 31 | // Override the reader sdk version with this parameter 32 | // Make sure the version is above min version 1.7.5 33 | readerSdkVersion = "1.7.5" 34 | } 35 | 36 | rootProject.buildDir = '../build' 37 | 38 | subprojects { 39 | project.buildDir = "${rootProject.buildDir}/${project.name}" 40 | project.evaluationDependsOn(':app') 41 | } 42 | 43 | tasks.register("clean", Delete) { 44 | delete rootProject.buildDir 45 | } 46 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Square Inc. 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | org.gradle.jvmargs=-Xmx4g 16 | android.useAndroidX=true 17 | android.enableJetifier=true 18 | ## Uncomment the properties below and set their correct value. 19 | 20 | ## The Application ID displayed on the Credentials tab in the Square Application Control Panel. 21 | #SQUARE_READER_SDK_APPLICATION_ID= 22 | 23 | ## The Application Secret from the OAuth tab in the Square Application Control Panel. 24 | #SQUARE_READER_SDK_REPOSITORY_PASSWORD= 25 | android.defaults.buildfeatures.buildconfig=true 26 | android.nonTransitiveRClass=false 27 | android.nonFinalResIds=false 28 | -------------------------------------------------------------------------------- /example/android/gradle.properties.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/gradle.properties.enc -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Mar 27 17:21:14 PDT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | 3 | def flutterProjectRoot = rootProject.projectDir.parentFile.toPath() 4 | 5 | def plugins = new Properties() 6 | def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins') 7 | if (pluginsFile.exists()) { 8 | pluginsFile.withReader('UTF-8') { reader -> plugins.load(reader) } 9 | } 10 | 11 | plugins.each { name, path -> 12 | def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile() 13 | include ":$name" 14 | project(":$name").projectDir = pluginDirectory 15 | } 16 | -------------------------------------------------------------------------------- /example/icons/ic_jewel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/icons/ic_jewel.png -------------------------------------------------------------------------------- /example/ios/.gitignore: -------------------------------------------------------------------------------- 1 | **/dgph 2 | *.mode1v3 3 | *.mode2v3 4 | *.moved-aside 5 | *.pbxuser 6 | *.perspectivev3 7 | **/*sync/ 8 | .sconsign.dblite 9 | .tags* 10 | **/.vagrant/ 11 | **/DerivedData/ 12 | Icon? 13 | **/Pods/ 14 | **/.symlinks/ 15 | profile 16 | xcuserdata 17 | **/.generated/ 18 | Flutter/App.framework 19 | Flutter/Flutter.framework 20 | Flutter/Flutter.podspec 21 | Flutter/Generated.xcconfig 22 | Flutter/ephemeral/ 23 | Flutter/app.flx 24 | Flutter/app.zip 25 | Flutter/flutter_assets/ 26 | Flutter/flutter_export_environment.sh 27 | ServiceDefinitions.json 28 | Runner/GeneratedPluginRegistrant.* 29 | 30 | # Exceptions to above rules. 31 | !default.mode1v3 32 | !default.mode2v3 33 | !default.pbxuser 34 | !default.perspectivev3 35 | -------------------------------------------------------------------------------- /example/ios/Flutter/AppFrameworkInfo.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | App 9 | CFBundleIdentifier 10 | io.flutter.flutter.app 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | App 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1.0 23 | MinimumOSVersion 24 | 9.0 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/ios/Flutter/Debug.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Flutter/Release.xcconfig: -------------------------------------------------------------------------------- 1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" 2 | #include "Generated.xcconfig" 3 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Uncomment this line to define a global platform for your project 2 | platform :ios, '11.1' 3 | 4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency. 5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true' 6 | 7 | project 'Runner', { 8 | 'Debug' => :debug, 9 | 'Profile' => :release, 10 | 'Release' => :release, 11 | } 12 | 13 | def flutter_root 14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) 15 | unless File.exist?(generated_xcode_build_settings_path) 16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" 17 | end 18 | 19 | File.foreach(generated_xcode_build_settings_path) do |line| 20 | matches = line.match(/FLUTTER_ROOT\=(.*)/) 21 | return matches[1].strip if matches 22 | end 23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" 24 | end 25 | 26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) 27 | 28 | flutter_ios_podfile_setup 29 | 30 | target 'Runner' do 31 | use_frameworks! 32 | use_modular_headers! 33 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) 34 | end 35 | 36 | post_install do |installer| 37 | installer.pods_project.targets.each do |target| 38 | flutter_additional_ios_build_settings(target) 39 | 40 | target.build_configurations.each do |config| 41 | config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ 42 | '$(inherited)', 43 | 44 | ## dart: PermissionGroup.camera 45 | 'PERMISSION_CAMERA=1', 46 | 47 | ## dart: PermissionGroup.microphone 48 | 'PERMISSION_MICROPHONE=1', 49 | 50 | ## dart: PermissionGroup.photos 51 | 'PERMISSION_PHOTOS=1', 52 | 53 | ## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse] 54 | 'PERMISSION_LOCATION=1', 55 | 56 | ## dart: PermissionGroup.mediaLibrary 57 | 'PERMISSION_MEDIA_LIBRARY=1', 58 | 59 | ## dart: PermissionGroup.bluetooth 60 | 'PERMISSION_BLUETOOTH=1', 61 | ] 62 | end 63 | # Barcode scanner has stale deployment target 64 | target.build_configurations.each do |config| 65 | #config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' 66 | config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' 67 | end 68 | end 69 | end -------------------------------------------------------------------------------- /example/ios/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - barcode_scan2 (0.0.1): 3 | - Flutter 4 | - MTBBarcodeScanner 5 | - SwiftProtobuf 6 | - Firebase/CoreOnly (9.3.0): 7 | - FirebaseCore (= 9.3.0) 8 | - firebase_core (1.20.1): 9 | - Firebase/CoreOnly (= 9.3.0) 10 | - Flutter 11 | - FirebaseCore (9.3.0): 12 | - FirebaseCoreDiagnostics (~> 9.0) 13 | - FirebaseCoreInternal (~> 9.0) 14 | - GoogleUtilities/Environment (~> 7.7) 15 | - GoogleUtilities/Logger (~> 7.7) 16 | - FirebaseCoreDiagnostics (9.4.0): 17 | - GoogleDataTransport (< 10.0.0, >= 9.1.4) 18 | - GoogleUtilities/Environment (~> 7.7) 19 | - GoogleUtilities/Logger (~> 7.7) 20 | - nanopb (< 2.30910.0, >= 2.30908.0) 21 | - FirebaseCoreInternal (9.4.0): 22 | - "GoogleUtilities/NSData+zlib (~> 7.7)" 23 | - Flutter (1.0.0) 24 | - GoogleDataTransport (9.2.0): 25 | - GoogleUtilities/Environment (~> 7.7) 26 | - nanopb (< 2.30910.0, >= 2.30908.0) 27 | - PromisesObjC (< 3.0, >= 1.2) 28 | - GoogleUtilities/Environment (7.7.0): 29 | - PromisesObjC (< 3.0, >= 1.2) 30 | - GoogleUtilities/Logger (7.7.0): 31 | - GoogleUtilities/Environment 32 | - "GoogleUtilities/NSData+zlib (7.7.0)" 33 | - MTBBarcodeScanner (5.0.11) 34 | - nanopb (2.30909.0): 35 | - nanopb/decode (= 2.30909.0) 36 | - nanopb/encode (= 2.30909.0) 37 | - nanopb/decode (2.30909.0) 38 | - nanopb/encode (2.30909.0) 39 | - permission_handler_apple (9.0.4): 40 | - Flutter 41 | - PromisesObjC (2.1.1) 42 | - square_reader_sdk (3.0.0): 43 | - Flutter 44 | - SwiftProtobuf (1.19.1) 45 | 46 | DEPENDENCIES: 47 | - barcode_scan2 (from `.symlinks/plugins/barcode_scan2/ios`) 48 | - firebase_core (from `.symlinks/plugins/firebase_core/ios`) 49 | - Flutter (from `Flutter`) 50 | - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) 51 | - square_reader_sdk (from `.symlinks/plugins/square_reader_sdk/ios`) 52 | 53 | SPEC REPOS: 54 | trunk: 55 | - Firebase 56 | - FirebaseCore 57 | - FirebaseCoreDiagnostics 58 | - FirebaseCoreInternal 59 | - GoogleDataTransport 60 | - GoogleUtilities 61 | - MTBBarcodeScanner 62 | - nanopb 63 | - PromisesObjC 64 | - SwiftProtobuf 65 | 66 | EXTERNAL SOURCES: 67 | barcode_scan2: 68 | :path: ".symlinks/plugins/barcode_scan2/ios" 69 | firebase_core: 70 | :path: ".symlinks/plugins/firebase_core/ios" 71 | Flutter: 72 | :path: Flutter 73 | permission_handler_apple: 74 | :path: ".symlinks/plugins/permission_handler_apple/ios" 75 | square_reader_sdk: 76 | :path: ".symlinks/plugins/square_reader_sdk/ios" 77 | 78 | SPEC CHECKSUMS: 79 | barcode_scan2: 0af2bb63c81b4565aab6cd78278e4c0fa136dbb0 80 | Firebase: ef75abb1cdbc746d5a38f4e26c422c807b189b8c 81 | firebase_core: e66a443ec996cb5e364dc70b4cfc1809c32cbb2e 82 | FirebaseCore: c088995ece701a021a48a1348ea0174877de2a6a 83 | FirebaseCoreDiagnostics: aaa87098082c4d4bdd1a9557b1186d18ca85ce8c 84 | FirebaseCoreInternal: a13302b0088fbf5f38b79b6ece49c2af7d3e05d6 85 | Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a 86 | GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f 87 | GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1 88 | MTBBarcodeScanner: f453b33c4b7dfe545d8c6484ed744d55671788cb 89 | nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431 90 | permission_handler_apple: 44366e37eaf29454a1e7b1b7d736c2cceaeb17ce 91 | PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb 92 | square_reader_sdk: 9f71e845136d9ebc33bf9e0dfc52f6cb1891655f 93 | SwiftProtobuf: 59d9ea2eb5f84b509f32d170a65f3348ae758f1e 94 | 95 | PODFILE CHECKSUM: 3ceefe9d94e435d066c1c3f69ed8e7d6a52397ff 96 | 97 | COCOAPODS: 1.11.2 98 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreviewsEnabled 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /example/ios/Runner/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import Flutter 3 | import SquareReaderSDK 4 | 5 | @UIApplicationMain 6 | @objc class AppDelegate: FlutterAppDelegate { 7 | override func application( 8 | _ application: UIApplication, 9 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 10 | ) -> Bool { 11 | GeneratedPluginRegistrant.register(with: self) 12 | SQRDReaderSDK.initialize(applicationLaunchOptions: launchOptions) 13 | return super.application(application, didFinishLaunchingWithOptions: launchOptions) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "20x20", 5 | "idiom" : "iphone", 6 | "filename" : "Icon-20@2x.png", 7 | "scale" : "2x" 8 | }, 9 | { 10 | "size" : "20x20", 11 | "idiom" : "iphone", 12 | "filename" : "Icon-20@3x.png", 13 | "scale" : "3x" 14 | }, 15 | { 16 | "size" : "29x29", 17 | "idiom" : "iphone", 18 | "filename" : "Icon-29@2x.png", 19 | "scale" : "2x" 20 | }, 21 | { 22 | "size" : "29x29", 23 | "idiom" : "iphone", 24 | "filename" : "Icon-29@3x.png", 25 | "scale" : "3x" 26 | }, 27 | { 28 | "size" : "40x40", 29 | "idiom" : "iphone", 30 | "filename" : "Icon-40@2x.png", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "size" : "40x40", 35 | "idiom" : "iphone", 36 | "filename" : "Icon-40@3x.png", 37 | "scale" : "3x" 38 | }, 39 | { 40 | "size" : "60x60", 41 | "idiom" : "iphone", 42 | "filename" : "Icon-60@2x.png", 43 | "scale" : "2x" 44 | }, 45 | { 46 | "size" : "60x60", 47 | "idiom" : "iphone", 48 | "filename" : "Icon-60@3x.png", 49 | "scale" : "3x" 50 | }, 51 | { 52 | "size" : "1024x1024", 53 | "idiom" : "ios-marketing", 54 | "filename" : "iTunesArtwork@2x.png", 55 | "scale" : "1x" 56 | } 57 | ], 58 | "info" : { 59 | "version" : 1, 60 | "author" : "xcode" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-20@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-20@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-29@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-29@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-40@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-40@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/AppIcon.appiconset/iTunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/iTunesArtwork@2x.png -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/Logo.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "Logo.pdf", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/ios/Runner/Assets.xcassets/Logo.imageset/Logo.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/example/ios/Runner/Assets.xcassets/Logo.imageset/Logo.pdf -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /example/ios/Runner/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /example/ios/Runner/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSBluetoothAlwaysUsageDescription 6 | This app integrates with Square for card processing. Square uses Bluetooth to connect your device to compatible hardware. 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | square_reader_sdk_example 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | $(FLUTTER_BUILD_NAME) 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | $(FLUTTER_BUILD_NUMBER) 25 | LSRequiresIPhoneOS 26 | 27 | NSBluetoothPeripheralUsageDescription 28 | This app integrates with Square for card processing. Square uses Bluetooth to connect your device to compatible hardware. 29 | NSCameraUsageDescription 30 | This app integrates with Square for card processing. Upload your account logo, feature photo and product images with the photos stored on your mobile device. 31 | NSLocationWhenInUseUsageDescription 32 | This app integrates with Square for card processing. To protect buyers and sellers, Square requires your location to process payments. 33 | NSMicrophoneUsageDescription 34 | This app integrates with Square for card processing. To swipe magnetic cards via the headphone jack, Square requires access to the microphone. 35 | NSPhotoLibraryUsageDescription 36 | This app integrates with Square for card processing. Upload your account logo, feature photo and product images with the photos stored on your mobile device. 37 | UILaunchStoryboardName 38 | LaunchScreen 39 | UIMainStoryboardFile 40 | Main 41 | UIStatusBarStyle 42 | UIStatusBarStyleLightContent 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | UISupportedInterfaceOrientations~ipad 50 | 51 | UIInterfaceOrientationPortrait 52 | UIInterfaceOrientationPortraitUpsideDown 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UIViewControllerBasedStatusBarAppearance 57 | 58 | CADisableMinimumFrameDurationOnPhone 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /example/ios/Runner/Runner-Bridging-Header.h: -------------------------------------------------------------------------------- 1 | #import "GeneratedPluginRegistrant.h" 2 | -------------------------------------------------------------------------------- /example/lib/generated_plugin_registrant.dart: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // ignore_for_file: directives_ordering 6 | // ignore_for_file: lines_longer_than_80_chars 7 | 8 | import 'package:firebase_core_web/firebase_core_web.dart'; 9 | 10 | import 'package:flutter_web_plugins/flutter_web_plugins.dart'; 11 | 12 | // ignore: public_member_api_docs 13 | void registerPlugins(Registrar registrar) { 14 | FirebaseCoreWeb.registerWith(registrar); 15 | registrar.registerMessageHandler(); 16 | } 17 | -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:flutter/material.dart'; 18 | import 'screens/authorize_screen.dart'; 19 | import 'screens/checkout_screen.dart'; 20 | import 'screens/manual_authorize_screen.dart'; 21 | import 'screens/splash_screen.dart'; 22 | 23 | void main() => runApp(ExampleApp()); 24 | 25 | /// The root of this example app 26 | class ExampleApp extends StatelessWidget { 27 | @override 28 | Widget build(BuildContext context) => MaterialApp( 29 | theme: _buildTheme(), 30 | initialRoute: '/', 31 | routes: { 32 | '/': (context) => SplashScreen(), 33 | '/authorize': (context) => AuthorizeScreen(), 34 | '/authorize/manual': (context) => ManualAuthorizeScreen(), 35 | '/checkout': (context) => CheckoutScreen(), 36 | }, 37 | ); 38 | } 39 | 40 | // override default theme 41 | ThemeData _buildTheme() { 42 | var base = ThemeData.light(); 43 | return base.copyWith( 44 | canvasColor: Colors.transparent, 45 | scaffoldBackgroundColor: Color.fromRGBO(64, 135, 225, 1.0), 46 | buttonTheme: ButtonThemeData( 47 | height: 64.0, 48 | ), 49 | hintColor: Colors.transparent, 50 | inputDecorationTheme: InputDecorationTheme( 51 | labelStyle: TextStyle( 52 | color: Colors.white, 53 | ), 54 | ), 55 | textTheme: TextTheme( 56 | labelLarge: TextStyle( 57 | fontSize: 20.0, 58 | fontWeight: FontWeight.w600, 59 | color: Colors.white, 60 | ), 61 | bodyLarge: TextStyle( 62 | fontSize: 24.0, 63 | fontWeight: FontWeight.w600, 64 | color: Colors.white, 65 | ), 66 | ), 67 | ); 68 | } 69 | -------------------------------------------------------------------------------- /example/lib/screens/authorize_screen.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:barcode_scan2/barcode_scan2.dart'; 18 | import 'package:flutter/material.dart'; 19 | import 'package:flutter/services.dart'; 20 | import 'package:square_reader_sdk/models.dart'; 21 | import 'package:square_reader_sdk/reader_sdk.dart'; 22 | 23 | import 'widgets/buttons.dart'; 24 | import 'widgets/dialog_modal.dart'; 25 | import 'widgets/loading.dart'; 26 | import 'widgets/square_logo.dart'; 27 | 28 | const _debug = !bool.fromEnvironment("dart.vm.product"); 29 | 30 | /// AuthorizeScreen authorizes the reader sdk using a mobile auth 31 | class AuthorizeScreen extends StatefulWidget { 32 | @override 33 | _AuthorizeScreenState createState() => _AuthorizeScreenState(); 34 | } 35 | 36 | class _AuthorizeScreenState extends State { 37 | bool _isLoading = false; 38 | 39 | void initState() { 40 | super.initState(); 41 | checkAuthAndNavigate(); 42 | } 43 | 44 | void checkAuthAndNavigate() async { 45 | var isAuthorized = await ReaderSdk.isAuthorized; 46 | if (isAuthorized) { 47 | Navigator.popAndPushNamed(context, '/checkout'); 48 | } 49 | } 50 | 51 | void authorizeQRCode(String authCode) async { 52 | try { 53 | setState(() { 54 | _isLoading = true; 55 | }); 56 | await ReaderSdk.authorize(authCode); 57 | Navigator.pushNamed(context, '/checkout'); 58 | } on ReaderSdkException catch (e) { 59 | switch (e.code) { 60 | case ErrorCode.authorizeErrorNoNetwork: 61 | displayErrorModal(context, 'Please connect your device to network.'); 62 | break; 63 | case ErrorCode.usageError: 64 | var errorMessage = e.message!; 65 | if (_debug) { 66 | errorMessage += '\n\nDebug Message: ${e.debugMessage}'; 67 | print('${e.code}:${e.debugCode}:${e.debugMessage}'); 68 | } 69 | displayErrorModal(context, errorMessage); 70 | break; 71 | } 72 | } finally { 73 | setState(() { 74 | _isLoading = false; 75 | }); 76 | } 77 | } 78 | 79 | Future scan() async { 80 | try { 81 | var result = await BarcodeScanner.scan(); 82 | authorizeQRCode(result.rawContent); 83 | } on PlatformException catch (e) { 84 | if (e.code == BarcodeScanner.cameraAccessDenied) { 85 | displayErrorModal(context, 'Camera Access was not granted'); 86 | } else { 87 | displayErrorModal(context, e.toString()); 88 | } 89 | } on Exception catch (e) { 90 | displayErrorModal(context, e.toString()); 91 | } 92 | } 93 | 94 | void scanQRCode() { 95 | scan(); 96 | } 97 | 98 | void manuallyEnterCode() { 99 | Navigator.pushNamed(context, '/authorize/manual'); 100 | } 101 | 102 | @override 103 | Widget build(BuildContext context) => Scaffold( 104 | body: _isLoading 105 | ? LoadingWidget() 106 | : Column( 107 | mainAxisAlignment: MainAxisAlignment.spaceBetween, 108 | children: [ 109 | SquareLogo(), 110 | _Description(), 111 | _Buttons( 112 | scanQRCode: scanQRCode, 113 | manuallyEnterCode: manuallyEnterCode, 114 | ), 115 | ]), 116 | ); 117 | } 118 | 119 | class _Description extends StatelessWidget { 120 | @override 121 | Widget build(BuildContext context) => Container( 122 | margin: EdgeInsets.symmetric(horizontal: 64.0), 123 | child: Column(children: [ 124 | Text( 125 | 'Authorize Reader SDK.', 126 | textAlign: TextAlign.center, 127 | ), 128 | Text( 129 | 'Generate an authorization code in the Reader SDK tab of the Developer Portal', 130 | textAlign: TextAlign.center, 131 | style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.w300), 132 | ), 133 | ]), 134 | ); 135 | } 136 | 137 | class _Buttons extends StatelessWidget { 138 | final VoidCallback manuallyEnterCode; 139 | final VoidCallback scanQRCode; 140 | 141 | _Buttons({ 142 | required this.scanQRCode, 143 | required this.manuallyEnterCode, 144 | }); 145 | 146 | @override 147 | Widget build(BuildContext context) => Container( 148 | child: SQButtonContainer(buttons: [ 149 | SQRaisedButton( 150 | text: 'Scan QR Code', 151 | onPressed: scanQRCode, 152 | ), 153 | SQOutlineButton( 154 | text: 'Manually Enter Code', onPressed: manuallyEnterCode), 155 | ])); 156 | } 157 | -------------------------------------------------------------------------------- /example/lib/screens/manual_authorize_screen.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:flutter/material.dart'; 18 | import 'package:square_reader_sdk/models.dart'; 19 | import 'package:square_reader_sdk/reader_sdk.dart'; 20 | 21 | import 'widgets/buttons.dart'; 22 | import 'widgets/dialog_modal.dart'; 23 | import 'widgets/loading.dart'; 24 | 25 | const _debug = !bool.fromEnvironment("dart.vm.product"); 26 | 27 | /// A screen that requires an authorization code in a text field 28 | class ManualAuthorizeScreen extends StatefulWidget { 29 | @override 30 | _ManualAuthorizeScreenState createState() => _ManualAuthorizeScreenState(); 31 | } 32 | 33 | class _ManualAuthorizeScreenState extends State { 34 | bool _isLoading = false; 35 | final TextEditingController textEditingController = TextEditingController(); 36 | 37 | void onCancel() async { 38 | Navigator.pop(context); 39 | } 40 | 41 | void onAuthorize() async { 42 | try { 43 | setState(() { 44 | _isLoading = true; 45 | }); 46 | await ReaderSdk.authorize(textEditingController.text); 47 | Navigator.popAndPushNamed(context, '/checkout'); 48 | } on ReaderSdkException catch (e) { 49 | switch (e.code) { 50 | case ErrorCode.authorizeErrorNoNetwork: 51 | displayErrorModal(context, 'Please connect your device to network.'); 52 | break; 53 | case ErrorCode.usageError: 54 | var errorMessage = e.message!; 55 | if (_debug) { 56 | errorMessage += '\n\nDebug Message: ${e.debugMessage}'; 57 | print('${e.code}:${e.debugCode}:${e.debugMessage}'); 58 | } 59 | displayErrorModal(context, errorMessage); 60 | break; 61 | } 62 | } finally { 63 | setState(() { 64 | _isLoading = false; 65 | }); 66 | } 67 | } 68 | 69 | Widget _buildManualAuthorizeScreen(BuildContext context) => 70 | Column(mainAxisAlignment: MainAxisAlignment.start, children: [ 71 | Container( 72 | margin: EdgeInsets.fromLTRB(32.0, 84.0, 32.0, 32.0), 73 | child: Text( 74 | 'Enter an authorization code.', 75 | textAlign: TextAlign.center, 76 | ), 77 | ), 78 | Container( 79 | // Container for text field 80 | margin: EdgeInsets.symmetric(horizontal: 32.0, vertical: 8.0), 81 | child: TextField( 82 | style: TextStyle( 83 | fontSize: 18.0, 84 | ), 85 | controller: textEditingController, 86 | decoration: InputDecoration( 87 | border: OutlineInputBorder( 88 | borderRadius: BorderRadius.circular(8.0), 89 | ), 90 | hintText: 'Authorization Code', 91 | hintStyle: TextStyle( 92 | color: Colors.white70, 93 | ), 94 | fillColor: Color.fromRGBO(83, 166, 255, 1.0), 95 | filled: true, 96 | ), 97 | ), 98 | ), 99 | Container( 100 | // Container for buttons 101 | child: SQButtonContainer(buttons: [ 102 | SQRaisedButton( 103 | text: 'Authorize', 104 | onPressed: onAuthorize, 105 | ), 106 | SQOutlineButton(text: 'Cancel', onPressed: onCancel), 107 | ]), 108 | ), 109 | ]); 110 | 111 | @override 112 | Widget build(BuildContext context) => Scaffold( 113 | body: 114 | _isLoading ? LoadingWidget() : _buildManualAuthorizeScreen(context)); 115 | } 116 | -------------------------------------------------------------------------------- /example/lib/screens/widgets/animated_square_logo.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:flutter/material.dart'; 18 | 19 | class _LogoAnimated extends AnimatedWidget { 20 | static final _alignmentTween = AlignmentTween( 21 | begin: Alignment.center, 22 | end: Alignment.topCenter, 23 | ); 24 | static final _sizeTween = Tween(begin: 80.0, end: 48.0); 25 | 26 | _LogoAnimated({Key? key, required Animation animation}) 27 | : super(key: key, listenable: animation); 28 | 29 | Widget build(BuildContext context) { 30 | final animation = listenable as Animation; 31 | return Container( 32 | alignment: _alignmentTween.evaluate(animation), 33 | margin: EdgeInsets.symmetric(vertical: 100.0), 34 | constraints: BoxConstraints(minHeight: 48.0), 35 | child: Image.asset( 36 | 'icons/ic_jewel.png', 37 | height: _sizeTween.evaluate(animation), 38 | width: _sizeTween.evaluate(animation), 39 | ), 40 | ); 41 | } 42 | } 43 | 44 | /// Displays the square logo with an opening animation 45 | class AnimatedSquareLogo extends StatefulWidget { 46 | /// initialize with a callback 47 | AnimatedSquareLogo({ 48 | this.onLogoAnimated, 49 | }); 50 | 51 | /// callback that fires after the logo animation is finished 52 | final VoidCallback? onLogoAnimated; 53 | 54 | _LogoState createState() => _LogoState(); 55 | } 56 | 57 | class _LogoState extends State 58 | with SingleTickerProviderStateMixin { 59 | late AnimationController controller; 60 | late Animation animation; 61 | 62 | void initState() { 63 | super.initState(); 64 | controller = AnimationController( 65 | duration: const Duration(milliseconds: 2000), vsync: this); 66 | animation = CurvedAnimation(parent: controller, curve: Curves.linear); 67 | animation.addStatusListener((var status) { 68 | if (status == AnimationStatus.completed) { 69 | widget.onLogoAnimated!(); 70 | } 71 | }); 72 | controller.forward(); 73 | } 74 | 75 | Widget build(BuildContext context) => _LogoAnimated(animation: animation); 76 | 77 | void dispose() { 78 | controller.dispose(); 79 | super.dispose(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /example/lib/screens/widgets/buttons.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:flutter/material.dart'; 18 | 19 | /// A container that lays out square-styled buttons 20 | class SQButtonContainer extends StatelessWidget { 21 | /// initialize with a list of buttons 22 | SQButtonContainer({ 23 | required this.buttons, 24 | }); 25 | 26 | /// buttons are that displays in the order they appear in the list 27 | final List buttons; 28 | 29 | _buildButtonContainers() { 30 | // last button has additional padding 31 | final lastButton = buttons.removeLast(); 32 | 33 | final buttonContainers = buttons 34 | .map((button) => Container( 35 | margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 32.0), 36 | width: double.infinity, 37 | child: button)) 38 | .toList(); 39 | 40 | buttonContainers.add(Container( 41 | margin: 42 | EdgeInsets.only(top: 8.0, bottom: 32.0, left: 32.0, right: 32.0), 43 | width: double.infinity, 44 | child: lastButton)); 45 | 46 | return buttonContainers; 47 | } 48 | 49 | @override 50 | Widget build(BuildContext context) => 51 | Column(children: _buildButtonContainers()); 52 | } 53 | 54 | /// A button that is styled with a white outline 55 | class SQOutlineButton extends StatelessWidget { 56 | /// initializer 57 | SQOutlineButton({ 58 | this.text, 59 | this.onPressed, 60 | }); 61 | 62 | /// the text displayed in the button 63 | final String? text; 64 | 65 | /// a callback that is fired when the button is pressed 66 | final void Function()? onPressed; 67 | 68 | @override 69 | Widget build(BuildContext context) => OutlinedButton( 70 | child: Text( 71 | text!, 72 | style: TextStyle(color: Colors.white), 73 | ), 74 | style: OutlinedButton.styleFrom( 75 | padding: EdgeInsets.all(20.0), 76 | side: BorderSide( 77 | color: Colors.white, style: BorderStyle.solid, width: 1.0), 78 | shape: 79 | RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), 80 | ), 81 | onPressed: onPressed, 82 | ); 83 | } 84 | 85 | /// A button that is styled with a white outline 86 | class SQSettingButton extends StatelessWidget { 87 | /// initializer 88 | SQSettingButton({ 89 | this.onPressed, 90 | }); 91 | 92 | /// a callback that is fired when the button is pressed 93 | final VoidCallback? onPressed; 94 | 95 | @override 96 | Widget build(BuildContext context) => OutlinedButton( 97 | child: Icon( 98 | Icons.settings, 99 | size: 35.0, 100 | color: Colors.white, 101 | ), 102 | style: OutlinedButton.styleFrom( 103 | padding: EdgeInsets.all(20.0), 104 | side: BorderSide( 105 | color: Colors.blue, style: BorderStyle.solid, width: 0.1), 106 | shape: 107 | RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), 108 | ), 109 | onPressed: onPressed, 110 | ); 111 | } 112 | 113 | /// A button with a blue background 114 | class SQRaisedButton extends StatelessWidget { 115 | /// initializer 116 | SQRaisedButton({ 117 | required this.text, 118 | required this.onPressed, 119 | }); 120 | 121 | /// the text displayed in the button 122 | final String text; 123 | 124 | /// a callback that is fired when the button is pressed 125 | final void Function() onPressed; 126 | 127 | @override 128 | Widget build(BuildContext context) => ElevatedButton( 129 | child: Text(text), 130 | style: ElevatedButton.styleFrom( 131 | backgroundColor: Color.fromRGBO(57, 114, 178, 1.0), 132 | padding: EdgeInsets.all(15.0), 133 | foregroundColor: Colors.white, 134 | shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), 135 | ), 136 | onPressed: onPressed, 137 | ); 138 | } 139 | -------------------------------------------------------------------------------- /example/lib/screens/widgets/dialog_modal.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:flutter/material.dart'; 18 | 19 | /// displays an error modal with the supplied message 20 | Future displayErrorModal(BuildContext context, String message) => 21 | showDialog( 22 | context: context, 23 | builder: (var context) => AlertDialog( 24 | title: Text( 25 | 'Error', 26 | style: TextStyle( 27 | color: Colors.black, 28 | ), 29 | ), 30 | content: SingleChildScrollView( 31 | child: ListBody( 32 | children: [ 33 | Text( 34 | message, 35 | style: TextStyle( 36 | color: Colors.black, 37 | ), 38 | ), 39 | ], 40 | ), 41 | ), 42 | actions: [ 43 | TextButton( 44 | child: Text('OK'), 45 | onPressed: () { 46 | Navigator.of(context).pop(); 47 | }, 48 | ), 49 | ], 50 | )); 51 | 52 | Future displayModal(BuildContext context, String message, void onPress) => 53 | showDialog( 54 | context: context, 55 | builder: (var context) => AlertDialog( 56 | title: Text('AlertDialog Title'), 57 | content: SingleChildScrollView( 58 | child: Column( 59 | children: [ 60 | Text('This is a demo alert dialog.'), 61 | Text('Would you like to approve of this message?'), 62 | ], 63 | ), 64 | ), 65 | actions: [ 66 | TextButton( 67 | child: Text('Confirm'), 68 | onPressed: () { 69 | print('Confirmed'); 70 | Navigator.of(context).pop(); 71 | onPress; 72 | }, 73 | ), 74 | TextButton( 75 | child: Text('Cancel'), 76 | onPressed: () { 77 | Navigator.of(context).pop(); 78 | }, 79 | ), 80 | ], 81 | )); 82 | 83 | Future confirmOnDeauthorize({ 84 | BuildContext? context, 85 | VoidCallback? onPressed, 86 | }) => 87 | showDialog( 88 | context: context!, 89 | barrierDismissible: false, // user must tap button! 90 | builder: (var context) => AlertDialog( 91 | title: const Text( 92 | 'Are you sure you want to Deauthorize Token ?', 93 | style: TextStyle(color: Colors.black, fontSize: 16), 94 | ), 95 | actions: [ 96 | TextButton( 97 | onPressed: () => Navigator.pop( 98 | context, 99 | ), 100 | child: const Text('Cancel'), 101 | ), 102 | TextButton( 103 | onPressed: onPressed, 104 | child: const Text('OK'), 105 | ), 106 | ], 107 | ), 108 | ); 109 | -------------------------------------------------------------------------------- /example/lib/screens/widgets/loading.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:flutter/material.dart'; 18 | 19 | /// displays a loading spinner 20 | class LoadingWidget extends StatelessWidget { 21 | @override 22 | Widget build(BuildContext context) => Center( 23 | child: CircularProgressIndicator( 24 | value: null, 25 | valueColor: AlwaysStoppedAnimation(Colors.white), 26 | strokeWidth: 7.0, 27 | ), 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /example/lib/screens/widgets/square_logo.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | import 'package:flutter/material.dart'; 18 | 19 | /// A static square logo 20 | class SquareLogo extends StatelessWidget { 21 | @override 22 | Widget build(BuildContext context) => Container( 23 | alignment: Alignment.center, 24 | margin: EdgeInsets.only(top: 100.0), 25 | child: Image.asset( 26 | 'icons/ic_jewel.png', 27 | height: 58.0, 28 | width: 58.0, 29 | ), 30 | ); 31 | } 32 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: square_reader_sdk_example 2 | description: Demonstrates how to use the square_reader_sdk plugin. 3 | 4 | # The following defines the version and build number for your application. 5 | # A version number is three numbers separated by dots, like 1.2.43 6 | # followed by an optional build number separated by a +. 7 | # Both the version and the builder number may be overridden in flutter 8 | # build by specifying --build-name and --build-number, respectively. 9 | # Read more about versioning at semver.org. 10 | version: 1.1.2+1 11 | 12 | environment: 13 | sdk: '>=2.14.0 <3.0.0' 14 | 15 | dependencies: 16 | flutter: 17 | sdk: flutter 18 | 19 | permission_handler: ^10.2.0 20 | barcode_scan2: ^4.3.3 21 | intl: ^0.17.0 22 | firebase_core: ^2.5.0 23 | 24 | # The following adds the Cupertino Icons font to your application. 25 | # Use with the CupertinoIcons class for iOS style icons. 26 | cupertino_icons: ^1.0.4 27 | 28 | dev_dependencies: 29 | square_reader_sdk: 30 | path: ../ 31 | 32 | # For information on the generic Dart part of this file, see the 33 | # following page: https://www.dartlang.org/tools/pub/pubspec 34 | 35 | # The following section is specific to Flutter. 36 | flutter: 37 | assets: 38 | - icons/ 39 | # The following line ensures that the Material Icons font is 40 | # included with your application, so that you can use the icons in 41 | # the material Icons class. 42 | uses-material-design: true 43 | -------------------------------------------------------------------------------- /ios/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vagrant/ 3 | .sconsign.dblite 4 | .svn/ 5 | 6 | .DS_Store 7 | *.swp 8 | profile 9 | 10 | DerivedData/ 11 | build/ 12 | GeneratedPluginRegistrant.h 13 | GeneratedPluginRegistrant.m 14 | 15 | .generated/ 16 | 17 | *.pbxuser 18 | *.mode1v3 19 | *.mode2v3 20 | *.perspectivev3 21 | 22 | !default.pbxuser 23 | !default.mode1v3 24 | !default.mode2v3 25 | !default.perspectivev3 26 | 27 | xcuserdata 28 | 29 | *.moved-aside 30 | 31 | *.pyc 32 | *sync/ 33 | Icon? 34 | .tags* 35 | 36 | /Flutter/Generated.xcconfig 37 | .clang-format 38 | -------------------------------------------------------------------------------- /ios/Assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/reader-sdk-flutter-plugin/a5857b443310eab0b5d63d58152916d6afbabfb5/ios/Assets/.gitkeep -------------------------------------------------------------------------------- /ios/Classes/Converters/FlutterReaderSDKDateFormatter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | 19 | 20 | @interface FlutterReaderSDKDateFormatter : NSObject 21 | 22 | + (NSString *)iso8601StringFromDate:(NSDate *)date; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/FlutterReaderSDKDateFormatter.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "FlutterReaderSDKDateFormatter.h" 18 | 19 | 20 | @implementation FlutterReaderSDKDateFormatter 21 | 22 | + (NSString *)iso8601StringFromDate:(NSDate *)date 23 | { 24 | return [self.dateFormatter stringFromDate:date]; 25 | } 26 | 27 | + (NSISO8601DateFormatter *)dateFormatter; 28 | { 29 | static NSISO8601DateFormatter *dateFormatter = nil; 30 | static dispatch_once_t onceToken = 0; 31 | 32 | dispatch_once(&onceToken, ^{ 33 | dateFormatter = [[NSISO8601DateFormatter alloc] init]; 34 | }); 35 | 36 | return dateFormatter; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDCard+FlutterReaderSDKAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | @import SquareReaderSDK; 18 | 19 | 20 | @interface SQRDCard (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDCard+FlutterReaderSDKAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SQRDCard+FlutterReaderSDKAdditions.h" 18 | #import "SQRDTender+FlutterReaderSDKAdditions.h" 19 | #import "SQRDMoney+FlutterReaderSDKAdditions.h" 20 | #import "FlutterReaderSDKDateFormatter.h" 21 | 22 | 23 | @implementation SQRDCard (FlutterReaderSDKAdditions) 24 | 25 | - (NSDictionary *)jsonDictionary 26 | { 27 | return @{ 28 | @"brand" : [self _stringFromBrand:self.brand], 29 | @"lastFourDigits" : self.lastFourDigits, 30 | @"expirationMonth" : self.expirationMonth ?: [NSNull null], 31 | @"expirationYear" : self.expirationYear ?: [NSNull null], 32 | @"id" : self.cardID ?: [NSNull null], 33 | @"cardholderName" : self.cardholderName ?: [NSNull null], 34 | }; 35 | } 36 | 37 | - (NSString *)_stringFromBrand:(SQRDCardBrand)brand 38 | { 39 | NSString *result = nil; 40 | switch (brand) { 41 | case SQRDCardBrandOtherBrand: 42 | result = @"OTHER_BRAND"; 43 | break; 44 | case SQRDCardBrandVisa: 45 | result = @"VISA"; 46 | break; 47 | case SQRDCardBrandMastercard: 48 | result = @"MASTERCARD"; 49 | break; 50 | case SQRDCardBrandAmericanExpress: 51 | result = @"AMERICAN_EXPRESS"; 52 | break; 53 | case SQRDCardBrandDiscover: 54 | result = @"DISCOVER"; 55 | break; 56 | case SQRDCardBrandDiscoverDiners: 57 | result = @"DISCOVER_DINERS"; 58 | break; 59 | case SQRDCardBrandInterac: 60 | result = @"INTERAC"; 61 | break; 62 | case SQRDCardBrandJCB: 63 | result = @"JCB"; 64 | break; 65 | case SQRDCardBrandChinaUnionPay: 66 | result = @"CHINA_UNIONPAY"; 67 | break; 68 | case SQRDCardBrandSquareGiftCard: 69 | result = @"SQUARE_GIFT_CARD"; 70 | break; 71 | case SQRDCardBrandEftpos: 72 | result = @"EFTPOS"; 73 | break; 74 | } 75 | return result; 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDCheckoutResult+FlutterReaderSDKAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | @import SquareReaderSDK; 18 | 19 | 20 | @interface SQRDCheckoutResult (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDCheckoutResult+FlutterReaderSDKAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SQRDCheckoutResult+FlutterReaderSDKAdditions.h" 18 | #import "SQRDTender+FlutterReaderSDKAdditions.h" 19 | #import "SQRDMoney+FlutterReaderSDKAdditions.h" 20 | #import "FlutterReaderSDKDateFormatter.h" 21 | 22 | 23 | @implementation SQRDCheckoutResult (FlutterReaderSDKAdditions) 24 | 25 | - (NSDictionary *)jsonDictionary 26 | { 27 | NSMutableArray *tenders = [[NSMutableArray alloc] init]; 28 | for (SQRDTender *tender in self.tenders) { 29 | [tenders addObject:[tender jsonDictionary]]; 30 | } 31 | 32 | return @{ 33 | @"transactionId" : self.transactionID ?: [NSNull null], 34 | @"transactionClientId" : self.transactionClientID, 35 | @"locationId" : self.locationID, 36 | @"createdAt" : [FlutterReaderSDKDateFormatter iso8601StringFromDate:self.createdAt], 37 | @"totalMoney" : [self.totalMoney jsonDictionary], 38 | @"totalTipMoney" : [self.totalTipMoney jsonDictionary], 39 | @"tenders" : tenders, 40 | }; 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDLocation+FlutterReaderSDKAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | @import SquareReaderSDK; 18 | 19 | 20 | @interface SQRDLocation (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDLocation+FlutterReaderSDKAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SQRDLocation+FlutterReaderSDKAdditions.h" 18 | #import "SQRDMoney+FlutterReaderSDKAdditions.h" 19 | 20 | 21 | @implementation SQRDLocation (FlutterReaderSDKAdditions) 22 | 23 | - (NSDictionary *)jsonDictionary 24 | { 25 | return @{ 26 | @"locationId" : self.locationID, 27 | @"name" : self.name, 28 | @"businessName" : self.businessName, 29 | @"isCardProcessingActivated" : @(self.isCardProcessingActivated), 30 | @"minimumCardPaymentAmountMoney" : [self.minimumCardPaymentAmountMoney jsonDictionary], 31 | @"maximumCardPaymentAmountMoney" : [self.maximumCardPaymentAmountMoney jsonDictionary], 32 | @"currencyCode" : SQRDCurrencyCodeGetISOCurrencyCode(self.currencyCode), 33 | }; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDMoney+FlutterReaderSDKAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | @import SquareReaderSDK; 18 | 19 | 20 | @interface SQRDMoney (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDMoney+FlutterReaderSDKAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SQRDMoney+FlutterReaderSDKAdditions.h" 18 | 19 | 20 | @implementation SQRDMoney (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary 23 | { 24 | return @{ 25 | @"amount" : @(self.amount), 26 | @"currencyCode" : SQRDCurrencyCodeGetISOCurrencyCode(self.currencyCode), 27 | }; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDTender+FlutterReaderSDKAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | @import SquareReaderSDK; 18 | 19 | 20 | @interface SQRDTender (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDTender+FlutterReaderSDKAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SQRDTender+FlutterReaderSDKAdditions.h" 18 | #import "SQRDMoney+FlutterReaderSDKAdditions.h" 19 | #import "SQRDTenderCardDetails+FlutterReaderSDKAdditions.h" 20 | #import "SQRDTenderCashDetails+FlutterReaderSDKAdditions.h" 21 | #import "FlutterReaderSDKDateFormatter.h" 22 | 23 | 24 | @implementation SQRDTender (FlutterReaderSDKAdditions) 25 | 26 | - (NSDictionary *)jsonDictionary; 27 | { 28 | NSMutableDictionary *tenderResult = [[NSMutableDictionary alloc] init]; 29 | tenderResult[@"createdAt"] = [FlutterReaderSDKDateFormatter iso8601StringFromDate:self.createdAt]; 30 | tenderResult[@"tipMoney"] = [self.tipMoney jsonDictionary]; 31 | tenderResult[@"totalMoney"] = [self.totalMoney jsonDictionary]; 32 | 33 | NSString *tenderType = nil; 34 | switch (self.type) { 35 | case SQRDTenderTypeCard: 36 | tenderType = @"card"; 37 | tenderResult[@"tenderId"] = self.tenderID; 38 | tenderResult[@"cardDetails"] = [self.cardDetails jsonDictionary]; 39 | break; 40 | case SQRDTenderTypeCash: 41 | tenderType = @"cash"; 42 | tenderResult[@"cashDetails"] = [self.cashDetails jsonDictionary]; 43 | break; 44 | case SQRDTenderTypeOther: 45 | tenderType = @"other"; 46 | break; 47 | } 48 | tenderResult[@"type"] = tenderType; 49 | return [tenderResult copy]; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDTenderCardDetails+FlutterReaderSDKAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | @import SquareReaderSDK; 18 | 19 | 20 | @interface SQRDTenderCardDetails (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDTenderCardDetails+FlutterReaderSDKAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SQRDTenderCardDetails+FlutterReaderSDKAdditions.h" 18 | #import "SQRDCard+FlutterReaderSDKAdditions.h" 19 | 20 | 21 | @implementation SQRDTenderCardDetails (FlutterReaderSDKAdditions) 22 | 23 | - (NSDictionary *)jsonDictionary 24 | { 25 | return @{ 26 | @"entryMethod" : [self _stringFromTenderCardDetailsEntryMethod:self.entryMethod], 27 | @"card" : [self.card jsonDictionary], 28 | }; 29 | } 30 | 31 | - (NSString *)_stringFromTenderCardDetailsEntryMethod:(SQRDTenderCardDetailsEntryMethod)method 32 | { 33 | NSString *result = nil; 34 | switch (method) { 35 | case SQRDTenderCardDetailsEntryMethodManuallyEntered: 36 | result = @"MANUALLY_ENTERED"; 37 | break; 38 | case SQRDTenderCardDetailsEntryMethodSwipe: 39 | result = @"SWIPE"; 40 | break; 41 | case SQRDTenderCardDetailsEntryMethodChip: 42 | result = @"CHIP"; 43 | break; 44 | case SQRDTenderCardDetailsEntryMethodContactless: 45 | result = @"CONTACTLESS"; 46 | break; 47 | case SQRDTenderCardDetailsEntryMethodUnknown: 48 | result = @"UNKNOWN"; 49 | break; 50 | } 51 | return result; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDTenderCashDetails+FlutterReaderSDKAdditions.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | @import SquareReaderSDK; 18 | 19 | 20 | @interface SQRDTenderCashDetails (FlutterReaderSDKAdditions) 21 | 22 | - (NSDictionary *)jsonDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /ios/Classes/Converters/SQRDTenderCashDetails+FlutterReaderSDKAdditions.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SQRDTenderCashDetails+FlutterReaderSDKAdditions.h" 18 | #import "SQRDMoney+FlutterReaderSDKAdditions.h" 19 | 20 | 21 | @implementation SQRDTenderCashDetails (FlutterReaderSDKAdditions) 22 | 23 | - (NSDictionary *)jsonDictionary 24 | { 25 | return @{ 26 | @"buyerTenderedMoney" : [self.buyerTenderedMoney jsonDictionary], 27 | @"changeBackMoney" : [self.changeBackMoney jsonDictionary], 28 | }; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKAuthorization.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | @import SquareReaderSDK; 19 | 20 | 21 | @interface FlutterReaderSDKAuthorization : NSObject 22 | 23 | - (void)isAuthorized:(FlutterResult)result; 24 | - (void)isAuthorizationInProgress:(FlutterResult)result; 25 | - (void)authorizedLocation:(FlutterResult)result; 26 | - (void)authorize:(FlutterResult)result authCode:(NSString *)authCode; 27 | - (void)canDeauthorize:(FlutterResult)result; 28 | - (void)deauthorize:(FlutterResult)result; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKAuthorization.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "FlutterReaderSDKAuthorization.h" 18 | #import "FlutterReaderSDKErrorUtilities.h" 19 | #import "Converters/SQRDLocation+FlutterReaderSDKAdditions.h" 20 | 21 | // Define all the error codes and messages below 22 | // These error codes and messages **MUST** align with android error codes and dart error codes 23 | // Search KEEP_IN_SYNC_AUTHORIZE_ERROR to update all places 24 | 25 | // Expected errors: 26 | static NSString *const FlutterReaderSDKAuthorizeNoNetwork = @"AUTHORIZE_NO_NETWORK"; 27 | 28 | // flutter plugin debug error codes 29 | static NSString *const FlutterReaderSDKAuthLocationNotAuthorized = @"fl_auth_location_not_authorized"; 30 | 31 | // flutter plugin debug messages 32 | static NSString *const FlutterReaderSDKMessageAuthLocationNotAuthorized = @"This device must be authorized with a Square location in order to get that location. Obtain an authorization code for a Square location from the mobile/authorization-code endpoint and then call authorizeAsync."; 33 | 34 | 35 | @implementation FlutterReaderSDKAuthorization 36 | 37 | - (void)isAuthorized:(FlutterResult)result 38 | { 39 | result(@(SQRDReaderSDK.sharedSDK.isAuthorized)); 40 | } 41 | 42 | - (void)isAuthorizationInProgress:(FlutterResult)result 43 | { 44 | result(@(SQRDReaderSDK.sharedSDK.isAuthorizationInProgress)); 45 | } 46 | 47 | - (void)authorizedLocation:(FlutterResult)result 48 | { 49 | if (SQRDReaderSDK.sharedSDK.isAuthorized) { 50 | result([SQRDReaderSDK.sharedSDK.authorizedLocation jsonDictionary]); 51 | } else { 52 | result([FlutterError errorWithCode:FlutterReaderSDKUsageError 53 | message:[FlutterReaderSDKErrorUtilities nativeModuleErrorMessage:FlutterReaderSDKAuthLocationNotAuthorized] 54 | details:[FlutterReaderSDKErrorUtilities debugErrorObject:FlutterReaderSDKAuthLocationNotAuthorized debugMessage:FlutterReaderSDKMessageAuthLocationNotAuthorized]]); 55 | } 56 | } 57 | 58 | - (void)authorize:(FlutterResult)result authCode:(NSString *)authCode 59 | { 60 | [SQRDReaderSDK.sharedSDK authorizeWithCode:authCode 61 | completionHandler:^(SQRDLocation *_Nullable location, NSError *_Nullable error) { 62 | if (error != nil) { 63 | NSString *debugCode = error.userInfo[SQRDErrorDebugCodeKey]; 64 | NSString *debugMessage = error.userInfo[SQRDErrorDebugMessageKey]; 65 | result([FlutterError errorWithCode:[self _authorizationErrorCodeFromNativeErrorCode:error.code] 66 | message:error.localizedDescription 67 | details:[FlutterReaderSDKErrorUtilities debugErrorObject:debugCode debugMessage:debugMessage]]); 68 | return; 69 | } 70 | result([location jsonDictionary]); 71 | }]; 72 | } 73 | 74 | - (void)canDeauthorize:(FlutterResult)result 75 | { 76 | result(@(SQRDReaderSDK.sharedSDK.canDeauthorize)); 77 | } 78 | 79 | - (void)deauthorize:(FlutterResult)result 80 | { 81 | [SQRDReaderSDK.sharedSDK deauthorizeWithCompletionHandler:^(NSError *_Nullable error) { 82 | if (error != nil) { 83 | NSString *debugCode = error.userInfo[SQRDErrorDebugCodeKey]; 84 | NSString *debugMessage = error.userInfo[SQRDErrorDebugMessageKey]; 85 | result([FlutterError errorWithCode:FlutterReaderSDKUsageError 86 | message:error.localizedDescription 87 | details:[FlutterReaderSDKErrorUtilities debugErrorObject:debugCode debugMessage:debugMessage]]); 88 | return; 89 | } 90 | result(nil); 91 | }]; 92 | } 93 | 94 | #pragma mark - Private Methods 95 | - (NSString *)_authorizationErrorCodeFromNativeErrorCode:(NSInteger)nativeErrorCode 96 | { 97 | NSString *errorCode = @"UNKNOWN"; 98 | if (nativeErrorCode == SQRDAuthorizationErrorUsageError) { 99 | errorCode = FlutterReaderSDKUsageError; 100 | } else { 101 | switch (nativeErrorCode) { 102 | case SQRDAuthorizationErrorNoNetworkConnection: 103 | errorCode = FlutterReaderSDKAuthorizeNoNetwork; 104 | break; 105 | } 106 | } 107 | return errorCode; 108 | } 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKCheckout.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | @import SquareReaderSDK; 19 | 20 | 21 | @interface FlutterReaderSDKCheckout : NSObject 22 | 23 | - (void)startCheckout:(FlutterResult)result checkoutParametersDictionary:(NSDictionary *)checkoutParametersDictionary; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKErrorUtilities.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | 19 | extern NSString *const FlutterReaderSDKUsageError; 20 | 21 | 22 | @interface FlutterReaderSDKErrorUtilities : NSObject 23 | 24 | + (NSString *)nativeModuleErrorMessage:(NSString *)nativeModuleErrorCode; 25 | 26 | + (NSDictionary *)debugErrorObject:(NSString *)debugCode debugMessage:(NSString *)debugMessage; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKErrorUtilities.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "FlutterReaderSDKErrorUtilities.h" 18 | @import SquareReaderSDK; 19 | 20 | // Usage error 21 | NSString *const FlutterReaderSDKUsageError = @"USAGE_ERROR"; 22 | 23 | 24 | @implementation FlutterReaderSDKErrorUtilities 25 | 26 | + (NSString *)nativeModuleErrorMessage:(NSString *)nativeModuleErrorCode 27 | { 28 | return [NSString stringWithFormat:@"Something went wrong. Please contact the developer of this application and provide them with this error code: %@", nativeModuleErrorCode]; 29 | } 30 | 31 | + (NSDictionary *)debugErrorObject:(NSString *)debugCode debugMessage:(NSString *)debugMessage 32 | { 33 | NSMutableDictionary *errorObject = [[NSMutableDictionary alloc] init]; 34 | errorObject[@"debugCode"] = debugCode; 35 | errorObject[@"debugMessage"] = debugMessage; 36 | return errorObject; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKReaderSettings.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | @import SquareReaderSDK; 19 | 20 | 21 | @interface FlutterReaderSDKReaderSettings : NSObject 22 | 23 | - (void)startReaderSettings:(FlutterResult)result; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKReaderSettings.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "FlutterReaderSDKReaderSettings.h" 18 | #import "FlutterReaderSDKErrorUtilities.h" 19 | 20 | 21 | @interface FlutterReaderSDKReaderSettings () 22 | 23 | @property (strong, readwrite) FlutterResult readerSettingResolver; 24 | 25 | @end 26 | 27 | // Define all the error codes and messages below 28 | // These error codes and messages **MUST** align with android error codes and dart error codes 29 | // Search KEEP_IN_SYNC_READER_SETTINGS_ERROR to update all places 30 | 31 | // Expected errors: 32 | static NSString *const FlutterReaderSDKReaderSettingsSdkNotAuthorized = @"READER_SETTINGS_SDK_NOT_AUTHORIZED"; 33 | 34 | // flutter plugin debug error codes 35 | static NSString *const FlutterReaderSDKReaderSettingsAlreadyInProgress = @"fl_reader_settings_already_in_progress"; 36 | 37 | // flutter plugin debug messages 38 | static NSString *const FlutterReaderSDKMessageReaderSettingsAlreadyInProgress = @"A reader settings operation is already in progress. Ensure that the in-progress reader settings is completed before calling startReaderSettingsAsync again."; 39 | 40 | 41 | @implementation FlutterReaderSDKReaderSettings 42 | 43 | - (void)startReaderSettings:(FlutterResult)result 44 | { 45 | if (self.readerSettingResolver != nil) { 46 | result([FlutterError errorWithCode:FlutterReaderSDKUsageError 47 | message:[FlutterReaderSDKErrorUtilities nativeModuleErrorMessage:FlutterReaderSDKReaderSettingsAlreadyInProgress] 48 | details:[FlutterReaderSDKErrorUtilities debugErrorObject:FlutterReaderSDKReaderSettingsAlreadyInProgress debugMessage:FlutterReaderSDKMessageReaderSettingsAlreadyInProgress]]); 49 | return; 50 | } 51 | SQRDReaderSettingsController *readerSettingsController = [[SQRDReaderSettingsController alloc] initWithDelegate:self]; 52 | self.readerSettingResolver = result; 53 | UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; 54 | [readerSettingsController presentFromViewController:rootViewController]; 55 | } 56 | 57 | - (void)readerSettingsControllerDidPresent:(SQRDReaderSettingsController *)readerSettingsController 58 | { 59 | self.readerSettingResolver([NSNull null]); 60 | [self _clearReaderSettingHooks]; 61 | } 62 | 63 | - (void)readerSettingsController:(SQRDReaderSettingsController *)readerSettingsController didFailToPresentWithError:(NSError *)error 64 | { 65 | NSString *debugCode = error.userInfo[SQRDErrorDebugCodeKey]; 66 | NSString *debugMessage = error.userInfo[SQRDErrorDebugMessageKey]; 67 | self.readerSettingResolver([FlutterError errorWithCode:[self _readerSettingsErrorCodeFromNativeErrorCode:error.code] 68 | message:error.localizedDescription 69 | details:[FlutterReaderSDKErrorUtilities debugErrorObject:debugCode debugMessage:debugMessage]]); 70 | [self _clearReaderSettingHooks]; 71 | } 72 | 73 | #pragma mark - Private Methods 74 | - (void)_clearReaderSettingHooks 75 | { 76 | self.readerSettingResolver = nil; 77 | } 78 | 79 | - (NSString *)_readerSettingsErrorCodeFromNativeErrorCode:(NSInteger)nativeErrorCode 80 | { 81 | NSString *errorCode = @"UNKNOWN"; 82 | if (nativeErrorCode == SQRDReaderSettingsControllerErrorUsageError) { 83 | errorCode = FlutterReaderSDKUsageError; 84 | } else { 85 | switch (nativeErrorCode) { 86 | case SQRDReaderSettingsControllerErrorSDKNotAuthorized: 87 | errorCode = FlutterReaderSDKReaderSettingsSdkNotAuthorized; 88 | break; 89 | } 90 | } 91 | return errorCode; 92 | } 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKStoreCustomerCard.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | @import SquareReaderSDK; 19 | 20 | 21 | @interface FlutterReaderSDKStoreCustomerCard : NSObject 22 | 23 | - (void)startStoreCard:(FlutterResult)result customerID:(NSString *)customerID; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /ios/Classes/FlutterReaderSDKStoreCustomerCard.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "FlutterReaderSDKStoreCustomerCard.h" 18 | #import "FlutterReaderSDKErrorUtilities.h" 19 | #import "Converters/SQRDCard+FlutterReaderSDKAdditions.h" 20 | 21 | 22 | @interface FlutterReaderSDKStoreCustomerCard () 23 | 24 | @property (strong, readwrite) FlutterResult storeCardResolver; 25 | 26 | @end 27 | 28 | // Define all the error codes and messages below 29 | // These error codes and messages **MUST** align with iOS error codes and javascript error codes 30 | // Search KEEP_IN_SYNC_STORE_CUSTOMER_CARD_ERROR to update all places 31 | 32 | // Expected errors: 33 | static NSString *const FlutterReaderSDKStoreCustomerCardCancelled = @"STORE_CUSTOMER_CARD_CANCELED"; 34 | static NSString *const FlutterReaderSDKStoreCustomerCardInvalidCustomerID = @"STORE_CUSTOMER_CARD_INVALID_CUSTOMER_ID"; 35 | static NSString *const FlutterReaderSDKStoreCustomerCardSdkNotAuthorized = @"STORE_CUSTOMER_CARD_SDK_NOT_AUTHORIZED"; 36 | static NSString *const FlutterReaderSDKStoreCustomerCardNoNetwork = @"STORE_CUSTOMER_CARD_NO_NETWORK"; 37 | 38 | // flutter plugin debug error codes 39 | static NSString *const FlutterReaderSDKStoreCustomerCardAlreadyInProgress = @"fl_add_customer_already_in_progress"; 40 | 41 | // flutter plugin debug messages 42 | static NSString *const FlutterReaderSDKMessageStoreCustomerCardAlreadyInProgress = @"A store customer card operation is already in progress. Ensure that the in-progress store customer card is completed before calling startStoreCardAsync again."; 43 | 44 | 45 | @implementation FlutterReaderSDKStoreCustomerCard 46 | 47 | - (void)startStoreCard:(FlutterResult)result customerID:(NSString *)customerID 48 | { 49 | if (self.storeCardResolver != nil) { 50 | self.storeCardResolver([FlutterError errorWithCode:FlutterReaderSDKUsageError 51 | message:[FlutterReaderSDKErrorUtilities 52 | nativeModuleErrorMessage:FlutterReaderSDKStoreCustomerCardAlreadyInProgress] 53 | details:[FlutterReaderSDKErrorUtilities 54 | debugErrorObject:FlutterReaderSDKStoreCustomerCardAlreadyInProgress 55 | debugMessage:FlutterReaderSDKMessageStoreCustomerCardAlreadyInProgress]]); 56 | return; 57 | } 58 | 59 | SQRDStoreCustomerCardController *storeCustomerCardContorller = [[SQRDStoreCustomerCardController alloc] initWithCustomerID:customerID delegate:self]; 60 | 61 | self.storeCardResolver = result; 62 | UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController; 63 | [storeCustomerCardContorller presentFromViewController:rootViewController]; 64 | } 65 | 66 | #pragma mark - SQRDCheckoutControllerDelegate 67 | - (void)storeCustomerCardController:(SQRDStoreCustomerCardController *)storeCustomerCardController didFinishWithCard:(nonnull SQRDCard *)card 68 | { 69 | self.storeCardResolver([card jsonDictionary]); 70 | [self _clearStoreCardHooks]; 71 | } 72 | 73 | - (void)storeCustomerCardController:(SQRDStoreCustomerCardController *)storeCustomerCardController didFailWithError:(NSError *)error 74 | { 75 | NSString *debugCode = error.userInfo[SQRDErrorDebugCodeKey]; 76 | NSString *debugMessage = error.userInfo[SQRDErrorDebugMessageKey]; 77 | self.storeCardResolver([FlutterError errorWithCode:[self _storeCustomerCardErrorCodeFromNativeErrorCode:error.code] 78 | message:error.localizedDescription 79 | details:[FlutterReaderSDKErrorUtilities debugErrorObject:debugCode debugMessage:debugMessage]]); 80 | [self _clearStoreCardHooks]; 81 | } 82 | 83 | - (void)storeCustomerCardControllerDidCancel:(SQRDStoreCustomerCardController *)storeCustomerCardController 84 | { 85 | // Return store card cancel as an error in order to align with Android implementation 86 | self.storeCardResolver([FlutterError errorWithCode:FlutterReaderSDKStoreCustomerCardCancelled 87 | message:[FlutterReaderSDKErrorUtilities nativeModuleErrorMessage:FlutterReaderSDKStoreCustomerCardCancelled] 88 | details:[FlutterReaderSDKErrorUtilities debugErrorObject:FlutterReaderSDKStoreCustomerCardCancelled debugMessage:@"The user canceled the store customer flow."]]); 89 | [self _clearStoreCardHooks]; 90 | } 91 | 92 | #pragma mark - Private Methods 93 | - (void)_clearStoreCardHooks 94 | { 95 | self.storeCardResolver = nil; 96 | } 97 | 98 | - (NSString *)_storeCustomerCardErrorCodeFromNativeErrorCode:(NSInteger)nativeErrorCode 99 | { 100 | NSString *errorCode = @"UNKNOWN"; 101 | if (nativeErrorCode == SQRDStoreCustomerCardControllerErrorUsageError) { 102 | errorCode = FlutterReaderSDKUsageError; 103 | } else { 104 | switch (nativeErrorCode) { 105 | case SQRDStoreCustomerCardControllerErrorInvalidCustomerID: 106 | errorCode = FlutterReaderSDKStoreCustomerCardInvalidCustomerID; 107 | break; 108 | case SQRDStoreCustomerCardControllerErrorSDKNotAuthorized: 109 | errorCode = FlutterReaderSDKStoreCustomerCardSdkNotAuthorized; 110 | break; 111 | case SQRDStoreCustomerCardControllerErrorNoNetworkConnection: 112 | errorCode = FlutterReaderSDKStoreCustomerCardNoNetwork; 113 | break; 114 | } 115 | } 116 | return errorCode; 117 | } 118 | 119 | @end 120 | -------------------------------------------------------------------------------- /ios/Classes/SquareReaderSdkFlutterPlugin.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import 18 | @import SquareReaderSDK; 19 | 20 | 21 | @interface SquareReaderSdkFlutterPlugin : NSObject 22 | @end 23 | -------------------------------------------------------------------------------- /ios/Classes/SquareReaderSdkFlutterPlugin.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | #import "SquareReaderSdkFlutterPlugin.h" 18 | #import "FlutterReaderSDKAuthorization.h" 19 | #import "FlutterReaderSDKCheckout.h" 20 | #import "FlutterReaderSDKReaderSettings.h" 21 | #import "FlutterReaderSDKStoreCustomerCard.h" 22 | 23 | 24 | @interface SquareReaderSdkFlutterPlugin () 25 | 26 | @property (strong, readwrite) FlutterReaderSDKAuthorization *authorization; 27 | @property (strong, readwrite) FlutterReaderSDKCheckout *checkout; 28 | @property (strong, readwrite) FlutterReaderSDKReaderSettings *readerSettings; 29 | @property (strong, readwrite) FlutterReaderSDKStoreCustomerCard *storeCustomerCard; 30 | 31 | @end 32 | 33 | 34 | @implementation SquareReaderSdkFlutterPlugin 35 | + (void)registerWithRegistrar:(NSObject *)registrar 36 | { 37 | FlutterMethodChannel *channel = [FlutterMethodChannel 38 | methodChannelWithName:@"square_reader_sdk" 39 | binaryMessenger:[registrar messenger]]; 40 | SquareReaderSdkFlutterPlugin *instance = [[SquareReaderSdkFlutterPlugin alloc] init]; 41 | [registrar addMethodCallDelegate:instance channel:channel]; 42 | } 43 | 44 | - (instancetype)init 45 | { 46 | self = [super init]; 47 | if (!self) { 48 | return nil; 49 | } 50 | self.authorization = [[FlutterReaderSDKAuthorization alloc] init]; 51 | self.checkout = [[FlutterReaderSDKCheckout alloc] init]; 52 | self.readerSettings = [[FlutterReaderSDKReaderSettings alloc] init]; 53 | self.storeCustomerCard = [[FlutterReaderSDKStoreCustomerCard alloc] init]; 54 | return self; 55 | } 56 | 57 | - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result 58 | { 59 | if ([@"isAuthorized" isEqualToString:call.method]) { 60 | [self.authorization isAuthorized:result]; 61 | } else if ([@"isAuthorizationInProgress" isEqualToString:call.method]) { 62 | [self.authorization isAuthorizationInProgress:result]; 63 | } else if ([@"authorizedLocation" isEqualToString:call.method]) { 64 | [self.authorization authorizedLocation:result]; 65 | } else if ([@"authorize" isEqualToString:call.method]) { 66 | NSString *authCode = call.arguments[@"authCode"]; 67 | [self.authorization authorize:result authCode:authCode]; 68 | } else if ([@"canDeauthorize" isEqualToString:call.method]) { 69 | [self.authorization canDeauthorize:result]; 70 | } else if ([@"deauthorize" isEqualToString:call.method]) { 71 | [self.authorization deauthorize:result]; 72 | } else if ([@"startCheckout" isEqualToString:call.method]) { 73 | [self.checkout startCheckout:result checkoutParametersDictionary:call.arguments[@"checkoutParams"]]; 74 | } else if ([@"startReaderSettings" isEqualToString:call.method]) { 75 | [self.readerSettings startReaderSettings:result]; 76 | } else if ([@"startStoreCard" isEqualToString:call.method]) { 77 | NSString *customerID = call.arguments[@"customerId"]; 78 | [self.storeCustomerCard startStoreCard:result customerID:customerID]; 79 | } else { 80 | result(FlutterMethodNotImplemented); 81 | } 82 | } 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /ios/square_reader_sdk.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 3 | # 4 | Pod::Spec.new do |s| 5 | s.name = 'square_reader_sdk' 6 | s.version = '3.0.0' 7 | s.summary = 'iOS part of a flutter plugin for Square Reader SDK.' 8 | s.description = <<-DESC 9 | iOS part of a flutter plugin for Square Reader SDK. 10 | DESC 11 | s.homepage = 'https://github.com/square/reader-sdk-flutter-plugin' 12 | s.license = { :file => '../LICENSE' } 13 | s.author = { 'Square, Inc.' => 'xiao@squareup.com' } 14 | s.source = { :path => '.' } 15 | s.source_files = 'Classes/**/*' 16 | s.public_header_files = 'Classes/**/*.h' 17 | s.dependency 'Flutter' 18 | s.frameworks = 'SquareReaderSDK' 19 | s.xcconfig = { 20 | 'OTHER_LDFLAGS' => '-framework SquareReaderSDK', 21 | 'ENABLE_BITCODE' => 'NO', 22 | 'FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]' => '$(inherited) $(PROJECT_DIR)/../SquareReaderSDK.xcframework/ios-arm64', 23 | 'FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]' => '$(inherited) $(PROJECT_DIR)/../SquareReaderSDK.xcframework/ios-arm64_x86_64-simulator' 24 | } 25 | s.vendored_frameworks = 'SquareReaderSDK.xcframework' 26 | # Flutter.framework does not contain a i386 slice. 27 | s.pod_target_xcconfig = { 28 | 'DEFINES_MODULE' => 'YES', 29 | 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386', 30 | } 31 | s.swift_version = '5.0' 32 | 33 | s.ios.deployment_target = '11.1' 34 | end 35 | 36 | -------------------------------------------------------------------------------- /lib/reader_sdk.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | import 'dart:async'; 17 | 18 | import 'package:built_value/standard_json_plugin.dart'; 19 | import 'package:flutter/services.dart'; 20 | import 'models.dart'; 21 | import 'src/serializers.dart'; 22 | 23 | // ignore: avoid_classes_with_only_static_members 24 | class ReaderSdk { 25 | static final _standardSerializers = 26 | (serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); 27 | 28 | static const MethodChannel _channel = MethodChannel('square_reader_sdk'); 29 | 30 | static Future get isAuthorized async { 31 | try { 32 | bool isAuthorized = await _channel.invokeMethod('isAuthorized'); 33 | return isAuthorized; 34 | } on PlatformException catch (ex) { 35 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 36 | ex.details['debugMessage']); 37 | } 38 | } 39 | 40 | static Future get isAuthorizationInProgress async { 41 | try { 42 | bool isAuthorizationInProgress = 43 | await _channel.invokeMethod('isAuthorizationInProgress'); 44 | return isAuthorizationInProgress; 45 | } on PlatformException catch (ex) { 46 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 47 | ex.details['debugMessage']); 48 | } 49 | } 50 | 51 | static Future get authorizedLocation async { 52 | try { 53 | var locationNativeObject = 54 | await _channel.invokeMethod('authorizedLocation'); 55 | return _standardSerializers.deserializeWith( 56 | Location.serializer, locationNativeObject)!; 57 | } on PlatformException catch (ex) { 58 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 59 | ex.details['debugMessage']); 60 | } 61 | } 62 | 63 | static Future authorize(String authCode) async { 64 | try { 65 | var params = { 66 | 'authCode': authCode, 67 | }; 68 | var locationNativeObject = 69 | await _channel.invokeMethod('authorize', params); 70 | return _standardSerializers.deserializeWith( 71 | Location.serializer, locationNativeObject)!; 72 | } on PlatformException catch (ex) { 73 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 74 | ex.details['debugMessage']); 75 | } 76 | } 77 | 78 | static Future get canDeauthorize async { 79 | try { 80 | bool canDeauthorize = await _channel.invokeMethod('canDeauthorize'); 81 | return canDeauthorize; 82 | } on PlatformException catch (ex) { 83 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 84 | ex.details['debugMessage']); 85 | } 86 | } 87 | 88 | static Future deauthorize() async { 89 | try { 90 | await _channel.invokeMethod('deauthorize'); 91 | } on PlatformException catch (ex) { 92 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 93 | ex.details['debugMessage']); 94 | } 95 | } 96 | 97 | static Future startCheckout( 98 | CheckoutParameters checkoutParams) async { 99 | try { 100 | var params = { 101 | 'checkoutParams': _standardSerializers.serializeWith( 102 | CheckoutParameters.serializer, checkoutParams), 103 | }; 104 | var checkoutResultNativeObject = 105 | await _channel.invokeMethod('startCheckout', params); 106 | return _standardSerializers.deserializeWith( 107 | CheckoutResult.serializer, checkoutResultNativeObject)!; 108 | } on PlatformException catch (ex) { 109 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 110 | ex.details['debugMessage']); 111 | } 112 | } 113 | 114 | static Future startReaderSettings() async { 115 | try { 116 | await _channel.invokeMethod('startReaderSettings'); 117 | } on PlatformException catch (ex) { 118 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 119 | ex.details['debugMessage']); 120 | } 121 | } 122 | 123 | static Future startStoreCard(String customerId) async { 124 | var params = { 125 | 'customerId': customerId, 126 | }; 127 | try { 128 | var cardObject = await _channel.invokeMethod('startStoreCard', params); 129 | return _standardSerializers.deserializeWith(Card.serializer, cardObject); 130 | } on PlatformException catch (ex) { 131 | throw ReaderSdkException(ex.code, ex.message, ex.details['debugCode'], 132 | ex.details['debugMessage']); 133 | } 134 | } 135 | } 136 | 137 | class ReaderSdkException implements Exception { 138 | static final _standardSerializers = 139 | (serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); 140 | 141 | final String _code; 142 | 143 | final String? message; 144 | 145 | final String debugCode; 146 | 147 | final String? debugMessage; 148 | 149 | ErrorCode? get code => 150 | _standardSerializers.deserializeWith(ErrorCode.serializer, _code); 151 | 152 | ReaderSdkException( 153 | this._code, 154 | this.message, 155 | this.debugCode, 156 | this.debugMessage, 157 | ); 158 | 159 | @override 160 | String toString() => 161 | 'PlatformException($code, $message, $debugCode, $debugMessage)'; 162 | } 163 | -------------------------------------------------------------------------------- /lib/src/serializers.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Square Inc. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | import 'package:built_collection/built_collection.dart'; 17 | import 'package:built_value/serializer.dart'; 18 | import '../models.dart'; 19 | 20 | part 'serializers.g.dart'; 21 | 22 | @SerializersFor([ 23 | Money, 24 | Location, 25 | CheckoutResult, 26 | TenderType, 27 | Tender, 28 | EntryMethod, 29 | CardDetails, 30 | CashDetails, 31 | Brand, 32 | Card, 33 | AdditionalPaymentType, 34 | CheckoutParameters, 35 | TipSettings, 36 | ErrorCode, 37 | ]) 38 | final Serializers serializers = _$serializers; 39 | -------------------------------------------------------------------------------- /lib/src/serializers.g.dart: -------------------------------------------------------------------------------- 1 | // GENERATED CODE - DO NOT MODIFY BY HAND 2 | 3 | part of 'serializers.dart'; 4 | 5 | // ************************************************************************** 6 | // BuiltValueGenerator 7 | // ************************************************************************** 8 | 9 | Serializers _$serializers = (new Serializers().toBuilder() 10 | ..add(AdditionalPaymentType.serializer) 11 | ..add(Brand.serializer) 12 | ..add(Card.serializer) 13 | ..add(CardDetails.serializer) 14 | ..add(CashDetails.serializer) 15 | ..add(CheckoutParameters.serializer) 16 | ..add(CheckoutResult.serializer) 17 | ..add(EntryMethod.serializer) 18 | ..add(ErrorCode.serializer) 19 | ..add(Location.serializer) 20 | ..add(Money.serializer) 21 | ..add(Tender.serializer) 22 | ..add(TenderType.serializer) 23 | ..add(TipSettings.serializer) 24 | ..addBuilderFactory( 25 | const FullType( 26 | BuiltList, const [const FullType(AdditionalPaymentType)]), 27 | () => new ListBuilder()) 28 | ..addBuilderFactory( 29 | const FullType(BuiltList, const [const FullType(Tender)]), 30 | () => new ListBuilder()) 31 | ..addBuilderFactory( 32 | const FullType(BuiltList, const [const FullType(int)]), 33 | () => new ListBuilder())) 34 | .build(); 35 | 36 | // ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new 37 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: square_reader_sdk 2 | description: An open source Flutter plugin for calling Square’s native Reader SDK implementations to take in-person payments on iOS and Android. 3 | version: 4.0.1 4 | homepage: https://github.com/square/reader-sdk-flutter-plugin 5 | 6 | environment: 7 | sdk: '>=2.14.0 <3.0.0' 8 | flutter: ">=2.0.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | built_value: ^8.0.6 14 | built_collection: ^5.0.0 15 | 16 | dev_dependencies: 17 | build: ^2.0.1 18 | build_runner: ^2.0.3 19 | source_gen: ^1.0.0 20 | built_value_generator: ^8.0.6 21 | 22 | # The following section is specific to Flutter. 23 | flutter: 24 | plugin: 25 | platforms: 26 | android: 27 | package: com.squareup.sdk.reader.flutter 28 | pluginClass: SquareReaderSdkFlutterPlugin 29 | ios: 30 | pluginClass: SquareReaderSdkFlutterPlugin 31 | --------------------------------------------------------------------------------