Coder Social home page Coder Social logo

thawanisdk's Introduction

ThawaniSDK (.NET) (.NET 5 / .NET Core)

You can download the package from Nuget by clicking here.

The error codes can be found on Thawani Docs.

For creating a Payment Session:

var checkout = new ThawaniPaySDK.Checkout();
//If you have your API Keys and want to use the Production instead of UAT
var checkout = new ThawaniPaySDK.Checkout("apiKey", "publicKey");
var products = new List<ThawaniPaySDK.Models.CommonModels.ProductModel>()
{
    new ThawaniPaySDK.Models.CommonModels.ProductModel()
    {
        name = "Product 1",
        quantity = 1,
        unit_amount = 100
    }
};

var sessionModel = new ThawaniPaySDK.Models.CheckoutModels.CheckoutSessionCreateRequestModel()
{
    success_url = "https://domain.com/success/",
    cancel_url = "https://domain.com/cancel/",
    mode = "payment",
    client_reference_id = "",
    customer_id = "", //If you have a customer id, the customer can save their cards. We will see how you can initiate a payment intent using a saved card
    products = products,
    metadata = new ThawaniPaySDK.Models.CommonModels.MetadataModel()
    {
        customer_email = "[email protected]", //Mandatory
        customer_name = "Customer Name", //Mandatory
        customer_phone = "968 12345678", //Mandatory
        customer_id = "", //Optional
        order_id = "" //Optional
    }
};

var sessionInfo = checkout.CreateSession(sessionModel);
var url = checkout.GeneratePaymentURL(sessionInfo.data.session_id);

The payment status of the Checkout Session, one of paid, unpaid, or cancelled. You can use this value to decide when to fulfill your customer’s order.

For creating a Customer (This is required before you can make Payment Intents):

var customer = new ThawaniPaySDK.Customer();
var customerCreateModel = customer.CreateCustomer(new ThawaniPaySDK.Models.CustomerModels.CustomerCreateRequestModel()
{
    client_customer_id = "",
    //A unique Identification from you, it could be an Email or a UserId.
    //It would later be used for retrieval of the Customer Info
});

var customerDeleteModel = customer.DeleteCustomer("customer_id");
//The above will delete customer

var paymentMethods = new ThawaniPaySDK.PaymentMethods();
var customerPaymentMethods = paymentMethods.ListCustomerPaymentMethods("customer_id");
//This above will list out all of the cards with their Masked Numbers, NickName, Brand and an Id (Payment Method Id)

var paymentMethodDeletedModel = paymentMethods.DeleteCustomerPaymentMethod("payment_method_id");
//The above will delete Payment Method

For creating a Payment Intent:

var paymentIntent = new ThawaniPaySDK.PaymentIntent();
//If you have your API Keys and want to use the Production instead of UAT
var paymentIntent = new ThawaniPaySDK.PaymentIntent("apiKey", "publicKey");
var paymentIntentModel = paymentIntent.CreatePaymentIntent(new ThawaniPaySDK.Models.PaymentIntentModels.CreatePaymentIntentRequestModel()
{
    amount = 100,
    client_reference_id = "", //The Customer Id
    metadata = new ThawaniPaySDK.Models.CommonModels.MetadataModel()
    {
        customer_email = "[email protected]", //Mandatory
        customer_name = "Customer Name", //Mandatory
        customer_phone = "968 12345678", //Mandatory
        customer_id = "", //Optional
        order_id = "" //Optional
    },
    payment_method_id = "", //The Card Id saved at Thawani
    return_url = "https://domain.com/returnURL"
});

var paymentIntentConfirmModel = paymentIntent.ConfirmPaymentIntent(new ThawaniPaySDK.Models.PaymentIntentModels.ConfirmPaymentIntentRequestModel()
{
    amount = 100,
    payment_method_id = "", //The Card Id saved at Thawani
},
paymentIntentModel.data.id);

var paymentIntentURL = paymentIntentConfirmModel.data.next_action.url;

var paymentIntentRetrieveModel = paymentIntent.RetrievePaymentIntent(paymentIntentModel.data.id);

Status of this PaymentIntent, one of requires_payment_method, requires_confirmation, requires_action, cancelled, or succeeded

For further details, you can check Thawani's official docs page.

thawanisdk's People

Contributors

ghulamostafa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.