mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 04:19:36 +00:00
Add anypay commited info for payments.
This commit is contained in:
parent
e9b27f93db
commit
0a7f8bf286
3 changed files with 41 additions and 10 deletions
17
lib/anypay/any_pay_payment_committed_info.dart
Normal file
17
lib/anypay/any_pay_payment_committed_info.dart
Normal file
|
@ -0,0 +1,17 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:cake_wallet/anypay/any_pay_trasnaction.dart';
|
||||
|
||||
class AnyPayPaymentCommittedInfo {
|
||||
const AnyPayPaymentCommittedInfo({
|
||||
@required this.uri,
|
||||
@required this.currency,
|
||||
@required this.chain,
|
||||
@required this.transactions,
|
||||
@required this.memo});
|
||||
|
||||
final String uri;
|
||||
final String currency;
|
||||
final String chain;
|
||||
final List<AnyPayTransaction> transactions;
|
||||
final String memo;
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
|
@ -57,7 +58,7 @@ class AnyPayApi {
|
|||
return AnyPayPayment.fromMap(decodedBody);
|
||||
}
|
||||
|
||||
Future<void> payment(
|
||||
Future<AnyPayPaymentCommittedInfo> payment(
|
||||
String uri,
|
||||
{@required String chain,
|
||||
@required String currency,
|
||||
|
@ -71,9 +72,21 @@ class AnyPayApi {
|
|||
'currency': currency,
|
||||
'transactions': transactions.map((tx) => {'tx': tx.tx, 'tx_hash': tx.id, 'tx_key': tx.key}).toList()};
|
||||
final response = await post(uri, headers: headers, body: utf8.encode(json.encode(body)));
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return null;
|
||||
if (response.statusCode == 400) {
|
||||
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
throw Exception(decodedBody['message'] as String);
|
||||
}
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Unexpected response');
|
||||
}
|
||||
|
||||
final decodedBody = json.decode(response.body) as Map<String, dynamic>;
|
||||
return AnyPayPaymentCommittedInfo(
|
||||
uri: uri,
|
||||
currency: currency,
|
||||
chain: chain,
|
||||
transactions: transactions,
|
||||
memo: decodedBody['memo'] as String);
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ import 'package:cake_wallet/anypay/any_pay_chain.dart';
|
|||
import 'package:cake_wallet/anypay/any_pay_trasnaction.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/monero/monero.dart';
|
||||
import 'package:cake_wallet/anypay/any_pay_payment_committed_info.dart';
|
||||
|
||||
class IoniaAnyPay {
|
||||
IoniaAnyPay(this.ioniaService, this.anyPayApi, this.wallet);
|
||||
|
@ -31,7 +32,7 @@ class IoniaAnyPay {
|
|||
return anyPayApi.paymentRequest(invoice.uri);
|
||||
}
|
||||
|
||||
Future<void> commitInvoice(AnyPayPayment payment) async {
|
||||
Future<AnyPayPaymentCommittedInfo> commitInvoice(AnyPayPayment payment) async {
|
||||
final transactionCredentials = payment.instructions
|
||||
.where((instruction) => instruction.type == AnyPayPaymentInstruction.transactionType)
|
||||
.map((AnyPayPaymentInstruction instruction) {
|
||||
|
@ -80,10 +81,10 @@ class IoniaAnyPay {
|
|||
})
|
||||
.toList();
|
||||
|
||||
await anyPayApi.payment(
|
||||
payment.paymentUrl,
|
||||
chain: payment.chain,
|
||||
currency: payment.chain,
|
||||
transactions: transactions);
|
||||
return await anyPayApi.payment(
|
||||
payment.paymentUrl,
|
||||
chain: payment.chain,
|
||||
currency: payment.chain,
|
||||
transactions: transactions);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue