diff --git a/src/main/Apis/Charge/Charge.cs b/src/main/Apis/Charge/Charge.cs index 245e719..ba1b6d0 100644 --- a/src/main/Apis/Charge/Charge.cs +++ b/src/main/Apis/Charge/Charge.cs @@ -142,7 +142,15 @@ public class Bank public string AccountNumber { get; set; } } - public class BankChargeRequest : RequestMetadataExtender + public class ChargeRequest : RequestMetadataExtender + { + public string Reference { get; set; } + + [JsonProperty("device_id")] + public string DeviceId { get; set; } + } + + public class BankChargeRequest : ChargeRequest { [JsonProperty("email")] public string Email { get; set; } @@ -173,7 +181,7 @@ public class Card public string ExpiryYear { get; set; } } - public class CardChargeRequest : RequestMetadataExtender + public class CardChargeRequest : ChargeRequest { [JsonProperty("email")] @@ -189,7 +197,7 @@ public class CardChargeRequest : RequestMetadataExtender public string Pin { get; set; } } - public class AuthorizationCodeChargeRequest : RequestMetadataExtender + public class AuthorizationCodeChargeRequest : ChargeRequest { [JsonProperty("email")] diff --git a/src/main/Apis/Charge/ChargeApi.cs b/src/main/Apis/Charge/ChargeApi.cs index a5ee5e9..5b7533b 100644 --- a/src/main/Apis/Charge/ChargeApi.cs +++ b/src/main/Apis/Charge/ChargeApi.cs @@ -11,21 +11,28 @@ public ChargeApi(PayStackApi api) this._api = api; } - public ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin) => + public ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin, string reference = null, bool makeReferenceUnique = false) => ChargeAuthorizationCode( new AuthorizationCodeChargeRequest { Email = email, Amount = amount, AuthorizationCode = authorizationCode, - Pin = pin - } + Pin = pin, + Reference = makeReferenceUnique && reference != null ? + $"{reference}-{Guid.NewGuid().ToString().Substring(0, 8)}" : reference + }, + makeReferenceUnique ); - public ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request) => - _api.Post("charge", request); + public ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request, bool makeReferenceUnique = false) + { + if (makeReferenceUnique && request.Reference != null) + request.Reference = $"{request.Reference}-{Guid.NewGuid().ToString().Substring(0, 8)}"; + return _api.Post("charge", request); + } - public ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber) => + public ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber, string reference = null, bool makeReferenceUnique = false) => ChargeBank( new BankChargeRequest { @@ -35,14 +42,21 @@ public ChargeResponse ChargeBank(string email, string amount, string bankCode, s { Code = bankCode, AccountNumber = bankAccountNumber - } - } + }, + Reference = reference + }, + makeReferenceUnique ); - public ChargeResponse ChargeBank(BankChargeRequest request) => - _api.Post("charge", request); + public ChargeResponse ChargeBank(BankChargeRequest request, bool makeReferenceUnique = false) + { + if (makeReferenceUnique && request.Reference != null) + request.Reference = $"{request.Reference}-{Guid.NewGuid().ToString().Substring(0, 8)}"; - public ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin) => + return _api.Post("charge", request); + } + + public ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin, string reference = null, bool makeReferenceUnique = false) => ChargeCard( new CardChargeRequest { @@ -55,12 +69,18 @@ public ChargeResponse ChargeCard(string email, string amount, string cardNumber, ExpiryMonth = cardExpiryMonth, ExpiryYear = cardExpiryYear }, - Pin = pin + Pin = pin, + Reference = reference } ); - public ChargeResponse ChargeCard(CardChargeRequest request) => - _api.Post("charge", request); + public ChargeResponse ChargeCard(CardChargeRequest request, bool makeReferenceUnique = false) + { + if (makeReferenceUnique && request.Reference != null) + request.Reference = $"{request.Reference}-{Guid.NewGuid().ToString().Substring(0, 8)}"; + + return _api.Post("charge", request); + } public ChargeResponse CheckPendingCharge(string reference) => _api.Get($"charge/{reference}"); diff --git a/src/main/Apis/Charge/IChargeApi.cs b/src/main/Apis/Charge/IChargeApi.cs index 33e706c..5987a22 100644 --- a/src/main/Apis/Charge/IChargeApi.cs +++ b/src/main/Apis/Charge/IChargeApi.cs @@ -7,17 +7,17 @@ public interface IChargeApi { ChargeTokenizeResponse Tokenize(string email, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear); - ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber); + ChargeResponse ChargeBank(string email, string amount, string bankCode, string bankAccountNumber, string reference = null, bool makeReferenceUnique = false); - ChargeResponse ChargeBank(BankChargeRequest request); + ChargeResponse ChargeBank(BankChargeRequest request, bool makeReferenceUnique = false); - ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin); + ChargeResponse ChargeCard(string email, string amount, string cardNumber, string cardCvv, string cardExpiryMonth, string cardExpiryYear, string pin, string reference = null, bool makeReferenceUnique = false); - ChargeResponse ChargeCard(CardChargeRequest request); + ChargeResponse ChargeCard(CardChargeRequest request, bool makeReferenceUnique = false); - ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin); + ChargeResponse ChargeAuthorizationCode(string email, string amount, string authorizationCode, string pin, string reference = null, bool makeReferenceUnique = false); - ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request); + ChargeResponse ChargeAuthorizationCode(AuthorizationCodeChargeRequest request, bool makeReferenceUnique = false); ChargeResponse SubmitPIN(string reference, string pin); @@ -28,6 +28,6 @@ public interface IChargeApi ChargeResponse SubmitBirthday(string reference, DateTime birthday); ChargeResponse CheckPendingCharge(string reference); - + } } \ No newline at end of file diff --git a/src/main/Apis/Transactions/TransactionsApi.cs b/src/main/Apis/Transactions/TransactionsApi.cs index 20806c0..79e91d9 100644 --- a/src/main/Apis/Transactions/TransactionsApi.cs +++ b/src/main/Apis/Transactions/TransactionsApi.cs @@ -53,7 +53,7 @@ public ChargeAuthorizationResponse ChargeAuthorization(string authorizationCode, AuthorizationCode = authorizationCode, Email = email, AmountInKobo = amountInKobo - }); + }, makeReferenceUnique); public ChargeAuthorizationResponse ChargeAuthorization(ChargeAuthorizationRequest request, bool makeReferenceUnique = false) { @@ -71,7 +71,7 @@ public ReAuthorizationResponse RequestReAuthorization(string authorizationCode, Email = email, AmountInKobo = amountInKobo, Reference = reference - }); + }, makeReferenceUnique); public ReAuthorizationResponse RequestReAuthorization(ReAuthorizationRequest request, bool makeReferenceUnique = false) { diff --git a/src/main/main.csproj b/src/main/main.csproj index 1288820..5525c18 100644 --- a/src/main/main.csproj +++ b/src/main/main.csproj @@ -4,7 +4,7 @@ false Paystack.Net PayStack API for .Net - 0.7.3 + 0.7.4 Adebisi Foluso A. PayStack.Net @@ -14,6 +14,10 @@ https://github.com/adebisi-fa/paystack-dotnet https://cdn-images-1.medium.com/fit/c/100/100/1*We_5HSqJAUVETQ7xgcJNQQ.png + -- v0.7.4 -- + * Bug fix. Adds ChargeApi missing request DTOs properties: Reference and DeviceId - (#12) + * Minor bug fixes. + -- v0.7.3 -- * Bug fix. Transaction's ChargeAuthorization method included (big thanks to Aghogho Bernard - @teghoz) * Transaction's CheckAuthorization and RequestReauthorization methods now included.