Покупка в приложении для Google Pay с Flutter - PullRequest
0 голосов
/ 28 мая 2020

Итак, я пытаюсь использовать Google Pay в моем приложении flutter, и ниже мой код. Когда я запускаю приложение, отображается диалоговое окно Google Pay с моим адресом электронной почты Google Pay и данными карты, а также сообщение об ошибке «Нераспознанное приложение. Перед продолжением убедитесь, что вы доверяете этому приложению. Когда я нажимаю кнопку« Продолжить », я получаю« Запрос не выполнен » «Непредвиденная ошибка разработчика. Повторите попытку позже». Что я делаю не так?

import 'dart:async';
import 'package:flutter/services.dart';
import 'package:google_pay/google_pay.dart';

void main() => runApp(MyApp());


class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _googlePayToken = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }



  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await GooglePay.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    await GooglePay.initializeGooglePay("my google play base64EncodedPublicKey");

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
              children: <Widget>[
                Text('Running on: $_platformVersion\n'),
                Text('Google pay token: $_googlePayToken\n'),
                FlatButton(
                  child: Text("Google Pay Button"),
                  onPressed: onButtonPressed,
                )
              ]
          ),
        ),
      ),
    );
  }

  void onButtonPressed() async{
    setState((){_googlePayToken = "Fetching";});
    try {
      await GooglePay.openGooglePaySetup(
          price: "10.0",
          onGooglePaySuccess: onSuccess,
          onGooglePayFailure: onFailure,
          onGooglePayCanceled: onCancelled);
      setState((){_googlePayToken = "Done Fetching";});
    } on PlatformException catch (ex) {
      setState((){_googlePayToken = "Failed Fetching";});
    }

  }

  void onSuccess(String token){
    setState((){_googlePayToken = token;});
  }

  void onFailure(){
    setState((){_googlePayToken = "Failure";});
  }

  void onCancelled(){
    setState((){_googlePayToken = "Cancelled";});
  }
} ```

When I run the application is shows google pay dialog with my google pay email and card details and an error "Unrecognised app. Please make sure that you trust this app before proceeding. When I press the "Continue" button I get "Request failed" "Unexpected developer error, please try again later" Please what am I doing wrong?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...