Paymongo is a powerful payment platform that provides a wide range of payment solutions for businesses of all sizes. With the Paymongo API, you can integrate payment processing into your .NET applications, allowing you to securely accept payments, manage transactions, and more.
This client wrapper is designed to make it easy for .NET developers to interact with the Paymongo API. It provides a simple, intuitive interface that abstracts the API, allowing you to access a typed client and focus on building your Paymongo-integrated application faster.
Install package from: Nuget using nuget cli or the nuget package manager.
Add Imports
using Paymongo.Sharp;
Initialize Client
var client = new PaymongoClient(secretKey: "<secret_key>");
Cli (Console)
WPF (With WebView 2 Control)
Blazor
This nuget package is not limited to these samples, it also supports the all .NET platforms including mono, android, and others.
This client is in active development and features are slowly being implemented but not all of them are supported as of now. You can track the support for all of Paymongo's official API actions below:
API Resource | Status | Added on |
---|---|---|
Checkout | Full | v0.1.2-pre+ |
Payment Intent | Not yet available | Not yet Added |
Payment Method | Not yet available | Not yet Added |
Payments | Full | v0.2.0+ |
Links | Full | v0.3.0+ |
Webhooks | Not yet available | Not yet Added |
Customers | Partial | v0.5.0+ |
Treasury | Not yet available | Not yet Added |
Installments | Not yet available | Not yet Added |
Sources | Full | v0.4.0+ |
- (v0.5.1+) All amount related properties should now be a
decimal
(up to 2 decimal places) - (v0.2.0+) PaymongoClient now only needs a Secret Key on initialization
- (v0.1.1-pre+) Updated root namespace to
Paymongo.Sharp
frompaymongo_sharp
If you want to get started with this Paymongo client, you can check the refernces for basic usage below.
- Create Checkout Session
- Retrieve a Checkout Session
- Expire a Checkout Session
Create a Checkout Session
// We create a new Checkout object
// This one includes the minimal required values
Checkout checkout = new Checkout() {
Description = "Test Checkout",
LineItems = new [] {
new LineItem {
Name = "item_name",
Quantity = 1,
Currency = Currency.Php,
Amount = 3500
}
},
PaymentMethodTypes = new [] {
PaymentMethod.GCash,
PaymentMethod.Card,
PaymentMethod.Paymaya
}
};
// We use the PaymongoClient from earlier
// This returns the Checkout object with the new server info for checkout url, id, and others
Checkout checkoutResult = await client.Checkouts.CreateCheckoutAsync(checkout);
Retrieve a Checkout Session
// We use the PaymongoClient from earlier
// Lets assume that the checkout id is "12345678"
// This returns a Checkout object from the server
Checkout checkoutResult = await client.Checkouts.RetrieveCheckoutAsync("12345678");
Expire a Checkout Session
// We use the PaymongoClient from earlier
// Lets assume that the checkout id is "12345678"
// This expires the checkout on the server and returns the expired Checkout object
Checkout checkoutResult = await client.Checkouts.ExpireCheckoutAsync("12345678");
For full Checkout API reference, please see: Checkout Session Resource
- Create Payment Intent
- Retrieve a Payment Intent
- Attach to a Payment Intent
- Attach to a Payment Intent
Pre Authorization and Capture
- Capture a Payment Intent
- Cancel a Payment Intent
For full Payment API reference, please see: The Payment Intent Object, (Pre-Authorization) Capture, (Pre-Authorization) Cancel
- Retrieve list of possible merchant payment methods
- Create a payment method
- Retrieve a payment method
- Update a payment method
For full Payment Method API reference, please see: The Payment Method Object
- Create a Payment
- List all Payments
- Retrieve a Payment
List All Payments
// We use the PaymongoClient from earlier
// This returns a list of Payment objects
IEnumerable<Payment> paymentsResult = await client.Payments.ListAllPaymentsAsync();
Retrieve a Payment
// We use the PaymongoClient from earlier
// Lets assume that the payment id is "12345678"
// This returns a Payment object from the server
Payment paymentResult = await client.Payments.RetrievePaymentAsync("12345678");
For full Payments API reference, please see: Payment Resource
- Create a Link
- Retrieve a Link
- Get Link by Reference Number
- Archive a Link
- Unarchive a Link
Create a Link
// We create a new Link object
// This one includes the minimal required values
Link link = new Link {
Description = "New Link",
Amount = 100000,
Currency = Currency.Php
};
// We use the PaymongoClient from earlier
// This returns the Link object with the new server info for checkout url, id, and others
Link linkResult = await client.Links.CreateLinkAsync(link);
Retrieve a Link
// We use the PaymongoClient from earlier
// Lets assume that the link id is "12345678"
// This returns a Link object from the server
Link linkResult = await client.Links.RetrieveLinkAsync("12345678");
Get Link by Reference Number
// We use the PaymongoClient from earlier
// Lets assume that the link id is "ABCD1234"
// This returns a Link object from the server
Link linkResult = await client.Links.GetLinkByReferenceNumberAsync("ABCD1234");
Archive a Link
// We use the PaymongoClient from earlier
// Lets assume that the Link id is "12345678"
// This returns the updated archived Link object
Link linkResult = await client.Links.ArchiveLinkAsync("12345678");
Unarchive a Link
// We use the PaymongoClient from earlier
// Lets assume that the payment id is "12345678"
// This returns the updated un-archived Link object
Link linkResult = await client.Links.UnarchiveLinkAsync("12345678");
For full Links API reference, please see: Links Resource
- Create a Webhook
- List all Webhooks
- Retrieve a Webhook
- Disable a Webhook
- Enable a Webhook
- Update a Webhook
For full Webhook API reference, please see: Webhook Resource
- Create a Refund
- Retrieve a Refund
- List all Refunds
For full Refunds API reference, please see: Refund Resource
- Create a Customer
- Retrieve a Customer
- Edit a Customer
- Delete a Customer
- Retrieve the Payment Methods of a Customer
- Delete a Payment Method of a Customer
Create a Customer
// We create a new Customer object
// This one includes the minimal required values
Customer customer = new Customer() {
FirstName = "First Name",
LastName = "Last Name",
Email = "[email protected]",
Phone = "+639234735258",
DefaultDevice = Device.Email
};
// We use the PaymongoClient from earlier
// This returns a Customer object from the server with an Id as confirmation
Customer customerResult = await client.Customers.CreateCustomerAsync(customer);
Retrieve a Customer
// We use the PaymongoClient from earlier
// Lets assume that the customer email is "[email protected]"
// Lets assume that the customer phone number is "+639876543210"
// This returns a Customer object from the server
Customer customerResult = await client.Customers.RetrieveCustomerAsync("[email protected]", "+639876543210");
Edit a Customer
// First lets get the customer we want to edit
Customer customerResult = await client.Customers.RetrieveCustomerAsync("[email protected]", "+639876543210");
// Lets edit some of the customer information
customerResult.FirstName = "New First Name";
customerResult.LastName = "New Last Name";
// After this update executes, this returns the Customer object with the updated information
var editCustomerResult = await client.Customers.EditCustomerAsync(customerResult);
Delete a Customer
// We use the PaymongoClient from earlier
// Lets assume that the customer id is "12345678"
// This returns true if the customer is deleted successfuly
bool deletedCustomerResult = await client.Customers.DeleteCustomerAsync("12345678");
For full Customers API reference, please see: Customer Resource
- Create a Source
- Retrieve a Source
Create a Source
// We create a new Source object
// This one includes the minimal required values
Source source = new Source {
Amount = 100000,
Billing = new Billing {
Name = "TestName",
Email = "[email protected]",
Phone = "9734534443",
Address = new Address {
Line1 = "TestAddress1",
Line2 = "TestAddress2",
PostalCode = "4506",
State = "TestState",
City = "TestCity",
Country = "PH"
}
},
Redirect = new Redirect {
Success = "http://127.0.0.1",
Failed = "http://127.0.0.1"
},
Type = SourceType.GCash,
Currency = Currency.Php
};
// We use the PaymongoClient from earlier
// This returns a Source object from the server
// containing the redirect object(with checkout url) and other info
Source sourceResult = await client.Sources.CreateSourceAsync(source);
Retrieve a Source
// We use the PaymongoClient from earlier
// Lets assume that the Source id is "12345678"
// This returns a Source object from the server
Link sourceResult = await client.Sources.RetrieveSourceAsync("12345678");
For full Sources API reference, please see: The Sources Object
Treasury has a couple of sub sections
- Retrieve Wallet by ID
- Retrieve Wallet Accounts
For full Transaction History API reference, please see: Wallet Account Resource
- Create a Wallet Transaction
- Retrieve List of all Receiving Institutions
For full Send Money API reference, please see: Wallet Transaction Resource
- Create a Batch Transaction
For full Transaction History API reference, please see: Batch Transaction Resource
- Retrieve a Wallet Transaction By ID
- Retrieve List of Wallet Transactions
- Retrieve List of Batches
- Retrieve Batch Object
For full Transaction History API reference, please see: Retrieve a Wallet Transaction By ID
- List Installment Plans
For full Installments API reference, please see: List Installment Plans
Something that I have in mind that might be easier to work with, for context let's compare the current api usage and the future fluent builder implementation for the Checkouts client.
var client = new PaymongoClient(secretKey: "<secret_key>");
Checkout checkout = new Checkout() {
Description = "Test Checkout",
LineItems = new [] {
new LineItem {
Name = "Item Name",
Quantity = 1,
Currency = Currency.Php,
Amount = 3500
}
},
PaymentMethodTypes = new [] {
PaymentMethod.GCash,
PaymentMethod.Card,
PaymentMethod.Paymaya
}
};
Checkout checkoutResult = await client.Checkouts.CreateCheckoutAsync(checkout);
var client = new PaymongoClient(secretKey: "<secret_key>");
Checkout checkoutResult = await CheckoutBuilder
.WithDescription("Test Checkout")
.WithLineItem(
LineItemBuilder.WithName("Item Name")
.WithQuantity(1)
.WithAmount(3500)
.WithCurrency(Currency.Php)
)
.WithPaymentMethod(PaymentMethod.Gcash)
.WithPaymentMethod(PaymentMethod.Card)
.WithPaymentMethod(PaymentMethod.Paymaya)
.CreateCheckoutAsync();
What do you think should be implemented in future versions of the client? Let your ideas be known and open an issue with a [feature-request] tag and it might make it into future updates. Or, if you tried something that works and is awesome try opening a pull request and if all is good, your contribution can be implemented into the project!
This is free and available for everyone to use, but still requires time for development and maintenance. By choosing to donate, you are not only helping develop this project, but you are also helping me dedicate more time for creating more tools that help the community ❤️
This project is made easier to develop by Jetbrains! They have provided Licenses to their IDE's to support development of this open-source project.