Skip to content

Commit

Permalink
add payout account crud operations (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuncaserhat authored Jul 21, 2023
1 parent 7393f29 commit ad22bc9
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 5 deletions.
59 changes: 55 additions & 4 deletions Craftgate/Adapter/SettlementAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,63 @@ public SettlementResponse CreateInstantWalletSettlement(
CreateHeaders(request, path, RequestOptions), request);
}

public Task<SettlementResponse> CreateInstantWalletSettlementAsync(
CreateInstantWalletSettlementRequest request)
public Task<SettlementResponse> CreateInstantWalletSettlementAsync(CreateInstantWalletSettlementRequest request)
{
var path = "/settlement/v1/instant-wallet-settlements";
return AsyncRestClient.Post<SettlementResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(request, path, RequestOptions), request);
return AsyncRestClient.Post<SettlementResponse>(RequestOptions.BaseUrl + path, CreateHeaders(request, path, RequestOptions), request);
}


public PayoutAccountResponse CreatePayoutAccount(CreatePayoutAccountRequest request)
{
var path = "/settlement/v1/payout-accounts";
return RestClient.Post<PayoutAccountResponse>(RequestOptions.BaseUrl + path, CreateHeaders(request, path, RequestOptions), request);
}

public Task<PayoutAccountResponse> CreatePayoutAccountAsync(CreatePayoutAccountRequest request)
{
var path = "/settlement/v1/payout-accounts";
return AsyncRestClient.Post<PayoutAccountResponse>(RequestOptions.BaseUrl + path, CreateHeaders(request, path, RequestOptions), request);
}

public void UpdatePayoutAccount(long id, UpdatePayoutAccountRequest request)
{
var path = "/settlement/v1/payout-accounts/" + id;
RestClient.Put<object>(RequestOptions.BaseUrl + path, CreateHeaders(request, path, RequestOptions), request);
}

public Task UpdatePayoutAccountAsync(long id, UpdatePayoutAccountRequest request)
{
var path = "/settlement/v1/payout-accounts/" + id;
return AsyncRestClient.Put<object>(RequestOptions.BaseUrl + path, CreateHeaders(request, path, RequestOptions), request);
}

public void DeletePayoutAccount(long id)
{
var path = "/settlement/v1/payout-accounts/" + id;
RestClient.Delete<object>(RequestOptions.BaseUrl + path, CreateHeaders(path, RequestOptions));
}

public Task DeletePayoutAccountAsync(long id)
{
var path = "/settlement/v1/payout-accounts/" + id;
return AsyncRestClient.Delete<object>(RequestOptions.BaseUrl + path, CreateHeaders(path, RequestOptions));
}

public PayoutAccountListResponse SearchPayoutAccounts(SearchPayoutAccountRequest request)
{
var queryParam = RequestQueryParamsBuilder.BuildQueryParam(request);
var path = "/settlement/v1/payout-accounts" + queryParam;
return RestClient.Get<PayoutAccountListResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(path, RequestOptions));
}

public Task<PayoutAccountListResponse> SearchPayoutAccountsAsync(SearchPayoutAccountRequest request)
{
var queryParam = RequestQueryParamsBuilder.BuildQueryParam(request);
var path = "/settlement/v1/payout-accounts" + queryParam;
return AsyncRestClient.Get<PayoutAccountListResponse>(RequestOptions.BaseUrl + path,
CreateHeaders(path, RequestOptions));
}
}
}
10 changes: 10 additions & 0 deletions Craftgate/Model/AccountOwner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.Serialization;

namespace Craftgate.Model
{
public enum AccountOwner
{
[EnumMember(Value = "MERCHANT")] MERCHANT,
[EnumMember(Value = "SUB_MERCHANT_MEMBER")] SUB_MERCHANT_MEMBER,
}
}
9 changes: 9 additions & 0 deletions Craftgate/Model/PayoutAccountType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Runtime.Serialization;

namespace Craftgate.Model
{
public enum PayoutAccountType
{
[EnumMember(Value = "WISE")] WISE,
}
}
3 changes: 2 additions & 1 deletion Craftgate/Model/SettlementEarningsDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Craftgate.Model
public enum SettlementEarningsDestination
{
[EnumMember(Value = "IBAN")] IBAN,
[EnumMember(Value = "WALLET")] WALLET
[EnumMember(Value = "WALLET")] WALLET,
[EnumMember(Value = "CROSS_BORDER")] CROSS_BORDER
}
}
14 changes: 14 additions & 0 deletions Craftgate/Request/CreatePayoutAccountRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Craftgate.Model;

namespace Craftgate.Request
{
public class CreatePayoutAccountRequest
{
public PayoutAccountType Type { get; set; }
public string ExternalAccountId { get; set; }
public Currency Currency { get; set; }
public AccountOwner AccountOwner { get; set; }
public long? SubMerchantMemberId { get; set; }
}
}
13 changes: 13 additions & 0 deletions Craftgate/Request/SearchPayoutAccountRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Craftgate.Model;

namespace Craftgate.Request
{
public class SearchPayoutAccountRequest
{
public Currency? Currency { get; set; }
public AccountOwner? AccountOwner { get; set; }
public long? SubMerchantMemberId { get; set; }
public int? Page { get; set; } = 0;
public int? Size { get; set; } = 10;
}
}
10 changes: 10 additions & 0 deletions Craftgate/Request/UpdatePayoutAccountRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Craftgate.Model;

namespace Craftgate.Request
{
public class UpdatePayoutAccountRequest
{
public PayoutAccountType Type { get; set; }
public string ExternalAccountId { get; set; }
}
}
8 changes: 8 additions & 0 deletions Craftgate/Response/PayoutAccountListResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Craftgate.Response.Common;

namespace Craftgate.Response
{
public class PayoutAccountListResponse : ListResponse<PayoutAccountResponse>
{
}
}
12 changes: 12 additions & 0 deletions Craftgate/Response/PayoutAccountResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Craftgate.Response
{
public class PayoutAccountResponse
{
public long Id { get; set; }
public string Type { get; set; }
public string ExternalAccountId { get; set; }
public string Currency { get; set; }
public string AccountOwner { get; set; }
public long? SubMerchantMemberId { get; set; }
}
}
64 changes: 64 additions & 0 deletions Samples/SettlementSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,69 @@ public void Create_Instant_Wallet_Settlement()
SettlementResponse response = _craftgateClient.Settlement().CreateInstantWalletSettlement(request);
Assert.NotNull(response.SettlementResultStatus);
}


[Test]
public void Create_Merchant_Payout_Account()
{
var request = new CreatePayoutAccountRequest
{
AccountOwner = AccountOwner.MERCHANT,
Currency = Currency.USD,
Type = PayoutAccountType.WISE,
ExternalAccountId = "wiseRecipientId"
};

PayoutAccountResponse response = _craftgateClient.Settlement().CreatePayoutAccount(request);
Assert.NotNull(response.Id);
}

[Test]
public void Create_Sub_Merchant_Payout_Account()
{
var request = new CreatePayoutAccountRequest
{
AccountOwner = AccountOwner.SUB_MERCHANT_MEMBER,
SubMerchantMemberId = 1L,
Currency = Currency.USD,
Type = PayoutAccountType.WISE,
ExternalAccountId = "wiseRecipientId"
};

PayoutAccountResponse response = _craftgateClient.Settlement().CreatePayoutAccount(request);
Assert.NotNull(response.Id);
}

[Test]
public void Update_Payout_Account()
{
var request = new UpdatePayoutAccountRequest()
{
Type = PayoutAccountType.WISE,
ExternalAccountId = "wiseRecipientId"
};

_craftgateClient.Settlement().UpdatePayoutAccount(15, request);
}

[Test]
public void Delete_Payout_Account()
{
_craftgateClient.Settlement().DeletePayoutAccount(13);
}


[Test]
public void Search_Payout_Account()
{
var request = new SearchPayoutAccountRequest()
{
AccountOwner = AccountOwner.MERCHANT,
Currency = Currency.USD
};

PayoutAccountListResponse response = _craftgateClient.Settlement().SearchPayoutAccounts(request);
Assert.NotNull(response.Items);
}
}
}

0 comments on commit ad22bc9

Please sign in to comment.