public void CreatePaymentTest_Validate_Approve_Status_Balance_Check() { decimal initialBalance = InMemoryData.CurrentBalance; CreatePaymentRequest request = new CreatePaymentRequest { Amount = 10, PaymentDate = DateTime.Now }; PaymentValidatorService validatorService = new PaymentValidatorService(); PaymentService paymentService = new PaymentService(validatorService); CreatePaymentResponse response = paymentService.CreatePayment(request); if (response.IsValid && response.Payment != null && response.Payment.RunningBalance == initialBalance && response.ErrorMessages.Count == 0 && response.Payment.Status == "Pending") { ApprovePaymentRequest approvePaymentRequest = new ApprovePaymentRequest(); approvePaymentRequest.PaymentId = response.Payment.PaymentId; ApprovePaymentResponse approvePaymentResponse = paymentService.ApprovePayment(approvePaymentRequest); if (approvePaymentResponse.IsValid) { Assert.IsTrue(approvePaymentResponse.Payment.Status == "Processed"); Assert.IsTrue(approvePaymentResponse.Payment.RunningBalance == (initialBalance - request.Amount)); Assert.IsTrue(approvePaymentResponse.Payment.Amount == request.Amount); } } else { string msg = string.Empty; string delimiter = Environment.NewLine; response.ErrorMessages.ForEach(x => msg += x + delimiter); Assert.Fail(msg); } }
static async Task <string> ApprovePayment(Guid paymentId) { Console.WriteLine(); Console.WriteLine("******Approve payment test***********"); Console.WriteLine(); Uri u = new Uri(baseUrl + "approvepayment"); var response = string.Empty; using (var client = new HttpClient()) { ApprovePaymentRequest payload = new ApprovePaymentRequest(); payload.PaymentId = paymentId; HttpResponseMessage res = await client.PostAsJsonAsync(u, payload); if (res.IsSuccessStatusCode) { ApprovePaymentResponse reply = await res.Content.ReadAsAsync <ApprovePaymentResponse>(); if (reply.Payment.PaymentId == paymentId && reply.Payment.Status == "Processed") { Console.WriteLine("Approve payment failed for payment id " + paymentId); } return(JsonConvert.SerializeObject(reply)); } } return(response); }
public ApprovePaymentResponse ValidateApprovePayment(ApprovePaymentRequest approvePaymentRequest) { ApprovePaymentResponse response = new ApprovePaymentResponse(); Payment payment = InMemoryData.Payments.FirstOrDefault(x => x.PaymentId == approvePaymentRequest.PaymentId); if (payment == null) { response.ErrorMessages.Add("Such a payment does not exists!!!!"); } else if (payment.Status == "Pending") { response.IsValid = true; response.Payment = payment; } else { response.ErrorMessages.Add("You cannot approve/cancel processed or closed payments"); } return(response); }
/// <summary> /// Resource /{merchantId}/payments/{paymentId}/approve /// - <a href="https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/dotnet/payments/approve.html">Approve payment</a> /// </summary> /// <param name="paymentId">string</param> /// <param name="body">ApprovePaymentRequest</param> /// <param name="context">CallContext</param> /// <returns>PaymentApprovalResponse</returns> /// <exception cref="ValidationException">if the request was not correct and couldn't be processed (HTTP status code BadRequest)</exception> /// <exception cref="AuthorizationException">if the request was not allowed (HTTP status code Forbidden)</exception> /// <exception cref="IdempotenceException">if an idempotent request caused a conflict (HTTP status code Conflict)</exception> /// <exception cref="ReferenceException">if an object was attempted to be referenced that doesn't exist or has been removed, /// or there was a conflict (HTTP status code NotFound, Conflict or Gone)</exception> /// <exception cref="GlobalCollectException">if something went wrong at the Ingenico ePayments platform, /// the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, /// or the service that you're trying to reach is temporary unavailable (HTTP status code InternalServerError, BadGateway or ServiceUnavailable)</exception> /// <exception cref="ApiException">if the Ingenico ePayments platform returned any other error</exception> public async Task <PaymentApprovalResponse> Approve(string paymentId, ApprovePaymentRequest body, CallContext context = null) { IDictionary <string, string> pathContext = new Dictionary <string, string>(); pathContext.Add("paymentId", paymentId); string uri = InstantiateUri("/v1/{merchantId}/payments/{paymentId}/approve", pathContext); try { return(await _communicator.Post <PaymentApprovalResponse>( uri, ClientHeaders, null, body, context)); } catch (ResponseException e) { object errorObject = _communicator.Marshaller.Unmarshal <ErrorResponse>(e.Body); throw CreateException(e.StatusCode, e.Body, errorObject, context); } }
public void CreatePaymentTest_Disallow_Cancel_On_Processed_Payments() { decimal initialBalance = InMemoryData.CurrentBalance; CreatePaymentRequest request = new CreatePaymentRequest { Amount = 10, PaymentDate = DateTime.Now }; PaymentValidatorService validatorService = new PaymentValidatorService(); PaymentService paymentService = new PaymentService(validatorService); CreatePaymentResponse response = paymentService.CreatePayment(request); if (response.IsValid && response.Payment != null && response.Payment.RunningBalance == initialBalance && response.ErrorMessages.Count == 0 && response.Payment.Status == "Pending") { ApprovePaymentRequest approvePaymentRequest = new ApprovePaymentRequest(); approvePaymentRequest.PaymentId = response.Payment.PaymentId; ApprovePaymentResponse approvePaymentResponse = paymentService.ApprovePayment(approvePaymentRequest); if (approvePaymentResponse.IsValid) { CancelPaymentRequest tryCancelClosedPayment = new CancelPaymentRequest(); tryCancelClosedPayment.PaymentId = approvePaymentResponse.Payment.PaymentId; CancelPaymentResponse disAllowedAction = paymentService.CancelPayment(tryCancelClosedPayment); Assert.IsFalse(disAllowedAction.IsValid); Assert.IsTrue(disAllowedAction.ErrorMessages.Count == 1); Assert.IsTrue(disAllowedAction.ErrorMessages[0] == "Only pending payment can be cancelled"); } } else { string msg = string.Empty; string delimiter = Environment.NewLine; response.ErrorMessages.ForEach(x => msg += x + delimiter); Assert.Fail(msg); } }
public async void Example() { #pragma warning disable 0168 using (Client client = GetClient()) { ApprovePaymentNonSepaDirectDebitPaymentMethodSpecificInput directDebitPaymentMethodSpecificInput = new ApprovePaymentNonSepaDirectDebitPaymentMethodSpecificInput(); directDebitPaymentMethodSpecificInput.DateCollect = "20150201"; directDebitPaymentMethodSpecificInput.Token = "bfa8a7e4-4530-455a-858d-204ba2afb77e"; OrderReferencesApprovePayment references = new OrderReferencesApprovePayment(); references.MerchantReference = "AcmeOrder0001"; OrderApprovePayment order = new OrderApprovePayment(); order.References = references; ApprovePaymentRequest body = new ApprovePaymentRequest(); body.Amount = 2980L; body.DirectDebitPaymentMethodSpecificInput = directDebitPaymentMethodSpecificInput; body.Order = order; PaymentApprovalResponse response = await client.Merchant("merchantId").Payments().Approve("paymentId", body); } #pragma warning restore 0168 }
public ApprovePaymentResponse ApprovePayment([FromBody] ApprovePaymentRequest request) { return(paymentService.ApprovePayment(request)); }
/// <summary> /// This method is for user story 3 /// </summary> /// <param name="approvePaymentRequest"></param> /// <returns></returns> public ApprovePaymentResponse ApprovePayment(ApprovePaymentRequest approvePaymentRequest) { return((ApprovePaymentResponse) new ApprovePaymentBL(this.PaymentValidatorService).ExecuteAction(approvePaymentRequest)); }