Giter Site home page Giter Site logo

russkyc / paymongo-sharp Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 2.0 19.45 MB

An unofficial C# client for the Paymongo API

Home Page: https://www.nuget.org/packages/Paymongo.Sharp

License: MIT License

C# 89.68% HTML 7.36% CSS 2.97%
csharp dotnet paymongo paymongo-client paymongo-csharp paymongo-sharp card-payment gcash maya paymaya

paymongo-sharp's Introduction

Paymongo.Sharp - The Unofficial Paymongo API Client for .NET

Nuget

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.

⬇️ Installation



Nuget

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>");

⭐ Payments Demo

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.

✨ What API Actions are currently Supported

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 Support (Paymongo API v1)

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+

💥 Breaking Changes

  • (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 from paymongo_sharp

📓 Basic Client API Reference

If you want to get started with this Paymongo client, you can check the refernces for basic usage below.

Checkout

  • 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


Payment Intent

  • 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


Payment Method

  • 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


Payments

  • 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


Links API

  • 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


Webhooks

  • 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


Refunds

  • Create a Refund
  • Retrieve a Refund
  • List all Refunds

For full Refunds API reference, please see: Refund Resource


Customers

  • 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


Sources (Gcash and GrabPay Checkout)

  • 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

Treasury has a couple of sub sections

Wallet
  • Retrieve Wallet by ID
  • Retrieve Wallet Accounts

For full Transaction History API reference, please see: Wallet Account Resource

Send Money
  • Create a Wallet Transaction
  • Retrieve List of all Receiving Institutions

For full Send Money API reference, please see: Wallet Transaction Resource

Disbursemenet
  • Create a Batch Transaction

For full Transaction History API reference, please see: Batch Transaction Resource

Transaction History
  • 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


Installments

  • List Installment Plans

For full Installments API reference, please see: List Installment Plans


Future Plans

Fluent Builder

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.

1. Current
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);
2. Future Fluent Builder
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();

Other Plans

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!


❤️ Donate

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 ❤️

🎉 Special Thanks

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.

JetBrains Logo (Main) logo.

paymongo-sharp's People

Contributors

russkyc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

cmejia49 essijie

paymongo-sharp's Issues

[Possible Bug] Payment link creation results in a 400(Bad Request) error

First, I want to express my gratitude for the amazing work you’ve done on this project. I've been using the library for quite some time now and I find it really easy to use.

I am not sure whether Paymongo has changed something on their API because right now I am getting 400 (Bad request) when creating a Payment Link. Upon checking their API doc, I found out that the Amount is integer but the library has decimal datatype - which perhaps is the culprit.

https://developers.paymongo.com/reference/create-a-link

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.