-
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
6903170
commit 7226da2
Showing
7 changed files
with
198 additions
and
2 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,34 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace MpesaSdk.Callbacks | ||
{ | ||
public class B2BExpressCheckoutCallback | ||
{ | ||
[JsonProperty("resultCode")] | ||
public string ResultCode { get; set; } | ||
|
||
[JsonProperty("resultDesc")] | ||
public string ResultDesc { get; set; } | ||
|
||
[JsonProperty("amount")] | ||
public string Amount { get; set; } | ||
|
||
[JsonProperty("requestId")] | ||
public string RequestId { get; set; } | ||
|
||
[JsonProperty("resultType")] | ||
public string ResultType { get; set; } | ||
|
||
[JsonProperty("conversationID")] | ||
public string ConversationId { get; set; } | ||
|
||
[JsonProperty("transactionId")] | ||
public string TransactionId { get; set; } | ||
|
||
[JsonProperty("status")] | ||
public string Status { get; set; } | ||
|
||
[JsonProperty("paymentReference")] | ||
public string PaymentReference { 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,39 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace MpesaSdk.Dtos | ||
{ | ||
public class B2BExpressCheckoutRequest | ||
{ | ||
[JsonProperty("primaryShortCode")] | ||
public string PrimaryShortCode { get; set; } | ||
|
||
[JsonProperty("receiverShortCode")] | ||
public string ReceiverShortCode { get; set; } | ||
|
||
[JsonProperty("amount")] | ||
public string Amount { get; set; } | ||
|
||
[JsonProperty("paymentRef")] | ||
public string PaymentRef { get; set; } | ||
|
||
[JsonProperty("callbackUrl")] | ||
public string CallbackUrl { get; set; } | ||
|
||
[JsonProperty("partnerName")] | ||
public string PartnerName { get; set; } | ||
|
||
[JsonProperty("RequestRefID")] | ||
public string RequestRefId { get; set; } | ||
|
||
public B2BExpressCheckoutRequest(string primaryShortCode, string receiverShortCode, string amount, string paymentRef, string callbackUrl, string partnerName, string requestRefId) | ||
{ | ||
PrimaryShortCode = primaryShortCode; | ||
ReceiverShortCode = receiverShortCode; | ||
Amount = amount; | ||
PaymentRef = paymentRef; | ||
CallbackUrl = callbackUrl; | ||
PartnerName = partnerName; | ||
RequestRefId = requestRefId; | ||
} | ||
} | ||
} |
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,13 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace MpesaSdk.Response | ||
{ | ||
public class B2BExpressCheckoutResponse | ||
{ | ||
[JsonProperty("code")] | ||
public string Code { get; set; } | ||
|
||
[JsonProperty("status")] | ||
public string Status { 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,69 @@ | ||
using FluentValidation; | ||
using MpesaSdk.Dtos; | ||
using System; | ||
|
||
namespace MpesaSdk.Validators | ||
{ | ||
public class B2BExpressCheckoutValidator : AbstractValidator<B2BExpressCheckoutRequest> | ||
{ | ||
public B2BExpressCheckoutValidator() | ||
{ | ||
RuleFor(x => x.PrimaryShortCode) | ||
.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.ReceiverShortCode) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The receiver paybill or till number shortcode should not be empty.") | ||
.Must(x => int.TryParse(x, out int value)) | ||
.WithMessage("{PropertyName} - The receiver paybill or till number must be a numeric value.") | ||
.Length(5, 7) | ||
.WithMessage("{PropertyName} - The receiver 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.PaymentRef) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The payment reference should not be empty.") | ||
.MaximumLength(12) | ||
.WithMessage("{PropertyName} - The payment reference should not be more than 12 characters."); | ||
|
||
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.PartnerName) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The partner name is required.") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - This partner name should not be empty."); | ||
|
||
RuleFor(x => x.RequestRefId) | ||
.NotNull() | ||
.WithMessage("{PropertyName} - The unique identifier is required.") | ||
.NotEmpty() | ||
.WithMessage("{PropertyName} - The unique identifier should not be empty."); | ||
} | ||
|
||
private static bool LinkMustBeAUri(string link) | ||
{ | ||
if (!Uri.IsWellFormedUriString(link, UriKind.Absolute)) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} |