Skip to content

Commit

Permalink
Modify RequestDTO in original RequestAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiMst00 committed Dec 21, 2023
1 parent 880a3ee commit 62aa6ec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
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": "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"ZarinpalMode": "Sandbox", // Original - Sandbox
"MerchantId": "41c2e177-2e5a-4f37-8cef-569f2b48bdcf",
"ZarinpalMode": "Original", // Original - Sandbox
"Currency": "IRT", // IRR - IRT
"UseAdvanced": true
}
Expand Down
5 changes: 4 additions & 1 deletion src/Zarinpal.AspNetCore/DTOs/ZarinpalRequestDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ public class ZarinpalRequestDTO

public string? VerifyCallbackUrl { get; set; }

public string? OrderId { get; set; }

public ZarinpalRequestDTO() { }

public ZarinpalRequestDTO(int amount, string description, string verifyCallbackUrl,
string? email = null, string? mobile = null)
string? email = null, string? mobile = null, string? orderId = null)
{
Amount = amount;
Description = description;
VerifyCallbackUrl = verifyCallbackUrl;
Email = email;
Mobile = mobile;
OrderId = orderId;
}
}
16 changes: 13 additions & 3 deletions src/Zarinpal.AspNetCore/Implementations/OriginalZarinpalService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Zarinpal.AspNetCore.Implementations;
using System.Text.Json.Serialization;

namespace Zarinpal.AspNetCore.Implementations;

public class OriginalZarinpalService : IZarinpalService
{
Expand Down Expand Up @@ -38,8 +40,16 @@ public async Task<ZarinpalRequestResultDTO> RequestAsync(ZarinpalRequestDTO requ
Description = request.Description,
VerifyCallbackUrl = request.VerifyCallbackUrl,
Currency = _zarinpalOptions.Currency,
Email = !string.IsNullOrEmpty(request.Email) ? request.Email : "",
Mobile = !string.IsNullOrEmpty(request.Mobile) ? request.Mobile : "",
Metadata = new RequestMetadataDTO
{
OrderId = request.OrderId,
Email = request.Email,
Mobile = request.Mobile,
}
},
new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
});

if (response.IsSuccessStatusCode)
Expand Down
21 changes: 15 additions & 6 deletions src/Zarinpal.AspNetCore/Models/Internal/Original/RequestDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ internal class RequestDTO
[JsonPropertyName("merchant_id")]
public string? MerchantId { get; set; }

[JsonPropertyName("email")]
public string? Email { get; set; }

[JsonPropertyName("mobile")]
public string? Mobile { get; set; }

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

Expand All @@ -24,6 +18,21 @@ internal class RequestDTO

[JsonPropertyName("callback_url")]
public string? VerifyCallbackUrl { get; set; }

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

internal class RequestMetadataDTO
{
[JsonPropertyName("email")]
public string? Email { get; set; }

[JsonPropertyName("mobile")]
public string? Mobile { get; set; }

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

internal class RequestResultData
Expand Down

0 comments on commit 62aa6ec

Please sign in to comment.