-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from VladiTitov/feature/create_requests_from_c…
…lient_ability_implementation Added the ability to create requests via Wallet Pay Client from outside
- Loading branch information
Showing
18 changed files
with
367 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ public enum ResponseStatus | |
{ | ||
SUCCESS, | ||
ALREADY, | ||
CONFLICT, | ||
ACCESS_DENIED, | ||
INVALID_REQUEST, | ||
INTERNAL_ERROR | ||
} |
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,100 @@ | ||
using Wallet.Pay.Requests.Orders; | ||
using Wallet.Pay.Responses.Orders; | ||
|
||
namespace Wallet.Pay.Extensions; | ||
|
||
public static class WalletPayClientExtensions | ||
{ | ||
/// <summary> | ||
/// Create an order | ||
/// </summary> | ||
/// <param name="walletPayClient"></param> | ||
/// <param name="amount"></param> | ||
/// <param name="currency"></param> | ||
/// <param name="description">Description of the order</param> | ||
/// <param name="externalId">Order ID in Merchant system. Use to prevent orders duplication due to request retries</param> | ||
/// <param name="timeoutSeconds">Order TTL, if the order is not paid within the timeout period</param> | ||
/// <param name="customerTelegramUserId">The customer's telegram id (User_id)</param> | ||
/// <param name="autoConversionCurrency">Crypto currency you want to receive no matter what crypto currency the payer will choose to pay.</param> | ||
/// <param name="returnUrl">Url to redirect after paying order</param> | ||
/// <param name="failReturnUrl">Url to redirect after unsuccessful order completion</param> | ||
/// <param name="customData">Any custom string, will be provided through webhook and order status polling</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>CreateOrderResponse</returns> | ||
public static Task<IResponse<CreateOrderResponse>> CreateOrderAsync( | ||
this IWalletPayClient walletPayClient, | ||
double amount, | ||
Currency currency, | ||
string description, | ||
string externalId, | ||
int timeoutSeconds, | ||
int customerTelegramUserId, | ||
ConversionCurrency? autoConversionCurrency = null, | ||
string? returnUrl = default, | ||
string? failReturnUrl = default, | ||
string? customData = default, | ||
CancellationToken cancellationToken = default) | ||
=> walletPayClient.MakeRequestAsync( | ||
request: new CreateOrderRequest() | ||
{ | ||
Amount = new() | ||
{ | ||
CurrencyCode = currency, | ||
Value = amount.ToString() | ||
}, | ||
Description = description, | ||
ExternalId = externalId, | ||
TimeoutSeconds = timeoutSeconds, | ||
CustomerTelegramUserId = customerTelegramUserId, | ||
AutoConversionCurrency = autoConversionCurrency, | ||
ReturnUrl = returnUrl, | ||
FailReturnUrl = failReturnUrl, | ||
CustomData = customData | ||
}, | ||
cancellationToken: cancellationToken); | ||
|
||
/// <summary> | ||
/// Retrieve the order information | ||
/// </summary> | ||
/// <param name="walletPayClient"></param> | ||
/// <param name="id">Order id</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>GetPreviewOrderResponse</returns> | ||
public static Task<IResponse<GetPreviewOrderResponse>> GetPreviewOrderAsync( | ||
this IWalletPayClient walletPayClient, | ||
string id, | ||
CancellationToken cancellationToken = default) | ||
=> walletPayClient.MakeRequestAsync( | ||
request: new GetPreviewOrderRequest(id), | ||
cancellationToken: cancellationToken); | ||
|
||
/// <summary> | ||
/// Return list of store orders sorted by creation time in ascending order | ||
/// </summary> | ||
/// <param name="walletPayClient"></param> | ||
/// <param name="offset">Specifying the amount of excluded from a response the first N orders</param> | ||
/// <param name="count">Specifying the limit of orders for the request</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>GetOrderListResponse</returns> | ||
public static Task<IResponse<GetOrderListResponse>> GetOrderListAsync( | ||
this IWalletPayClient walletPayClient, | ||
int offset, | ||
int count, | ||
CancellationToken cancellationToken = default) | ||
=> walletPayClient.MakeRequestAsync( | ||
request: new GetOrderListRequest(offset, count), | ||
cancellationToken: cancellationToken); | ||
|
||
/// <summary> | ||
/// Returns total count of all created orders in the Store, including all - paid and unpaid | ||
/// </summary> | ||
/// <param name="walletPayClient"></param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>GetOrderAmountResponse</returns> | ||
public static Task<IResponse<GetOrderAmountResponse>> GetOrderAmountAsync( | ||
this IWalletPayClient walletPayClient, | ||
CancellationToken cancellationToken = default) | ||
=> walletPayClient.MakeRequestAsync( | ||
request: new GetOrderAmountRequest(), | ||
cancellationToken: cancellationToken); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
namespace Wallet.Pay; | ||
|
||
/// <summary> | ||
/// A client interface to use the Telegram Wallet Pay API | ||
/// </summary> | ||
public interface IWalletPayClient | ||
{ | ||
Task<ResponseBase<TResponse>?> MakeRequestAsync<TResponse>( | ||
/// <summary> | ||
/// Send a request to Wallet Pay API | ||
/// </summary> | ||
/// <typeparam name="TResponse">Type of expected result in the response object</typeparam> | ||
/// <param name="request">API request object</param> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns>Result of the API request</returns> | ||
Task<IResponse<TResponse>> MakeRequestAsync<TResponse>( | ||
IRequest<TResponse> request, | ||
CancellationToken cancellationToken = default) where TResponse : class; | ||
} |
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 |
---|---|---|
@@ -1,9 +1,23 @@ | ||
namespace Wallet.Pay.Models; | ||
|
||
/// <summary> | ||
/// Amount model | ||
/// </summary> | ||
#nullable disable | ||
public class Amount | ||
{ | ||
/// <summary> | ||
/// Big decimal string representation. | ||
/// Note that the max precision (number of digits after decimal point) depends on the currencyCode. | ||
/// E.g. for all fiat currencies is 2 (0.01), for TON is 9, for BTC is 8, for USDT is 6. | ||
/// There's also min order amount for creating an order. | ||
/// It's 0.001 TON / 0.000001 BTC / 0.01 USDT / 0.01 USD / 0.01 EUR / 0.1 RUB. | ||
/// </summary> | ||
[JsonProperty("amount")] | ||
public string Value { get; set; } | ||
|
||
/// <summary> | ||
/// Currency code | ||
/// </summary> | ||
public Currency CurrencyCode { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,12 +1,38 @@ | ||
namespace Wallet.Pay.Models; | ||
|
||
/// <summary> | ||
/// Order model | ||
/// </summary> | ||
#nullable disable | ||
public class Order | ||
{ | ||
/// <summary> | ||
/// Order id | ||
/// </summary> | ||
public string Id { get; set; } | ||
|
||
/// <summary> | ||
/// Order status | ||
/// </summary> | ||
public OrderStatus Status { get; set; } | ||
|
||
/// <summary> | ||
/// <see cref="Amount"/> | ||
/// </summary> | ||
public Amount Amount { get; set; } | ||
public Currency AutoConversionCurrency { get; set; } | ||
|
||
/// <summary> | ||
/// Crypto currency you want to receive no matter what crypto currency the payer will choose to pay. | ||
/// </summary> | ||
public Currency? AutoConversionCurrency { get; set; } | ||
|
||
/// <summary> | ||
/// ISO-8601 date time when order was created | ||
/// </summary> | ||
public DateTimeOffset CreatedDateTime { get; set; } | ||
|
||
/// <summary> | ||
/// ISO-8601 date time when order timeout expires | ||
/// </summary> | ||
public DateTimeOffset ExpirationDateTime { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,8 +1,24 @@ | ||
namespace Wallet.Pay.Requests; | ||
|
||
/// <summary> | ||
/// Represents a request interface to Wallet Pay API | ||
/// </summary> | ||
/// <typeparam name="TResponse">Type of result expected in result</typeparam> | ||
public interface IRequest<TResponse> | ||
{ | ||
/// <summary> | ||
/// HTTP method of request | ||
/// </summary> | ||
HttpMethod Method { get; } | ||
|
||
/// <summary> | ||
/// API uri path | ||
/// </summary> | ||
string UriPath { get; } | ||
|
||
/// <summary> | ||
/// Generate content of HTTP message | ||
/// </summary> | ||
/// <returns>Content of HTTP request</returns> | ||
HttpContent? ToHttpContent(); | ||
} |
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 |
---|---|---|
@@ -1,10 +1,23 @@ | ||
using Wallet.Pay.Enums; | ||
namespace Wallet.Pay.Responses; | ||
|
||
namespace Wallet.Pay.Responses; | ||
|
||
internal interface IResponse<TResponse> | ||
/// <summary> | ||
/// API response interface | ||
/// </summary> | ||
/// <typeparam name="TResponse">Type of result expected in result</typeparam> | ||
public interface IResponse<TResponse> | ||
{ | ||
/// <summary> | ||
/// Response status | ||
/// </summary> | ||
public ResponseStatus Status { get; set; } | ||
|
||
/// <summary> | ||
/// Verbose reason of non-success result | ||
/// </summary> | ||
public string Message { get; set; } | ||
|
||
/// <summary> | ||
/// Response payload, present if status is SUCCESS | ||
/// </summary> | ||
public TResponse Data { get; set; } | ||
} |
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
Oops, something went wrong.