Gagri Global IT services is having a team of executives who have good experience in developing applications on various platforms like SharePoint 2013/2010, Silverlight, net Framework 4.5 and Mobile tools.
Posted on December 14, 2023 by Amruthavalli
private static string CalculateSha256Hash(string payload)
{
using (SHA256 sha256 = SHA256.Create())
{
byte[] inputBytes = Encoding.UTF8.GetBytes(payload);
byte[] hashBytes = sha256.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("x2"));
}
sb.Append("###1");
return sb.ToString();
}
}
public async Task
{
var apiUrl = "your localhost sandbox api url";
var client = new RestClient(apiUrl);
var url = client.BaseUrl;
var base64Payload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(paymentRequest)));
string saltKey = "your salt key value";
var payload = base64Payload + "/pg/v1/pay" + saltKey;
var verifyHeaderValue = CalculateSha256Hash(payload);
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("X-VERIFY", verifyHeaderValue);
var jsonRequest = new
{
request = base64Payload
};
request.AddJsonBody(jsonRequest);
IRestResponse response = client.Execute(request
if (response.StatusCode == HttpStatusCode.OK
{
var responseBody = response.Content;
var responseObject = JObject.Parse(responseBody);
return Ok(responseObject
}
else
{
var errorResponse = response.Content;
return BadRequest(errorResponse);
//return BadRequest(response.Content);
}
}
public class PaymentRequestDto
{
public string merchantId { get; set; }
public string merchantTransactionId { get; set; }
public string merchantUserId { get; set;
public decimal amount { get; set; }
public string redirectUrl { get; set; }
public string redirectMode { get; set; }
public string callbackUrl { get; set; }
public string mobileNumber { get; set; }
public PaymentInstrumentDto paymentInstrument { get; set; }
}
public class PaymentInstrumentDto
{
public string type { get; set;
}
public class PaymentResponse
{
public bool Success { get; set; }
public string Code { get; set; }
public string Message { get; set; }
public PaymentData Data { get; set; }
}
public class PaymentData
{
public string MerchantId { get; set; }
public string MerchantTransactionId { get; set; }
public InstrumentResponse InstrumentResponse { get; set; }
}
public class InstrumentResponse
{
public string Type { get; set; }
public RedirectInfo RedirectInfo { get; set; }
}
public class RedirectInfo
{
public string Url { get; set; }
public string Method { get; set; }
}
public class refund
{
// Define the properties of the refund class here
public string PropertyName { get; set; }
// ...
}
Paywithphonepe123(Package_ID) {
debugger
var d = new Date(),
n = d.getTime();
this.TaxnId = n;
const apiUrl = `send your api url`;
const httpHeaders = new HttpHeaders({
'Content-Type': 'application/json',
'X-VERIFY': 'your xverify value',
}); // Replace with your headers
const dynamicCallbackUrl = 'your payment status call back url';
this.paymentRequest = {
"merchantId": "PGTESTPAYUAT91",
"merchantTransactionId": "MT7850590068188114",
"merchantUserId": "MUID123",
"amount": 10000,
"redirectUrl": "https://webhook.site/redirect-url",
"redirectMode": "POST",
"callbackUrl": "https://webhook.site/callback-url",
"mobileNumber": "9999999999",
"paymentInstrument": {
"type": "PAY_PAGE"
} // this is my sample payment request
};
debugger
this.https.post(apiUrl, this.paymentRequest, { headers: httpHeaders }).subscribe(
(response: any) => {
debugger
let redirectUrl = response.data.instrumentResponse.redirectInfo.url;
window.location.href = redirectUrl;
console.log('API response:', response);
localStorage.setItem("TransId", this.TaxnId);
// this.Gettransactionstatus(this.TaxnId, Package_ID);
}, (error: any) => {
console.error('API error:', error);
}
)
}
All design and content Copyright © 2012-2018 Gagri Global IT Services Pvt.Ltd. All rights reserved