/// <summary> /// 发起退款请求 /// </summary> /// <param name="out_order_no">订单号必填</param> /// <param name="create_time">否,当仅上送out_order_no需上送,若不上送,默认当天</param> /// <param name="num8">退款金额</param> /// <returns></returns> private bool RefundRequest(string out_order_no, string create_time, double num8) { string refund_request_no = Guid.NewGuid().ToString("N").ToString(); string refundResult = HeMaPay.Refund(out_order_no.ToString(), refund_request_no, num8, create_time); if (string.IsNullOrWhiteSpace(refundResult)) { return(RefundDB(refund_request_no, out_order_no, refundResult, "0")); } else { JObject retRefundObj = JObject.Parse(refundResult); if (retRefundObj["code"].ToString().Equals("200")) { JObject retRefundDetailObj = JObject.Parse(retRefundObj["data"].ToString()); if (retRefundDetailObj["sub_code"].ToString().Equals("REFUND_SUCCESS")) { return(RefundDB(refund_request_no, out_order_no, refundResult, "1")); } else { return(RefundDB(refund_request_no, out_order_no, refundResult, "0")); } } else { return(RefundDB(refund_request_no, out_order_no, refundResult, "0")); } } }
private void RefundFailedTask() { DbUtil dbUtil = new DbUtil(); DataTable dataTable2 = dbUtil.ExecuteQuery("SELECT * FROM he_ma_pay_refund_failed"); if (dataTable2 != null) { for (int i = 0; i < dataTable2.Rows.Count; i++) { DataRow dataRow = dataTable2.Rows[i]; string out_order_no = dataRow["out_order_no"].ToString(); string total_amount = dataRow["total_amount"].ToString(); string create_time = dataRow["create_time"].ToString(); // 发起退款请求 string refundResult = HeMaPay.Refund(out_order_no, Guid.NewGuid().ToString("N").ToString(), double.Parse(total_amount), create_time); if (!string.IsNullOrWhiteSpace(refundResult)) { JObject retRefundObj2 = JObject.Parse(refundResult); if (retRefundObj2["code"].ToString().Equals("200")) { JObject retRefundDetailObj2 = JObject.Parse(retRefundObj2["data"].ToString()); if (retRefundDetailObj2["sub_code"].ToString().Equals("REFUND_SUCCESS")) { // 退款成功修改数据 refundOK(out_order_no, refundResult); } } } } } }
/// <summary> /// 退款 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { string refund_request_no = Guid.NewGuid().ToString(); this.textBox_refund_request_no.Text = refund_request_no; string out_order_no = this.textBox1.Text; string amount = this.textBox2.Text; string order_create_time = strToTime(this.textBox3.Text); if (string.IsNullOrWhiteSpace(out_order_no) || string.IsNullOrWhiteSpace(amount) || string.IsNullOrWhiteSpace(order_create_time)) { WMMessageBox.Show(this, "请选择退款错误的数据!"); return; } double refund_fee = double.Parse(amount); string refundResult = HeMaPay.Refund(out_order_no, refund_request_no, refund_fee, order_create_time); if (string.IsNullOrWhiteSpace(refundResult)) { RefundDB(out_order_no, refundResult, "0"); WMMessageBox.Show(this, "退款失败,请稍后再试!"); return; } else { JObject retRefundObj = JObject.Parse(refundResult); if (retRefundObj["code"].ToString().Equals("200")) { JObject retRefundDetailObj = JObject.Parse(retRefundObj["data"].ToString()); if (retRefundDetailObj["sub_code"].ToString().Equals("REFUND_SUCCESS")) { refundOK(out_order_no, refundResult); cleanData(); initDGV(); WMMessageBox.Show(this, "退款成功!"); return; } else { RefundDB(out_order_no, refundResult, "0"); showCauseOfError(retRefundDetailObj); WMMessageBox.Show(this, "退款失败!"); return; } } else { RefundDB(out_order_no, refundResult, "0"); showCauseOfError(retRefundObj); WMMessageBox.Show(this, "退款失败!"); return; } } }