2 Commits 2fba8b6ef1 ... 1a87e57644

Autor SHA1 Nachricht Datum
  zinab_elgendy 1a87e57644 merge payment branch vor 2 Monaten
  zinab_elgendy c678e86012 amazonPay settings vor 3 Monaten

+ 20 - 0
MTWorkHR.API/Controllers/CallbackController.cs

@@ -0,0 +1,20 @@
+using Microsoft.AspNetCore.Mvc;
+
+[ApiController]
+[Route("api/[controller]")]
+public class CallbackController : ControllerBase
+{
+    [HttpGet("review")]
+    public IActionResult CheckoutReview()
+    {
+        // Handle review page logic
+        return Ok("Review page");
+    }
+
+    [HttpGet("result")]
+    public IActionResult CheckoutResult()
+    {
+        // Handle payment result logic
+        return Ok("Result page");
+    }
+}

+ 21 - 33
MTWorkHR.API/Controllers/PaymentController.cs

@@ -1,40 +1,28 @@
-using Microsoft.AspNetCore.Authorization;
-
-using Microsoft.AspNetCore.Mvc;
-using MTWorkHR.Application.Filters;
+using Microsoft.AspNetCore.Mvc;
 using MTWorkHR.Application.Services.Interfaces;
+using System.Threading.Tasks;
 
-namespace MTWorkHR.API.Controllers
+[ApiController]
+[Route("api/[controller]")]
+public class PaymentController : ControllerBase
 {
-    [Route("api/[controller]")]
-    [ApiController]
-    [AppAuthorize]
-    public class PaymentController : ControllerBase
-    {
-        private readonly IMatchMoveService _PaymentService;
-        public PaymentController(IMatchMoveService PaymentService)
-        {
-            this._PaymentService = PaymentService;
-        }
-      
-        [HttpPost]
-        public async Task<IActionResult> ProcessPayment([FromBody] object paymentRequest)
-        {
-            try
-            {
-                // Step 1: Get OAuth token
-                var token = await _PaymentService.GetAccessTokenAsync();
-
-                // Step 2: Process the payment
-                var response = await _PaymentService.ProcessPaymentAsync(token, paymentRequest);
+    private readonly IAmazonPayService _amazonPayService;
 
-                return Ok(response); // Return the MatchMove API response
-            }
-            catch (Exception ex)
-            {
-                return BadRequest(new { error = ex.Message });
-            }
-        }
+    public PaymentController(AmazonPayService amazonPayService)
+    {
+        _amazonPayService = amazonPayService;
+    }
 
+    [HttpPost("checkout")]
+    public async Task<IActionResult> CreateCheckoutSession([FromBody] CheckoutRequest request)
+    {
+        var response = await _amazonPayService.CreateCheckoutSessionAsync(request.Amount, request.CurrencyCode);
+        return Ok(response);
     }
 }
+
+public class CheckoutRequest
+{
+    public decimal Amount { get; set; }
+    public string CurrencyCode { get; set; }
+}

+ 7 - 0
MTWorkHR.API/appsettings.json

@@ -53,6 +53,13 @@
     "ClientSecret": "your-client-secret",
     "GrantType": "client_credentials"
   },
+  "AmazonPay": {
+    "MerchantId": "YOUR_MERCHANT_ID",
+    "AccessKey": "YOUR_ACCESS_KEY",
+    "SecretKey": "YOUR_SECRET_KEY",
+    "Region": "us", // or "eu", "jp" depending on your region
+    "Sandbox": true // Set to false for production
+  },
 
   "AllowedHosts": "*"
 }

+ 4 - 0
MTWorkHR.Application/ApplicationServiceRegistration.cs

@@ -43,6 +43,10 @@ namespace MTWorkHR.Application
             services.AddScoped<ILogService<UserLog>, LogService<UserLog>>();
             services.AddScoped<ISubscriptionService, SubscriptionService>();
             services.AddScoped<IMatchMoveService, MatchMoveService>();
+            services.AddScoped<IAmazonPayService, AmazonPayService>();
+
+            services.AddHttpClient<AmazonPayService>();
+
 
             return services;
         }

+ 13 - 0
MTWorkHR.Application/Services/Interfaces/Payment/IAmazonPayService.cs

@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Application.Services.Interfaces
+{
+    public interface IAmazonPayService
+    {
+        Task<string> CreateCheckoutSessionAsync(decimal amount, string currencyCode);
+    }
+}

+ 68 - 0
MTWorkHR.Application/Services/Payment/AmazonPayService.cs

@@ -0,0 +1,68 @@
+using System.Net.Http;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Configuration;
+using MTWorkHR.Application.Services.Interfaces;
+using Newtonsoft.Json;
+
+public class AmazonPayService: IAmazonPayService
+{
+    private readonly HttpClient _httpClient;
+    private readonly string _merchantId;
+    private readonly string _accessKey;
+    private readonly string _secretKey;
+    private readonly string _region;
+    private readonly bool _sandbox;
+
+    public AmazonPayService(IConfiguration configuration, HttpClient httpClient)
+    {
+        _httpClient = httpClient;
+        _merchantId = configuration["AmazonPay:MerchantId"];
+        _accessKey = configuration["AmazonPay:AccessKey"];
+        _secretKey = configuration["AmazonPay:SecretKey"];
+        _region = configuration["AmazonPay:Region"];
+        _sandbox = configuration.GetValue<bool>("AmazonPay:Sandbox");
+    }
+
+    public async Task<string> CreateCheckoutSessionAsync(decimal amount, string currencyCode)
+    {
+        var baseUrl = _sandbox ? "https://pay-api.amazon.com/sandbox" : "https://pay-api.amazon.com";
+        var endpoint = $"{baseUrl}/{_region}/checkout-sessions";
+
+        var payload = new
+        {
+            checkoutReviewReturnUrl = "https://yourwebsite.com/review",
+            checkoutResultReturnUrl = "https://yourwebsite.com/result",
+            chargeAmount = new
+            {
+                amount = amount.ToString("F2"),
+                currencyCode = currencyCode
+            },
+            merchantMetadata = new
+            {
+                merchantReferenceId = Guid.NewGuid().ToString(),
+                merchantStoreName = "Your Store Name"
+            }
+        };
+
+        var content = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json");
+
+        // Add required headers
+        _httpClient.DefaultRequestHeaders.Clear();
+        _httpClient.DefaultRequestHeaders.Add("x-amz-pay-idempotency-key", Guid.NewGuid().ToString());
+        _httpClient.DefaultRequestHeaders.Add("x-amz-pay-authtoken", GenerateAuthToken());
+
+        var response = await _httpClient.PostAsync(endpoint, content);
+        response.EnsureSuccessStatusCode();
+
+        var responseBody = await response.Content.ReadAsStringAsync();
+        return responseBody;
+    }
+
+    private string GenerateAuthToken()
+    {
+        // Implement Amazon Pay's signature calculation logic here.
+        // Refer to Amazon Pay's documentation for details: https://developer.amazon.com/docs/amazon-pay-api/signature.html
+        return "YOUR_AUTH_TOKEN";
+    }
+}

+ 44 - 0
MTWorkHR.Infrastructure/Configurations/SubscriptionLimitsConfiguration.cs

@@ -0,0 +1,44 @@
+using Microsoft.AspNetCore.Identity;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Entities;
+using Countries.NET.Database;
+using System.Runtime.ConstrainedExecution;
+
+namespace MTWorkHR.Infrastructure.Configurations
+{
+    public class SubscriptionLimitsConfiguration : IEntityTypeConfiguration<SubscriptionConfiguration>
+    {
+
+        public void Configure(EntityTypeBuilder<SubscriptionConfiguration> builder)
+        {
+            
+            builder.HasData(
+                new SubscriptionConfiguration {
+                    Id = 1,
+                    ContractDocumentationFees =0,
+                    CreateDate = new DateTime(2025, 1,1),
+                    DeductedFirstSearchAmount=0,
+                    DistinguishedEmployeeCompanyFeesPerc=0,
+                    DistinguishedEmployeePerc=0,
+                    ExperienceCertificateFees=0,
+                    FirstRegisterationCompanyFees=0,
+                    MonthlyCompanyFees=0,
+                    MonthlyEmployeeServicesCompanyFees=0,
+                    OrdinaryEmployeePerc=0, 
+                    RequestDisputeResolutionFees=0,
+                    YearlyCompanyFees=0,
+                    IsDeleted=false,
+                    CreateUser = "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA",
+                }
+            );
+        }
+    }
+}

Datei-Diff unterdrückt, da er zu groß ist
+ 5846 - 0
MTWorkHR.Infrastructure/Migrations/20250112135729_addSubscLimitDefault.Designer.cs


+ 29 - 0
MTWorkHR.Infrastructure/Migrations/20250112135729_addSubscLimitDefault.cs

@@ -0,0 +1,29 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class addSubscLimitDefault : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.InsertData(
+                table: "SubscriptionConfiguration",
+                columns: new[] { "Id", "ContractDocumentationFees", "CreateDate", "CreateUser", "DeductedFirstSearchAmount", "DeleteUserId", "DistinguishedEmployeeCompanyFeesPerc", "DistinguishedEmployeePerc", "ExperienceCertificateFees", "FirstRegisterationCompanyFees", "IsDeleted", "MonthlyCompanyFees", "MonthlyEmployeeServicesCompanyFees", "OrdinaryEmployeePerc", "RequestDisputeResolutionFees", "UpdateDate", "UpdateUser", "YearlyCompanyFees" },
+                values: new object[] { 1L, 0m, new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA", 0m, null, 0m, 0m, 0m, 0m, false, 0m, 0m, 0m, 0m, null, null, 0m });
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DeleteData(
+                table: "SubscriptionConfiguration",
+                keyColumn: "Id",
+                keyValue: 1L);
+        }
+    }
+}

+ 20 - 0
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -4258,6 +4258,26 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.HasKey("Id");
 
                     b.ToTable("SubscriptionConfiguration");
+
+                    b.HasData(
+                        new
+                        {
+                            Id = 1L,
+                            ContractDocumentationFees = 0m,
+                            CreateDate = new DateTime(2025, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
+                            CreateUser = "ADMB3B92-2311-48F8-9DEC-F9FAEF1F21UA",
+                            DeductedFirstSearchAmount = 0m,
+                            DistinguishedEmployeeCompanyFeesPerc = 0m,
+                            DistinguishedEmployeePerc = 0m,
+                            ExperienceCertificateFees = 0m,
+                            FirstRegisterationCompanyFees = 0m,
+                            IsDeleted = false,
+                            MonthlyCompanyFees = 0m,
+                            MonthlyEmployeeServicesCompanyFees = 0m,
+                            OrdinaryEmployeePerc = 0m,
+                            RequestDisputeResolutionFees = 0m,
+                            YearlyCompanyFees = 0m
+                        });
                 });
 
             modelBuilder.Entity("MTWorkHR.Core.Entities.TaskUser", b =>