public IPaymentResult RefundPayment(IInvoice invoice, IPayment payment, decimal amount) { var api = new QuickPayApi(_settings.ApiKey); var paymentId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.QuickpayPaymentId); var amountMinor = IsZeroDecimalCurrency(invoice.CurrencyCode()) ? amount.ToString("F0") : (amount * 100).ToString("F0"); try { var refundResult = api.RefundPayment(paymentId, amountMinor); if (refundResult.Accepted && refundResult.Operations.Any(x => x.Type == "refund" && x.Amount.ToString("F0") == amountMinor)) { LogHelper.Info <QuickPayPaymentProcessor>(string.Format("QuickPay Refund PaymentId {0} Success:\r\n{1}", paymentId, refundResult)); return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, invoice.ShippingLineItems().Any())); } else { LogHelper.Info <QuickPayPaymentProcessor>(string.Format("QuickPay Refund PaymentId {0} Error:\r\n{1}", paymentId, refundResult)); return(new PaymentResult(Attempt <IPayment> .Fail(payment, new Exception(string.Format("{0}", "QuickPay Refund Unknown Error"))), invoice, false)); } } catch (Exception x) { LogHelper.Error <QuickPayPaymentProcessor>(string.Format("QuickPay Refund PaymentId {0} Error:\r\n{1}", paymentId, x.Message), x); return(new PaymentResult(Attempt <IPayment> .Fail(payment, new Exception(string.Format("{0}", "QuickPay Refund Unknown Error"))), invoice, false)); } }
public IPaymentResult PriorAuthorizeCapturePayment(IInvoice invoice, IPayment payment, decimal amount) { var api = new QuickPayApi(_settings.ApiKey); var paymentId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.QuickpayPaymentId); //var amountMinor = int.Parse(payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.QuickpayPaymentAmount)); var amountMinor = IsZeroDecimalCurrency(invoice.CurrencyCode()) ? amount.ToString("F0") : (amount * 100).ToString("F0"); try { var captureResult = api.CapturePayment(paymentId, amountMinor); if (captureResult.Accepted && captureResult.Operations.Any(x => x.Type == "capture" && x.Amount.ToString("F0") == amountMinor)) { LogHelper.Info<QuickPayPaymentProcessor>(string.Format("QuickPay Capture PaymentId {0} Success:\r\n{1}", paymentId, captureResult)); return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, invoice.ShippingLineItems().Any()); } else { LogHelper.Info<QuickPayPaymentProcessor>(string.Format("QuickPay Capture PaymentId {0} Error:\r\n{1}", paymentId, captureResult)); return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("{0}", "QuickPay unknown error"))), invoice, false); } } catch (Exception x) { LogHelper.Error<QuickPayPaymentProcessor>(string.Format("QuickPay Capture PaymentId {0} Error:\r\n{1}", paymentId, x.Message), x); return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("{0}", "QuickPay unknown error"))), invoice, false); } }
public IPaymentResult VoidPayment(IInvoice invoice, IPayment payment) { var api = new QuickPayApi(_settings.ApiKey); var paymentId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.QuickpayPaymentId); try { var cancelResult = api.CancelPayment(paymentId); if (cancelResult.Accepted && cancelResult.Operations.Any(x => x.Type == "cancel")) { LogHelper.Info <QuickPayPaymentProcessor>(string.Format("QuickPay Cancel PaymentId {0} Success:\r\n{1}", paymentId, cancelResult)); return(new PaymentResult(Attempt <IPayment> .Succeed(payment), invoice, invoice.ShippingLineItems().Any())); } else { LogHelper.Info <QuickPayPaymentProcessor>(string.Format("QuickPay Cancel PaymentId {0} Error:\r\n{1}", paymentId, cancelResult)); return(new PaymentResult(Attempt <IPayment> .Fail(payment, new Exception(string.Format("{0}", "QuickPay Cancel Unknown Error"))), invoice, false)); } } catch (Exception x) { LogHelper.Error <QuickPayPaymentProcessor>(string.Format("QuickPay Cancel PaymentId {0} Error:\r\n{1}", paymentId, x.Message), x); return(new PaymentResult(Attempt <IPayment> .Fail(payment, new Exception(string.Format("{0}", "QuickPay Cancel Unknown Error"))), invoice, false)); } }
public IPaymentResult VoidPayment(IInvoice invoice, IPayment payment) { var api = new QuickPayApi(_settings.ApiKey); var paymentId = payment.ExtendedData.GetValue(Constants.ExtendedDataKeys.QuickpayPaymentId); try { var cancelResult = api.CancelPayment(paymentId); if (cancelResult.Accepted && cancelResult.Operations.Any(x => x.Type == "cancel")) { LogHelper.Info<QuickPayPaymentProcessor>(string.Format("QuickPay Cancel PaymentId {0} Success:\r\n{1}", paymentId, cancelResult)); return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, invoice.ShippingLineItems().Any()); } else { LogHelper.Info<QuickPayPaymentProcessor>(string.Format("QuickPay Cancel PaymentId {0} Error:\r\n{1}", paymentId, cancelResult)); return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("{0}", "QuickPay Cancel Unknown Error"))), invoice, false); } } catch (Exception x) { LogHelper.Error<QuickPayPaymentProcessor>(string.Format("QuickPay Cancel PaymentId {0} Error:\r\n{1}", paymentId, x.Message), x); return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("{0}", "QuickPay Cancel Unknown Error"))), invoice, false); } }