package io.renren.demo;

import com.alibaba.fastjson.JSON;

import io.renren.common.utils.DateUtils;
import io.renren.common.utils.HttpClientUtil;
import io.renren.vo.AgreeApplyParams;
import io.renren.vo.AgreePageQueryParams;
import io.renren.vo.AgreeQueryParams;

/**
 * 用户委托协议申请/修改 Demo
 */
public class PapAgreeApplyAndModifyDemo {
    public static void main(String[] args) {
    	//apply();
        //modify();
    	//query();
    	queryPage();
    }
    
    public static void queryPage() {
    	AgreePageQueryParams params = new AgreePageQueryParams();
        params.setTimestamp(DateUtils.getTimestamp());
        params.setOid_partner(Constant.OidPartner);
        params.setUser_id("LLianPayTest-En-User-123");
        params.setStatus("Enabled");
        params.setPage_no("1");
        params.setPage_size("10");
        
        String url = "https://accpapi-ste.lianlianpay-inc.com/v1/txn/pap-agree-pagequery";
        String resultJsonStr = HttpClientUtil.sendRequest(url, JSON.toJSONString(params),Constant.MerchantPrivateKey,Constant.LLianPayPublicKey);
        System.out.println(resultJsonStr);
    }

    /**
     * 用户委托协议申请
     */
    public static void apply() {
        AgreeApplyParams params = new AgreeApplyParams();
        String timestamp = DateUtils.getTimestamp();
        params.setTimestamp(timestamp);
        params.setOid_partner(Constant.OidPartner);
        params.setTxn_seqno("LLianPayTest" + timestamp);
        params.setTxn_time(timestamp);
        params.setUser_id("LLianPayTest-En-User-123");
        params.setFlag_chnl("H5");
        params.setNotify_url("https://test.lianlianpay/notify");
        params.setReturn_url("https://open.lianlianpay.com?jump=page");

        // 设置签约信息
        AgreeApplyParams.AgreeSignInfoParam papAgreeSignInfo = params.new AgreeSignInfoParam();
        papAgreeSignInfo.setSign_start_time("20221029");
        papAgreeSignInfo.setSign_invalid_time("20331001");
        papAgreeSignInfo.setSingle_limit(50000.00);
        papAgreeSignInfo.setDaily_limit(100000.00);
        papAgreeSignInfo.setMonthly_limit(500000.00);
        /*
        免密协议类型。
        WITH_HOLD：免密代扣
        WITH_WITHDRAW：免密提现
        注：若不填写，则默认为免密代扣。
         */
        papAgreeSignInfo.setAgreement_type("WITH_HOLD");
        params.setPapSignInfo(papAgreeSignInfo);

        // 测试环境URL
        String url = "https://accpgw-ste.lianlianpay-inc.com/v1/txn/pap-agree-apply";
        String resultJsonStr = HttpClientUtil.sendRequest(url, JSON.toJSONString(params),Constant.MerchantPrivateKey,Constant.LLianPayPublicKey);
        System.out.println(resultJsonStr);
    }

    /**
     * 用户委托协议修改
     */
    public static void modify() {
        AgreeApplyParams params = new AgreeApplyParams();
        String timestamp = DateUtils.getTimestamp();
        params.setTimestamp(timestamp);
        params.setOid_partner(Constant.OidPartner);
        params.setTxn_seqno("LLianPayTest" + timestamp);
        params.setTxn_time(timestamp);
        params.setUser_id("LLianPayTest-In-User-12345");
        params.setPap_agree_no("2022093000265008");
        params.setFlag_chnl("H5");
        params.setNotify_url("https://test.lianlianpay/notify");
        params.setReturn_url("https://open.lianlianpay.com?jump=page");

        // 设置签约信息
/*        PapAgreeSignInfo papAgreeSignInfo = new PapAgreeSignInfo();
        papAgreeSignInfo.setSign_start_time("20221001");
        papAgreeSignInfo.setSign_invalid_time("20231001");
        papAgreeSignInfo.setSingle_limit(100.00);
        papAgreeSignInfo.setDaily_limit(1000.00);
        papAgreeSignInfo.setMonthly_limit(5000.00);
        *//*
        免密协议类型。
        WITH_HOLD：免密代扣
        WITH_WITHDRAW：免密提现
        注：若不填写，则默认为免密代扣。
         *//*
        papAgreeSignInfo.setAgreement_type("WITH_HOLD");
        params.setPapSignInfo(papAgreeSignInfo);*/

        // 测试环境URL
        String url = "https://accpgw-ste.lianlianpay-inc.com/v1/txn/pap-agree-modify";
        String resultJsonStr = HttpClientUtil.sendRequest(url, JSON.toJSONString(params),Constant.MerchantPrivateKey,Constant.LLianPayPublicKey);
        System.out.println(resultJsonStr);
    }


    public static void query() {
    	AgreeQueryParams params = new AgreeQueryParams();
        String timestamp = DateUtils.getTimestamp();
        params.setTimestamp(timestamp);
        params.setOid_partner(Constant.OidPartner);
        params.setOri_txn_seqno("LLianPayTest20221023151230");
        params.setUser_id("LLianPayTest-En-User-123");


        // 测试环境URL
        String url = "https://accpapi-ste.lianlianpay-inc.com/v1/txn/pap-agree-query";
        String resultJsonStr = HttpClientUtil.sendRequest(url, JSON.toJSONString(params),Constant.MerchantPrivateKey,Constant.LLianPayPublicKey);
        System.out.println(resultJsonStr);
    }
}
