|
|
@ -1,28 +1,34 @@
|
|
|
|
package au.com.royalpay.payment.manage.gateway.beans;
|
|
|
|
package au.com.royalpay.payment.manage.gateway.beans;
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
|
|
|
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.system.core.impl.ClientContractServiceImpl;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
|
|
|
import cn.yixblog.platform.http.HttpRequestGenerator;
|
|
|
|
|
|
|
|
import cn.yixblog.platform.http.HttpRequestResult;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.annotation.JSONField;
|
|
|
|
import com.alibaba.fastjson.annotation.JSONField;
|
|
|
|
import lombok.Data;
|
|
|
|
import lombok.Data;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.time.DateUtils;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
@Data
|
|
|
|
public class ClientSettleConfig {
|
|
|
|
public class ClientSettleConfig {
|
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(ClientContractServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@JSONField(name = "swift_code")
|
|
|
|
@JSONField(name = "swift_code")
|
|
|
|
private String swiftCode;
|
|
|
|
private String swiftCode;
|
|
|
|
@JSONField(name = "bsb_no")
|
|
|
|
@JSONField(name = "bsb_no")
|
|
|
|
private String bsbNo;
|
|
|
|
private String bsbNo;
|
|
|
|
private String bank;
|
|
|
|
|
|
|
|
private String city;
|
|
|
|
|
|
|
|
private String address;
|
|
|
|
|
|
|
|
private String system;
|
|
|
|
|
|
|
|
private String postcode;
|
|
|
|
|
|
|
|
private String state;
|
|
|
|
|
|
|
|
private String branch;
|
|
|
|
|
|
|
|
@JSONField(name = "account_no")
|
|
|
|
@JSONField(name = "account_no")
|
|
|
|
private String accountNo;
|
|
|
|
private String accountNo;
|
|
|
|
@JSONField(name = "account_name")
|
|
|
|
@JSONField(name = "account_name")
|
|
|
@ -41,21 +47,19 @@ public class ClientSettleConfig {
|
|
|
|
private String activeTime;
|
|
|
|
private String activeTime;
|
|
|
|
@JSONField(name = "expire_time")
|
|
|
|
@JSONField(name = "expire_time")
|
|
|
|
private String expireTime;
|
|
|
|
private String expireTime;
|
|
|
|
|
|
|
|
private JSONObject bankQueryInfo;
|
|
|
|
|
|
|
|
private Date activeTimeDate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String[] WHITE_LIST = {"bankQueryInfo","activeTimeDate"};
|
|
|
|
private static Pattern ACCOUNT_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9 &]+$");
|
|
|
|
private static Pattern ACCOUNT_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9 &]+$");
|
|
|
|
|
|
|
|
|
|
|
|
public void checkParamsInvalid() throws IllegalAccessException {
|
|
|
|
public void checkParamsInvalid() throws IllegalAccessException {
|
|
|
|
for (Field field : getClass().getDeclaredFields()) {
|
|
|
|
for (Field field : getClass().getDeclaredFields()) {
|
|
|
|
field.setAccessible(true);
|
|
|
|
field.setAccessible(true);
|
|
|
|
if (field.get(this) == null) {
|
|
|
|
if (field.get(this) == null && !Arrays.asList(WHITE_LIST).contains(field.getName())) {
|
|
|
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
|
|
|
throw new ParamInvalidException(field.getName(), "Required Param " + field.getName() +" not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSONObject insertBankInfo() {
|
|
|
|
|
|
|
|
JSONObject bankInfo = new JSONObject();
|
|
|
|
|
|
|
|
if (swiftCode.length() > 12) {
|
|
|
|
if (swiftCode.length() > 12) {
|
|
|
|
throw new BadRequestException("PARAM_ERROR:Switft code must be less than 12 characters");
|
|
|
|
throw new BadRequestException("PARAM_ERROR:Switft code must be less than 12 characters");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -68,21 +72,46 @@ public class ClientSettleConfig {
|
|
|
|
if (accountName.length() > 50) {
|
|
|
|
if (accountName.length() > 50) {
|
|
|
|
throw new BadRequestException("PARAM_ERROR:Account Name must be less than 50 characters");
|
|
|
|
throw new BadRequestException("PARAM_ERROR:Account Name must be less than 50 characters");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Matcher matcher = ACCOUNT_NAME_PATTERN.matcher(accountName);
|
|
|
|
Matcher matcher = ACCOUNT_NAME_PATTERN.matcher(accountName);
|
|
|
|
if (!matcher.matches()) {
|
|
|
|
if (!matcher.matches()) {
|
|
|
|
throw new BadRequestException("PARAM_ERROR:Invalid Account Name format");
|
|
|
|
throw new BadRequestException("PARAM_ERROR:Invalid Account Name format");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bankQueryInfo = getBankInfo(bsbNo);
|
|
|
|
|
|
|
|
if (bankQueryInfo == null || bankQueryInfo.isEmpty() || !bankQueryInfo.getBooleanValue("valid")) {
|
|
|
|
|
|
|
|
throw new BadRequestException("PARAM_ERROR:BSB No is invalid");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
activeTimeDate = DateUtils.parseDate(activeTime, new String[]{"yyyy-MM-dd HH:mm:ss"});
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
throw new BadRequestException("PARAM_ERROR:Invalid ActiveTime format");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public JSONObject insertBankInfo() {
|
|
|
|
|
|
|
|
JSONObject bankInfo = new JSONObject();
|
|
|
|
bankInfo.put("swift_code", swiftCode);
|
|
|
|
bankInfo.put("swift_code", swiftCode);
|
|
|
|
bankInfo.put("bsb_no", bsbNo);
|
|
|
|
bankInfo.put("bsb_no", bsbNo);
|
|
|
|
bankInfo.put("account_no", accountNo);
|
|
|
|
bankInfo.put("account_no", accountNo);
|
|
|
|
bankInfo.put("account_name", accountName);
|
|
|
|
bankInfo.put("account_name", accountName);
|
|
|
|
bankInfo.put("bank", bank);
|
|
|
|
bankInfo.putAll(bankQueryInfo);
|
|
|
|
bankInfo.put("city", city);
|
|
|
|
|
|
|
|
bankInfo.put("address", address);
|
|
|
|
|
|
|
|
bankInfo.put("system", system);
|
|
|
|
|
|
|
|
bankInfo.put("postcode", postcode);
|
|
|
|
|
|
|
|
bankInfo.put("state", state);
|
|
|
|
|
|
|
|
bankInfo.put("branch", branch);
|
|
|
|
|
|
|
|
return bankInfo;
|
|
|
|
return bankInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private JSONObject getBankInfo(String bsb_no) {
|
|
|
|
|
|
|
|
// bd451cc3e3ad66c75165dc852507e8f0
|
|
|
|
|
|
|
|
// 收费 ab9379cfdab559509bbdcdd11923489f
|
|
|
|
|
|
|
|
String url = "https://api.bank.codes/au-bsb/json/ab9379cfdab559509bbdcdd11923489f/" + bsb_no;
|
|
|
|
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
HttpRequestResult result = new HttpRequestGenerator(url, RequestMethod.GET).execute();
|
|
|
|
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
|
|
|
|
res = result.getResponseContentJSONObj();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|