Skip to content

Commit

Permalink
Add wages, card_pan to original request
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiMst00 committed Dec 21, 2023
1 parent 62aa6ec commit 18333a0
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 40 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public async Task<IActionResult> VerifyPayment()

## What is `IAdvancedZarinpalService`?
- If you wanna use 'UnVerified' method, you must inject `IAdvancedZarinpalService` to service container. (Automatically not injected)
- So let's come back into `Program.cs` and edit it (Or Set it in `appsettings.json` like [sample](https://github.com/MehdiMst00/Zarinpal.AspNetCore/blob/master/samples/Zarinpal.AspNetCore.Sample/appsettings.json)):
- So let's come back into `Program.cs` and edit it (Or Set it in `appsettings.json` like [sample](https://github.com/MehdiMst00/Zarinpal.AspNetCore/blob/net8.0/samples/Zarinpal.AspNetCore.Sample/appsettings.json)):
```c#
builder.Services.AddZarinpal(options =>
{
Expand Down Expand Up @@ -182,6 +182,9 @@ var message = ZarinpalStatusCode.St100.GetStatusCodeMessage();
## Support
For support, [click here](https://github.com/MehdiMst00#-you-can-reach-me-on).

## Docs
V4 Zarinpal Docs: [click here](https://www.zarinpal.com/docs/paymentGateway/).

## Give a star ⭐️ !!!
If you liked the project, please give a star :)

Expand Down
17 changes: 10 additions & 7 deletions samples/Zarinpal.AspNetCore.Sample/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Zarinpal.AspNetCore.DTOs;
using Zarinpal.AspNetCore.Extensions;
using Zarinpal.AspNetCore.Interfaces;
using Zarinpal.AspNetCore.Models;

namespace Zarinpal.AspNetCore.Sample.Controllers;

Expand Down Expand Up @@ -41,18 +42,20 @@ public async Task<IActionResult> RequestPayment()

var request = new ZarinpalRequestDTO(toman, "خرید",
"https://localhost:7219/Home/VerifyPayment",
"[email protected]", "09123456789");
email: "[email protected]",
mobile: "09123456789",
orderId: "1111");

var result = await _zarinpalService.RequestAsync(request);

if (result.Data != null)
{
// You can store or log zarinpal data in database
string authority = result.Data.Authority;
string? authority = result.Data.Authority;
int code = result.Data.Code;
int fee = result.Data.Fee;
string feeType = result.Data.FeeType;
string message = result.Data.Message;
string? feeType = result.Data.FeeType;
string? message = result.Data.Message;
}

if (result.IsSuccessStatusCode)
Expand Down Expand Up @@ -98,10 +101,10 @@ public async Task<IActionResult> VerifyPayment()
// You can store or log zarinpal data in database
ulong refId = response.Data.RefId;
int fee = response.Data.Fee;
string feeType = response.Data.FeeType;
string? feeType = response.Data.FeeType;
int code = response.Data.Code;
string cardHash = response.Data.CardHash;
string cardPan = response.Data.CardPan;
string? cardHash = response.Data.CardHash;
string? cardPan = response.Data.CardPan;
}

if (response.IsSuccessStatusCode)
Expand Down
4 changes: 2 additions & 2 deletions samples/Zarinpal.AspNetCore.Sample/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
},
"AllowedHosts": "*",
"Zarinpal": {
"MerchantId": "41c2e177-2e5a-4f37-8cef-569f2b48bdcf",
"ZarinpalMode": "Original", // Original - Sandbox
"MerchantId": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"ZarinpalMode": "Sandbox", // Original - Sandbox
"Currency": "IRT", // IRR - IRT
"UseAdvanced": true
}
Expand Down
16 changes: 14 additions & 2 deletions src/Zarinpal.AspNetCore/DTOs/ZarinpalRequestDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ public class ZarinpalRequestDTO

public string? OrderId { get; set; }

public string? CardPan { get; set; }

public List<ZarinpalWages>? Wages { get; set; }

public ZarinpalRequestDTO() { }

public ZarinpalRequestDTO(int amount, string description, string verifyCallbackUrl,
string? email = null, string? mobile = null, string? orderId = null)
public ZarinpalRequestDTO(int amount,
string description,
string verifyCallbackUrl,
string? email = null,
string? mobile = null,
string? orderId = null,
string? cardPan = null,
List<ZarinpalWages>? wages = null)
{
Amount = amount;
Description = description;
VerifyCallbackUrl = verifyCallbackUrl;
Email = email;
Mobile = mobile;
OrderId = orderId;
CardPan = cardPan;
Wages = wages;
}
}
6 changes: 3 additions & 3 deletions src/Zarinpal.AspNetCore/DTOs/ZarinpalRequestResultDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public ZarinpalRequestResultDTO(bool isSuccessStatusCode, string redirectUrl,
public class ZarinpalRequestData
{
public int Code { get; set; }
public string Message { get; set; } = null!;
public string Authority { get; set; } = null!;
public string FeeType { get; set; } = null!;
public string? Message { get; set; } = null;
public string? Authority { get; set; } = null;
public string? FeeType { get; set; } = null;
public int Fee { get; set; }
}
7 changes: 4 additions & 3 deletions src/Zarinpal.AspNetCore/DTOs/ZarinpalVerifyResultDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public class ZarinpalVerifyResultData
{
public int Code { get; set; }
public ulong RefId { get; set; }
public string CardPan { get; set; } = null!;
public string CardHash { get; set; } = null!;
public string FeeType { get; set; } = null!;
public string? CardPan { get; set; } = null;
public string? CardHash { get; set; } = null;
public string? FeeType { get; set; } = null;
public int Fee { get; set; }
public List<ZarinpalWages>? Wages { get; set; } = null;
}
1 change: 1 addition & 0 deletions src/Zarinpal.AspNetCore/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
global using System.Net.Http.Json;
global using System.Text.Json;
global using System.Text.Json.Nodes;
global using System.Text.Json.Serialization;
global using Zarinpal.AspNetCore.Consts;
global using Zarinpal.AspNetCore.DTOs;
global using Zarinpal.AspNetCore.Enums;
Expand Down
21 changes: 11 additions & 10 deletions src/Zarinpal.AspNetCore/Implementations/OriginalZarinpalService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;

namespace Zarinpal.AspNetCore.Implementations;
namespace Zarinpal.AspNetCore.Implementations;

public class OriginalZarinpalService : IZarinpalService
{
Expand Down Expand Up @@ -45,7 +43,9 @@ public async Task<ZarinpalRequestResultDTO> RequestAsync(ZarinpalRequestDTO requ
OrderId = request.OrderId,
Email = request.Email,
Mobile = request.Mobile,
}
CardPan = request.CardPan,
},
Wages = request.Wages
},
new JsonSerializerOptions
{
Expand All @@ -71,11 +71,11 @@ public async Task<ZarinpalRequestResultDTO> RequestAsync(ZarinpalRequestDTO requ
{
Data = new ZarinpalRequestData
{
Authority = requestResult.Authority ?? string.Empty,
Authority = requestResult.Authority,
Code = requestResult.Code.GetValueOrDefault(),
Fee = requestResult.Fee.GetValueOrDefault(),
FeeType = requestResult.FeeType ?? string.Empty,
Message = requestResult.Message ?? string.Empty,
FeeType = requestResult.FeeType,
Message = requestResult.Message,
}
};
}
Expand Down Expand Up @@ -142,10 +142,11 @@ public async Task<ZarinpalVerifyResultDTO> VerifyAsync(ZarinpalVerifyDTO verify)
{
RefId = requestResult.RefId,
Fee = requestResult.Fee,
FeeType = requestResult.FeeType ?? string.Empty,
CardHash = requestResult.CardHash ?? string.Empty,
CardPan = requestResult.CardPan ?? string.Empty,
FeeType = requestResult.FeeType,
CardHash = requestResult.CardHash,
CardPan = requestResult.CardPan,
Code = requestResult.Code,
Wages = requestResult.Wages
}
};
}
Expand Down
10 changes: 7 additions & 3 deletions src/Zarinpal.AspNetCore/Models/Internal/Original/RequestDTO.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;

namespace Zarinpal.AspNetCore.Models.Internal.Original;
namespace Zarinpal.AspNetCore.Models.Internal.Original;

internal class RequestDTO
{
Expand All @@ -21,6 +19,9 @@ internal class RequestDTO

[JsonPropertyName("metadata")]
public RequestMetadataDTO? Metadata { get; set; }

[JsonPropertyName("wages")]
public List<ZarinpalWages>? Wages { get; set; }
}

internal class RequestMetadataDTO
Expand All @@ -33,6 +34,9 @@ internal class RequestMetadataDTO

[JsonPropertyName("order_id")]
public string? OrderId { get; set; }

[JsonPropertyName("card_pan")]
public string? CardPan { get; set; }
}

internal class RequestResultData
Expand Down
10 changes: 7 additions & 3 deletions src/Zarinpal.AspNetCore/Models/Internal/Original/VerifyDTO.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;

namespace Zarinpal.AspNetCore.Models.Internal.Original;
namespace Zarinpal.AspNetCore.Models.Internal.Original;

internal class VerifyDTO
{
Expand All @@ -12,6 +10,9 @@ internal class VerifyDTO

[JsonPropertyName("authority")]
public string? Authority { get; set; }

[JsonPropertyName("wages")]
public List<ZarinpalWages>? Wages { get; set; }
}

internal class VerifyResultData
Expand All @@ -33,4 +34,7 @@ internal class VerifyResultData

[JsonPropertyName("fee")]
public int Fee { get; set; }

[JsonPropertyName("wages")]
public List<ZarinpalWages>? Wages { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;

namespace Zarinpal.AspNetCore.Models.Internal.Sandbox;
namespace Zarinpal.AspNetCore.Models.Internal.Sandbox;

internal class SandboxRequestDTO
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json.Serialization;

namespace Zarinpal.AspNetCore.Models.Internal.Sandbox;
namespace Zarinpal.AspNetCore.Models.Internal.Sandbox;

internal class SandboxVerifyDTO
{
Expand Down
24 changes: 24 additions & 0 deletions src/Zarinpal.AspNetCore/Models/ZarinpalWages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Zarinpal.AspNetCore.Models;

public class ZarinpalWages
{
[JsonPropertyName("iban")]
public string? Iban { get; set; }

[JsonPropertyName("amount")]
public int Amount { get; set; }

[JsonPropertyName("description")]
public string? Description { get; set; }

public ZarinpalWages() { }

public ZarinpalWages(string iban,
int amount,
string description)
{
Iban = iban;
Amount = amount;
Description = description;
}
}

0 comments on commit 18333a0

Please sign in to comment.