-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
135 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
part of 'models.dart'; | ||
|
||
/// Contains information about the affiliate that received a commission | ||
/// via this transaction. | ||
class AffiliateInfo { | ||
/// The bot or the user that received an affiliate commission if it was | ||
/// received by a bot or a user. | ||
final User? affiliateUser; | ||
|
||
/// The chat that received an affiliate commission if it was received by a chat. | ||
final Chat? affiliateChat; | ||
|
||
/// The number of Telegram Stars received by the affiliate for each 1000 | ||
/// Telegram Stars received by the bot from referred users. | ||
final int commissionPerMille; | ||
|
||
/// Integer amount of Telegram Stars received by the affiliate from the transaction, | ||
/// rounded to 0; can be negative for refunds. | ||
final int amount; | ||
|
||
/// The number of 1/1000000000 shares of Telegram Stars received by the affiliate; | ||
/// from -999999999 to 999999999; can be negative for refunds. | ||
final int? nanostarAmount; | ||
|
||
/// Constructs an [AffiliateInfo] object. | ||
const AffiliateInfo({ | ||
this.affiliateUser, | ||
this.affiliateChat, | ||
required this.commissionPerMille, | ||
required this.amount, | ||
this.nanostarAmount, | ||
}); | ||
|
||
/// Creates an [AffiliateInfo] object from JSON. | ||
factory AffiliateInfo.fromJson(Map<String, dynamic> json) { | ||
return AffiliateInfo( | ||
affiliateUser: json['affiliate_user'] != null | ||
? User.fromJson(json['affiliate_user']) | ||
: null, | ||
affiliateChat: json['affiliate_chat'] != null | ||
? Chat.fromJson(json['affiliate_chat']) | ||
: null, | ||
commissionPerMille: json['commission_per_mille'], | ||
amount: json['amount'], | ||
nanostarAmount: json['nanostar_amount'], | ||
); | ||
} | ||
|
||
/// Converts an [AffiliateInfo] object to JSON. | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'affiliate_user': affiliateUser?.toJson(), | ||
'affiliate_chat': affiliateChat?.toJson(), | ||
'commission_per_mille': commissionPerMille, | ||
'amount': amount, | ||
'nanostar_amount': nanostarAmount, | ||
}..removeWhere(_nullFilter); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
lib/src/telegram/models/transaction_partner_affiliate_program.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,43 @@ | ||
part of 'models.dart'; | ||
|
||
/// Describes the affiliate program that issued the affiliate commission | ||
/// received via this transaction. | ||
class TransactionPartnerAffiliateProgram extends TransactionPartner { | ||
@override | ||
TransactionPartnerType get type => TransactionPartnerType.affiliateProgram; | ||
|
||
/// Information about the bot that sponsored the affiliate program. | ||
final User? sponsorUser; | ||
|
||
/// The number of Telegram Stars received by the bot for each 1000 Telegram | ||
/// Stars received by the affiliate program sponsor from referred users. | ||
final int commissionPerMille; | ||
|
||
/// Constructs a [TransactionPartnerAffiliateProgram] object. | ||
const TransactionPartnerAffiliateProgram({ | ||
this.sponsorUser, | ||
required this.commissionPerMille, | ||
}); | ||
|
||
/// Creates a [TransactionPartnerAffiliateProgram] object from JSON. | ||
factory TransactionPartnerAffiliateProgram.fromJson( | ||
Map<String, dynamic> json, | ||
) { | ||
return TransactionPartnerAffiliateProgram( | ||
sponsorUser: json['sponsor_user'] != null | ||
? User.fromJson(json['sponsor_user']) | ||
: null, | ||
commissionPerMille: json['commission_per_mille'], | ||
); | ||
} | ||
|
||
/// Converts a [TransactionPartnerAffiliateProgram] object to JSON. | ||
@override | ||
Map<String, dynamic> toJson() { | ||
return { | ||
'type': type.value, | ||
'sponsor_user': sponsorUser?.toJson(), | ||
'commission_per_mille': commissionPerMille, | ||
}; | ||
} | ||
} |
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