This library is the abstraction of Xendit API for access from applications written with C# .NET.
Please note that this library is not official from Xendit. You can refer to Xendit Github for the complete list of their official API client libraries.
- Installation
- API Documentation
- Requirements
- Usage
- Disbursement Services
- Invoice services
- Virtual Account Services
- Batch Disbursement Services
- E-Wallet Services
- Exception Handling
- Contributing
- TODO
We recommended you to install using our NuGet Package, however you can clone this repo and embed it into your projects.
Please check Xendit API Reference.
This library is built on .NET Standard 2.0. You only need to make sure that your code is compatible with .NET Standard 2.0, if not, you can build this project on other .NET version easily.
You need to use secret API key in order to use functionality in this library. The key can be obtained from your Xendit Dashboard.
using Xendit.ApiClient;
public class Program
{
public static void Main()
{
var xendit = new XenditClient("PUT YOUR API KEY HERE");
// The rest of the code...
}
}
For complete configuration, you can use the XenditClient
constructor that accepts XenditConfiguration
.
Example: Create a specified Fixed Virtual Account (assuming your code is asynchronous, otherwise you can easily call .Result
or .GetAwaiter().GetResult()
after the async method depending on your case).
using System.Threading.Tasks;
using Xendit.ApiClient.Constants;
using Xendit.ApiClient.VirtualAccount;
public class Program
{
public static void Main()
{
MainBusiness().Wait();
}
private async Task MainBusiness()
{
var xendit = new XenditClient("PUT YOUR API KEY HERE");
// You can create non-specified fixed VA number by not providing `VirtualAccountNumber` property value.
var requestedVA = new XenditVACreateRequest
{
ExternalId = "VA_fixed-1234567890",
Name = "Steve Woznike",
BankCode = XenditVABankCode.MANDIRI,
VirtualAccountNumber = "9999000002"
};
var va = await xendit.VirtualAccount.CreateAsync(requestedVA);
}
}
Note: in a real project, we recommend to use dependency injection to create XenditClient
object as singleton, you can also use IXenditClient
interface for your unit tests.
var requestedDisbursement = new XenditDisbursementCreateRequest
{
ExternalId = "My-Disb-1234567890",
Amount = 125000,
BankCode = XenditDisbursementBankCode.MANDIRI,
AccountHolderName = "Andilau Sinarasa",
AccountNumber = "1234567890",
Description = "Disbursement description."
};
var disbursement = await xendit.Disbursement.CreateAsync(requestedDisbursement);
var availableDisbBanks = await xendit.Disbursement.GetAvailableBanksAsync();
var disbursement = await xendit.Disbursement.GetByExternalIdAsync("EXAMPLE_EXTERNAL_ID");
var disbursement = await xendit.Disbursement.GetByIdAsync("EXAMPLE_ID");
var requestedInvoice = new XenditInvoiceCreateRequest
{
ExternalId = "My-Invoice-1234567890",
Amount = 75000,
PayerEmail = "customer@example.com",
Description = "Invoice for a random gadget"
};
var invoice = await xendit.Invoice.CreateAsync(requestedInvoice);
You can bind the invoice to a Virtual Account by providing Virtual Account Id to property VANumberId
of XenditInvoiceCreateRequest
above.
var invoice = await xendit.Invoice.GetAsync("EXAMPLE_ID");
var options = new XenditInvoiceOptions
{
Limit = 3,
Statuses = new List<XenditInvoiceStatus> { XenditInvoiceStatus.SETTLED, XenditInvoiceStatus.EXPIRED }
};
var invoices = await xendit.Invoice.GetAllAsync(options);
var invoice = await xendit.Invoice.ExpireAsync("EXAMPLE_ID");
new XenditVACreateRequest { ExternalId = "my-VA-fixed-closed-1234568", BankCode = XenditVABankCode.BNI, Name = "VA Test", IsClosedVA = true, ExpectedAmount = 1350000 }; |
new XenditVACreateRequest { ExternalId = "my-VA-fixed-closed-1234568", BankCode = XenditVABankCode.BNI, Name = "VA Test", }; |
// Just unassign `IsClosedVA` and `ExpectedAmount` to create Opened VA.
var requestedVA = new XenditVACreateRequest
{
ExternalId = "my-VA-fixed-closed-1234568",
BankCode = XenditVABankCode.BNI,
Name = "VA Test",
IsClosedVA = true,
ExpectedAmount = 1350000
};
var va = await xendit.VirtualAccount.CreateAsync(requestedVA);
var availableVABanks = await xendit.VirtualAccount.GetAvailableBanksAsync();
var va = await xendit.VirtualAccount.GetAsync("EXAMPLE_ID");
var expiredVA = await xendit.VirtualAccount.ExpireAsync("EXAMPLE_ID");
var item = new XenditBatchDisbursementCreateRequestItem
{
ExternalId = "My Disb item Id 1",
Amount = 10000,
BankCode = XenditDisbursementBankCode.BRI_SYR,
AccountHolderName = "Buye Loku",
AccountNumber = "1234567890",
Description = "Description for the item disbursement",
EmailTo = new string[] { "buye.loku@example.com", "email2@example.com" }
};
var batchDisbursement = await xendit.Disbursement.CreateBatchAsync(new XenditBatchDisbursementCreateRequest
{
Reference = "My reference Id",
Disbursements = new List<XenditBatchDisbursementCreateRequestItem> { /* put the items here */ }
});
var availableDisbBanks = await xendit.Disbursement.GetAvailableBanksAsync();
var linkAjaPaymentItems = new List<XenditEWalletCreateLinkAjaPaymentRequestItem>
{
new XenditEWalletCreateLinkAjaPaymentRequestItem
{
Id = "id_test_karton123",
Name = "Kertas Karton",
Price = 15000,
Quantity = 2
}
};
var linkAjaPayment = new XenditEWalletCreateLinkAjaPaymentRequest
{
ExternalId = "linkaja-ewallet-1234",
Amount = 30000,
CallbackUrl = "https://example.com/callback_url",
RedirectUrl = "https://example.com/redirect_url",
Phone = "089911111111",
Items = linkAjaPaymentItems
};
var linkAjaPaymentResponse = await xendit.EWallet.CreateLinkAjaPaymentAsync(linkAjaPayment);
var danaPayment = new XenditEWalletCreateDanaPaymentRequest
{
ExternalId = "dana-ewallet-1234",
Amount = 25000,
CallbackUrl = "https://example.com/callback_url",
RedirectUrl = "https://example.com/redirect_url"
};
var danaPaymentResponse = await xendit.EWallet.CreateDanaPaymentAsync(danaPayment);
var ovoPayment = new XenditEWalletCreateOvoPaymentRequest
{
ExternalId = "ovo-ewallet-1234",
Amount = 12500,
Phone = "088889998888"
};
var ovoPaymentResponse = await xendit.EWallet.CreateOvoPaymentAsync(ovoPayment);
You can use other Xendit API version for OVO using ApiVersion
property of XenditEWalletCreateOvoPaymentRequest
, by default it uses the latest version. You can access the predefined versions using XenditEWalletOvoVersion
class. If you are using Visual Studio or Visual Studio Code, you should be able to see the summary of each version.
var payment = await xendit.EWallet.GetPaymentStatusAsync("ovo-ewallet-1234", XenditEWalletType.OVO);
This library throws exception with type XenditHttpResponseException
when the API response is not successful (non 2xx
HTTP status code).
There are some properties of this serializable exception that you can use to track problems related with API request and response.
In order to get response content to know what Xendit API says about the response, you can just use Content
property, you may also want to deserialize it for your need.
Normally these exception's properties are enough to investigate what really happened to the request and response of the corresponding API call, although a bit expensive.
-
There are some Xendit's API endpoints that haven't been implemented to this library:
- Balance
- Credit Card
- Cardless Transaction
- Retail Outlets
- Recurring Payments
- Payouts
-
CI/CD
We welcome any contributions to this project. :)