public virtual async Task HandleRefundTransaction(HSOrderWorksheet worksheet, HSPayment creditCardPayment, HSPaymentTransaction creditCardPaymentTransaction, decimal totalToRefund, RMA rma) { try { CardConnectRefundRequest requestedRefund = new CardConnectRefundRequest() { currency = worksheet.Order.xp.Currency.ToString(), merchid = creditCardPaymentTransaction.xp.CardConnectResponse.merchid, retref = creditCardPaymentTransaction.xp.CardConnectResponse.retref, amount = totalToRefund.ToString("F2"), }; CardConnectRefundResponse response = await _cardConnect.Refund(requestedRefund); HSPayment newCreditCardPayment = new HSPayment() { Amount = response.amount }; await _oc.Payments.CreateTransactionAsync(OrderDirection.Incoming, rma.SourceOrderID, creditCardPayment.ID, CardConnectMapper.Map(newCreditCardPayment, response)); } catch (CreditCardRefundException ex) { throw new CatalystBaseException(new ApiError { ErrorCode = "Payment.FailedToRefund", Message = ex.ApiError.Message }); } }
private async Task CapturePaymentAsync(HSOrder order, HSPayment payment, HSPaymentTransaction transaction) { try { var response = await _cardConnect.Capture(new CardConnectCaptureRequest { merchid = transaction.xp.CardConnectResponse.merchid, retref = transaction.xp.CardConnectResponse.retref, currency = order.xp.Currency.ToString() }); await _oc.Payments.CreateTransactionAsync(OrderDirection.Incoming, order.ID, payment.ID, CardConnectMapper.Map(payment, response)); } catch (CardConnectInquireException ex) { throw new PaymentCaptureJobException("Error inquiring payment. Message: {ex.ApiError.Message}, ErrorCode: {ex.ApiError.ErrorCode}", order.ID, payment.ID, transaction.ID); } catch (CardConnectCaptureException ex) { await _oc.Payments.CreateTransactionAsync(OrderDirection.Incoming, order.ID, payment.ID, CardConnectMapper.Map(payment, ex.Response)); throw new PaymentCaptureJobException($"Error capturing payment. Message: {ex.ApiError.Message}, ErrorCode: {ex.ApiError.ErrorCode}", order.ID, payment.ID, transaction.ID); } }