-
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
a9d27bc
commit 4648346
Showing
9 changed files
with
336 additions
and
1 deletion.
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,43 @@ | ||
using Newtonsoft.Json; | ||
using System.Collections.Generic; | ||
|
||
namespace MpesaSdk.Callbacks | ||
{ | ||
public class StandingOrderCallback | ||
{ | ||
[JsonProperty("responseHeader")] | ||
public ResponseHeader ResponseHeader { get; set; } | ||
|
||
[JsonProperty("ResponseBody")] | ||
public ResponseBody ResponseBody { get; set; } | ||
} | ||
|
||
public class ResponseHeader | ||
{ | ||
[JsonProperty("responseRefID")] | ||
public string ResponseRefId { get; set; } | ||
|
||
[JsonProperty("requestRefID")] | ||
public string RequestRefId { get; set; } | ||
|
||
[JsonProperty("responseCode")] | ||
public long ResponseCode { get; set; } | ||
|
||
[JsonProperty("responseDescription")] | ||
public string ResponseDescription { get; set; } | ||
} | ||
|
||
public class ResponseBody | ||
{ | ||
[JsonProperty("responseData")] | ||
public List<StandingOrderCallbackMetadataItem> ResponseData { get; set; } | ||
} | ||
|
||
public class StandingOrderCallbackMetadataItem | ||
{ | ||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
[JsonProperty("value")] | ||
public string Value { get; set; } | ||
} | ||
} |
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,76 @@ | ||
using MpesaSdk.Enums; | ||
using Newtonsoft.Json; | ||
using System; | ||
|
||
namespace MpesaSdk.Dtos | ||
{ | ||
public class StandingOrderRequest | ||
{ | ||
[JsonProperty("StandingOrderName")] | ||
public string StandingOrderName { get; set; } | ||
|
||
[JsonProperty("StartDate")] | ||
public string StartDate { get; set; } | ||
|
||
[JsonProperty("EndDate")] | ||
public string EndDate { get; set; } | ||
|
||
[JsonProperty("BusinessShortCode")] | ||
public string BusinessShortCode { get; set; } | ||
|
||
[JsonProperty("TransactionType")] | ||
public string TransactionType { get; set; } | ||
|
||
[JsonProperty("ReceiverPartyIdentifierType")] | ||
public string ReceiverPartyIdentifierType { get; set; } | ||
|
||
[JsonProperty("Amount")] | ||
public string Amount { get; set; } | ||
|
||
[JsonProperty("PartyA")] | ||
public string PartyA { get; set; } | ||
|
||
[JsonProperty("CallBackURL")] | ||
public string CallBackUrl { get; set; } | ||
|
||
[JsonProperty("AccountReference")] | ||
public string AccountReference { get; set; } | ||
|
||
[JsonProperty("TransactionDesc")] | ||
public string TransactionDesc { get; set; } | ||
|
||
[JsonProperty("Frequency")] | ||
public string Frequency { get; set; } | ||
|
||
/// <summary> | ||
/// The Standing Order APIs enable teams to integrate with the standing order solution by initiating a request to create a standing order on the customer profile. | ||
/// </summary> | ||
/// <param name="standingOrderName"></param> | ||
/// <param name="startDate"></param> | ||
/// <param name="endDate"></param> | ||
/// <param name="businessShortCode"></param> | ||
/// <param name="transactionType"></param> | ||
/// <param name="receiverPartyIdentifierType"></param> | ||
/// <param name="amount"></param> | ||
/// <param name="partyA"></param> | ||
/// <param name="callBackUrl"></param> | ||
/// <param name="accountReference"></param> | ||
/// <param name="transactionDesc"></param> | ||
/// <param name="frequency"></param> | ||
public StandingOrderRequest(string standingOrderName, DateTime startDate, DateTime endDate, string businessShortCode, string transactionType, IdentifierTypes receiverPartyIdentifierType, string amount, string partyA, string callBackUrl, string accountReference, string transactionDesc, FrequencyTypes frequency) | ||
{ | ||
StandingOrderName = standingOrderName; | ||
StartDate = startDate.ToString("yyyyMMdd"); | ||
EndDate = endDate.ToString("yyyyMMdd"); | ||
BusinessShortCode = businessShortCode; | ||
TransactionType = transactionType; | ||
ReceiverPartyIdentifierType = ((int)receiverPartyIdentifierType).ToString(); | ||
Amount = amount; | ||
PartyA = partyA; | ||
CallBackUrl = callBackUrl; | ||
AccountReference = accountReference; | ||
TransactionDesc = transactionDesc; | ||
Frequency = ((int)frequency).ToString(); | ||
} | ||
} | ||
} |
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,14 @@ | ||
namespace MpesaSdk.Enums | ||
{ | ||
public enum FrequencyTypes | ||
{ | ||
One_Off = 1, | ||
Daily = 2, | ||
Weekly = 3, | ||
Monthly = 4, | ||
Bi_Monthly = 5, | ||
Quarterly = 6, | ||
Half_Year = 7, | ||
Yearly = 8 | ||
} | ||
} |
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,37 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace MpesaSdk.Response | ||
{ | ||
public class StandingOrderResponse | ||
{ | ||
[JsonProperty("ResponseHeader")] | ||
public ResponseHeader ResponseHeader { get; set; } | ||
|
||
[JsonProperty("ResponseBody")] | ||
public ResponseBody ResponseBody { get; set; } | ||
} | ||
|
||
public class ResponseBody | ||
{ | ||
[JsonProperty("responseDescription")] | ||
public string ResponseDescription { get; set; } | ||
|
||
[JsonProperty("responseCode")] | ||
public string ResponseCode { get; set; } | ||
} | ||
|
||
public class ResponseHeader | ||
{ | ||
[JsonProperty("responseRefID")] | ||
public string ResponseRefId { get; set; } | ||
|
||
[JsonProperty("responseCode")] | ||
public string ResponseCode { get; set; } | ||
|
||
[JsonProperty("responseDescription")] | ||
public string ResponseDescription { get; set; } | ||
|
||
[JsonProperty("ResultDesc")] | ||
public string ResultDesc { get; set; } | ||
} | ||
} |
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,101 @@ | ||
using FluentValidation; | ||
using MpesaSdk.Dtos; | ||
using System; | ||
|
||
namespace MpesaSdk.Validators | ||
{ | ||
public class StandingOrderValidator : AbstractValidator<StandingOrderRequest> | ||
{ | ||
public StandingOrderValidator() | ||
{ | ||
RuleFor(x => x.StandingOrderName) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The Standing order name is required") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The Standing order name must not be empty"); | ||
|
||
RuleFor(x => x.StartDate) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The start date is required") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The start date must not be empty"); | ||
|
||
RuleFor(x => x.EndDate) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The end date is required") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The end date must not be empty"); | ||
|
||
RuleFor(x => x.TransactionType) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The Transaction type is required") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The Transaction type must not be empty"); | ||
|
||
RuleFor(x => x.BusinessShortCode) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The paybill or till number shortcode should not be empty.") | ||
.Must(x => int.TryParse(x, out int value)) | ||
.WithMessage("{PropertyName} - The paybill or till number must be a numeric value.") | ||
.Length(5, 7) | ||
.WithMessage("{PropertyName} - The paybill or till number should be 5 to 7 account number digits."); | ||
|
||
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 mobile number is required.") | ||
.SetValidator(new PhoneNumberValidator<StandingOrderRequest, string>()) | ||
.WithMessage("{PropertyName} - The mobile number should start with 2547XXXX.") | ||
.MaximumLength(12) | ||
.WithMessage("{PropertyName} - The mobile number should be 12 digit."); | ||
|
||
RuleFor(x => x.CallBackUrl) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The callback url is required.") | ||
.Must(x => LinkMustBeAUri(x)) | ||
.WithMessage("{PropertyName} - The callback 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.TransactionDesc) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The transaction description should not be empty.") | ||
.MaximumLength(13) | ||
.WithMessage("{PropertyName} - The transaction description should not be more than 13 characters."); | ||
|
||
RuleFor(x => x.Frequency) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The Frequency is required") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The Frequency must not be empty"); | ||
|
||
RuleFor(x => x.ReceiverPartyIdentifierType) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The Receiver party identifier type is required") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The Receiver party identifier type must not be empty") | ||
.NotEqual("1") | ||
.WithMessage("{PropertyName} - The Receiver party does not support MSISDN"); | ||
} | ||
|
||
private static bool LinkMustBeAUri(string link) | ||
{ | ||
if (!Uri.IsWellFormedUriString(link, UriKind.Absolute)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} |