Skip to content

Commit 5590f19

Browse files
authored
Merge pull request #72 from alipay/feature-isv
新增ISV接入模式
2 parents 0fb4cca + 2a8663c commit 5590f19

File tree

9 files changed

+162
-3
lines changed

9 files changed

+162
-3
lines changed

CHANGE.log

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,6 @@ update --- 支付方式枚举类新增ABA
168168
49、Version:2.0.58
169169
1. Antom 印度渠道接入AMS拒付相关接口的标准变更
170170
2. Antom印度渠道接入(UPI/CARD/NETBAKING)相关接口标准变更
171-
3. CKP二期支持商户传入支付方式地区和支付方式要素
171+
3. CKP二期支持商户传入支付方式地区和支付方式要素
172+
49、Version:2.0.59
173+
1. 新增ISV模式

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ https://mvnrepository.com/artifact/com.alipay.global.sdk/global-open-sdk-java
1212
<dependency>
1313
<groupId>com.alipay.global.sdk</groupId>
1414
<artifactId>global-open-sdk-java</artifactId>
15-
<version>2.0.58</version>
15+
<version>2.0.59</version>
1616
</dependency>
1717
```
1818

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.alipay.global.sdk</groupId>
55
<artifactId>global-open-sdk-java</artifactId>
66
<packaging>jar</packaging>
7-
<version>2.0.58</version>
7+
<version>2.0.59</version>
88
<name>global-open-sdk-java</name>
99
<url>https://github.com/alipay/global-open-sdk-java</url>
1010
<description>

src/main/java/com/alipay/global/api/BaseAlipayClient.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public abstract class BaseAlipayClient implements AlipayClient {
4040
*/
4141
private boolean isSandboxMode = false;
4242

43+
private String agentToken;
44+
4345
public BaseAlipayClient() {
4446
}
4547

@@ -61,6 +63,19 @@ public BaseAlipayClient(String gatewayUrl, String merchantPrivateKey, String ali
6163
}
6264
}
6365

66+
public BaseAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey, String clientId, String agentToken) {
67+
this.gatewayUrl = gatewayUrl;
68+
this.merchantPrivateKey = merchantPrivateKey;
69+
this.alipayPublicKey = alipayPublicKey;
70+
this.clientId = clientId;
71+
this.agentToken = agentToken;
72+
73+
// if client id starts with SANDBOX_, set to sandbox mode
74+
if (clientId.startsWith("SANDBOX_")) {
75+
this.isSandboxMode = true;
76+
}
77+
}
78+
6479
public <T extends AlipayResponse> T execute(AlipayRequest<T> alipayRequest) throws AlipayApiException {
6580

6681
// compatible with old version which clientId does not exist in BaseAlipayClient
@@ -224,6 +239,9 @@ private Map<String, String> buildBaseHeader(String requestTime, String clientId,
224239
}
225240
String signatureHeader = "algorithm=RSA256,keyVersion=" + keyVersion + ",signature=" + signatureValue;
226241
header.put(Constants.REQ_SIGN_HEADER, signatureHeader);
242+
if (StringUtils.isNotBlank(agentToken)) {
243+
header.put(Constants.AGENT_TOKEN_HEADER, agentToken);
244+
}
227245
return header;
228246
}
229247

src/main/java/com/alipay/global/api/DefaultAlipayClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public DefaultAlipayClient(String gatewayUrl, String merchantPrivateKey, String
1616
super(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId);
1717
}
1818

19+
public DefaultAlipayClient(String gatewayUrl, String merchantPrivateKey, String alipayPublicKey, String clientId, String agentToken) {
20+
super(gatewayUrl, merchantPrivateKey, alipayPublicKey, clientId, agentToken);
21+
}
22+
1923
@Override
2024
public Map<String, String> buildCustomHeader() {
2125
return null;

src/main/java/com/alipay/global/api/example/CashierPayDemoCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static void executeConsult() {
7070

7171
try {
7272
alipayPayConsultResponse = CLIENT.execute(alipayPayConsultRequest);
73+
System.out.println(JSONObject.toJSON(alipayPayConsultResponse));
7374
} catch (AlipayApiException e) {
7475
String errorMsg = e.getMessage();
7576
// handle error condition
@@ -139,6 +140,7 @@ public static void executePayWithCard() {
139140
AlipayPayResponse alipayPayResponse = null;
140141
try {
141142
alipayPayResponse = CLIENT.execute(alipayPayRequest);
143+
System.out.println(JSONObject.toJSON(alipayPayResponse));
142144
} catch (AlipayApiException e) {
143145
String errorMsg = e.getMessage();
144146
// handle error condition
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
package com.alipay.global.api.example;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import com.alipay.global.api.AlipayClient;
5+
import com.alipay.global.api.DefaultAlipayClient;
6+
import com.alipay.global.api.exception.AlipayApiException;
7+
import com.alipay.global.api.model.ams.*;
8+
import com.alipay.global.api.model.constants.EndPointConstants;
9+
import com.alipay.global.api.request.ams.pay.AlipayPayConsultRequest;
10+
import com.alipay.global.api.request.ams.pay.AlipayPayRequest;
11+
import com.alipay.global.api.response.ams.pay.AlipayPayConsultResponse;
12+
import com.alipay.global.api.response.ams.pay.AlipayPayResponse;
13+
14+
import java.util.UUID;
15+
16+
public class IsvPayDemo {
17+
18+
/**
19+
* replace with your client id.
20+
* find your client id here: <a href="https://dashboard.alipay.com/global-payments/developers/quickStart">quickStart</a>
21+
*/
22+
public static final String CLIENT_ID = "";
23+
24+
/**
25+
* replace with your antom public key (used to verify signature).
26+
* find your antom public key here: <a href="https://dashboard.alipay.com/global-payments/developers/quickStart">quickStart</a>
27+
*/
28+
public static final String ANTOM_PUBLIC_KEY = "";
29+
30+
/**
31+
* replace with your private key (used to sign).
32+
* please ensure the secure storage of your private key to prevent leakage
33+
*/
34+
public static final String MERCHANT_PRIVATE_KEY = "";
35+
36+
/**
37+
* ISV agentToken
38+
*/
39+
public static final String AGENT_TOKEN = "";
40+
41+
/**
42+
* please replace with your endpoint.
43+
* find your endpoint here: <a href="https://dashboard.alipay.com/global-payments/developers/quickStart">quickStart</a>
44+
*/
45+
private final static AlipayClient CLIENT = new DefaultAlipayClient(
46+
EndPointConstants.SG, MERCHANT_PRIVATE_KEY, ANTOM_PUBLIC_KEY, CLIENT_ID, AGENT_TOKEN);
47+
48+
public static void main(String[] args) {
49+
executeConsult();
50+
// executePayWithBlik();
51+
}
52+
53+
public static void executeConsult() {
54+
AlipayPayConsultRequest alipayPayConsultRequest = new AlipayPayConsultRequest();
55+
alipayPayConsultRequest.setProductCode(ProductCodeType.CASHIER_PAYMENT);
56+
57+
// set amount
58+
Amount amount = Amount.builder().value("4200").currency("BRL").build();
59+
alipayPayConsultRequest.setPaymentAmount(amount);
60+
61+
// set env Info
62+
Env env = Env.builder().terminalType(TerminalType.WEB).build();
63+
alipayPayConsultRequest.setEnv(env);
64+
65+
AlipayPayConsultResponse alipayPayConsultResponse = null;
66+
67+
try {
68+
alipayPayConsultResponse = CLIENT.execute(alipayPayConsultRequest);
69+
System.out.println(JSONObject.toJSON(alipayPayConsultResponse));
70+
} catch (AlipayApiException e) {
71+
String errorMsg = e.getMessage();
72+
e.printStackTrace();
73+
}
74+
}
75+
76+
/**
77+
* show how to finish a payment by Blik
78+
*/
79+
public static void executePayWithBlik() {
80+
AlipayPayRequest alipayPayRequest = new AlipayPayRequest();
81+
alipayPayRequest.setProductCode(ProductCodeType.CASHIER_PAYMENT);
82+
83+
// replace with your paymentRequestId
84+
String paymentRequestId = UUID.randomUUID().toString();
85+
alipayPayRequest.setPaymentRequestId(paymentRequestId);
86+
87+
// set amount
88+
Amount amount = Amount.builder().value("4200").currency("PLN").build();
89+
alipayPayRequest.setPaymentAmount(amount);
90+
91+
// set paymentMethod
92+
PaymentMethod paymentMethod = PaymentMethod.builder().paymentMethodType("BLIK").build();
93+
alipayPayRequest.setPaymentMethod(paymentMethod);
94+
95+
// replace with your orderId
96+
String orderId = UUID.randomUUID().toString();
97+
98+
// set buyer info
99+
Buyer buyer = Buyer.builder().referenceBuyerId("yourBuyerId").build();
100+
101+
// set order info
102+
Order order = Order.builder().referenceOrderId(orderId)
103+
.orderDescription("antom testing order").orderAmount(amount).buyer(buyer).build();
104+
alipayPayRequest.setOrder(order);
105+
106+
// set env info
107+
Env env = Env.builder().terminalType(TerminalType.WEB)
108+
.clientIp("1.2.3.4").build();
109+
alipayPayRequest.setEnv(env);
110+
111+
// replace with your notify url
112+
alipayPayRequest.setPaymentNotifyUrl("http://www.yourNotifyUrl.com");
113+
114+
// replace with your redirect url
115+
alipayPayRequest.setPaymentRedirectUrl("http://www.yourRedirectUrl.com");
116+
117+
// do payment
118+
AlipayPayResponse alipayPayResponse = null;
119+
try {
120+
alipayPayResponse = CLIENT.execute(alipayPayRequest);
121+
System.out.println(JSONObject.toJSON(alipayPayResponse));
122+
} catch (AlipayApiException e) {
123+
String errorMsg = e.getMessage();
124+
System.out.println(errorMsg);
125+
}
126+
}
127+
128+
129+
}

src/main/java/com/alipay/global/api/model/ams/PaymentResultInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,6 @@ public class PaymentResultInfo {
7676

7777
private String expiryYear;
7878

79+
private String accountNo;
80+
7981
}

src/main/java/com/alipay/global/api/tools/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public interface Constants {
2424

2525
String RSP_TIME_HEADER = "response-time";
2626

27+
String AGENT_TOKEN_HEADER = "agent-token";
28+
2729
int HTTP_SUCCESS_CODE = 200;
2830

2931
}

0 commit comments

Comments
 (0)