Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加小程序支付管理之创建订单接口 #2772

Merged
merged 5 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -515,4 +515,10 @@ public interface WxMaService extends WxService {
* @return getWxMaShopCouponService
*/
WxMaShopCouponService getWxMaShopCouponService();

/**
* 小程序支付管理-订单支付
* @return getWxMaShopPayService
*/
WxMaShopPayService getWxMaShopPayService();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.binarywang.wx.miniapp.api;

import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse;
import me.chanjar.weixin.common.error.WxErrorException;

/**
* 小程序支付管理订单相关接口
*
* @author liming1019
*/
public interface WxMaShopPayService {

/**
* 创建订单
* 文档地址:<a href="https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/wxafunds/API/order/create_order.html">文档地址</a>
*
* @param request 创建订单参数
* @return 创建订单结果
* @throws WxErrorException .
*/
WxMaShopPayCreateOrderResponse createOrder(WxMaShopPayCreateOrderRequest request)
throws WxErrorException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH
private final WxMaProductService productService = new WxMaProductServiceImpl(this);
private final WxMaProductOrderService productOrderService = new WxMaProductOrderServiceImpl(this);
private final WxMaShopCouponService wxMaShopCouponService = new WxMaShopCouponServiceImpl(this);
private final WxMaShopPayService wxMaShopPayService = new WxMaShopPayServiceImpl(this);
private Map<String, WxMaConfig> configMap;
private int retrySleepMillis = 1000;
private int maxRetryTimes = 5;
Expand Down Expand Up @@ -612,4 +613,8 @@ public WxMaShopCouponService getWxMaShopCouponService() {
return this.wxMaShopCouponService;
}

@Override
public WxMaShopPayService getWxMaShopPayService() {
return this.wxMaShopPayService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cn.binarywang.wx.miniapp.api.impl;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.WxMaShopPayService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.json.WxGsonBuilder;

import static cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants.Shop.Pay.CREATE_ORDER;

/**
* 小程序支付管理订单相关接口
*
* @author liming1019
*/
@RequiredArgsConstructor
@Slf4j
public class WxMaShopPayServiceImpl implements WxMaShopPayService {
private final WxMaService wxMaService;

@Override
public WxMaShopPayCreateOrderResponse createOrder(WxMaShopPayCreateOrderRequest request) throws WxErrorException {
String response = this.wxMaService.post(CREATE_ORDER, request);
return WxGsonBuilder.create().fromJson(response, WxMaShopPayCreateOrderResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cn.binarywang.wx.miniapp.bean.shop.request;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
* @author liming1019
* @date 2022/8/10
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaShopPayCreateOrderRequest implements Serializable {
private static final long serialVersionUID = -5597409427574429095L;

@SerializedName("openid")
private String openid;
@SerializedName("combine_trade_no")
private String combineTradeNo;
@SerializedName("expire_time")
private Long expireTime;
@SerializedName("sub_orders")
private List<SubOrdersDTO> subOrders;

@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public static class SubOrdersDTO {
@SerializedName("mchid")
private String mchid;
@SerializedName("amount")
private Integer amount;
@SerializedName("trade_no")
private String tradeNo;
@SerializedName("description")
private String description;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cn.binarywang.wx.miniapp.bean.shop.response;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* @author liming1019
* @date 2022/8/10
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxMaShopPayCreateOrderResponse extends WxMaShopBaseResponse implements Serializable {
private static final long serialVersionUID = -375471325664721192L;

@SerializedName("payment_params")
private PaymentParamsDTO paymentParams;

@NoArgsConstructor
@Data
public static class PaymentParamsDTO {
@SerializedName("timeStamp")
private Integer timeStamp;
@SerializedName("nonceStr")
private String nonceStr;
@SerializedName("package")
private String packageX;
@SerializedName("paySign")
private String paySign;
@SerializedName("signType")
private String signType;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,10 @@ interface Coupon {
String UPDATE_USER_COUPON = "https://api.weixin.qq.com/shop/coupon/update_user_coupon";
String UPDATE_USER_COUPON_STATUS = "https://api.weixin.qq.com/shop/coupon/update_usercoupon_status";
}

interface Pay {
String CREATE_ORDER = "https://api.weixin.qq.com/shop/pay/createorder";
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cn.binarywang.wx.miniapp.api.impl;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.shop.request.WxMaShopPayCreateOrderRequest;
import cn.binarywang.wx.miniapp.bean.shop.response.WxMaShopPayCreateOrderResponse;
import cn.binarywang.wx.miniapp.test.ApiTestModule;
import com.google.inject.Inject;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;

import java.util.Arrays;

import static org.assertj.core.api.Assertions.assertThat;

@Test
@Guice(modules = ApiTestModule.class)
public class WxMaShopPayServiceImplTest {

@Inject
private WxMaService wxService;

@Test
public void testCreateOrder() throws Exception {
WxMaShopPayCreateOrderRequest request =
WxMaShopPayCreateOrderRequest.builder()
.openid("")
.combineTradeNo("")
.expireTime(1234L)
.subOrders(Arrays.asList(WxMaShopPayCreateOrderRequest.SubOrdersDTO.builder()
.mchid("")
.amount(0)
.tradeNo("")
.description("")
.build()
))
.build();
WxMaShopPayCreateOrderResponse response = wxService.getWxMaShopPayService().createOrder(request);
assertThat(response).isNotNull();
}
}