package com.yonge.toolset.payment.adapay.config;

import com.huifu.adapay.Adapay;
import com.huifu.adapay.model.MerConfig;
import com.yonge.toolset.payment.adapay.constant.AdapayConstant;
import com.yonge.toolset.payment.base.enums.OpenEnum;
import com.yonge.toolset.payment.core.service.SysConfigPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: liweifan
 * @Data: 2022/5/12 10:12
 */
@Configuration
public class AdapayConfiguration {
    @Autowired
    private SysConfigPaymentService configPaymentService;

    @Bean
    public MerConfig merConfig() {
        MerConfig merConfig = new MerConfig();
        merConfig.setApiKey(configPaymentService.getPaymentConfig(OpenEnum.ADAPAY, AdapayConstant.API_KEY).getParamValue());
        merConfig.setApiMockKey(configPaymentService.getPaymentConfig(OpenEnum.ADAPAY, AdapayConstant.MOCK_API_KEY).getParamValue());
        merConfig.setRSAPrivateKey(configPaymentService.getPaymentConfig(OpenEnum.ADAPAY, AdapayConstant.RSA_PRIVATE_KEY).getParamValue());
        try {
            Adapay.initWithMerConfig(merConfig);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return merConfig;
    }
}
