SDK&DEMO
public static void main(String[] args) {
String pattern = "yyyyMMdd";
String tradeNo = DateUtils.formatDate(new Date(), pattern) + System.currentTimeMillis();
// refund(tradeNo, tradeNo);
createTrade(tradeNo);
// queryPay();
// pay();
// queryTrade();
}
public static CashierClient getClient() {
CashierConfig config = new CashierConfig();
config.setAppId("ebuyfc163adf6a81");
config.setAppSecret("r0t1ngvqtp72xma6iy7m6hzy43ol5hz0");
config.setLang("zh_CN");
config.setUrl(Constants.UAT_URL);
return CashierClient.getCashierClient(config);
}
/**
* 统一下单
*/
public static void createTrade(String tradeNo) {
CashierClient cashierClient = getClient();
CreateTradeRequest createTradeRequest = new CreateTradeRequest();
//流水号格式固定
createTradeRequest.setOutTradeNo(tradeNo);
//使用场景必填,易百分配
createTradeRequest.setUseScene("H5");
//可提供给易百,易百配置
createTradeRequest.setNotifyUrl("https://develop.tuesday-tech.com/pcs/ebuy/notify");
//请求支付总金额
//如果有不走易百渠道优惠,扣除优惠部分
createTradeRequest.setTotalAmount(BigDecimal.valueOf(1.00));
//币种,国际标准
createTradeRequest.setCurrency("CNY");
//交易数据需区分到门店,需上传
//有优惠限制到门店,需上传
//有结算到门店,需上传
//其他需要上传门店信息到场景,需上传
// StoreInfo storeInfo = new StoreInfo();
// //店名称
// storeInfo.setName("test");
// //店号
// storeInfo.setShopNo("test");
// createTradeRequest.setStoreInfo(storeInfo);
//产品信息,建议所有订单产品上传
//有不需要走易百优惠的产品,不上传
//goodsDetail最大产品数限制100
List<OutGoodsDto> goodsDetail = new ArrayList<>();
OutGoodsDto outGoodsDto = new OutGoodsDto();
//产品名称,长度限制50
outGoodsDto.setGoodsName("测试产品");
//产品sku
outGoodsDto.setGoodsId("1061797738");
//产品数量
outGoodsDto.setGoodsNum(1);
//产品金额
outGoodsDto.setPriceSale(BigDecimal.valueOf(1.00));
goodsDetail.add(outGoodsDto);
createTradeRequest.setGoodsDetail(goodsDetail);
//支付方式集合
//支持优惠券coupon、商户储值卡cashcard、商户积分points、电子钱包cash(支付宝、微信等)、数字人民币ECNY
List<PayMethod> payMethod = new ArrayList<>();
PayMethod method = new PayMethod();
//coupon,cashcard的资产类型非必填,优先取易百路由结果
//其他场景必填
method.setAssetType("cash");
//coupon,cashcard的资产类型非必填,优先取易百路由结果
//其他场景必填
method.setPayWay("WECHAT");
//coupon不填,其他场景必填
method.setAmount(BigDecimal.valueOf(0.00));
//coupon,cashcard的资产必填
//如有密钥格式是cardCoupon01|secret01
method.setCardCoupons("10089234876342347753");
//指定优惠用在SKU为A的产品,如果A产品没上传,交易失败
method.setGoodsId("A");
/**
* 渠道会员id
* method.setThirdUserId("okKky5fnJb68U6c7Ujui3ZKVo6Ea");
*/
/**
* 资产使用限制规则
* method.setUseLimit("product");
*/
payMethod.add(method);
createTradeRequest.setPayMethod(payMethod);
//需要易百记录此笔交易中其他的支付信息
// List<Subsidy> subsidies = new ArrayList<>();
// Subsidy subsidy = new Subsidy();
// //支付主体
// subsidy.setAccount("xx");
// //支付金额
// subsidy.setAmount(BigDecimal.valueOf(20));
// subsidies.add(subsidy);
// createTradeRequest.setSubsidy(subsidies);
PaasResponse<CreateTradeResponse> createTradeResponse = cashierClient.createTrade(createTradeRequest);
System.out.println(createTradeResponse);
//只有全部成功此处是true,其他均为false
//如false,content不一定有
createTradeResponse.isSuccess();
//返回报文签名
createTradeResponse.getSign();
//uuid和请求一致
createTradeResponse.getUuid();
//报错码
createTradeResponse.getErrorCode();
//报错原因
createTradeResponse.getErrorMessage();
if (createTradeResponse.getContent() != null) {
CreateTradeResponse body = (CreateTradeResponse) createTradeResponse.getContent();
//PaidResult 某种资产(商家券、商家卡、商家积分、电子钱包和数字人民币)支付结果
PaidResult paidResult = body.getCardPaid();
if (paidResult != null) {
//此支付资产支付总金额
paidResult.getPaidAmount();
//此支付资产用户实付金额
paidResult.getUserAmount();
//此支付资产商户实收金额
paidResult.getMerchantAmount();
//此支付资产优惠金额入账编码
paidResult.getDiscountCode();
//此支付资产实收金额入账编码
paidResult.getTenderCode();
//此支付资产使用明显,正常不返回
paidResult.getUseList();
}
//电子钱包支付详情,字段描述同上
body.getCashPaid();
//优惠券支付详情,字段描述同上
body.getCouponPaid();
//电子钱包支付渠道的app id
body.getChannelAppId();
//唤起电子钱包支付渠道支付台报文
body.getChannelParams();
//总支付成功金额
body.getPaidAmount();
//总用户实付总金额
body.getUserPaid();
//总商户实收总金额
body.getMerchantAmount();
//电子钱包预支付id
body.getPrepayId();
//支付二维码
body.getQrCodeUrl();
//支付跳转页面
body.getRedirectUrl();
}
}
No Comments