58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
using Marco.Pms.Model.Employees;
|
|
using Marco.Pms.Model.ViewModels.PaymentGetway;
|
|
using Razorpay.Api;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace Marco.Pms.Services.Helpers
|
|
{
|
|
public class PaymentHelper
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly string key = "YOUR_RAZORPAY_KEY";
|
|
private readonly string secret = "YOUR_RAZORPAY_SECRET";
|
|
public PaymentHelper(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
key = configuration["Razorpay:Key"] ?? "";
|
|
secret = configuration["Razorpay:Secret"] ?? "";
|
|
}
|
|
|
|
public CreateOrderVM CreateOrder(double amount, Employee loggedInEmployee, Guid tenantId)
|
|
{
|
|
RazorpayClient client = new RazorpayClient(key, secret);
|
|
|
|
var receipt = $"rec_{Guid.NewGuid()}";
|
|
var length = receipt.Length;
|
|
|
|
Dictionary<string, object> options = new Dictionary<string, object>
|
|
{
|
|
{ "amount", amount * 100 }, // amount in paise
|
|
{ "currency", "INR" },
|
|
{ "receipt", receipt},
|
|
{ "payment_capture", 1 }
|
|
};
|
|
|
|
Order order = client.Order.Create(options);
|
|
var response = new CreateOrderVM
|
|
{
|
|
OrderId = order["id"],
|
|
Key = key
|
|
};
|
|
return response;
|
|
}
|
|
|
|
public string GetExpectedSignature(string payload)
|
|
{
|
|
string expectedSignature;
|
|
using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret)))
|
|
{
|
|
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(payload));
|
|
expectedSignature = Convert.ToHexString(hash).ToLower();
|
|
}
|
|
|
|
return expectedSignature;
|
|
}
|
|
}
|
|
}
|