diff --git a/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithCryptoQuote.cs b/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithCryptoQuote.cs index 6aadd9c..2db716f 100644 --- a/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithCryptoQuote.cs +++ b/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithCryptoQuote.cs @@ -16,30 +16,18 @@ public partial class ThirdwebPay /// Thrown if the HTTP response is not successful. public static async Task GetBuyWithCryptoQuote(ThirdwebClient client, BuyWithCryptoQuoteParams buyWithCryptoParams) { - var queryString = new Dictionary - { - { "fromAddress", buyWithCryptoParams.FromAddress }, - { "fromChainId", buyWithCryptoParams.FromChainId?.ToString() }, - { "fromTokenAddress", buyWithCryptoParams.FromTokenAddress }, - { "fromAmount", buyWithCryptoParams.FromAmount }, - { "fromAmountWei", buyWithCryptoParams.FromAmountWei }, - { "toChainId", buyWithCryptoParams.ToChainId?.ToString() }, - { "toTokenAddress", buyWithCryptoParams.ToTokenAddress }, - { "toAmount", buyWithCryptoParams.ToAmount }, - { "toAmountWei", buyWithCryptoParams.ToAmountWei }, - { "toAddress", buyWithCryptoParams.ToAddress }, - { "maxSlippageBPS", buyWithCryptoParams.MaxSlippageBPS?.ToString() }, - { "intentId", buyWithCryptoParams.IntentId } - }; - - var queryStringFormatted = string.Join("&", queryString.Where(kv => kv.Value != null).Select(kv => $"{Uri.EscapeDataString(kv.Key)}={Uri.EscapeDataString(kv.Value)}")); - var url = $"{THIRDWEB_PAY_CRYPTO_QUOTE_ENDPOINT}?{queryStringFormatted}"; - - var getResponse = await client.HttpClient.GetAsync(url); - - var content = await getResponse.Content.ReadAsStringAsync(); - - if (!getResponse.IsSuccessStatusCode) + var response = await client.HttpClient.PostAsync( + THIRDWEB_PAY_CRYPTO_QUOTE_ENDPOINT, + new StringContent( + JsonConvert.SerializeObject(buyWithCryptoParams, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), + System.Text.Encoding.UTF8, + "application/json" + ) + ); + + var content = await response.Content.ReadAsStringAsync(); + + if (!response.IsSuccessStatusCode) { ErrorResponse error; try @@ -56,14 +44,12 @@ public static async Task GetBuyWithCryptoQuote(Thirdwe Reason = "Unknown", Code = "Unknown", Stack = "Unknown", - StatusCode = (int)getResponse.StatusCode + StatusCode = (int)response.StatusCode } }; } - throw new Exception( - $"HTTP error! Code: {error.Error.Code} Message: {error.Error.Message} Reason: {error.Error.Reason} StatusCode: {error.Error.StatusCode} Stack: {error.Error.Stack}" - ); + throw new Exception($"HTTP error! Code: {error.Error.Code} Message: {error.Error.Message} Reason: {error.Error.Reason} StatusCode: {error.Error.StatusCode} Stack: {error.Error.Stack}"); } var data = JsonConvert.DeserializeObject(content); diff --git a/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithFiatQuote.cs b/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithFiatQuote.cs index 9fdcaef..57bb207 100644 --- a/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithFiatQuote.cs +++ b/Thirdweb/Thirdweb.Pay/ThirdwebPay.GetBuyWithFiatQuote.cs @@ -16,29 +16,18 @@ public partial class ThirdwebPay /// Thrown if the HTTP response is not successful. public static async Task GetBuyWithFiatQuote(ThirdwebClient client, BuyWithFiatQuoteParams buyWithFiatParams) { - var queryString = new Dictionary - { - { "fromCurrencySymbol", buyWithFiatParams.FromCurrencySymbol }, - { "fromAmount", buyWithFiatParams.FromAmount }, - { "fromAmountUnits", buyWithFiatParams.FromAmountUnits }, - { "toAddress", buyWithFiatParams.ToAddress }, - { "toChainId", buyWithFiatParams.ToChainId }, - { "toTokenAddress", buyWithFiatParams.ToTokenAddress }, - { "toAmount", buyWithFiatParams.ToAmount }, - { "toAmountWei", buyWithFiatParams.ToAmountWei }, - { "preferredProvider", buyWithFiatParams.PreferredProvider }, - { "maxSlippageBPS", buyWithFiatParams.MaxSlippageBPS?.ToString() } - }; - - var queryStringFormatted = string.Join("&", queryString.Where(kv => kv.Value != null).Select(kv => $"{Uri.EscapeDataString(kv.Key)}={Uri.EscapeDataString(kv.Value)}")); - var url = $"{THIRDWEB_PAY_FIAT_QUOTE_ENDPOINT}?{queryStringFormatted}"; - url += buyWithFiatParams.IsTestMode ? "&isTestMode=true" : "&isTestMode=false"; - - var getResponse = await client.HttpClient.GetAsync(url); - - var content = await getResponse.Content.ReadAsStringAsync(); - - if (!getResponse.IsSuccessStatusCode) + var response = await client.HttpClient.PostAsync( + THIRDWEB_PAY_FIAT_QUOTE_ENDPOINT, + new StringContent( + JsonConvert.SerializeObject(buyWithFiatParams, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), + System.Text.Encoding.UTF8, + "application/json" + ) + ); + + var content = await response.Content.ReadAsStringAsync(); + + if (!response.IsSuccessStatusCode) { ErrorResponse error; try @@ -55,14 +44,12 @@ public static async Task GetBuyWithFiatQuote(ThirdwebCli Reason = "Unknown", Code = "Unknown", Stack = "Unknown", - StatusCode = (int)getResponse.StatusCode + StatusCode = (int)response.StatusCode } }; } - throw new Exception( - $"HTTP error! Code: {error.Error.Code} Message: {error.Error.Message} Reason: {error.Error.Reason} StatusCode: {error.Error.StatusCode} Stack: {error.Error.Stack}" - ); + throw new Exception($"HTTP error! Code: {error.Error.Code} Message: {error.Error.Message} Reason: {error.Error.Reason} StatusCode: {error.Error.StatusCode} Stack: {error.Error.Stack}"); } var data = JsonConvert.DeserializeObject(content); diff --git a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoQuote.cs b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoQuote.cs index 49b1d40..3180090 100644 --- a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoQuote.cs +++ b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoQuote.cs @@ -21,7 +21,8 @@ public class BuyWithCryptoQuoteParams( string toAmountWei = null, string toAddress = null, double? maxSlippageBPS = null, - string intentId = null + string intentId = null, + object purchaseData = null ) { /// @@ -95,6 +96,12 @@ public class BuyWithCryptoQuoteParams( /// [JsonProperty("intentId")] public string IntentId { get; set; } = intentId; + + /// + /// Additional data for the purchase. Useful with direct transfer flow. + /// + [JsonProperty("purchaseData")] + public object PurchaseData { get; set; } = purchaseData; } /// diff --git a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoStatus.cs b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoStatus.cs index e25dd2f..10a1c2f 100644 --- a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoStatus.cs +++ b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithCryptoStatus.cs @@ -78,6 +78,12 @@ public class BuyWithCryptoStatusResult /// [JsonProperty("bridge")] public string Bridge { get; set; } + + /// + /// Additional data for the purchase. Useful with direct transfer flow. + /// + [JsonProperty("purchaseData")] + public object PurchaseData { get; set; } } /// diff --git a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatQuote.cs b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatQuote.cs index 1cb5dba..2b07e2d 100644 --- a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatQuote.cs +++ b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatQuote.cs @@ -19,7 +19,8 @@ public class BuyWithFiatQuoteParams( string toAmountWei = null, double? maxSlippageBPS = null, bool isTestMode = false, - string preferredProvider = null + string preferredProvider = null, + object purchaseData = null ) { /// @@ -40,11 +41,6 @@ public class BuyWithFiatQuoteParams( [JsonProperty("fromAmountUnits")] public string FromAmountUnits { get; set; } = fromAmountUnits; - /// - /// The provider to use on the application for thirdweb pay - /// - [JsonProperty("preferredProvider")] - public string PreferredProvider { get; set; } = preferredProvider; /// /// The address to receive the purchased tokens. /// @@ -86,6 +82,18 @@ public class BuyWithFiatQuoteParams( /// [JsonProperty("isTestMode")] public bool IsTestMode { get; set; } = isTestMode; + + /// + /// The provider to use on the application for thirdweb pay + /// + [JsonProperty("preferredProvider")] + public string PreferredProvider { get; set; } = preferredProvider; + + /// + /// Additional data for the purchase. Useful with direct transfer flow. + /// + [JsonProperty("purchaseData")] + public object PurchaseData { get; set; } = purchaseData; } /// diff --git a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatStatus.cs b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatStatus.cs index c41dba6..b4f9a21 100644 --- a/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatStatus.cs +++ b/Thirdweb/Thirdweb.Pay/Types.GetBuyWithFiatStatus.cs @@ -60,6 +60,12 @@ public class BuyWithFiatStatusResult /// [JsonProperty("failureMessage")] public string FailureMessage { get; set; } + + /// + /// Additional data for the purchase. Useful with direct transfer flow. + /// + [JsonProperty("purchaseData")] + public object PurchaseData { get; set; } } /// diff --git a/Thirdweb/Thirdweb.Utils/Utils.cs b/Thirdweb/Thirdweb.Utils/Utils.cs index c4b32ad..7a7bd86 100644 --- a/Thirdweb/Thirdweb.Utils/Utils.cs +++ b/Thirdweb/Thirdweb.Utils/Utils.cs @@ -306,7 +306,24 @@ public static string GenerateSIWE(LoginPayloadData loginPayloadData) /// True if it is a zkSync chain ID, otherwise false. public static async Task IsZkSync(ThirdwebClient client, BigInteger chainId) { - if (chainId.Equals(324) || chainId.Equals(300) || chainId.Equals(302) || chainId.Equals(11124) || chainId.Equals(4654) || chainId.Equals(333271) || chainId.Equals(37111)) + if ( + chainId.Equals(324) + || chainId.Equals(300) + || chainId.Equals(302) + || chainId.Equals(11124) + || chainId.Equals(282) + || chainId.Equals(388) + || chainId.Equals(4654) + || chainId.Equals(333271) + || chainId.Equals(37111) + || chainId.Equals(978658) + || chainId.Equals(531050104) + || chainId.Equals(4457845) + || chainId.Equals(2741) + || chainId.Equals(240) + || chainId.Equals(61166) + || chainId.Equals(555271) + ) { return true; }