package org.springblade.payment.callback.inivtation;

import org.springblade.common.enums.AppConstant;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.flow.mall.service.IAuditMallService;
import org.springblade.flow.shop.entity.InvitationCallbackData;
import org.springblade.yeePay.service.YeePayService;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author: lianghanqiang
 * @description: 商场入网通知回调
 * @since: 9/15/21 -- 5:26 PM
 */
public class MallInvitationCallback implements InvitationCallbackHandle {

	private final YeePayService yeePayService;
	private final IAuditMallService auditMallService;

	//初始化各状态回调处理
	{
		this.yeePayService = SpringUtil.getBean(YeePayService.class);
		this.auditMallService = SpringUtil.getBean(IAuditMallService.class);
	}

	@Override
	public void handle(HttpServletRequest httpRequest, AppConstant.InvitationType invitationType) {
		Map<String, String[]> parameterMap = httpRequest.getParameterMap();
		InvitationCallbackData invitationCallbackData = yeePayService.deCodeNotifyData(parameterMap.get("cipherText")[0], InvitationCallbackData.class);
		auditMallService.invitationCallback(invitationCallbackData);
	}
}
