Skip to content

Commit

Permalink
Unmanaged payouts
Browse files Browse the repository at this point in the history
  • Loading branch information
SuzanneRobert committed May 16, 2024
1 parent ecdf366 commit 69205a6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Nexus.Sdk.Token.Tests/Helpers/MockTokenServerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Task<SignablePaymentResponse> CreatePaymentsAsync(IEnumerable<PaymentDefi
throw new NotImplementedException();
}

public Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null)
public Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null, string? blockchainTransactionId = null)
{
throw new NotImplementedException();
}
Expand Down Expand Up @@ -287,7 +287,7 @@ public Task<DeleteCustomerResponse> DeleteCustomer(DeleteCustomerRequest request
throw new NotImplementedException();
}

public Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null)
public Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null, string? blockchainTransactionId = null)
{
throw new NotImplementedException();
}
Expand Down
14 changes: 12 additions & 2 deletions Nexus.Sdk.Token/Facades/Interfaces/IOperationsFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public interface IOperationsFacade

/// <summary>
/// Withdraw token from an account
///
/// If tokens have already been withdrawn from an account outside of Nexus, you can still create a payout inside Nexus without creating another onchain transaction.
/// To do this provide the existing blockchain transaction id in the request.
/// Note that this can only be done for unmanaged accounts and that providing the memo, message and expireSeconds will no longer have any affect due to no onchain transaction having to be created.
/// </summary>
/// <param name="accountCode">{crypto}-{publickey} combination of the account. E.g. XLM-GAW6GBLA5U4KCXV4E5SZTVERBF3AUASEPNTN4ZXSXLCROOTJ7KQQW4S7</param>
/// <param name="tokenCode">Unique Nexus identifier of the token that will be withdrawn from this account</param>
Expand All @@ -77,18 +81,24 @@ public interface IOperationsFacade
/// <param name="memo">An optional message that is added to the transaction and will be visible on the blockchain</param>
/// <param name="message">This value will be put in the Message field of a funding transaction and will not be stored on the blockchain</param>
/// <param name="paymentReference">Optional reference to bank payment</param>
/// <param name="blockchainTransactionId">Only provide the blockchain transaction ID if available and no onchain transaction should be created.</param>
/// <returns>A transaction that needs to be signed using the private key that matches the provided account</returns>
public Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null);
public Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null, string? blockchainTransactionId = null);

/// <summary>
/// Simulate the withdrawal of token from an account.
///
/// If tokens have already been withdrawn from an account outside of Nexus, you can still create a payout inside Nexus without creating another onchain transaction.
/// To do this provide the existing blockchain transaction id in the request.
/// Note that this can only be done for unmanaged accounts and that providing the memo, message and expireSeconds will no longer have any affect due to no onchain transaction having to be created.
/// </summary>
/// <param name="accountCode">{crypto}-{publickey} combination of the account. E.g. XLM-GAW6GBLA5U4KCXV4E5SZTVERBF3AUASEPNTN4ZXSXLCROOTJ7KQQW4S7</param>
/// <param name="tokenCode">Unique Nexus identifier of the token that should be withdrawn from this account</param>
/// <param name="amount">The amount of tokens that should be withdrawn from this account</param>
/// <param name="pm">An optional payment method that is used to calculate fees</param>
/// <param name="memo">An optional message that is added to the transaction and would be visible on the blockchain</param>
/// <param name="paymentReference">Optional reference to bank payment</param>
/// <param name="blockchainTransactionId">Only provide the blockchain transaction ID if available and no onchain transaction should be created.</param>
/// <returns>A simulated withdrawal that includes fees.</returns>
public Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null);
public Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null, string? blockchainTransactionId = null);
}
8 changes: 4 additions & 4 deletions Nexus.Sdk.Token/Facades/OperationsFacade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public async Task<SignablePaymentResponse> CreatePaymentsAsync(PaymentDefinition
return await _provider.CreatePaymentsAsync(definitions, memo, message, cryptoCode, callbackUrl, customerIPAddress);
}

public async Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null)
public async Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null, string? blockchainTransactionId = null)
{
return await _provider.CreatePayoutAsync(accountCode, tokenCode, amount, pm, memo, message, paymentReference, customerIPAddress);
return await _provider.CreatePayoutAsync(accountCode, tokenCode, amount, pm, memo, message, paymentReference, customerIPAddress, blockchainTransactionId);
}

public async Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null)
public async Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null, string? blockchainTransactionId = null)
{
return await _provider.SimulatePayoutAsync(accountCode, tokenCode, amount, pm, memo, paymentReference);
return await _provider.SimulatePayoutAsync(accountCode, tokenCode, amount, pm, memo, paymentReference, blockchainTransactionId);
}
}
5 changes: 3 additions & 2 deletions Nexus.Sdk.Token/ITokenServerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ public interface ITokenServerProvider : IServerProvider
/// <param name="message"></param>
/// <param name="paymentReference"></param>
/// <param name="customerIPAddress">Optional IP address of the customer used for tracing their actions</param>
/// <param name="blockchainTransactionId">Only provide the blockchain transaction ID if available and no onchain transaction should be created.</param>
/// <returns></returns>
Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null);
Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null, string? blockchainTransactionId = null);

Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null);
Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null, string? blockchainTransactionId = null);

/// <summary>
///
Expand Down
3 changes: 3 additions & 0 deletions Nexus.Sdk.Token/Requests/OperationsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ public record PayoutOperationRequest

[JsonPropertyName("paymentReference")]
public string? PaymentReference { get; set; }

[JsonPropertyName("blockchainTransactionId")]
public string? BlockchainTransactionId { get; set; }
}
10 changes: 6 additions & 4 deletions Nexus.Sdk.Token/TokenServerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public async Task<SignablePaymentResponse> CreatePaymentsAsync(IEnumerable<Payme
/// <param name="customerIPAddress">Optional IP address of the customer used for tracing their actions</param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
public async Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null)
public async Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? message = null, string? paymentReference = null, string? customerIPAddress = null, string? blockchainTransactionId = null)
{
if (string.IsNullOrWhiteSpace(pm) && string.IsNullOrWhiteSpace(_options.PaymentMethodOptions.Payout))
{
Expand All @@ -378,13 +378,14 @@ public async Task<SignablePayoutResponse> CreatePayoutAsync(string accountCode,
TokenCode = tokenCode,
PaymentReference = paymentReference,
Memo = memo,
Message = message
Message = message,
BlockchainTransactionId = blockchainTransactionId
};

return await builder.ExecutePost<PayoutOperationRequest, SignablePayoutResponse>(request);
}

public async Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null)
public async Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCode, string tokenCode, decimal amount, string? pm = null, string? memo = null, string? paymentReference = null, string? blockchainTransactionId = null)
{
if (string.IsNullOrWhiteSpace(pm) && string.IsNullOrWhiteSpace(_options.PaymentMethodOptions.Payout))
{
Expand All @@ -400,7 +401,8 @@ public async Task<PayoutOperationResponse> SimulatePayoutAsync(string accountCod
Amount = amount,
TokenCode = tokenCode,
PaymentReference = paymentReference,
Memo = memo
Memo = memo,
BlockchainTransactionId = blockchainTransactionId
};

return await builder.ExecutePost<PayoutOperationRequest, PayoutOperationResponse>(request);
Expand Down

0 comments on commit 69205a6

Please sign in to comment.