tobias

repository·main·Indexed 20 days ago

https://github.com/openflutter/tobias

A Flutter plugin that integrates the AliPay SDK to enable payment and authentication capabilities on iOS, Android, and OpenHarmony platforms. It provides methods for performing payments via pay_V2, executing authentication, registering merchant appIds, and verifying AliPay installation status and versions.

Tokens
2.4K
Snippets
15
Records
16
Agent score
70%

What's inside tobias

  1. Setup Tobias for Android, iOS, and OpenHarmony

    main

    Before using Tobias, you must configure platform-specific settings:

    Android & iOS

    Configure a url_scheme in your pubspec.yaml. This is a unique string used to relaunch your app. Note: The underscore _ character is invalid in the scheme.

    iOS Specifics

    • You must configure and pass a Universal Link. Refer to the Alipay documentation for details.
    • If you encounter utdid issues on iOS, enable no_utdid: true in your pubspec.yaml.

    OpenHarmony

    In your module.json5 file, add alipays to the module.querySchemes array:

    {
      "module": {
        "querySchemes": [
          "alipays"
        ],
      }
    }
  2. Migrate to Tobias 1.0.0 (iOS AppDelegate)

    main

    Since version 1.0.0, there is no need to manually override AppDelegate methods to handle AliPay URL opening.

    If you have existing code in your AppDelegate.m (Objective-C) that handles openURL, you should remove it. If you must keep these overrides for other purposes, ensure you call super to allow the plugin to function correctly.

    // If you must override, ensure super is called:
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
        return [super application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
    }
    
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
        return [super application:application openURL:url options:options];
    }
  3. Customize iOS Launch Screen Assets

    main

    You can customize the iOS launch screen by replacing the image files located in the example/ios/Runner/Assets.xcassets/LaunchImage.imageset/ directory with your own assets.

    Alternatively, you can manage these assets through Xcode:

    1. Open your Flutter project's iOS workspace using open ios/Runner.xcworkspace.
    2. In the Xcode Project Navigator, select Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog to replace the existing ones.
    open ios/Runner.xcworkspace
  4. Get Started with Tobias

    main

    Tobias is a Flutter plugin for AliPaySDK that supports iOS, Android, and OpenHarmony. Before using Tobias, it is highly recommended to read the official AliPay documentation.

    Platform Configuration

    iOS

    Configure a url_scheme in your pubspec.yaml. This is a unique string used to resume your app on iOS. Note: The underscore character _ is invalid in the scheme.

    If you encounter conflicts with utdid on iOS, you can set no_utdid: true in your pubspec.yaml.

    OpenHarmony

    You must add the alipays scheme to the module.json5 file in your project.

    {
      "module": {
        "querySchemes": [
          "alipays"
        ],
      }
    }
  5. Use the tobias_example project

    main
    The tobias_example project serves as a demonstration of how to implement the tobias plugin within a Flutter application. It provides a functional starting point for developers looking to integrate Tobias payment capabilities into their own Flutter apps.
  6. Use Alipay Authorization Login

    main

    You can use Tobias to perform Alipay authorization login by passing your auth string to the auth method.

    Note: Authorization login is currently not supported on OpenHarmony.

    import 'package:tobias/tobias.dart';
    
    Tobias tobias = Tobias();
    tobias.auth("your auth str");
  7. Check if Alipay is installed and get SDK version

    main

    Use the following methods to check the device state:

    • isAliPayInstalled: Returns a boolean indicating if the Alipay app is installed.
    • version: Returns a Map containing the SDK version and the platform (e.g., iOS or android).
    Tobias tobias = Tobias();
    
    // Check installation
    var isInstalled = await tobias.isAliPayInstalled;
    
    // Get SDK version info
    var versionInfo = tobias.version;
  8. Perform Alipay Payments with Tobias

    main

    To initiate a payment, pass the order string obtained from your server to the pay method. Tobias uses pay_V2.

    Troubleshooting Android: If you encounter Unhandled Exception: MissingPluginException(No implementation found for method pay on channel com.jarvanmo/tobias), ensure your android/build.gradle version matches the plugin requirements.

    Return Value: The method returns a Map containing the Alipay payment result, including an additional platform field with the value iOS or android.

    import 'package:tobias/tobias.dart';
    
    Tobias tobias = Tobias();
    // yourOrder is the string received from your server
    tobias.pay(yourOrder);
  9. Verify AliPay Installation and Version

    main

    You can check if the AliPay app is installed on the device or retrieve the current Tobias version and platform information using the following methods.

    Tobias tobias = Tobias();
    
    // Check if AliPay is installed
    var isInstalled = await tobias.isAliPayInstalled;
    
    // Get version information (returns a Map containing 'version' and 'platform')
    var versionInfo = tobias.version;
  10. Perform an AliPay Payment

    main

    To initiate a payment, pass the order information received from your server to the pay method. Tobias uses pay_V2 internally.

    Note for iOS: You must add and pass a universal link as per the AliPay configuration guide.

    The pay method returns a Map containing the results from AliPay. This map includes an external field named platform which indicates whether the result originated from iOS or android.

    import 'package:tobias/tobias.dart';
    
    Tobias tobias = Tobias();
    // yourOrder should be the order info string from your server
    tobias.pay(yourOrder);