package com.stylefeng.guns.modular.cloudPayment.example;
|
|
import com.stylefeng.guns.modular.cloudPayment.mock.MockData;
|
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
|
import com.unionpay.upyzt.Upyzt;
|
import com.unionpay.upyzt.exception.UpyztException;
|
import com.unionpay.upyzt.model.Allocation;
|
import com.unionpay.upyzt.resp.AllocationResp;
|
import com.unionpay.upyzt.util.StringUtils;
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.io.Serializable;
|
import java.time.OffsetDateTime;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Slf4j
|
public class AllocationExample implements Serializable {
|
|
|
/**
|
* 分账
|
*
|
* @return 返回参数
|
* @throws UpyztException 异常
|
*/
|
public static AllocationResp create(AllocationReq allocationReq) throws UpyztException {
|
Map<String, Object> params = new HashMap<>();
|
params.put("out_order_no", allocationReq.getOutOrderNo());
|
params.put("sent_at", OffsetDateTime.now().toString());
|
params.put("pay_balance_acct_id", allocationReq.getPayBalanceAcctId());
|
|
List<Map<String, Object>> transferParams = new ArrayList<>();
|
Map<String, Object> transferParam = new HashMap<>();
|
transferParam.put("recv_balance_acct_id", allocationReq.getRecvBalanceAcctId());
|
transferParam.put("amount", allocationReq.getAmount());
|
// transferParam.put("metadata", MockData.metadata());
|
transferParam.put("extra", MockData.allocationExtra(allocationReq));
|
transferParams.add(transferParam);
|
params.put("transfer_params", transferParams);
|
if(!StringUtils.isBlank(allocationReq.getPassword())){
|
params.put("password", Upyzt.encryptField(allocationReq.getPassword()));
|
}
|
// params.put("remark", "用于 SDK 示例测试 ");
|
|
return Allocation.create(params);
|
}
|
|
/**
|
* 分账订单查询(系统订单号)
|
*
|
* @return 返回参数
|
* @throws UpyztException 异常
|
*/
|
public AllocationResp retrieveById(String allocationId) throws UpyztException {
|
return Allocation.retrieveById(allocationId);
|
}
|
|
/**
|
* 分账订单查询(平台订单号)
|
*
|
* @return 返回参数
|
* @throws UpyztException 异常
|
*/
|
public AllocationResp retrieveByOutOrderNo(String outOrderNo) throws UpyztException {
|
return Allocation.retrieveByOutOrderNo(outOrderNo);
|
}
|
|
}
|