Skip to content

Commit 0d717ee

Browse files
committed
fix type (int -> long) for Amount fields
1 parent 09eb2cb commit 0d717ee

9 files changed

Lines changed: 17 additions & 24 deletions

File tree

src/Telegram.Bot/Extend.Types.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ namespace Payments
218218
public partial class LabeledPrice
219219
{
220220
/// <summary>Instantiates a new <see cref="LabeledPrice"/> from a tuple</summary>
221-
public static implicit operator LabeledPrice((string label, int amount) t) => new(t.label, t.amount);
221+
public static implicit operator LabeledPrice((string label, long amount) t) => new(t.label, t.amount);
222222
}
223223
}
224224

src/Telegram.Bot/Types/Payments/AffiliateInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public partial class AffiliateInfo
1919

2020
/// <summary>Integer amount of Telegram Stars received by the affiliate from the transaction, rounded to 0; can be negative for refunds</summary>
2121
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
22-
public int Amount { get; set; }
22+
public long Amount { get; set; }
2323

2424
/// <summary><em>Optional</em>. The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to 999999999; can be negative for refunds</summary>
2525
[JsonPropertyName("nanostar_amount")]

src/Telegram.Bot/Types/Payments/LabeledPrice.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public partial class LabeledPrice
1010

1111
/// <summary>Price of the product in the <em>smallest units</em> of the <a href="https://core.telegram.org/bots/payments#supported-currencies">currency</a> (integer, <b>not</b> float/double). For example, for a price of <c>US$ 1.45</c> pass <c>amount = 145</c>. See the <em>exp</em> parameter in <a href="https://core.telegram.org/bots/payments/currencies.json">currencies.json</a>, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).</summary>
1212
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
13-
public required int Amount { get; set; }
13+
public required long Amount { get; set; }
1414

1515
/// <summary>Initializes an instance of <see cref="LabeledPrice"/></summary>
1616
/// <param name="label">Portion label</param>
1717
/// <param name="amount">Price of the product in the <em>smallest units</em> of the <a href="https://core.telegram.org/bots/payments#supported-currencies">currency</a> (integer, <b>not</b> float/double). For example, for a price of <c>US$ 1.45</c> pass <c>amount = 145</c>. See the <em>exp</em> parameter in <a href="https://core.telegram.org/bots/payments/currencies.json">currencies.json</a>, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).</param>
1818
[SetsRequiredMembers]
19-
public LabeledPrice(string label, int amount)
19+
public LabeledPrice(string label, long amount)
2020
{
2121
Label = label;
2222
Amount = amount;

src/Telegram.Bot/Types/Payments/StarTransaction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public partial class StarTransaction
1010

1111
/// <summary>Integer amount of Telegram Stars transferred by the transaction</summary>
1212
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
13-
public int Amount { get; set; }
13+
public long Amount { get; set; }
1414

1515
/// <summary><em>Optional</em>. The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999</summary>
1616
[JsonPropertyName("nanostar_amount")]

src/Telegram.Bot/Types/StarAmount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public partial class StarAmount
66
{
77
/// <summary>Integer amount of Telegram Stars, rounded to 0; can be negative</summary>
88
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
9-
public int Amount { get; set; }
9+
public long Amount { get; set; }
1010

1111
/// <summary><em>Optional</em>. The number of 1/1000000000 shares of Telegram Stars; from -999999999 to 999999999; can be negative if and only if <see cref="Amount">Amount</see> is non-positive</summary>
1212
[JsonPropertyName("nanostar_amount")]

src/Telegram.Bot/Types/SuggestedPostPaid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public partial class SuggestedPostPaid
1313
public string Currency { get; set; } = default!;
1414

1515
/// <summary><em>Optional</em>. The amount of the currency that was received by the channel in nanotoncoins; for payments in toncoins only</summary>
16-
public int? Amount { get; set; }
16+
public long? Amount { get; set; }
1717

1818
/// <summary><em>Optional</em>. The amount of Telegram Stars that was received by the channel; for payments in Telegram Stars only</summary>
1919
[JsonPropertyName("star_amount")]

src/Telegram.Bot/Types/SuggestedPostPrice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ public partial class SuggestedPostPrice
1010

1111
/// <summary>The amount of the currency that will be paid for the post in the <em>smallest units</em> of the currency, i.e. Telegram Stars or nanotoncoins. Currently, price in Telegram Stars must be between 5 and 100000, and price in nanotoncoins must be between 10000000 and 10000000000000.</summary>
1212
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
13-
public int Amount { get; set; }
13+
public long Amount { get; set; }
1414
}

test/Telegram.Bot.Tests.Integ/Payments/PaymentTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ await Fixture.BotClient.AnswerPreCheckoutQuery(
170170
);
171171

172172
PreliminaryInvoice preliminaryInvoice = paymentsBuilder.GetPreliminaryInvoice();
173-
int totalAmount = paymentsBuilder.GetTotalAmount();
173+
long totalAmount = paymentsBuilder.GetTotalAmount();
174174

175175
Assert.Equal(UpdateType.PreCheckoutQuery, preCheckoutUpdate.Type);
176176
Assert.NotNull(query.Id);
@@ -246,7 +246,7 @@ await Fixture.BotClient.AnswerPreCheckoutQuery(
246246

247247
Update successfulPaymentUpdate = await GetSuccessfulPaymentUpdate();
248248
SuccessfulPayment successfulPayment = successfulPaymentUpdate.Message!.SuccessfulPayment;
249-
int totalAmount = paymentsBuilder.GetTotalAmount();
249+
long totalAmount = paymentsBuilder.GetTotalAmount();
250250

251251
Assert.Equal(totalAmount, successfulPayment!.TotalAmount);
252252
Assert.Equal("<my-payload>", successfulPayment.InvoicePayload);
@@ -308,10 +308,10 @@ await Fixture.BotClient.AnswerPreCheckoutQuery(
308308

309309
Update successfulPaymentUpdate = await GetSuccessfulPaymentUpdate();
310310
SuccessfulPayment successfulPayment = successfulPaymentUpdate.Message!.SuccessfulPayment;
311-
int totalAmount = paymentsBuilder.GetTotalAmount();
311+
long totalAmount = paymentsBuilder.GetTotalAmount();
312312

313313
int[] suggestedTips = [100, 150, 200];
314-
int[] totalAmountWithTip = suggestedTips.Select(_ => _ + totalAmount).ToArray();
314+
long[] totalAmountWithTip = [.. suggestedTips.Select(_ => _ + totalAmount)];
315315

316316
Assert.Contains(totalAmountWithTip, _ => _ == successfulPayment!.TotalAmount);
317317
Assert.Equal("<my-payload>", successfulPayment!.InvoicePayload);
@@ -653,5 +653,5 @@ public static string FormatInstructionWithCurrency(FormattableString instruction
653653
public static class Extensions
654654
{
655655
// ReSharper disable once PossibleLossOfFraction
656-
public static double CurrencyFormat(this int amount) => amount * 0.01;
656+
public static double CurrencyFormat(this long amount) => amount * 0.01;
657657
}

test/Telegram.Bot.Tests.Integ/Payments/PaymentsBuilder.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,11 @@ public PreliminaryInvoice GetPreliminaryInvoice()
170170
};
171171
}
172172

173-
public Shipping GetShippingOptions() => new([.. _shippingOptions]);
174-
175-
public int GetTotalAmount() =>
173+
public long GetTotalAmount() =>
176174
(_product?.ProductPrices.Sum(price => price.Amount) ?? 0) +
177-
_shippingOptions.Take(1).Sum(x => x.Prices.Sum(p => p.Amount));
175+
(_shippingOptions.FirstOrDefault()?.Prices.Sum(p => p.Amount) ?? 0);
178176

179-
public int GetTotalAmountWithoutShippingCost() => _product?.ProductPrices.Sum(price => price.Amount) ?? 0;
177+
public long GetTotalAmountWithoutShippingCost() => _product?.ProductPrices.Sum(price => price.Amount) ?? 0;
180178

181179
public async Task<Types.Message> MakeInvoiceRequest(TestsFixture fixture)
182180
{
@@ -357,11 +355,6 @@ public record PreliminaryInvoice
357355
public string Description { get; init; } = default!;
358356
public string? StartParameter { get; init; }
359357
public string Currency { get; init; } = default!;
360-
public int TotalAmount { get; init; }
361-
}
362-
363-
public record Shipping(IReadOnlyList<ShippingOption> ShippingOptions)
364-
{
365-
public int TotalAmount => ShippingOptions.Sum(x => x.Prices.Sum(p => p.Amount));
358+
public long TotalAmount { get; init; }
366359
}
367360
}

0 commit comments

Comments
 (0)