public async Task CanGenerateTransactionReference_Unit() { PaystackSetting paystackSetting = new PaystackSetting() { UsePublicKey = false, ApiBaseUrl = "https://api.paystack.co/", ReferencePrefix = "PV", PublicKey = "pk_test_0b413fb09eeb29832cded5a56918a0f5f6a4c2f0", SecretKey = "sk_test_6ce9543acf5dd68127387f49ce437f7f82aafb47", ListTransactionEndPoint = "/transaction", VerifyTransactionEndPoint = "/transaction/verify/", FetchTransactionEndPoint = "/transaction/", InitializeTransactionEndPoint = "/transaction/initialize", TransactionTotalEndPoint = "/transaction/totals", FetchSettlementsEndPoint = "/settlement", APIAcceptHeaderKey = "accept", APIAcceptHeaderValue = "application/json", APIAuthorizationHeaderKey = "Authorization", APIAuthorizationHeaderValue = "Bearer", APIFromQueryParameterKey = "from", APIToQueryParameterKey = "to", APIAmountQueryParameterKey = "amount", APIStatusQueryParameterKey = "status", APIReferenceParameterKey = "reference", APIAmountParameterKey = "amount", APICallbackUrlParameterKey = "callback_url", APIEmailParameterKey = "email", APICustomFieldsParameterKey = "custom_fields", APIMetaDataParameterKey = "metadata", TransactionSearchDateFormat = "yyyy-MM-dd", }; string tranxRef = "099885321155456"; PaystackTransactionLog transactionLog = new PaystackTransactionLog() { Reference = tranxRef, TransactionDate = DateTime.UtcNow, }; _settingService.Setup(x => x.GetSetting <PaystackSetting>()).Returns(Task.FromResult(paystackSetting)); _gatewayLuncher.Setup(x => x.CreateTransactionRef(paystackSetting.ReferencePrefix)).Returns(Task.FromResult(tranxRef)); _transactionLogService.Setup(x => x.SaveAsync(transactionLog)).Verifiable(); var transactionRef = new TransactionReference(_transactionLogService.Object, _gatewayLuncher.Object, _settingService.Object, _widgetProvider.Object); var response = await transactionRef.InvokeAsync(); var result = (ViewViewComponentResult)response; Assert.NotNull(result); Assert.NotNull(response); Assert.IsType <ViewViewComponentResult>(response); Assert.IsType <string>(result.ViewData.Model); }
public void Update(PaystackTransactionLog paystackTransactionLog) { if (paystackTransactionLog == null) { throw new ArgumentNullException("paystackTransactionLog"); } _paystackTransactionLogRepository.Update(paystackTransactionLog); }
public static PaystackTransactionLog ToTransactionLog(this PaystackTransaction paystackTransaction) { if (paystackTransaction == null || paystackTransaction.Data == null) { throw new ArgumentNullException("paystackTransaction"); } PaystackTransactionLog transactionLog = new PaystackTransactionLog(); transactionLog = ToTransactionLogHelper(paystackTransaction, transactionLog); return(transactionLog); }
public static IList <PaystackTransactionLog> ToTransactionLog(this IList <TransactionLogModel> transactionLogModels, bool includeId) { //if (transactionLogModels.IsNullOrEmpty()) //{ // throw new ArgumentNullException("transactionLogModels"); //} Guard.NotEmpty(transactionLogModels, nameof(transactionLogModels)); IList <PaystackTransactionLog> transactionLogs = new List <PaystackTransactionLog>(); foreach (TransactionLogModel transactionLogModel in transactionLogModels) { PaystackTransactionLog transactionLog = new PaystackTransactionLog(); if (includeId) { transactionLog.Id = transactionLogModel.Id; } transactionLog.RegistrationId = transactionLogModel.RegistrationId; transactionLog.Amount = transactionLogModel.Amount; transactionLog.Currency = transactionLogModel.Currency; transactionLog.TransactionDate = transactionLogModel.TransactionDate; transactionLog.Status = transactionLogModel.Status; transactionLog.Reference = transactionLogModel.Reference; transactionLog.Domain = transactionLogModel.Domain; transactionLog.GatewayResponse = transactionLogModel.GatewayResponse; transactionLog.IPAddress = transactionLogModel.IPAddress; transactionLog.Fees = transactionLogModel.Fees; transactionLog.AuthorizationUrl = transactionLogModel.AuthorizationUrl; transactionLog.AccessCode = transactionLogModel.AccessCode; transactionLog.AuthorizationCode = transactionLogModel.AuthorizationCode; transactionLog.CardType = transactionLogModel.CardType; transactionLog.Last4 = transactionLogModel.Last4; transactionLog.ExpiryMonth = transactionLogModel.ExpiryMonth; transactionLog.ExpiryYear = transactionLogModel.ExpiryYear; transactionLog.Bin = transactionLogModel.Bin; transactionLog.Bank = transactionLogModel.Bank; transactionLog.Channel = transactionLogModel.Channel; transactionLog.Signature = transactionLogModel.Signature; transactionLog.Brand = transactionLogModel.Brand; transactionLog.Reusable = transactionLogModel.Reusable; transactionLog.CountryCode = transactionLogModel.CountryCode; transactionLog.Message = transactionLogModel.Message; transactionLogs.Add(transactionLog); } return(transactionLogs); }
public async Task <bool> TransactionReferenceExistAsync(string transactionReference) { bool isExist = false; if (!transactionReference.HasValue()) { throw new ArgumentNullException("transactionReference"); } PaystackTransactionLog transactionLog = await GetByReferenceAsync(transactionReference); if (transactionLog != null && transactionLog.Reference.HasValue()) { isExist = true; } return(isExist); }
public async Task LogTransaction(PaystackTransaction paystackTransaction) { if (paystackTransaction == null || paystackTransaction.Data == null) { throw new ArgumentNullException("paystackTransaction"); } PaystackTransactionLog transactionLog = await _transactionLogService.GetByReferenceAsync(paystackTransaction.Data.reference); if (transactionLog == null || transactionLog.Id <= 0) { throw new ArgumentNullException("Transaction Log failed on Retrieval!"); } paystackTransaction.RegisterationId = GatewayLuncher.RegistrationId; transactionLog = paystackTransaction.ToTransactionLog(transactionLog); _transactionLogService.Update(transactionLog); }
private async Task <string> LogTransactionReference() { PaystackSetting setting = await _settingService.GetSetting <PaystackSetting>(); if (setting == null) { return(null); } string transactionRef = await _gatewayLuncher.CreateTransactionRef(setting.ReferencePrefix); PaystackTransactionLog transactionLog = new PaystackTransactionLog() { Reference = transactionRef, TransactionDate = DateTime.UtcNow, }; await _transactionLogService.SaveAsync(transactionLog); return(transactionRef); }
public async Task SaveAsync(PaystackTransactionLog paystackTransactionLog) { Guard.NotNull(paystackTransactionLog, nameof(paystackTransactionLog)); await _paystackTransactionLogRepository.AddAsync(paystackTransactionLog); }
public static PaystackTransactionLog ToTransactionLog(this PaystackTransaction paystackTransaction, PaystackTransactionLog transactionLog) { if (paystackTransaction == null || paystackTransaction.Data == null) { throw new ArgumentNullException("paystackTransaction"); } if (transactionLog == null || transactionLog.Id <= 0) { throw new ArgumentNullException("transactionLog"); } return(ToTransactionLogHelper(paystackTransaction, transactionLog)); }
private static PaystackTransactionLog ToTransactionLogHelper(PaystackTransaction paystackTransaction, PaystackTransactionLog transactionLog) { transactionLog.Message = paystackTransaction.message; transactionLog.RegistrationId = paystackTransaction.RegisterationId.GetValueOrDefault(); if (paystackTransaction.Data != null) { transactionLog.Amount = paystackTransaction.Data.amount; transactionLog.Currency = paystackTransaction.Data.currency; transactionLog.TransactionDate = paystackTransaction.Data.transaction_date; transactionLog.Status = paystackTransaction.Data.status; transactionLog.Reference = paystackTransaction.Data.reference; transactionLog.Domain = paystackTransaction.Data.domain; transactionLog.GatewayResponse = paystackTransaction.Data.gateway_response; transactionLog.IPAddress = paystackTransaction.Data.ip_address; transactionLog.Fees = paystackTransaction.Data.fees; if (!paystackTransaction.Data.authorization_url.IsEmpty()) { transactionLog.AuthorizationUrl = paystackTransaction.Data.authorization_url; } if (!paystackTransaction.Data.access_code.IsEmpty()) { transactionLog.AccessCode = paystackTransaction.Data.access_code; } } if (paystackTransaction.Data.authorization != null) { transactionLog.AuthorizationCode = paystackTransaction.Data.authorization.authorization_code; transactionLog.CardType = paystackTransaction.Data.authorization.card_type; transactionLog.Last4 = paystackTransaction.Data.authorization.last4; transactionLog.ExpiryMonth = paystackTransaction.Data.authorization.exp_month; transactionLog.ExpiryYear = paystackTransaction.Data.authorization.exp_year; transactionLog.Bin = paystackTransaction.Data.authorization.bin; transactionLog.Bank = paystackTransaction.Data.authorization.bank; transactionLog.Channel = paystackTransaction.Data.authorization.channel; transactionLog.Signature = paystackTransaction.Data.authorization.signature; transactionLog.Brand = paystackTransaction.Data.authorization.brand; transactionLog.Reusable = paystackTransaction.Data.authorization.reusable; transactionLog.CountryCode = paystackTransaction.Data.authorization.country_code; } return(transactionLog); }