Skip to content

Commit

Permalink
Merge pull request #14 from adzshaf/refactor/initialization-client
Browse files Browse the repository at this point in the history
refactor: add multiple instance of endpoint
  • Loading branch information
muthmainnah234 authored Sep 27, 2021
2 parents 4062fd5 + 778f3de commit 7b4fd2b
Show file tree
Hide file tree
Showing 139 changed files with 3,500 additions and 1,645 deletions.
331 changes: 230 additions & 101 deletions README.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Xendit.net/Xendit.net/Enum/BankCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public enum BankCode
Unknown,

[EnumMember(Value = "BCA")]
BCA,
Bca,

[EnumMember(Value = "BNI")]
BNI,
Bni,

[EnumMember(Value = "BNI_SYARIAH")]
BNISyariah,
BniSyariah,

[EnumMember(Value = "BRI")]
BRI,
Bri,

[EnumMember(Value = "MANDIRI")]
Mandiri,
Expand Down
28 changes: 14 additions & 14 deletions Xendit.net/Xendit.net/Enum/InvoicePaymentChannelType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ public enum InvoicePaymentChannelType
CreditCard,

[EnumMember(Value = "BCA")]
BCA,
Bca,

[EnumMember(Value = "BNI")]
BNI,
Bni,

[EnumMember(Value = "BNI_SYARIAH")]
BNISyariah,
BniSyariah,

[EnumMember(Value = "BRI")]
BRI,
Bri,

[EnumMember(Value = "MANDIRI")]
Mandiri,
Expand All @@ -40,36 +40,36 @@ public enum InvoicePaymentChannelType
SevenEleven,

[EnumMember(Value = "OVO")]
OVO,
Ovo,

[EnumMember(Value = "DANA")]
Dana,

[EnumMember(Value = "SHOPEEPAY")]
ShopeePay,
Shopeepay,

[EnumMember(Value = "LINKAJA")]
LinkAja,
Linkaja,

[EnumMember(Value = "GRABPAY")]
GrabPay,
Grabpay,

[EnumMember(Value = "GCASH")]
GCash,
Gcash,

[EnumMember(Value = "PAYMAYA")]
PayMaya,
Paymaya,

[EnumMember(Value = "QRIS")]
QRIS,
Qris,

[EnumMember(Value = "DD_BRI")]
DirectDebitBRI,
DirectDebitBri,

[EnumMember(Value = "DD_BPI")]
DirectDebitBPI,
DirectDebitBpi,

[EnumMember(Value = "DD_UBP")]
DirectDebitUBP,
DirectDebitUbp,
}
}
41 changes: 0 additions & 41 deletions Xendit.net/Xendit.net/Model/AccessibleLinkedAccount.cs

This file was deleted.

21 changes: 21 additions & 0 deletions Xendit.net/Xendit.net/Model/Balance/Balance.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Xendit.net.Model.Balance
{
using System.Threading.Tasks;
using Xendit.net.Enum;
using Xendit.net.Struct;

public class Balance
{
/// <summary>
/// Get balance from your account based on given account type.
/// </summary>
/// <param name="accountType">Selected balance type <see cref="BalanceAccountType"/>.</param>
/// <param name="headers">Custom headers <see cref="HeaderParameter"/>. Use property based on <see href="https://developers.xendit.co/api-reference/#get-balance"/>.</param>
/// <returns>A Task of <see cref="BalanceResponse"/>.</returns>
public static async Task<BalanceResponse> Get(BalanceAccountType? accountType = null, HeaderParameter? headers = null)
{
BalanceClient client = new BalanceClient();
return await client.Get(accountType, headers);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
namespace Xendit.net.Model
namespace Xendit.net.Model.Balance
{
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Xendit.net.Enum;
using Xendit.net.Network;
using Xendit.net.Struct;

public class Balance
public class BalanceClient : BaseClient
{
[JsonPropertyName("balance")]
public long Value { get; set; }
public BalanceClient(string apiKey = null, INetworkClient requestClient = null, string baseUrl = null)
: base(apiKey, requestClient, baseUrl)
{
}

/// <summary>
/// Get balance from your account based on given account type.
/// </summary>
/// <param name="accountType">Selected balance type <see cref="BalanceAccountType"/>.</param>
/// <param name="headers">Custom headers <see cref="HeaderParameter"/>. Use property based on <see href="https://developers.xendit.co/api-reference/#get-balance"/>.</param>
/// <returns>A Task of <see cref="Balance"/>.</returns>
public static async Task<Balance> Get(BalanceAccountType? accountType = null, HeaderParameter? headers = null)
{
return await GetBalanceRequest(accountType, headers);
}

private static async Task<Balance> GetBalanceRequest(BalanceAccountType? accountType, HeaderParameter? headers)
/// <returns>A Task of <see cref="BalanceResponse"/>.</returns>
public async Task<BalanceResponse> Get(BalanceAccountType? accountType = null, HeaderParameter? headers = null)
{
string url = string.Format("{0}{1}", XenditConfiguration.ApiUrl, "/balance");

string url = "/balance";
if (accountType != null)
{
string accountTypeParam = JsonSerializer.Deserialize<string>(JsonSerializer.Serialize(accountType));
url = string.Format("{0}{1}{2}", url, "?account_type=", accountTypeParam);
}

var balance = await XenditConfiguration.RequestClient.Request<Balance>(HttpMethod.Get, headers, url);
return balance;
var client = this.requestClient ?? XenditConfiguration.RequestClient;
return await client.Request<BalanceResponse>(HttpMethod.Get, url, this.ApiKey, this.BaseUrl, headers);
}
}
}
10 changes: 10 additions & 0 deletions Xendit.net/Xendit.net/Model/Balance/BalanceResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Xendit.net.Model.Balance
{
using System.Text.Json.Serialization;

public class BalanceResponse
{
[JsonPropertyName("balance")]
public long Balance { get; set; }
}
}
36 changes: 36 additions & 0 deletions Xendit.net/Xendit.net/Model/BaseClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Xendit.net.Model
{
using Xendit.net.Network;

public class BaseClient
{
protected string apiKey;
protected string baseUrl;
protected INetworkClient requestClient;

public BaseClient(string apiKey = null, INetworkClient requestClient = null, string baseUrl = null)
{
this.apiKey = apiKey;
this.baseUrl = baseUrl;
this.requestClient = requestClient;
}

public string ApiKey
{
get => this.apiKey;
set => this.apiKey = value;
}

public string BaseUrl
{
get => this.baseUrl;
set => this.baseUrl = value;
}

public INetworkClient RequestClient
{
get => this.requestClient;
set => this.requestClient = value;
}
}
}
2 changes: 1 addition & 1 deletion Xendit.net/Xendit.net/Model/Customer/BusinessDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BusinessDetail
public string BusinessName { get; set; }

[JsonPropertyName("business_type")]
public CustomerBusinessType BusinessType { get; set; }
public CustomerBusinessType? BusinessType { get; set; }

[JsonPropertyName("nature_of_business")]
public string NatureOfBusiness { get; set; }
Expand Down
104 changes: 8 additions & 96 deletions Xendit.net/Xendit.net/Model/Customer/Customer.cs
Original file line number Diff line number Diff line change
@@ -1,87 +1,22 @@
namespace Xendit.net.Model.Customer
{
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Xendit.net.Enum;
using Xendit.net.Struct;

public class Customer
{
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonPropertyName("reference_id")]
public string ReferenceId { get; set; }

[JsonPropertyName("mobile_number")]
public string MobileNumber { get; set; }

[JsonPropertyName("email")]
public string Email { get; set; }

[JsonPropertyName("given_names")]
public string GivenNames { get; set; }

[JsonPropertyName("middle_name")]
public string MiddleName { get; set; }

[JsonPropertyName("surname")]
public string Surname { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

[JsonPropertyName("phone_number")]
public string PhoneNumber { get; set; }

[JsonPropertyName("nationality")]
public string Nationality { get; set; }

[JsonPropertyName("addresses")]
public Address[] Addresses { get; set; }

[JsonPropertyName("date_of_birth")]
public string DateOfBirth { get; set; }

[JsonPropertyName("metadata")]
public Dictionary<string, object> Metadata { get; set; }

[JsonPropertyName("type")]
public CustomerType Type { get; set; }

[JsonPropertyName("individual_detail")]
public IndividualDetail IndividualDetail { get; set; }

[JsonPropertyName("business_detail")]
public BusinessDetail BusinessDetail { get; set; }

[JsonPropertyName("identity_accounts")]
public IdentityAccount[] IdentityAccount { get; set; }

[JsonPropertyName("kyc_documents")]
public KycDocument[] KycDocuments { get; set; }

[JsonPropertyName("data")]
public Customer[] Data { get; set; }

[JsonPropertyName("has_more")]
public bool HasMore { get; set; }

/// <summary>
/// Create customer with parameters.
/// </summary>
/// <param name="parameter">Parameter listed here <see cref="CustomerParameter"/>.</param>
/// <param name="headers">Custom headers <see cref="HeaderParameter"/>. Use property based on <see href="https://developers.xendit.co/api-reference/#create-customer"/>.</param>
/// <param name="version">API version that will be used to request <see cref="ApiVersion"/>.</param>
/// <returns>A Task of <see cref="Customer"/>.</returns>
public static async Task<Customer> Create(CustomerParameter parameter, HeaderParameter? headers = null, ApiVersion version = ApiVersion.Version20201031)
/// <returns>A Task of <see cref="CustomerResponse"/>.</returns>
public static async Task<CustomerResponse> Create(CustomerParameter parameter, HeaderParameter? headers = null, ApiVersion version = ApiVersion.Version20201031)
{
HeaderParameter validHeaders = headers ?? new HeaderParameter { };
validHeaders.ApiVersion = version;

return await CreateCustomerRequest(parameter, validHeaders);
CustomerClient client = new CustomerClient();
return await client.Create(parameter, headers, version);
}

/// <summary>
Expand All @@ -90,34 +25,11 @@ public static async Task<Customer> Create(CustomerParameter parameter, HeaderPar
/// <param name="referenceId">Merchant-provided identifier for the customer.</param>
/// <param name="headers">Custom headers <see cref="HeaderParameter"/>. Use property based on <see href="https://developers.xendit.co/api-reference/#get-customer-by-reference-id"/>.</param>
/// <param name="version">API version that will be used to request <see cref="ApiVersion"/>.</param>
/// <returns>A Task of <see cref="Customer[]"/>.</returns>
public static async Task<Customer> Get(string referenceId, HeaderParameter? headers = null, ApiVersion version = ApiVersion.Version20201031)
/// <returns>A Task of <see cref="CustomerResponse[]"/>.</returns>
public static async Task<CustomerResponse> Get(string referenceId, HeaderParameter? headers = null, ApiVersion version = ApiVersion.Version20201031)
{
HeaderParameter validHeaders = headers ?? new HeaderParameter { };
validHeaders.ApiVersion = version;

return await GetCustomerRequest(referenceId, validHeaders);
}

private static async Task<Customer> CreateCustomerRequest(CustomerParameter parameter, HeaderParameter? headers)
{
string url = string.Format("{0}/{1}", XenditConfiguration.ApiUrl, "customers");
return await XenditConfiguration.RequestClient.Request<CustomerParameter, Customer>(HttpMethod.Post, headers, url, parameter);
}

private static async Task<Customer> GetCustomerRequest(string referenceId, HeaderParameter headers)
{
string url = string.Format("{0}{1}{2}", XenditConfiguration.ApiUrl, "/customers?reference_id=", referenceId);

if (headers.ApiVersion == ApiVersion.Version20200519)
{
Customer[] customerData = await XenditConfiguration.RequestClient.Request<Dictionary<string, string>, Customer[]>(HttpMethod.Get, headers, url, null);
Customer customer = new Customer { Data = customerData };

return customer;
}

return await XenditConfiguration.RequestClient.Request<Dictionary<string, string>, Customer>(HttpMethod.Get, headers, url, null);
CustomerClient client = new CustomerClient();
return await client.Get(referenceId, headers, version);
}
}
}
Loading

0 comments on commit 7b4fd2b

Please sign in to comment.