-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved edit methods and code quality
- Loading branch information
Showing
27 changed files
with
837 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
lib/src/telegram/models/abstracts/revenue_withdrawal_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
part of '../models.dart'; | ||
|
||
/// This object describes the state of a revenue withdrawal operation. | ||
/// Currently, it can be one of [RevenueWithdrawalStatePending], [RevenueWithdrawalStateSucceeded], [RevenueWithdrawalStateFailed]. | ||
abstract class RevenueWithdrawalState { | ||
/// Type of the revenue withdrawal state. | ||
RevenueWithdrawalStateType get type; | ||
|
||
/// Creates a new [RevenueWithdrawalState] object. | ||
/// This method decides which [RevenueWithdrawalState] subclass to use based on the [type] field. | ||
static RevenueWithdrawalState fromJson(Map<String, dynamic> json) { | ||
switch (RevenueWithdrawalStateType.fromJson(json['type'])) { | ||
case RevenueWithdrawalStateType.pending: | ||
return RevenueWithdrawalStatePending.fromJson(json); | ||
case RevenueWithdrawalStateType.succeeded: | ||
return RevenueWithdrawalStateSucceeded.fromJson(json); | ||
case RevenueWithdrawalStateType.failed: | ||
return RevenueWithdrawalStateFailed.fromJson(json); | ||
default: | ||
throw ArgumentError('Invalid revenue withdrawal state type'); | ||
} | ||
} | ||
|
||
/// Creates a new [RevenueWithdrawalState] object from JSON. | ||
const RevenueWithdrawalState(); | ||
|
||
/// Converts a [RevenueWithdrawalState] to a [Map] for JSON encoding. | ||
Map<String, dynamic> toJson(); | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/src/telegram/models/abstracts/transaction_partner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
part of '../models.dart'; | ||
|
||
/// This object describes the source of a transaction, or its recipient for outgoing transactions. | ||
/// Currently, it can be one of [TransactionPartnerFragment], [TransactionPartnerUser], [TransactionPartnerOther]. | ||
abstract class TransactionPartner { | ||
/// Type of the transaction partner. | ||
TransactionPartnerType get type; | ||
|
||
/// Creates a new [TransactionPartner] object. | ||
/// This method decides which [TransactionPartner] subclass to use based on the [type] field. | ||
static TransactionPartner fromJson(Map<String, dynamic> json) { | ||
return switch (json['type']) { | ||
'fragment' => TransactionPartnerFragment.fromJson(json), | ||
'user' => TransactionPartnerUser.fromJson(json), | ||
'other' => TransactionPartnerOther.fromJson(json), | ||
_ => throw ArgumentError('Invalid transaction partner type') | ||
}; | ||
} | ||
|
||
/// Creates a new [TransactionPartner] object from JSON. | ||
const TransactionPartner(); | ||
|
||
/// Converts a [TransactionPartner] to a [Map] for JSON encoding. | ||
Map<String, dynamic> toJson(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
lib/src/telegram/models/revenue_withdrawal_state_failed.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
part of 'models.dart'; | ||
|
||
/// The withdrawal failed and the transaction was refunded. | ||
class RevenueWithdrawalStateFailed extends RevenueWithdrawalState { | ||
@override | ||
RevenueWithdrawalStateType get type => RevenueWithdrawalStateType.failed; | ||
|
||
/// Constructs a [RevenueWithdrawalStateFailed] object. | ||
const RevenueWithdrawalStateFailed(); | ||
|
||
/// Creates a [RevenueWithdrawalStateFailed] object from JSON. | ||
factory RevenueWithdrawalStateFailed.fromJson(Map<String, dynamic> json) { | ||
return RevenueWithdrawalStateFailed(); | ||
} | ||
|
||
/// Converts a [RevenueWithdrawalStateFailed] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.toJson(), | ||
}; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
lib/src/telegram/models/revenue_withdrawal_state_pending.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
part of 'models.dart'; | ||
|
||
/// The withdrawal is in progress. | ||
class RevenueWithdrawalStatePending extends RevenueWithdrawalState { | ||
@override | ||
RevenueWithdrawalStateType get type => RevenueWithdrawalStateType.pending; | ||
|
||
/// Constructs a [RevenueWithdrawalStatePending] object. | ||
const RevenueWithdrawalStatePending(); | ||
|
||
/// Creates a [RevenueWithdrawalStatePending] object from JSON. | ||
factory RevenueWithdrawalStatePending.fromJson(Map<String, dynamic> json) { | ||
return RevenueWithdrawalStatePending(); | ||
} | ||
|
||
/// Converts a [RevenueWithdrawalStatePending] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.toJson(), | ||
}; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
lib/src/telegram/models/revenue_withdrawal_state_succeeded.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
part of 'models.dart'; | ||
|
||
/// The withdrawal succeeded. | ||
class RevenueWithdrawalStateSucceeded extends RevenueWithdrawalState { | ||
@override | ||
RevenueWithdrawalStateType get type => RevenueWithdrawalStateType.succeeded; | ||
|
||
/// Date the withdrawal was completed in Unix time. | ||
final int date; | ||
|
||
/// An HTTPS URL that can be used to see transaction details. | ||
final String url; | ||
|
||
/// Constructs a [RevenueWithdrawalStateSucceeded] object. | ||
const RevenueWithdrawalStateSucceeded({ | ||
required this.date, | ||
required this.url, | ||
}); | ||
|
||
/// Creates a [RevenueWithdrawalStateSucceeded] object from JSON. | ||
factory RevenueWithdrawalStateSucceeded.fromJson(Map<String, dynamic> json) { | ||
return RevenueWithdrawalStateSucceeded( | ||
date: json['date'], | ||
url: json['url'], | ||
); | ||
} | ||
|
||
/// Converts a [RevenueWithdrawalStateSucceeded] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.toJson(), | ||
'date': date, | ||
'url': url, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
part of 'models.dart'; | ||
|
||
/// This object describes a Telegram Star transaction. | ||
class StarTransaction { | ||
/// Unique identifier of the transaction. | ||
/// Coincides with the identifier of the original transaction for refund transactions. | ||
/// Coincides with [SuccessfulPayment.telegramPaymentChargeId] for successful incoming payments from users. | ||
final String id; | ||
|
||
/// Number of Telegram Stars transferred by the transaction. | ||
final int amount; | ||
|
||
/// Date the transaction was created in Unix time. | ||
final int date; | ||
|
||
/// Optional. Source of an incoming transaction (e.g., a user purchasing goods or services, | ||
/// Fragment refunding a failed withdrawal). Only for incoming transactions. | ||
final TransactionPartner? source; | ||
|
||
/// Optional. Receiver of an outgoing transaction (e.g., a user for a purchase refund, | ||
/// Fragment for a withdrawal). Only for outgoing transactions. | ||
final TransactionPartner? receiver; | ||
|
||
/// Creates a new [StarTransaction] object. | ||
const StarTransaction({ | ||
required this.id, | ||
required this.amount, | ||
required this.date, | ||
this.source, | ||
this.receiver, | ||
}); | ||
|
||
/// Creates a new [StarTransaction] object from json. | ||
factory StarTransaction.fromJson(Map<String, dynamic> json) { | ||
return StarTransaction( | ||
id: json['id'], | ||
amount: json['amount'], | ||
date: json['date'], | ||
source: json['source'] != null | ||
? TransactionPartner.fromJson(json['source']) | ||
: null, | ||
receiver: json['receiver'] != null | ||
? TransactionPartner.fromJson(json['receiver']) | ||
: null, | ||
); | ||
} | ||
|
||
/// Converts a [StarTransaction] object to json. | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'id': id, | ||
'amount': amount, | ||
'date': date, | ||
'source': source?.toJson(), | ||
'receiver': receiver?.toJson(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
part of 'models.dart'; | ||
|
||
/// This object represents a list of Telegram Star transactions. | ||
class StarTransactions { | ||
/// The list of transactions. | ||
final List<StarTransaction> transactions; | ||
|
||
/// Creates a new [StarTransactions] object. | ||
const StarTransactions({ | ||
required this.transactions, | ||
}); | ||
|
||
/// Creates a new [StarTransactions] object from json. | ||
factory StarTransactions.fromJson(Map<String, dynamic> json) { | ||
return StarTransactions( | ||
transactions: (json['transactions'] as List) | ||
.map((item) => StarTransaction.fromJson(item)) | ||
.toList(), | ||
); | ||
} | ||
|
||
/// Converts a [StarTransactions] object to json. | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'transactions': transactions.map((item) => item.toJson()).toList(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
part of 'models.dart'; | ||
|
||
/// Describes a withdrawal transaction with Fragment. | ||
class TransactionPartnerFragment extends TransactionPartner { | ||
@override | ||
TransactionPartnerType get type => TransactionPartnerType.fragment; | ||
|
||
/// State of the transaction if the transaction is outgoing. | ||
final RevenueWithdrawalState? withdrawalState; | ||
|
||
/// Constructs a [TransactionPartnerFragment] object. | ||
const TransactionPartnerFragment({ | ||
this.withdrawalState, | ||
}); | ||
|
||
/// Creates a [TransactionPartnerFragment] object from JSON. | ||
factory TransactionPartnerFragment.fromJson(Map<String, dynamic> json) { | ||
return TransactionPartnerFragment( | ||
withdrawalState: json['withdrawal_state'] != null | ||
? RevenueWithdrawalState.fromJson(json['withdrawal_state']) | ||
: null, | ||
); | ||
} | ||
|
||
/// Converts a [TransactionPartnerFragment] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type, | ||
'withdrawal_state': withdrawalState?.toJson(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
part of 'models.dart'; | ||
|
||
/// Describes a transaction with an unknown source or recipient. | ||
class TransactionPartnerOther extends TransactionPartner { | ||
@override | ||
TransactionPartnerType get type => TransactionPartnerType.other; | ||
|
||
/// Constructs a [TransactionPartnerOther] object. | ||
const TransactionPartnerOther(); | ||
|
||
/// Creates a [TransactionPartnerOther] object from JSON. | ||
factory TransactionPartnerOther.fromJson(Map<String, dynamic> json) { | ||
return TransactionPartnerOther(); | ||
} | ||
|
||
/// Converts a [TransactionPartnerOther] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type, | ||
}; | ||
} | ||
} |
Oops, something went wrong.