Подключение QR‑код от Яндекс Пэй Flutter SDK
Шаг 1. Добавьте зависимость
# pubspec.yaml
dependencies:
yandex_quick_pay: ^1.1.0
flutter pub get
Актуальная версия: pub.dev/packages/yandex_quick_pay.
Шаг 2. Настройте нативные платформы
Android
- OAuth Client ID: инструкция.
- build.gradle: укажите
YANDEX_CLIENT_IDв manifestPlaceholders. - AndroidManifest: для deep links настройте intent filters по инструкции нативных SDK.
iOS
- OAuth Client ID: инструкция.
- Info.plist: YandexClientID и URL Scheme.
- Entitlements: Associated Domains.
- AppDelegate: передавайте URL в
YandexQuickPay.instance.handleOpenURL(url).
Шаг 3. Инициализируйте SDK
Вызовите YandexQuickPay.initialize() в main() до runApp():
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await YandexQuickPay.initialize(
config: const QuickPayConfig(
merchantId: 'YOUR_MERCHANT_ID',
environment: QuickPayEnvironment.sandbox,
locale: QuickPayLocale.system,
theme: QuickPayThemeColorScheme.system,
),
listener: QuickPaymentStateListener(
onPaymentEnabledStateChanged: (isEnabled) {
if (isEnabled) refreshSession();
},
onSessionExpired: () => refreshSession(),
onPaymentResult: (result) => refreshSession(),
),
);
runApp(const MyApp());
}
Шаг 4. Вызовите initUi() перед оплатой
await YandexQuickPay.instance.initUi();
UI инициализируется автоматически при появлении Activity, но для надёжности вызывайте initUi() перед getPaymentSessionId() и enableQuickPayment().
Шаг 5. Добавьте виджеты
YandexPaymentMethodsWidget
Список способов оплаты и управление быстрой оплатой:
YandexPaymentMethodsWidget(
minHeight: 100,
width: double.infinity,
animationDuration: const Duration(milliseconds: 200),
)
YandexActivePaymentMethodBadge
Бейдж активного способа оплаты (например, на кнопке «Оплатить»):
YandexActivePaymentMethodBadge(
height: 48,
width: double.infinity,
)
Управление видимостью бейджа: showActivePaymentMethod(), hideActivePaymentMethod().
Шаг 6. Обработайте deep links
При возврате из приложения банка/Яндекс Пэй:
Android:
// В обработчике intent
final uri = intent.data?.toString();
if (uri != null) {
await YandexQuickPay.instance.handleUserActivity(uri);
// или handleOpenURL(uri)
}
iOS: в AppDelegate:
// Передать URL в Flutter-плагин
// Плагин вызовет YandexQuickPay.instance.handleOpenURL
Шаг 7. Работайте с платёжной сессией
final isEnabled = await YandexQuickPay.instance.isQuickPaymentEnabled();
if (isEnabled) {
final sessionId = await YandexQuickPay.instance.getPaymentSessionId();
// Сгенерировать QR из sessionId
} else {
await YandexQuickPay.instance.enableQuickPayment();
}
Когда обновлять QR: первое отображение экрана, onSessionExpired(), onPaymentResult(), onPaymentEnabledStateChanged(true).
Окружение при сборке
Окружение задаётся через --dart-define=QUICKPAY_ENVIRONMENT:
# Sandbox (по умолчанию для debug)
flutter run --dart-define=QUICKPAY_ENVIRONMENT=sandbox
# Production
flutter run --release --dart-define=QUICKPAY_ENVIRONMENT=production
В Android Studio: Run → Edit Configurations → Additional run args: --dart-define=QUICKPAY_ENVIRONMENT=sandbox.
Тестирование
Используйте QuickPayEnvironment.sandbox для разработки. Перед релизом — QuickPayEnvironment.production.