mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
redirect to checkout
This commit is contained in:
parent
2ad0659cbc
commit
b30976c0f0
2 changed files with 30 additions and 5 deletions
|
@ -21,10 +21,13 @@ class BuyWarningPopup extends StatelessWidget {
|
||||||
final SimplexQuote quote;
|
final SimplexQuote quote;
|
||||||
|
|
||||||
Future<BuyResponse<SimplexOrder>> newOrder(SimplexQuote quote) async {
|
Future<BuyResponse<SimplexOrder>> newOrder(SimplexQuote quote) async {
|
||||||
// BuyResponse<SimplexOrder> order = ;
|
|
||||||
return SimplexAPI.instance.newOrder(quote);
|
return SimplexAPI.instance.newOrder(quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<BuyResponse<bool>> redirect(SimplexOrder order) async {
|
||||||
|
return SimplexAPI.instance.redirect(order);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return StackDialog(
|
return StackDialog(
|
||||||
|
@ -40,6 +43,8 @@ class BuyWarningPopup extends StatelessWidget {
|
||||||
label: "Continue",
|
label: "Continue",
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
BuyResponse<SimplexOrder> order = await newOrder(quote);
|
BuyResponse<SimplexOrder> order = await newOrder(quote);
|
||||||
|
BuyResponse<bool> response =
|
||||||
|
await redirect(order.value as SimplexOrder);
|
||||||
// TODO save order and redirect
|
// TODO save order and redirect
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
@ -5,13 +5,13 @@ import 'package:decimal/decimal.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:http/http.dart' as http;
|
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/crypto.dart';
|
|
||||||
import 'package:stackwallet/models/buy/response_objects/fiat.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/order.dart';
|
||||||
import 'package:stackwallet/models/buy/response_objects/quote.dart';
|
import 'package:stackwallet/models/buy/response_objects/quote.dart';
|
||||||
import 'package:stackwallet/services/buy/buy_response.dart';
|
import 'package:stackwallet/services/buy/buy_response.dart';
|
||||||
import 'package:stackwallet/utilities/logger.dart';
|
import 'package:stackwallet/utilities/logger.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class SimplexAPI {
|
class SimplexAPI {
|
||||||
static const String scheme = "https";
|
static const String scheme = "https";
|
||||||
|
@ -199,9 +199,8 @@ class SimplexAPI {
|
||||||
if (res.statusCode != 200) {
|
if (res.statusCode != 200) {
|
||||||
throw Exception('newOrder exception: statusCode= ${res.statusCode}');
|
throw Exception('newOrder exception: statusCode= ${res.statusCode}');
|
||||||
}
|
}
|
||||||
final jsonArray = jsonDecode(res.body); // TODO check if json
|
final jsonArray = jsonDecode(res.body); // TODO check if valid json
|
||||||
// TODO create and return SimplexOrder here
|
print(jsonArray);
|
||||||
|
|
||||||
SimplexOrder _order = SimplexOrder(
|
SimplexOrder _order = SimplexOrder(
|
||||||
quote: quote,
|
quote: quote,
|
||||||
paymentId: "${jsonArray['paymentId']}",
|
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,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue