From b30976c0f0518376a40285308a57c35dc05eb8c3 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 20 Jan 2023 09:27:24 -0600 Subject: [PATCH] redirect to checkout --- .../sub_widgets/buy_warning_popup.dart | 7 ++++- lib/services/buy/simplex/simplex_api.dart | 28 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart b/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart index 9104c79a6..1f5b36c2d 100644 --- a/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart +++ b/lib/pages/buy_view/sub_widgets/buy_warning_popup.dart @@ -21,10 +21,13 @@ class BuyWarningPopup extends StatelessWidget { final SimplexQuote quote; Future> newOrder(SimplexQuote quote) async { - // BuyResponse order = ; return SimplexAPI.instance.newOrder(quote); } + Future> redirect(SimplexOrder order) async { + return SimplexAPI.instance.redirect(order); + } + @override Widget build(BuildContext context) { return StackDialog( @@ -40,6 +43,8 @@ class BuyWarningPopup extends StatelessWidget { label: "Continue", onPressed: () async { BuyResponse order = await newOrder(quote); + BuyResponse response = + await redirect(order.value as SimplexOrder); // TODO save order and redirect }, ), diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index 1bf3da8fd..4aae2b20a 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -5,13 +5,13 @@ import 'package:decimal/decimal.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; import 'package:stackwallet/models/buy/response_objects/crypto.dart'; -// import 'package:stackwallet/models/buy/response_objects/crypto.dart'; import 'package:stackwallet/models/buy/response_objects/fiat.dart'; import 'package:stackwallet/models/buy/response_objects/order.dart'; import 'package:stackwallet/models/buy/response_objects/quote.dart'; import 'package:stackwallet/services/buy/buy_response.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:tuple/tuple.dart'; +import 'package:url_launcher/url_launcher.dart'; class SimplexAPI { static const String scheme = "https"; @@ -199,9 +199,8 @@ class SimplexAPI { if (res.statusCode != 200) { throw Exception('newOrder exception: statusCode= ${res.statusCode}'); } - final jsonArray = jsonDecode(res.body); // TODO check if json - // TODO create and return SimplexOrder here - + final jsonArray = jsonDecode(res.body); // TODO check if valid json + print(jsonArray); SimplexOrder _order = SimplexOrder( quote: quote, paymentId: "${jsonArray['paymentId']}", @@ -220,4 +219,25 @@ class SimplexAPI { ); } } + + Future> redirect(SimplexOrder order) async { + try { + bool status = await launchUrl( + Uri.parse( + "http://localhost/api.php/redirect?PAYMENT_ID=${order.paymentId}"), + mode: LaunchMode.externalApplication, + ); + + print(status); + + return BuyResponse(value: status); + } catch (e, s) { + Logging.instance.log("newOrder exception: $e\n$s", level: LogLevel.Error); + return BuyResponse( + exception: BuyException( + e.toString(), + BuyExceptionType.generic, + )); + } + } }