Skip to content

Commit

Permalink
v1.0.14 Bug fix in WeChatDirect Process, added AliPayDirectProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
PayXpert Integration committed Feb 26, 2019
1 parent 84f243c commit 33371b2
Show file tree
Hide file tree
Showing 45 changed files with 3,142 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>Connect2pay Java Client</name>
<groupId>com.payxpert</groupId>
<artifactId>connect2pay-client</artifactId>
<version>1.0.13</version>
<version>1.0.14</version>
<packaging>jar</packaging>
<description>This is the Java implementation of the PayXpert Connect2pay Payment Page API.</description>
<url>https://www.payxpert.com/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.slf4j.LoggerFactory;

import com.payxpert.connect2pay.client.requests.AccountInformationRequest;
import com.payxpert.connect2pay.client.requests.AlipayDirectProcessRequest;
import com.payxpert.connect2pay.client.requests.PaymentRequest;
import com.payxpert.connect2pay.client.requests.PaymentStatusRequest;
import com.payxpert.connect2pay.client.requests.SubscriptionCancelRequest;
Expand All @@ -21,6 +22,7 @@
import com.payxpert.connect2pay.client.requests.TransactionRefundRequest;
import com.payxpert.connect2pay.client.requests.WeChatDirectProcessRequest;
import com.payxpert.connect2pay.client.response.AccountInformationResponse;
import com.payxpert.connect2pay.client.response.AlipayDirectProcessResponse;
import com.payxpert.connect2pay.client.response.PaymentResponse;
import com.payxpert.connect2pay.client.response.PaymentStatusResponse;
import com.payxpert.connect2pay.client.response.SubscriptionCancelResponse;
Expand Down Expand Up @@ -583,7 +585,7 @@ public WeChatDirectProcessResponse weChatDirectProcess(WeChatDirectProcessReques
}

String url = APIRoute.WECHAT_DIRECT.getRoute().replaceAll(":customerToken", request.getCustomerToken());
this.httpClient.setUrl(this.serviceUrl + url);
this.httpClient.setUrl(this.serviceUrl + url).setBody(request.toJson());

if (logger.isDebugEnabled()) {
logger.debug("Doing WeChat direct process request.");
Expand All @@ -609,4 +611,42 @@ public WeChatDirectProcessResponse weChatDirectProcess(WeChatDirectProcessReques
return response;
}

/**
* Do a direct Alipay transaction process
*
* @param request
* The Alipay direct process request object to use
* @return The AlipayDirectProcessResponse object or null on error
*/
public AlipayDirectProcessResponse aliPayDirectProcess(AlipayDirectProcessRequest request) throws Exception {
if (request == null) {
throw new NullPointerException();
}

String url = APIRoute.ALIPAY_DIRECT.getRoute().replaceAll(":customerToken", request.getCustomerToken());
this.httpClient.setUrl(this.serviceUrl + url).setBody(request.toJson());

if (logger.isDebugEnabled()) {
logger.debug("Doing Alipay direct process request.");
}

AlipayDirectProcessResponse response = null;
try {
String json = this.httpClient.post();

response = new AlipayDirectProcessResponse().fromJson(json);
if (response != null) {
response.setCode(ResultCode.SUCCESS);
}
} catch (HttpForbiddenException e) {
response = new AlipayDirectProcessResponse().fromJson(AUTH_FAILED_JSON);
} catch (HttpNotFoundException e) {
response = new AlipayDirectProcessResponse().fromJson(NOT_FOUND_JSON);
} catch (Exception e) {
logger.error("Alipay Direct Process call failed: " + e.getClass().getSimpleName() + " - " + e.getMessage());
throw e;
}

return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.payxpert.connect2pay.client.requests;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.payxpert.connect2pay.constants.AlipayIdentityCodeType;
import com.payxpert.connect2pay.constants.AlipayPaymentMode;

import net.sf.oval.constraint.CheckWith;
import net.sf.oval.constraint.CheckWithCheck;
import net.sf.oval.constraint.MaxLength;
import net.sf.oval.constraint.NotNull;

/**
* Request for the Alipay Direct Process API call.
*
*/
public class AlipayDirectProcessRequest extends GenericRequest<AlipayDirectProcessRequest> {
@NotNull
@JsonIgnore
private String customerToken;

@NotNull
private AlipayPaymentMode mode;

@CheckWith(ignoreIfNull = false, value = IdentityCodeValidator.class)
private AlipayIdentityCodeType identityCodeType;

@MaxLength(32)
@CheckWith(ignoreIfNull = false, value = IdentityCodeValidator.class)
private String buyerIdentityCode;

@MaxLength(10)
private String notificationLang;

@MaxLength(64)
private String notificationTimeZone;

public String getCustomerToken() {
return customerToken;
}

public AlipayDirectProcessRequest setCustomerToken(String customerToken) {
this.customerToken = customerToken;
return getThis();
}

public AlipayPaymentMode getMode() {
return mode;
}

public AlipayDirectProcessRequest setMode(AlipayPaymentMode mode) {
this.mode = mode;
return getThis();
}

public String getBuyerIdentityCode() {
return buyerIdentityCode;
}

public AlipayDirectProcessRequest setBuyerIdentityCode(String buyerIdentityCode) {
this.buyerIdentityCode = this.limitLength(buyerIdentityCode, 32);
return getThis();
}

public AlipayIdentityCodeType getIdentityCodeType() {
return identityCodeType;
}

public AlipayDirectProcessRequest setIdentityCodeType(AlipayIdentityCodeType identityCodeType) {
this.identityCodeType = identityCodeType;
return getThis();
}

public String getNotificationLang() {
return notificationLang;
}

public AlipayDirectProcessRequest setNotificationLang(String notificationLang) {
this.notificationLang = this.limitLength(notificationLang, 10);
return getThis();
}

public String getNotificationTimeZone() {
return notificationTimeZone;
}

public AlipayDirectProcessRequest setNotificationTimeZone(String notificationTimeZone) {
this.notificationTimeZone = this.limitLength(notificationTimeZone, 64);
return getThis();
}

@Override
protected AlipayDirectProcessRequest getThis() {
return this;
}

private static class IdentityCodeValidator implements CheckWithCheck.SimpleCheck {
private static final long serialVersionUID = 1L;

@Override
public boolean isSatisfied(Object obj, Object value) {
if (obj != null && AlipayDirectProcessRequest.class.isAssignableFrom(obj.getClass())) {
AlipayDirectProcessRequest request = AlipayDirectProcessRequest.class.cast(obj);

if (AlipayPaymentMode.APP.equals(request.mode) && value == null) {
return false;
}
}

return true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.payxpert.connect2pay.client.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.payxpert.connect2pay.client.Connect2payClient;
import com.payxpert.connect2pay.client.containers.TransactionAttempt;
import com.payxpert.connect2pay.constants.ResultCode;

/**
* This class represents the response to a Alipay Direct Process request.
*
*/
public class AlipayDirectProcessResponse extends GenericResponse<AlipayDirectProcessResponse> {
// Library internal field, not returned by the API call
private ResultCode code;
private String message;

private String apiVersion;

private Double exchangeRate;

private String qrCode;

private String qrCodeUrl;

private String webSocketUrl;

@JsonProperty("transactionID")
private String transactionId;

private TransactionAttempt transactionInfo;

/**
* @return the result code
*/
public ResultCode getCode() {
return code;
}

/**
* @param code
* the code to set
*/
public void setCode(ResultCode code) {
this.code = code;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

/**
* The API version for the response
*/
public String getApiVersion() {
return apiVersion;
}

public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
}

/**
* @return The currency exchange rate between the payment currency and RMB
*/
public Double getExchangeRate() {
return exchangeRate;
}

public void setExchangeRate(Double exchangeRate) {
this.exchangeRate = exchangeRate;
}

/**
* @return The QR code as PNG base64 encoded
*/
public String getQrCode() {
return qrCode;
}

public void setQrCode(String qrCode) {
this.qrCode = qrCode;
}

/**
* @return The URL to embed in a QR code
*/
public String getQrCodeUrl() {
return qrCodeUrl;
}

public void setQrCodeUrl(String qrCodeUrl) {
this.qrCodeUrl = qrCodeUrl;
}

/**
* @return The URL of the WebSocket to monitor the payment status in real time
*/
public String getWebSocketUrl() {
return webSocketUrl;
}

public void setWebSocketUrl(String webSocketUrl) {
this.webSocketUrl = webSocketUrl;
}

/**
* @return The identifier of the generated transaction, can be used to poll the transaction information
* @see Connect2payClient#getTransactionInfo(com.payxpert.connect2pay.client.requests.TransactionInfoRequest)
*/
public String getTransactionId() {
return transactionId;
}

public void setTransactionId(String transactionId) {
this.transactionId = transactionId;
}

/**
* @return The information about the processed transaction (APP mode only)
*/
public TransactionAttempt getTransactionInfo() {
return transactionInfo;
}

public void setTransactionInfo(TransactionAttempt transactionInfo) {
this.transactionInfo = transactionInfo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public enum APIRoute {
/* */
WECHAT_DIRECT("/payment/:customerToken/process/wechat/direct"),
/* */
ALIPAY_DIRECT("/payment/:customerToken/process/alipay/direct"),
/* */
SUB_CANCEL("/subscription/:subscriptionID/cancel"),
/* */
ACCOUNT_INFO("/account");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.payxpert.connect2pay.constants;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* The Alipay identity code types available for Alipay direct process call
*
*/
public enum AlipayIdentityCodeType {
/**
* QR code
*/
QRCODE,

/**
* Bar code
*/
BARCODE;

@JsonValue
public String getFormattedName() {
return this.name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.payxpert.connect2pay.constants;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* The Alipay modes available for Alipay direct process call
*
*/
public enum AlipayPaymentMode {
/**
* POS mode: the payer scans the merchant's QR codes
*/
POS,

/**
* APP mode: The merchant scans the payer's QR code
*/
APP;

@JsonValue
public String getFormattedName() {
return this.name().toLowerCase();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum PaymentMethod {
TODITO_CASH("ToditoCash", false), /* */
WECHAT("WeChat", false), /* */
LINE("Line", false), /* */
ALIPAY("AliPay", false), /* */
ALIPAY("Alipay", false), /* */
CHARGEBACK("Chargeback", false), /* */
REVERSAL("Reversal", false);

Expand Down
Loading

0 comments on commit 33371b2

Please sign in to comment.