diff --git a/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerConfigStorage.java b/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerConfigStorage.java index 3bec5ef..20324de 100644 --- a/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerConfigStorage.java +++ b/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerConfigStorage.java @@ -15,6 +15,10 @@ public class PayoneerConfigStorage extends BasePayConfigStorage { * 商户Id */ public String programId; + /** + * PayoneerPay 用户名 + */ + public String userName; /** * 应用id @@ -26,6 +30,7 @@ public class PayoneerConfigStorage extends BasePayConfigStorage { } + /** * 合作商唯一标识 * @@ -37,15 +42,48 @@ public class PayoneerConfigStorage extends BasePayConfigStorage { @Override public String getSeller() { - return null; + return userName; } + /** + * 获取商户Id + * @return 商户Id + */ public String getProgramId() { return programId; } + /** + * 设置商户Id + * @param programId 商户Id + */ public void setProgramId(String programId) { this.programId = programId; } + /** + * PayoneerPay 用户名 + * @param userName 用户名 + */ + public void setUserName(String userName){ + this.userName = userName; + } + + public String getUserName() { + return userName; + } + + /** + * 设置PayoneerPay API password + * @param apiPassword api密钥 + */ + public void setApiPassword(String apiPassword){ + setKeyPrivate(apiPassword); + } + /** + * 获取 PayoneerPay API password + */ + public String getApiPassword(){ + return getKeyPrivate(); + } } diff --git a/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java b/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java index 6d39166..f1bbd1c 100644 --- a/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java +++ b/pay-java-payoneer/src/main/java/com/egzosn/pay/payoneer/api/PayoneerPayService.java @@ -3,7 +3,6 @@ package com.egzosn.pay.payoneer.api; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.egzosn.pay.common.api.BasePayService; -import com.egzosn.pay.common.api.Callback; import com.egzosn.pay.common.api.PayConfigStorage; import com.egzosn.pay.common.bean.*; import com.egzosn.pay.common.bean.outbuilder.PayTextOutMessage; @@ -12,17 +11,16 @@ import com.egzosn.pay.common.exception.PayErrorException; import com.egzosn.pay.common.http.HttpConfigStorage; import com.egzosn.pay.common.http.HttpHeader; import com.egzosn.pay.common.http.HttpStringEntity; +import com.egzosn.pay.common.http.UriVariables; import com.egzosn.pay.payoneer.bean.PayoneerTransactionType; +import org.apache.http.Header; import org.apache.http.client.utils.DateUtils; import org.apache.http.entity.ContentType; import org.apache.http.message.BasicHeader; -import org.apache.http.protocol.HTTP; import java.awt.image.BufferedImage; import java.math.BigDecimal; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * payoneer业务逻辑 @@ -62,6 +60,17 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer super(payConfigStorage, configStorage); } + /** + * 获取授权请求头 + * @return 授权请求头 + */ + private HttpHeader authHeader(){ + + List
headers = new ArrayList<>(); + headers.add(new BasicHeader("Authorization", "Basic " + authorizationString(getPayConfigStorage().getSeller(), getPayConfigStorage().getKeyPrivate()))); + + return new HttpHeader(headers); + } /** * 获取授权页面 * @@ -73,6 +82,8 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer public String getAuthorizationPage(String payeeId) { HttpStringEntity entity = new HttpStringEntity("{\"payee_id\":\"" + payeeId + "\"}", ContentType.APPLICATION_JSON); + //设置 base atuh + entity.setHeaders(authHeader()); JSONObject response = getHttpRequestTemplate().postForObject(getReqUrl(PayoneerTransactionType.REGISTRATION), entity, JSONObject.class); if (response != null && 0 == response.getIntValue(CODE)) { return response.getString("registration_link"); @@ -250,6 +261,8 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer @Override public Map microPay(PayOrder order) { HttpStringEntity entity = new HttpStringEntity(JSON.toJSONString(orderInfo(order)), ContentType.APPLICATION_JSON); + //设置 base atuh + entity.setHeaders(authHeader()); JSONObject response = getHttpRequestTemplate().postForObject(getReqUrl(PayoneerTransactionType.CHARGE), entity, JSONObject.class); if (response != null) { return response; @@ -351,7 +364,13 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer */ @Override public Map secondaryInterface(Object tradeNoOrBillDate, String outTradeNoBillType, TransactionType transactionType) { - JSONObject result = getHttpRequestTemplate().getForObject(getReqUrl(transactionType), JSONObject.class, outTradeNoBillType); + MethodType methodType = null; + if (transactionType == PayoneerTransactionType.CHARGE_CANCEL) { // 退款 + methodType = MethodType.POST; + }else { + methodType = MethodType.GET; + } + JSONObject result = getHttpRequestTemplate().doExecute(UriVariables.getUri(getReqUrl(transactionType), outTradeNoBillType), authHeader() ,JSONObject.class, methodType); return result; } @@ -375,6 +394,7 @@ public class PayoneerPayService extends BasePayService implements AdvancedPaySer info.put("payout_date", DateUtils.formatDate(new Date(), "yyyy-MM-dd")); info.put("group_id", order.getPayerName()); HttpStringEntity entity = new HttpStringEntity(JSON.toJSONString(info), ContentType.APPLICATION_JSON); + entity.setHeaders(authHeader()); JSONObject response = getHttpRequestTemplate().postForObject(getReqUrl(PayoneerTransactionType.PAYOUTS), entity, JSONObject.class); return response; }