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.
Request
Use StandardCheckoutPayRequest.builder() to create the payment request. Below are the key attributes you can set:
| Paramters | Type | Mandatory | Description | Constraints |
amount | Number | Yes | Order amount in Paisa | Minimum amount should be 100 Paisa |
merchantOrderId | String | Yes | The unique order ID assigned by the merchant | Length should be less than 63 characters<br/>2. No special characters allowed except underscore “_” and hyphen “-“ |
| paymentModeConfig | PaymentModeConfig | No | Only enabled or disabled modes can be passed in the request | PaymentModeConstraint |
redirectUrl | String | No | URL where user will be redirected after success/failed payment. |
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));Response
The function returns a StandardCheckoutPayResponse object with the following properties:
| Parameter Name | Data Type | Description |
state | String | State of the order. Expected value is PENDING. |
redirectUrl | String | The url for the PG Standard Checkout (merchant is supposed to redirect user to complete payment) |
orderId | String | Order Id created by PhonePe |
expireAt | Long | Order expire date in epoch |
What’s Next?
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 .