phonepe-pg-sdk-dotnet
2.1.3
dotnet add package phonepe-pg-sdk-dotnet --version 2.1.3
NuGet\Install-Package phonepe-pg-sdk-dotnet -Version 2.1.3
<PackageReference Include="phonepe-pg-sdk-dotnet" Version="2.1.3" />
<PackageVersion Include="phonepe-pg-sdk-dotnet" Version="2.1.3" />
<PackageReference Include="phonepe-pg-sdk-dotnet" />
paket add phonepe-pg-sdk-dotnet --version 2.1.3
#r "nuget: phonepe-pg-sdk-dotnet, 2.1.3"
#:package phonepe-pg-sdk-dotnet@2.1.3
#addin nuget:?package=phonepe-pg-sdk-dotnet&version=2.1.3
#tool nuget:?package=phonepe-pg-sdk-dotnet&version=2.1.3
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:
clientIdclientSecretclientVersion
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,ValidateCallbackwill throw aPhonePeException.
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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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 | Versions 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.2)
- Microsoft.Extensions.Http (>= 9.0.2)
- Microsoft.Extensions.Logging (>= 9.0.2)
- Microsoft.Extensions.Logging.Console (>= 9.0.2)
- Newtonsoft.Json (>= 13.0.3)
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 |
|---|