|
|
@@ -551,6 +551,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Object devConfig() {
|
|
|
+ // 创建卡券模版
|
|
|
+ cardTemplate();
|
|
|
var headers = new HttpHeaders();
|
|
|
headers.addHeader("Accept", "application/json");
|
|
|
headers.addHeader("Content-Type", "application/json");
|
|
|
@@ -561,6 +563,25 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
return res.getServiceResponse();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建电子发票卡券模版
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void cardTemplate() {
|
|
|
+ var headers = new HttpHeaders();
|
|
|
+ headers.addHeader("Accept", "application/json");
|
|
|
+ headers.addHeader("Content-Type", "application/json");
|
|
|
+ var params = JSONObject.of(
|
|
|
+ "card_appid", "wx93b0ef1be901bd19", // 公众号appid,不是小程序appid
|
|
|
+ "card_template_information", JSONObject.of(
|
|
|
+ "logo_url", "https://kym-static.oss-cn-shenzhen.aliyuncs.com/logo/K7.png"
|
|
|
+ )
|
|
|
+ );
|
|
|
+ var requestBody = new JsonRequestBody.Builder().body(params.toJSONString()).build();
|
|
|
+ var res = wxHttpClient.post(headers, fapiaoConfig.getCardTemplate(), requestBody, JSONObject.class);
|
|
|
+ LOGGER.info("创建电子发票卡券模版:{}", res);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询商户配置的开发选项
|
|
|
*/
|
|
|
@@ -696,11 +717,14 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 申请发票
|
|
|
+ * 开具电子发票
|
|
|
*/
|
|
|
@Override
|
|
|
- public void applyInvoice(String invoiceId) {
|
|
|
+ public void fapiaoApplication(String invoiceId) {
|
|
|
var invoice = invoiceService.lambdaQuery().eq(Invoice::getId, invoiceId).one();
|
|
|
+
|
|
|
+ // TODO: 2023-10-14 订单金额+ ,服务费优惠金额- 服务费优惠金额单独一个item,金额为负数
|
|
|
+
|
|
|
// 电费 税务商品编码:1100101020000000000
|
|
|
var elecMoney = invoice.getOrderDetails().stream().mapToInt(InvoiceOrderDetail::getElecMoney).sum();
|
|
|
var elecMoneyItem = new FaPiao.FaPiaoInfomation.IssueItem().setTotalAmount(elecMoney).setTaxCode("1100101020000000000");
|
|
|
@@ -713,10 +737,6 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
headers.addHeader("Content-Type", "application/json");
|
|
|
headers.addHeader("Wechatpay-Serial", conf.getMchsn());
|
|
|
|
|
|
- // 发票申请单号
|
|
|
- var fapiaoApplyId = OrderUtils.getOrderNo();
|
|
|
- invoiceService.lambdaUpdate().set(Invoice::getApplyId, fapiaoApplyId).eq(Invoice::getId, invoiceId).update();
|
|
|
-
|
|
|
// 客户开票信息
|
|
|
var buyerInformation = new FaPiao.BuyerInformation()
|
|
|
.setType(invoice.getInvoiceType())
|
|
|
@@ -737,7 +757,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
// 请求参数
|
|
|
var fapiao = new FaPiao()
|
|
|
.setScene("WITHOUT_WECHATPAY")
|
|
|
- .setFapiao_apply_id(fapiaoApplyId)
|
|
|
+ .setFapiao_apply_id(invoice.getApplyId())
|
|
|
.setBuyer_information(buyerInformation)
|
|
|
.setFapiao_information(List.of(fapiaoInformation));
|
|
|
|
|
|
@@ -834,4 +854,5 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|