package com.izouma.nineth.config;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import lombok.AllArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@AllArgsConstructor
@Configuration
@EnableConfigurationProperties({AlipayProperties.class})
public class AlipayConfig {
    private final AlipayProperties properties;

    @Bean
    public AlipayClient alipayClient() {
        com.alipay.api.AlipayConfig config = new com.alipay.api.AlipayConfig();
        config.setAppId(properties.getAppId());
        config.setPrivateKey(properties.getPrivateKey());
        config.setAlipayPublicKey(properties.getAliPublicKey());
        //config.setSignType("RSA2");
        AlipayClient alipayClient = null;
        try {
            alipayClient = new DefaultAlipayClient(config);
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }

        return alipayClient;
    }
}
