package cn.hmsoft.pay.impl.anxinpay;

import java.io.OutputStream;

import cn.hmsoft.frame.util.FrameAssertUtil;
import cn.hmsoft.helper.qrcode.QrCodeEntity;
import cn.hmsoft.helper.qrcode.QrCodeHelper;
import cn.hmsoft.pay.data.model.PayBill;
import cn.hmsoft.pay.impl.PayAnxinPayChannelImpl;
import cn.hmsoft.pay.util.PayModuleConfig;
import cn.hmsoft.pay.util.PayParamUtil;

/***********************
 * 安心付工具
 * @author zxq
 * @create 2019-03-04 09:40:09
 * @version 5.0.0
 * @email: revisit@126.com
 * @Company: www.hmsoft.cn
 */
public class AnxinPayUtil {
	/***********************************
	 * 生成支付二维码
	 */
	public static void makeQrCode(String code, OutputStream stream) {
		// String url = "weixin://wxpay/bizpayurl?sr=" + code;
		QrCodeEntity entity = new QrCodeEntity();
		entity.setQrContent(code);
		QrCodeHelper.encode(entity, stream);
	}
	
	

	/************************************
	 * 生成支付订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param fee_amount 订单金额
	 * @param customer_id 客户编号
	 * @param business_id 业务编号
	 * @return
	 */
	public static PayBill makePayBill(String merchant_id, String channel_id,
			int order_amount, String customer_id, String business_id) {
		return makePayBill(merchant_id, channel_id, order_amount,
				customer_id, PayParamUtil.DefaultBusinessType, business_id,
				null);

	}

	

	/************************************
	 * 生成支付订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param fee_amount 订单金额
	 * @param customer_id 客户编号
	 * @param business_type 业务类型
	 * @param business_id 业务编号
	 * @return
	 */
	public static PayBill makePayBill(String merchant_id, String channel_id,
			int order_amount, String customer_id, String business_type,
			String business_id) {
		return makePayBill(merchant_id, channel_id,  order_amount,
				customer_id, business_type, business_id, null);

	}


	/************************************
	 * 生成支付订单
	 * 
	 * @param merchant_id 商户编号
	 * @param channel_id 渠道编号
	 * @param fee_amount 订单金额
	 * @param customer_id 客户编号
	 * @param business_type 业务类型
	 * @param business_id 业务编号
	 * @param product_name 商品名称
	 * @return
	 */
	public static PayBill makePayBill(String merchant_id, String channel_id,
			int order_amount, String customer_id,
			String business_type, String business_id, String product_name) {
	
		FrameAssertUtil.checkParam(merchant_id, channel_id);
		PayAnxinPayChannelImpl payImpl = (PayAnxinPayChannelImpl) PayModuleConfig
				.getPayImpl(merchant_id, channel_id);
		FrameAssertUtil.isNotNull(payImpl, "该商户指定的支付渠道未能成功加载，请联系技术部门");
		return payImpl.makePayBill( order_amount, customer_id,
				business_type, business_id, product_name);
	}
}
