Initiate Payment with .NET SDK


The Initiate Payment step allows you to start a payment transaction by creating a payment request with essential details like order ID, amount, and redirect URL. This request prepares the transaction on PhonePe’s platform and generates a redirect URL where users complete their payment securely.

Use StandardCheckoutPayRequest.builder() to create the payment request. Below are the key attributes you can set:

ParamtersTypeMandatoryDescriptionConstraints
amountLongYesOrder amount in PaisaMinimum amount should be 100 Paisa
merchantOrderIdStringYesThe unique order ID assigned by the merchantLength should be less than 63 characters.
No special characters allowed except underscore “_” and hyphen “-“
metaInfoObjectNoMeta information is defined by you to store additional information. The same data will be returned in status and callback response.
metaInfo.udf1-15StringNoOptional details you can add for more information.Maximum length = 256 characters
redirectUrlStringNoURL where user will be redirected after success/failed payment.
Sample Request
using pg_sdk_dotnet.Common.Models;

var redirectUrl = "https://www.merchant.com/redirect";
var metaInfo = MetaInfo.Builder()
                    .SetUdf1("udf1")
                    .SetUdf2("udf2") // upto 15 udf's can be passed
                    .Build();
  
var merchantOrderID = Guid.NewGuid().ToString();
 
var payRequest = StandardCheckoutPayRequest.Builder()
            .SetMerchantOrderId(merchantOrderID)
            .SetAmount(100)
            .SetRedirectUrl(redirectUrl)
            .SetExpireAfter(300)
            .SetMetaInfo(metaInfo)
            .Build();
 
StandardCheckoutPayResponse response = await checkoutClient.Pay(payRequest);
logger.LogInformation("Pay API Response:\n{Response}", JsonSerializer.Serialize(response, JsonOptions.IndentedWithRelaxedEscaping));

The function returns a StandardCheckoutPayResponse object with the following properties:

Parameter NameData TypeDescription
stateStringState of the order. Expected value is PENDING.
redirectUrlStringThe url for the PG Standard Checkout (merchant is supposed to redirect user to complete payment)
orderIdStringOrder Id created by PhonePe
expireAtLongOrder expire date in epoch

After using the pay method to initiate a payment via the PhonePe PG, you can create a payment request and start the payment process. The next step is to create the order SDK.

Proceed to the next section to learn how to Create Order SDK .

Is this article helpful?