public static PaymentLinkData ToLinkData(this PaymentLink link) { var paymentStatus = string.IsNullOrWhiteSpace(link.LastPaymentResponse) ? CreditCardPaymentStatuses.Created : JsonConvert.DeserializeObject <PaymentResponse>(link.LastPaymentResponse).Status; return(new PaymentLinkData(link.Amount, link.Email, link.ServiceType, link.Currency, link.Comment, link.ReferenceCode, paymentStatus, link.Code, link.Created)); }
public void TestGetPaymentLinkById() { string filepath = "dummy_payment_link.json"; string url = string.Format("{0}/{1}", paymentLinkURL, PAYMENTLINKID); Client client = new Client(ACCESSID, SECRETKEY, Helper.GetMockRequestFactory(filepath, url)); PaymentLink paymentLink = client.PaymentLink.Retrieve(PAYMENTLINKID); string expectedJsonString = Helper.GetJsonString(filepath); Helper.AssertEntity(paymentLink, expectedJsonString); }
public Task <Result <PaymentLink> > Register(PaymentLinkCreationRequest paymentLinkCreationData) { return(Validate(paymentLinkCreationData) .Map(CreateLink)); Result Validate(PaymentLinkCreationRequest linkData) { var linkSettings = _paymentLinkOptions.ClientSettings; return(GenericValidator <PaymentLinkCreationRequest> .Validate(v => { v.RuleFor(data => data.ServiceType).IsInEnum(); v.RuleFor(data => data.Currency).IsInEnum(); v.RuleFor(data => data.Amount).GreaterThan(decimal.Zero); v.RuleFor(data => data.Email).EmailAddress(); v.RuleFor(data => data.Comment).NotEmpty(); v.RuleFor(data => data.Currency) .Must(linkSettings.Currencies.Contains); v.RuleFor(data => data.ServiceType) .Must(serviceType => linkSettings.ServiceTypes.ContainsKey(serviceType)); }, linkData)); } async Task <PaymentLink> CreateLink() { var referenceCode = await _tagProcessor.GenerateNonSequentialReferenceCode(paymentLinkCreationData.ServiceType, LinkDestinationCode); var paymentLink = new PaymentLink { Email = paymentLinkCreationData.Email, Amount = paymentLinkCreationData.Amount, Currency = paymentLinkCreationData.Currency, ServiceType = paymentLinkCreationData.ServiceType, Comment = paymentLinkCreationData.Comment, Created = _dateTimeProvider.UtcNow(), Code = Base64UrlEncoder.Encode(Guid.NewGuid().ToByteArray()), ReferenceCode = referenceCode, PaymentProcessor = paymentLinkCreationData.PaymentProcessor, InvoiceNumber = paymentLinkCreationData.InvoiceNumber }; _context.PaymentLinks.Add(paymentLink); await _context.SaveChangesAsync(); return(paymentLink); } }
public void OnTick_CheckResultFailsForSomeReason_NotCallingEventNorUpdate() { var paymentLinkEventCalled = false; var options = new PardakhtVasetClientOptions(); options.ApiKey = "foo"; options.Password = "******"; options.ConnectionString = "fake connection string"; options.TablePrefix = ""; var mockedRepository = new Mock <IPaymentLinkRepository>(); var mockedPayRequest = new Mock <IPayRequestV2>(); var nextPaymentLink = new PaymentLink(); nextPaymentLink.Amount = 26000; nextPaymentLink.BankReferenceId = null; nextPaymentLink.CreateDate = new DateTime(2017, 12, 3); nextPaymentLink.Description = "بابت مانده حساب"; nextPaymentLink.ExpireDays = 30; nextPaymentLink.FollowId = "324"; nextPaymentLink.LastCheckForUpdateDate = new DateTime(2017, 12, 3); nextPaymentLink.PaymentStatus = (int)RequestStatus.Initiated; nextPaymentLink.ResultDate = null; nextPaymentLink.Token = "1d372049-17de-4550-aecc-06111fdf2a9b"; nextPaymentLink.Url = "https://pardakhtvaset.com/pay?token=1d372049-17de-4550-aecc-06111fdf2a9b"; mockedRepository.Setup(x => x.GetNextLinkForCheck(It.IsAny <string>())).Returns(nextPaymentLink); var fakeEpayResult = new EPayRequestCheckResult(); fakeEpayResult.BankReferenceId = null; fakeEpayResult.RequestStatus = RequestStatus.Initiated; fakeEpayResult.ExceptionType = ExceptionType.ArgumentException; fakeEpayResult.Message = "some random error message"; fakeEpayResult.Success = false; fakeEpayResult.VerifyDate = null; mockedPayRequest.Setup(x => x.Check(options.ApiKey, options.Password, nextPaymentLink.Token)).Returns(fakeEpayResult); var service = new PaymentLinkNotificationService(options, mockedRepository.Object, mockedPayRequest.Object); service.PaymentLinkChanged += (o, e) => paymentLinkEventCalled = true; service.OnTick(); mockedRepository.Verify(x => x.GetNextLinkForCheck(It.IsAny <string>()), Times.Once()); mockedPayRequest.Verify(x => x.Check(options.ApiKey, options.Password, nextPaymentLink.Token), Times.Once()); mockedRepository.Verify(x => x.Update(nextPaymentLink), Times.Never()); Assert.True(paymentLinkEventCalled); }
public void PaymentLink_Serialize_PropertyNamesAsExpected() { // Arrange var paymentLink = new PaymentLink(); // Act var serializedObject = JsonConvert.SerializeObject(paymentLink); // Assert Assert.AreEqual(@"{ ""order_id"":null, ""payment_url"":null, ""custom_info"":null }".RemoveWhiteSpace(), serializedObject.RemoveWhiteSpace()); }
public void TestCreatePaymentLink() { string filepath = "dummy_payment_link.json"; Client client = new Client(ACCESSID, SECRETKEY, Helper.GetMockRequestFactory(filepath, paymentLinkURL)); IDictionary <string, object> options = new Dictionary <string, object> (); options.Add("customer_id", "cust_2WmsOoSRZMWWkcZg"); options.Add("due_date", 1539171804); options.Add("currency", "INR"); options.Add("amount", 100); PaymentLink paymentLink = client.PaymentLink.Create(options); string expectedJsonString = Helper.GetJsonString(filepath); Helper.AssertEntity(paymentLink, expectedJsonString); }
public void OnTick_WithPaidLinkAndHandlingPaymentLinkEvent_WorksAsExpected() { var options = new PardakhtVasetClientOptions(); options.ApiKey = "foo"; options.Password = "******"; options.ConnectionString = "fake connection string"; options.TablePrefix = ""; var mockedRepository = new Mock <IPaymentLinkRepository>(); var mockedPayRequest = new Mock <IPayRequestV2>(); var nextPaymentLink = new PaymentLink(); nextPaymentLink.Amount = 26000; nextPaymentLink.BankReferenceId = null; nextPaymentLink.CreateDate = new DateTime(2017, 12, 3); nextPaymentLink.Description = "بابت مانده حساب"; nextPaymentLink.ExpireDays = 30; nextPaymentLink.FollowId = "324"; nextPaymentLink.LastCheckForUpdateDate = new DateTime(2017, 12, 3); nextPaymentLink.PaymentStatus = (int)RequestStatus.Initiated; nextPaymentLink.ResultDate = null; nextPaymentLink.Token = "1d372049-17de-4550-aecc-06111fdf2a9b"; nextPaymentLink.Url = "https://pardakhtvaset.com/pay?token=1d372049-17de-4550-aecc-06111fdf2a9b"; mockedRepository.Setup(x => x.GetNextLinkForCheck(null)).Returns(nextPaymentLink); var fakeEpayResult = new EPayRequestCheckResult(); fakeEpayResult.BankReferenceId = "57430753503405340"; fakeEpayResult.RequestStatus = RequestStatus.Paid; fakeEpayResult.Success = true; fakeEpayResult.VerifyDate = new DateTime(2017, 12, 4); mockedPayRequest.Setup(x => x.Check(options.ApiKey, options.Password, nextPaymentLink.Token)).Returns(fakeEpayResult); var service = new PaymentLinkNotificationService(options, mockedRepository.Object, mockedPayRequest.Object); service.PaymentLinkChanged += (o, e) => e.Handled = true; service.OnTick(); mockedRepository.Verify(x => x.GetNextLinkForCheck(It.IsAny <string>()), Times.Once()); mockedPayRequest.Verify(x => x.Check(options.ApiKey, options.Password, nextPaymentLink.Token), Times.Once()); mockedRepository.Verify(x => x.Update(nextPaymentLink), Times.Once()); }
public static PaymentLinkData ToLinkData(this PaymentLink link) { var paymentStatus = string.IsNullOrWhiteSpace(link.LastPaymentResponse) ? CreditCardPaymentStatuses.Created : JsonConvert.DeserializeObject <PaymentResponse>(link.LastPaymentResponse).Status; return(new PaymentLinkData(amount: link.Amount, email: link.Email, serviceType: link.ServiceType, currency: link.Currency, comment: link.Comment, referenceCode: link.ReferenceCode, creditCardPaymentStatus: paymentStatus, code: link.Code, date: link.Created.DateTime, paymentProcessor: link.PaymentProcessor)); }
public void TestGetAllPaymentsForPaymentLink() { string filepath = "dummy_payment_link.json"; string url = string.Format("{0}/{1}", paymentLinkURL, PAYMENTLINKID); Client client = new Client(ACCESSID, SECRETKEY, Helper.GetMockRequestFactory(filepath, url)); PaymentLink paymentLink = client.PaymentLink.Retrieve(PAYMENTLINKID); string expectedJsonString = Helper.GetJsonString(filepath); Helper.AssertEntity(paymentLink, expectedJsonString); string filepath2 = "dummy_payment_collection.json"; string payments_url = string.Format("{0}/payments", url); client = new Client(ACCESSID, SECRETKEY, Helper.GetMockRequestFactory(filepath2, payments_url)); var result = paymentLink.Payments(); expectedJsonString = Helper.GetJsonString(filepath2); Helper.AssertEntity(result, expectedJsonString); }
private Task <Result <PaymentResponse> > ProcessPay(PaymentLink link, string code, string token, string ip, string languageCode) { return(Pay() .CheckIf(IsPaymentComplete, CheckPaymentAmount) .TapIf(IsPaymentComplete, SendConfirmation) .Map(ToPaymentResponse) .Tap(StorePaymentResult)); Task <Result <CreditCardPaymentResult> > Pay() => _payfortService.Pay(new CreditCardPaymentRequest( link.Amount, link.Currency, new PaymentTokenInfo(token, PaymentTokenTypes.OneTime), null, link.Email, ip, link.ReferenceCode, languageCode, true, // Is not needed for new card null, link.ReferenceCode)); Result CheckPaymentAmount(CreditCardPaymentResult paymentResult) { return(link.Amount == paymentResult.Amount ? Result.Success() : Result.Failure($"Payment amount invalid, expected '{link.Amount}' but was '{paymentResult.Amount}'")); } bool IsPaymentComplete(CreditCardPaymentResult paymentResult) => paymentResult.Status == CreditCardPaymentStatuses.Success; Task SendConfirmation() => this.SendConfirmation(link.ToLinkData()); PaymentResponse ToPaymentResponse(CreditCardPaymentResult cr) => new PaymentResponse(cr.Secure3d, cr.Status, cr.Message); Task StorePaymentResult(PaymentResponse response) => _storage.UpdatePaymentStatus(code, response); }