private static StripeAppointmentCharge MapStripeAppointmentCharge(IDataReader reader) { int indexCounter = 0; StripeAppointmentCharge charge = new StripeAppointmentCharge(); charge.AppointmentId = reader.GetSafeInt32(indexCounter++); charge.StripeChargeId = reader.GetSafeString(indexCounter++); charge.IsRefunded = reader.GetSafeBool(indexCounter++); return(charge); }
public ActionResult <SuccessResponse> RefundAppointmentCharge(int id, string reason) { int responseCode = 200; BaseResponse responseData = null; try { // Get charge id using appointment id StripeAppointmentCharge appointmentCharge = _service.GetChargeByAppointmentId(id); if (appointmentCharge == null) { string msg = "This appointment does not have an associated charge."; responseCode = 404; responseData = new ErrorResponse(msg); return(StatusCode(responseCode, responseData)); } else if (appointmentCharge.IsRefunded == true) { string msg = "This appointment has already been refunded."; responseCode = 400; responseData = new ErrorResponse(msg); return(StatusCode(responseCode, responseData)); } string chargeId = appointmentCharge.StripeChargeId; // Process a refund for this charge with chargeId Refund refund = RefundCharge(chargeId); if (refund.Status != "succeeded") { string msg = "This charge is not refundable."; responseCode = 404; responseData = new ErrorResponse(msg); return(StatusCode(responseCode, responseData)); } // Update stripe appointment charge table _service.UpdateStripeChargeByAppointmentId(id, true); _service.CancelAppointment(id, reason); // When successful return success response responseData = new SuccessResponse(); } catch (Exception exception) { responseCode = 500; responseData = new ErrorResponse($"Generic Error: {exception.Message}"); base.Logger.LogError(exception.ToString()); } return(StatusCode(responseCode, responseData)); }
public StripeAppointmentCharge GetChargeByChargeId(string ChargeId) { StripeAppointmentCharge charge = null; string procName = "[dbo].[StripeAppointmentCharges_SelectByChargeId]"; _data.ExecuteCmd( procName, delegate(SqlParameterCollection inputCollection) { inputCollection.AddWithValue("@StripeChargeId", ChargeId); }, delegate(IDataReader reader, short set) { charge = MapStripeAppointmentCharge(reader); } ); return(charge); }
public ActionResult <SuccessResponse> TransferChargeToProvider(ChargeTransferRequest request) { int responseCode = 200; BaseResponse responseData = null; try { int appointmentId = request.AppointmentId; int providerId = request.ProviderId; // Get charge id using appointment id StripeAppointmentCharge appointmentCharge = _service.GetChargeByAppointmentId(appointmentId); if (appointmentCharge == null) { string msg = "This appointment does not have an associated charge."; responseCode = 404; responseData = new ErrorResponse(msg); return(StatusCode(responseCode, responseData)); } else if (appointmentCharge.IsRefunded == true) { string msg = "This appointment has been refunded."; responseCode = 400; responseData = new ErrorResponse(msg); return(StatusCode(responseCode, responseData)); } string chargeId = appointmentCharge.StripeChargeId; // Get account id using provider id string accountId = _service.GetAccountId(providerId); if (String.IsNullOrEmpty(accountId)) { string msg = "This user does not have a Connect Id."; responseCode = 404; responseData = new ErrorResponse(msg); return(StatusCode(responseCode, responseData)); } // Create the transfer using charge and account ids Transfer transfer = TransferCharge(chargeId, accountId); if (transfer == null) { string msg = "Transfer could not be created."; responseCode = 404; responseData = new ErrorResponse(msg); return(StatusCode(responseCode, responseData)); } _service.DeleteAppointment(request.AppointmentId); // When successful return success response responseData = new SuccessResponse(); } catch (Exception exception) { responseCode = 500; responseData = new ErrorResponse($"Generic Error: {exception.Message}"); base.Logger.LogError(exception.ToString()); } return(StatusCode(responseCode, responseData)); }