-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9eed72e
commit c0cc72a
Showing
9 changed files
with
201 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace MpesaSdk.Callbacks | ||
{ | ||
public class B2CAccountTopUpCallback : BaseCallback | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace MpesaSdk.Dtos | ||
{ | ||
public class B2CAccountTopUpRequest | ||
{ | ||
[JsonProperty("Initiator")] | ||
public string Initiator { get; private set; } | ||
|
||
[JsonProperty("SecurityCredential")] | ||
public string SecurityCredential { get; private set; } | ||
|
||
[JsonProperty("CommandID")] | ||
public string CommandId { get; private set; } = Transaction_Type.BusinessPayToBulk; | ||
|
||
[JsonProperty("SenderIdentifierType")] | ||
public string SenderIdentifierType { get; private set; } = "4"; | ||
|
||
[JsonProperty("RecieverIdentifierType")] | ||
public string RecieverIdentifierType { get; private set; } = "4"; | ||
|
||
[JsonProperty("Amount")] | ||
public string Amount { get; private set; } | ||
|
||
[JsonProperty("PartyA")] | ||
public string PartyA { get; private set; } | ||
|
||
[JsonProperty("PartyB")] | ||
public string PartyB { get; private set; } | ||
|
||
[JsonProperty("AccountReference")] | ||
public string AccountReference { get; private set; } | ||
|
||
[JsonProperty("Requester")] | ||
public string Requester { get; private set; } | ||
|
||
[JsonProperty("Remarks")] | ||
public string Remarks { get; private set; } | ||
|
||
[JsonProperty("QueueTimeOutURL")] | ||
public string QueueTimeOutUrl { get; private set; } | ||
|
||
[JsonProperty("ResultURL")] | ||
public string ResultUrl { get; private set; } | ||
|
||
public B2CAccountTopUpRequest(string initiator, string securityCredential, string amount, string partyA, string partyB, string accountReference, string requester, string remarks, string queueTimeOutUrl, string resultUrl) | ||
{ | ||
Initiator = initiator; | ||
SecurityCredential = securityCredential; | ||
Amount = amount; | ||
PartyA = partyA; | ||
PartyB = partyB; | ||
AccountReference = accountReference; | ||
Requester = requester; | ||
Remarks = remarks; | ||
QueueTimeOutUrl = queueTimeOutUrl; | ||
ResultUrl = resultUrl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using FluentValidation; | ||
using MpesaSdk.Dtos; | ||
using System; | ||
|
||
namespace MpesaSdk.Validators | ||
{ | ||
public class B2CAccountTopUpValidator : AbstractValidator<B2CAccountTopUpRequest> | ||
{ | ||
public B2CAccountTopUpValidator() | ||
{ | ||
RuleFor(x => x.Initiator) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The name of the initiator is required.") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The name of the intiator should not be empty."); | ||
|
||
RuleFor(x => x.SecurityCredential) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The encrypted credential is required.") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The encrypted credential should not be empty."); | ||
|
||
RuleFor(x => x.QueueTimeOutUrl) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The queuetimeout url is required.") | ||
.Must(x => LinkMustBeAUri(x)) | ||
.WithMessage("{PropertyName} - The queuetimeout url should be a valid secure url."); | ||
|
||
RuleFor(x => x.Amount) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - Amount is required.") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - Amount must not be empty") | ||
.Must(x => int.TryParse(x, out int value)) | ||
.WithMessage("{PropertyName} - The amount should be in numeric value."); | ||
|
||
RuleFor(x => x.PartyA) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The shortcode is required.") | ||
.Length(5, 7) | ||
.WithMessage("{PropertyName} - The shortcode should be between 5 and 7 digit."); | ||
|
||
RuleFor(x => x.PartyB) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The account number is required.") | ||
.Must(x => int.TryParse(x, out int value)) | ||
.WithMessage("{PropertyName} - The account must be a numeric value."); | ||
|
||
RuleFor(x => x.ResultUrl) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The result url is required.") | ||
.Must(x => LinkMustBeAUri(x)) | ||
.WithMessage("{PropertyName} - The result url should be a valid secure url."); | ||
|
||
RuleFor(x => x.AccountReference) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The account reference should not be empty.") | ||
.MaximumLength(12) | ||
.WithMessage("{PropertyName} - The account reference should not be more than 12 characters."); | ||
|
||
RuleFor(x => x.Remarks) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The remarks should not be empty.") | ||
.MaximumLength(100) | ||
.WithMessage("{PropertyName} - The remarks should not be more than 100 characters."); | ||
} | ||
|
||
private static bool LinkMustBeAUri(string link) | ||
{ | ||
if (!Uri.IsWellFormedUriString(link, UriKind.Absolute)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} |