退款实现

回调校验实现
This commit is contained in:
egan
2018-05-02 17:02:12 +08:00
parent 0366ca5470
commit edf53c9b7c
4 changed files with 60 additions and 7 deletions

View File

@@ -75,6 +75,7 @@ public interface PayService {
* @param id 业务id, 数据的真实性.
* @return true通过
*/
@Deprecated
boolean verifySource(String id);

View File

@@ -38,6 +38,15 @@ public class RefundOrder {
*/
private Date orderDate;
/**
* 货币
*/
private CurType curType;
/**
* 退款说明
*/
private String description;
public String getRefundNo() {
return refundNo;
}
@@ -86,6 +95,22 @@ public class RefundOrder {
this.orderDate = orderDate;
}
public CurType getCurType() {
return curType;
}
public void setCurType(CurType curType) {
this.curType = curType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public RefundOrder() {
}
@@ -109,4 +134,6 @@ public class RefundOrder {
this.refundAmount = refundAmount;
this.totalAmount = totalAmount;
}
}

View File

@@ -128,17 +128,22 @@ public class PayPalPayService extends BasePayService{
@Override
public boolean verify(Map<String, Object> params) {
return false;
HttpStringEntity httpEntity = new HttpStringEntity("{\"payer_id\":\""+(String)params.get("PayerID")+"\"}", ContentType.APPLICATION_JSON);
httpEntity.setHeaders(authHeader());
JSONObject resp = getHttpRequestTemplate().postForObject(String.format(getReqUrl(PayPalTransactionType.EXECUTE), (String) params.get("paymentId")), httpEntity, JSONObject.class);
return "approved".equals(resp.getString("state"));
}
@Override
public boolean signVerify(Map<String, Object> params, String sign) {
return false;
return true;
}
@Override
public boolean verifySource(String id) {
return false;
return true;
}
/**
@@ -265,9 +270,22 @@ public class PayPalPayService extends BasePayService{
*/
@Override
public Map<String, Object> refund(RefundOrder refundOrder) {
// JSONObject resp = getHttpRequestTemplate().getForObject(String.format(getReqUrl(PayPalTransactionType.REFUND), refundOrder.getTradeNo()), authHeader(), JSONObject.class);
// return resp;
return null;
JSONObject request = new JSONObject();
if (null != refundOrder.getRefundAmount() && BigDecimal.ZERO.compareTo( refundOrder.getRefundAmount()) > 0){
Amount amount = new Amount();
amount.setCurrency(refundOrder.getCurType().name());
amount.setTotal(refundOrder.getRefundAmount().toString());
request.put("amount", amount);
request.put("description", refundOrder.getDescription());
}
HttpStringEntity httpEntity = new HttpStringEntity(request, ContentType.APPLICATION_JSON);
httpEntity.setHeaders(authHeader());
JSONObject resp = getHttpRequestTemplate().postForObject(String.format(getReqUrl(PayPalTransactionType.REFUND), refundOrder.getTradeNo()), httpEntity, JSONObject.class);
return resp;
//
// return null;
}
/**
* 查询退款

View File

@@ -25,10 +25,17 @@ public enum PayPalTransactionType implements TransactionType {
* 付款 网页支付
*/
sale("payments/payment"),
REFUND("payments/sale/{0}/refund"),
/**
* sale 支付退款
*/
REFUND("payments/sale/{saleId}/refund"),
REFUND_QUERY("payments/refund/{refundId}"),
PAYOUT("payments/payouts/{payoutBatchId}"),
ORDERS("payments/orders/{orderId}"),
/**
* 回调订单状态查询
*/
EXECUTE("v1/payments/payment/{paymentId}/execute"),
;