package com.fs.huifuPay.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fs.huifuPay.domain.*;
import com.fs.huifuPay.sdk.opps.core.request.*;
import com.fs.huifuPay.service.impl.HuiFuServiceImpl;
import java.util.HashMap;
import java.util.Map;

public class test {
    static HuiFuServiceImpl huiFuService = new HuiFuServiceImpl();
    public static void main(String[] args)throws Exception {
//        onlinePay();
        createOrder();
    }
    public static void  createOrder()throws Exception {
        HuiFuCreateOrder order = new HuiFuCreateOrder();
        //    T_MINIAPP: 微信小程序
        //    A_NATIVE: 支付宝正扫
        order.setTradeType("A_NATIVE");
       order.setOpenid("oCtcH7pwOWlPMBJJyQQQz32qq2og");
        order.setReqSeqId("inquiry-117");
        order.setTransAmt("0.01");
        // 商品描述
        order.setGoodsDesc("hibs自动化-通用版验证");
        HuifuCreateOrderResult result = huiFuService.createOrder(order);
        System.out.println(result);
    }
    public static void  queryOrder()throws Exception {
        V2TradePaymentScanpayQueryRequest request = new V2TradePaymentScanpayQueryRequest();
        //日期必须正确
         request.setOrgReqDate("20240419");
        //选其一
        // request.setOrgHfSeqId("002900TOP1A240417114227P471ac139c3f00000");
         request.setOrgReqSeqId("inquiry-117");
        HuiFuQueryOrderResult result = huiFuService.queryOrder(request);
        System.out.println(result);
    }
    public static void  close()throws Exception {
        V2TradePaymentScanpayCloseRequest request = new V2TradePaymentScanpayCloseRequest();
        request.setOrgReqDate("20240417");
        request.setReqSeqId("close-111");
        Map<String, Object> extendInfoMap = new HashMap<>();
        extendInfoMap.put("org_req_seq_id", "inquiry-111");
        request.setExtendInfo(extendInfoMap);
        HuiFuCloseResult huiFuCloseResult = huiFuService.closeOrder(request);
        System.out.println(huiFuCloseResult);
    }

    public static void  refund()throws Exception {
        V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
        request.setOrdAmt("0.01");
        //订单创建日期
        request.setOrgReqDate("20240419");
        //退款单号
        request.setReqSeqId("refund-117");
        Map<String, Object> extendInfoMap = new HashMap<>();
        extendInfoMap.put("org_req_seq_id", "inquiry-117");
        request.setExtendInfo(extendInfoMap);
        HuiFuRefundResult refund = huiFuService.refund(request);
        System.out.println(refund);
    }

    public static void  queryRefund()throws Exception {
        V2TradePaymentScanpayRefundqueryRequest request = new V2TradePaymentScanpayRefundqueryRequest();
        // 退款请求日期
        request.setOrgReqDate("20240419");
        //自己传的
        request.setOrgReqSeqId("refund-117");
      //  request.setOrgHfSeqId("003100TOP1A240417140920P850ac139c3b00000");
        HuiFuRefundResult huiFuRefundResult = huiFuService.queryRefundOrder(request);
        System.out.println(huiFuRefundResult);
    }

    public static void  onlinePay()throws Exception {
        V2TradeOnlinepaymentTransferAccountRequest request = new V2TradeOnlinepaymentTransferAccountRequest();
        request.setReqSeqId("DE-333");
//        request.setCertificateName("测试");
//        request.setBankCardNo("6214180300000380805");
        request.setTransAmt("0.01");
        request.setGoodsDesc("商品描述001");
        HuiFuOnlinePayResult huiFuOnlinePayResult = huiFuService.onlinepaymentTransferAccount(request);
        System.out.println(huiFuOnlinePayResult);
    }
    public static void  onlineQuery()throws Exception {
        V2TradeOnlinepaymentTransferAccountQueryRequest request = new V2TradeOnlinepaymentTransferAccountQueryRequest();
        request.setOrgReqSeqId("DE-222");
        // 原请求日期
        request.setOrgReqDate("20240418");
        // 打款结束日期
        request.setTransEndDate("20240418");
        HuiFuOnlinePayQueryResult huiFuOnlinePayQueryResult = huiFuService.onlinepaymentTransferAccountQuery(request);
        System.out.println(huiFuOnlinePayQueryResult);
    }
    public static void  onlineRefund()throws Exception {
        V2TradeOnlinepaymentRefundRequest request = new V2TradeOnlinepaymentRefundRequest();
        request.setReqSeqId("refund-222");
        request.setOrdAmt("0.01");
        Map<String, Object> extendInfoMap = new HashMap<>();
        extendInfoMap.put("org_req_seq_id", "DE-222");
        extendInfoMap.put("org_req_date", "20240418");
        request.setExtendInfo(extendInfoMap);
        HuiFuOnlineRefundResult huiFuOnlineRefundResult = huiFuService.onlinepaymentRefund(request);
        System.out.println(huiFuOnlineRefundResult);
    }


    public static void  onlineRefundQuery()throws Exception {
        V2TradeOnlinepaymentRefundQueryRequest request = new V2TradeOnlinepaymentRefundQueryRequest();
        request.setOrgReqDate("20240418");
        Map<String, Object> extendInfoMap = new HashMap<>();
        extendInfoMap.put("org_req_seq_id", "refund-222");
        request.setExtendInfo(extendInfoMap);
        HuiFuOnlineRefundQueryResult result = huiFuService.onlinepaymentRefundQuery(request);
        System.out.println(result);
    }
    public static void  acctPay()throws Exception {
        V2TradeAcctpaymentPayRequest request = new V2TradeAcctpaymentPayRequest();
        request.setReqSeqId("acc-111");
        // 出款方商户号
        request.setOutHuifuId("6666000149635112");
        request.setOrdAmt("0.01");
        // 分账对象
        JSONObject acctSplitBunch = new JSONObject();
        JSONObject acctInfo = new JSONObject();
        acctInfo.put("div_amt", "0.01");
        acctInfo.put("huifu_id", "6666000149635112");
        JSONArray dtoList = new JSONArray();
        dtoList.add(acctInfo);
        acctSplitBunch.put("acct_infos", acctInfo);
        request.setAcctSplitBunch(acctSplitBunch.toJSONString());
        acctPayResult acctPayResult = huiFuService.acctPay(request);
        System.out.println(acctPayResult);
    }
    public static void  acctQuery()throws Exception {
        V2TradeAcctpaymentPayQueryRequest request = new V2TradeAcctpaymentPayQueryRequest();
        request.setOrgReqDate("20240418");
        // 设置非必填字段
        Map<String, Object> extendInfoMap = new HashMap<>();
        // 原交易请求流水号
        extendInfoMap.put("org_req_seq_id", "202110210012100005");
        // 原交易全局流水号
        extendInfoMap.put("org_hf_seq_id", "");
        request.setExtendInfo(extendInfoMap);
        acctPayQueryResult acctPayQueryResult = huiFuService.acctPayQuery(request);
        System.out.println(acctPayQueryResult);
    }
    public static void  acctRefund()throws Exception {
        V2TradeAcctpaymentRefundRequest request = new V2TradeAcctpaymentRefundRequest();
        // 请求流水号
        request.setReqSeqId("refund-111");
        request.setOrgReqDate("20240418");
        // 退款金额
        request.setOrdAmt("0.01");
        Map<String, Object> extendInfoMap = new HashMap<>();
        // 备注
        extendInfoMap.put("remark", "1234567890");
        // 原余额支付请求流水号
        extendInfoMap.put("org_req_seq_id", "202110210012100005");
        // 原余额支付支付全局流水号
        extendInfoMap.put("org_hf_seq_id", "");
        request.setExtendInfo(extendInfoMap);
        acctPayRefundResult acctPayRefundResult = huiFuService.acctPayRefund(request);
        System.out.println(acctPayRefundResult);
    }
    public static void  acctRefundQuery()throws Exception {
        V2TradeAcctpaymentRefundQueryRequest request = new V2TradeAcctpaymentRefundQueryRequest();
        request.setOrgReqSeqId("rund-1111");
        request.setOrgReqDate("20211021");
        acctPayRefundQueryResult acctPayRefundQueryResult = huiFuService.acctPayRefundQuery(request);
        System.out.println(acctPayRefundQueryResult);
    }
}
