Initial commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'tokenization_screen.dart';
|
||||
|
||||
class App extends StatelessWidget {
|
||||
const App({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: "Example app",
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: const TokenizationScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'app.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const App());
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:yookassa_payments_flutter/input_data/saved_card_module_input_data.dart';
|
||||
import 'package:yookassa_payments_flutter/models/tokenization_result.dart';
|
||||
import 'package:yookassa_payments_flutter/yookassa_payments_flutter.dart';
|
||||
|
||||
class SuccessTokenizationScreen extends StatefulWidget {
|
||||
const SuccessTokenizationScreen({Key? key, required this.result, this.tokenizationData, this.repeatData}) : super(key: key);
|
||||
|
||||
final TokenizationResult result;
|
||||
final TokenizationModuleInputData? tokenizationData;
|
||||
final SavedBankCardModuleInputData? repeatData;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => SuccessTokenizationScreenState(result, tokenizationData, repeatData);
|
||||
}
|
||||
|
||||
class SuccessTokenizationScreenState extends State<SuccessTokenizationScreen> {
|
||||
final TokenizationResult result;
|
||||
final TokenizationModuleInputData? tokenizationData;
|
||||
final SavedBankCardModuleInputData? repeatData;
|
||||
|
||||
SuccessTokenizationScreenState(this.result, this.tokenizationData, this.repeatData);
|
||||
|
||||
late TextEditingController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
controller = TextEditingController();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Flutter Example App"),
|
||||
),
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const ListTile(
|
||||
leading: Icon(Icons.done, color: Colors.green),
|
||||
title: Text("Токен готов"),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
hintText: "3ds / App2App ссылка"
|
||||
),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await YookassaPaymentsFlutter.confirmation(controller.text, result.paymentMethodType);
|
||||
showDialog(context: context, builder: (context) => const AlertDialog(
|
||||
content: Text("Confirmation process is done"),
|
||||
));
|
||||
},
|
||||
child: const Text("Подтвердить")
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
showDialog(context: context, builder: (context) => AlertDialog(
|
||||
content: Text(result.token),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Clipboard.setData(ClipboardData(text: result.token));
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text('Скопировать'),
|
||||
),
|
||||
]
|
||||
));
|
||||
},
|
||||
child: const Text("Показать токен")
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:yookassa_payments_flutter/yookassa_payments_flutter.dart';
|
||||
import 'package:yookassa_payments_flutter_example/success_tokenization_screen.dart';
|
||||
|
||||
class TokenizationScreen extends StatefulWidget{
|
||||
const TokenizationScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<TokenizationScreen> createState() => TokenizationScreenState();
|
||||
}
|
||||
|
||||
class TokenizationScreenState extends State<TokenizationScreen> {
|
||||
late TextEditingController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
controller = TextEditingController(text: "10.0");
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Flutter Example App"),
|
||||
),
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
startTokenization();
|
||||
},
|
||||
child: const Text("Оплатить")
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void startTokenization() async {
|
||||
var clientApplicationKey = "<Ключ для клиентских приложений>";
|
||||
var amount = Amount(value: double.parse(controller.text), currency: Currency.rub);
|
||||
var moneyAuthClientId = "<ID для центра авторизации в системе YooMoney>";
|
||||
var applePayID = "<Идентификатор продавца Apple Pay>";
|
||||
var shopId = "<Идентификатор магазина в ЮKassa>";
|
||||
var applicationScheme = "<Схема вашего приложения для deeplink>" "://";
|
||||
var tokenizationModuleInputData = TokenizationModuleInputData(
|
||||
clientApplicationKey: clientApplicationKey,
|
||||
title: "Космические объекты",
|
||||
subtitle: "Комета повышенной яркости, период обращения — 112 лет",
|
||||
amount: amount,
|
||||
savePaymentMethod: SavePaymentMethod.userSelects,
|
||||
isLoggingEnabled: true,
|
||||
moneyAuthClientId: moneyAuthClientId,
|
||||
applePayID: applePayID,
|
||||
shopId: shopId,
|
||||
customerId: "<Уникальный идентификатор покупателя>",
|
||||
applicationScheme: applicationScheme,
|
||||
tokenizationSettings: const TokenizationSettings(
|
||||
PaymentMethodTypes([
|
||||
PaymentMethod.bankCard,
|
||||
PaymentMethod.yooMoney,
|
||||
PaymentMethod.sberbank
|
||||
])
|
||||
),
|
||||
testModeSettings: null
|
||||
);
|
||||
var result = await YookassaPaymentsFlutter.tokenization(tokenizationModuleInputData);
|
||||
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => SuccessTokenizationScreen(result: result, tokenizationData: tokenizationModuleInputData)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user