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
amountNumberYesOrder amount in PaisaMinimum amount should be 100 Paisa
merchantOrderIdStringYesThe unique order ID assigned by the merchantLength should be less than 63 characters<br/>2. No special characters allowed except underscore “_” and hyphen “-“
paymentModeConfigPaymentModeConfigNoOnly enabled or disabled modes can be passed in the requestPaymentModeConstraint
redirectUrlStringNoURL where user will be redirected after success/failed payment.
Sample Request
var redirectUrl = "https://www.merchant.com/redirect";
var metaInfo = MetaInfo.builder()
                    .udf1("udf1")
                    .udf2("udf2")
                    .build();
  
var merchantOrderID = Guid.NewGuid().ToString();
 
var payRequest = StandardCheckoutPayRequest.Builder()
            .SetMerchantOrderId(merchantOrderID)
            .SetAmount(100)
            .SetRedirectUrl(redirectUrl)
            .SetExpireAfter(300)
            .SetMetaInfo(metaInfo)
            .SetMessage("message")
            .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?