package com.younike.wxpay.service.impl;

import com.younike.wxpay.enums.TransactionType;
import com.younike.wxpay.params.CloseParams;
import com.younike.wxpay.params.QueryParams;
import com.younike.wxpay.params.TransactionParams;
import com.younike.wxpay.responses.CloseResponse;
import com.younike.wxpay.responses.QueryResponse;
import com.younike.wxpay.responses.TransactionResponse;
import com.younike.wxpay.service.IMerchantPayService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class MerchantPayServiceImpl extends BasePayServiceImpl implements IMerchantPayService {

    @PostConstruct
    public void setup() {
        super.setup(PaymentConfig.builder()
                .isSupplier(false)
                .mchId("1562727221")
                .appId("wxcc56354382c8f8b4")
                .mchSerialNo("74473FC19D98634149603AF018CA84A217D85CD2")
                .apiV3Key("olJz7dYC7GbikgTw0QwTAmAjlFc7az9p")
                .certificatesPath("certs/uxx-merchant")
                .build());
    }

    @Override
    public TransactionResponse transaction(TransactionType type, TransactionParams params) {
        params.setMchid(config.mchId);
        params.setAppid(config.appId);
        return super.transaction(type, params);
    }

    @Override
    public QueryResponse query(String outTradeNo, QueryParams params) {
        params.setMchid(config.mchId);
        return super.query(outTradeNo, params);
    }

    @Override
    public CloseResponse close(String outTradeNo, CloseParams params) {
        params.setMchid(config.mchId);
        return super.close(outTradeNo, params);
    }
}
