phonepe-pg-sdk-dotnet 2.1.3

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package phonepe-pg-sdk-dotnet --version 2.1.3
                    
NuGet\Install-Package phonepe-pg-sdk-dotnet -Version 2.1.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="phonepe-pg-sdk-dotnet" Version="2.1.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="phonepe-pg-sdk-dotnet" Version="2.1.3" />
                    
Directory.Packages.props
<PackageReference Include="phonepe-pg-sdk-dotnet" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add phonepe-pg-sdk-dotnet --version 2.1.3
                    
#r "nuget: phonepe-pg-sdk-dotnet, 2.1.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package phonepe-pg-sdk-dotnet@2.1.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=phonepe-pg-sdk-dotnet&version=2.1.3
                    
Install as a Cake Addin
#tool nuget:?package=phonepe-pg-sdk-dotnet&version=2.1.3
                    
Install as a Cake Tool

PhonePe PG .NET SDK Installation & Quick Start Guide

Minimum Requirements

  • .NET Version: v8.0

Installation

Install the dependency via the CLI:

dotnet add package phonepe-pg-sdk-dotnet --version 2.1.2

Quick Start

To get your API keys, visit the PhonePe PG Merchant Onboarding Portal.

You will need the following credentials:

  • clientId
  • clientSecret
  • clientVersion

Class Initialization

Create an instance of StandardCheckoutClient using your credentials.

using Microsoft.Extensions.Logging;
using pg_sdk_dotnet;
using pg_sdk_dotnet.Payments.v2;

// Initialize logger  
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
    builder.AddConsole();
});

string clientId = "<clientId>";
string clientSecret = "<clientSecret>";
int clientVersion = 1; // Your client version

Env env = Env.SANDBOX; // Use Env.PRODUCTION in live mode

StandardCheckoutClient checkoutClient = StandardCheckoutClient.GetInstance(
    clientId,
    clientSecret,
    clientVersion,
    env,
    loggerFactory // null if you do not want logging enabled
);

Note:
If you donot want logs from SDK pass null instead of loggerFactory as the 5th parameter in the checkoutClient.


Initiate an Order Using Checkout Page

To initiate a payment, use the StandardCheckoutPayRequest.Builder() and invoke the Pay method.

Code Example

using pg_sdk_dotnet.Payments.v2;
using pg_sdk_dotnet.Payments.v2.Models.Request;
using pg_sdk_dotnet.Payments.v2.Models.Response;

var merchantOrderID = Guid.NewGuid().ToString();;
var amount= 100;
var redirectUrl = "https://www.merchant.com/redirect";

var payRequest = StandardCheckoutPayRequest.Builder()
    .SetMerchantOrderId(merchantOrderID)
    .SetAmount(amount)
    .SetRedirectUrl(redirectUrl)
    .Build();

StandardCheckoutPayResponse payResponse = await checkoutClient.Pay(payRequest);

Console.WriteLine("Redirect URL: " + payResponse.RedirectUrl);

Check Status of an Order

Use GetOrderStatus to fetch the status of an order:

using pg_sdk_dotnet;
using pg_sdk_dotnet.Payments.v2;

var merchantOrderID  = "<INSERT_ORDER_ID>"; // merchantOrderID passed in the Pay request

var orderStatusResponse = await checkoutClient.GetOrderStatus(merchantOrderID);
Console.WriteLine("Order Status: " + orderStatusResponse.State);

You can extract the state and other order details from the response object.


Callback Handling

You will receive a callback from PhonePe on the configured URL in the dashboard. It is essential to validate the callback using ValidateCallback.

using System.Text.Json;
using pg_sdk_dotnet.Common.Models.Response;
using pg_sdk_dotnet.Payments.v2;

string authorizationHeaderData = "ef4c914c591698b268db3c64163eafda7209a630f236ebf0eebf045460df723a"; // Received in the response headers
string phonepeS2SCallbackResponseBodyString = @"{
    ""event"": ""pg.order.completed"",
    ""payload"": { 
    }
}";

var usernameConfigured = "<MERCHANT_USERNAME>";
var passwordConfigured = "<MERCHANT_PASSWORD>";

CallbackResponse callbackResponse = checkoutClient.ValidateCallback(
    usernameConfigured,
    passwordConfigured,
    authorizationHeaderData,
    phonepeS2SCallbackResponseBodyString
);

var orderId = callbackResponse.payload.orderId;
var state = callbackResponse.payload.state;

Note:
If the callback is invalid, ValidateCallback will throw a PhonePeException.


Create SDK Order

Use CreateSdkOrder to initiate an order for SDK-based integration (e.g., native apps):

using pg_sdk_dotnet.Common.Models.Request;
using pg_sdk_dotnet.Common.Models.Response;
using pg_sdk_dotnet.Payments.v2;
using pg_sdk_dotnet.Payments.v2.Models.Request;
using pg_sdk_dotnet.Payments.v2.Models.Response;

var redirectUrl = "https://www.merchant.com/redirect";
var merchantOrderID = Guid.NewGuid().ToString();;
var amount = 100;

var sdkOrderRequest = CreateSdkOrderRequest.StandardCheckoutBuilder()
    .SetMerchantOrderId(merchantOrderID)
    .SetAmount(amount)
    .SetDisablePaymentRetry(true)
    .SetRedirectUrl(redirectUrl)
    .Build();

CreateSdkOrderResponse createSdkOrderResponse = await checkoutClient.CreateSdkOrder(sdkOrderRequest);

var token = createSdkOrderResponse.Token;

The function returns a CreateSdkOrderResponse object. Merchant should retrieve the token from the received response.

Documentation

For detailed API documentation, advanced features, and integration options:

Contributing

Contributions to the PhonePe PG SDK for PHP are welcome. Here's how you can contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please ensure your code follows the project's coding standards and includes appropriate tests.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Copyright 2025 PhonePe Private Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated