redirect to checkout

This commit is contained in:
sneurlax 2023-01-20 09:27:24 -06:00
parent 2ad0659cbc
commit b30976c0f0
2 changed files with 30 additions and 5 deletions

View file

@ -21,10 +21,13 @@ class BuyWarningPopup extends StatelessWidget {
final SimplexQuote quote;
Future<BuyResponse<SimplexOrder>> newOrder(SimplexQuote quote) async {
// BuyResponse<SimplexOrder> order = ;
return SimplexAPI.instance.newOrder(quote);
}
Future<BuyResponse<bool>> 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<SimplexOrder> order = await newOrder(quote);
BuyResponse<bool> response =
await redirect(order.value as SimplexOrder);
// TODO save order and redirect
},
),

View file

@ -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<BuyResponse<bool>> 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,
));
}
}
}