|
|
@@ -92,6 +92,36 @@ public class LinePay implements Serializable {
|
|
|
return sendBody;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * set the header info
|
|
|
+ * @param request
|
|
|
+ * @throws URISyntaxException
|
|
|
+ */
|
|
|
+ private void setHeaderAndEntity(HttpPost request, String sendBody) throws URISyntaxException {
|
|
|
+ String nonce = UUID.randomUUID().toString();
|
|
|
+ request.setHeader("Content-Type", "application/json");
|
|
|
+ request.setHeader("X-LINE-ChannelId", lineConfig.channelId);
|
|
|
+ request.setHeader("X-LINE-Authorization-Nonce", nonce);
|
|
|
+
|
|
|
+ StringBuffer message = new StringBuffer();
|
|
|
+ //channelSecret
|
|
|
+ message.append(lineConfig.channelSecret);
|
|
|
+ //path
|
|
|
+ message.append(request.getUri().getPath());
|
|
|
+ //body
|
|
|
+ message.append(sendBody);
|
|
|
+ //nonce
|
|
|
+ message.append(nonce);
|
|
|
+
|
|
|
+ byte[] bytes = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_SHA_256, lineConfig.channelSecret.getBytes()).doFinal(message.toString().getBytes());
|
|
|
+
|
|
|
+ byte[] byteArray = Base64.encodeBase64(bytes);
|
|
|
+
|
|
|
+ request.setHeader("X-LINE-Authorization", new String(byteArray));
|
|
|
+
|
|
|
+ request.setEntity(new StringEntity(sendBody, ContentType.APPLICATION_JSON));
|
|
|
+
|
|
|
+ }
|
|
|
/**
|
|
|
* line pay
|
|
|
* @param orderManageTotal
|
|
|
@@ -103,35 +133,13 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
|
- String nonce = UUID.randomUUID().toString();
|
|
|
-
|
|
|
LinePayAPOD response = null;
|
|
|
|
|
|
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
|
|
|
HttpPost request = new HttpPost(lineConfig.payUrl);
|
|
|
|
|
|
- request.setHeader("Content-Type", "application/json");
|
|
|
- request.setHeader("X-LINE-ChannelId", lineConfig.channelId);
|
|
|
- request.setHeader("X-LINE-Authorization-Nonce", nonce);
|
|
|
-
|
|
|
- StringBuffer message = new StringBuffer();
|
|
|
- //channelSecret
|
|
|
- message.append(lineConfig.channelSecret);
|
|
|
- //path
|
|
|
- message.append(request.getUri().getPath());
|
|
|
- //body
|
|
|
- message.append(mapper.writeValueAsString(sendBody));
|
|
|
- //nonce
|
|
|
- message.append(nonce);
|
|
|
-
|
|
|
- byte[] bytes = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_SHA_256, lineConfig.channelSecret.getBytes()).doFinal(message.toString().getBytes());
|
|
|
-
|
|
|
- byte[] byteArray = Base64.encodeBase64(bytes);
|
|
|
-
|
|
|
- request.setHeader("X-LINE-Authorization", new String(byteArray));
|
|
|
-
|
|
|
- request.setEntity(new StringEntity(mapper.writeValueAsString(sendBody), ContentType.APPLICATION_JSON));
|
|
|
+ setHeaderAndEntity(request, mapper.writeValueAsString(sendBody));
|
|
|
|
|
|
response = client.execute(request, httpResponse ->
|
|
|
mapper.readValue(EntityUtils.toString(httpResponse.getEntity()), LinePayAPOD.class));
|
|
|
@@ -158,9 +166,7 @@ public class LinePay implements Serializable {
|
|
|
body.setAmount(total);
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
-
|
|
|
- String nonce = UUID.randomUUID().toString();
|
|
|
-
|
|
|
+
|
|
|
MessageFormat form = new MessageFormat(lineConfig.confirmUrl);
|
|
|
|
|
|
String formatStr = form.format(new Object[] {transactionId});
|
|
|
@@ -171,27 +177,7 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
HttpPost request = new HttpPost(formatStr);
|
|
|
|
|
|
- request.setHeader("Content-Type", "application/json");
|
|
|
- request.setHeader("X-LINE-ChannelId", lineConfig.channelId);
|
|
|
- request.setHeader("X-LINE-Authorization-Nonce", nonce);
|
|
|
-
|
|
|
- StringBuffer message = new StringBuffer();
|
|
|
- //channelSecret
|
|
|
- message.append(lineConfig.channelSecret);
|
|
|
- //path
|
|
|
- message.append(request.getUri().getPath());
|
|
|
- //body
|
|
|
- message.append(mapper.writeValueAsString(body));
|
|
|
- //nonce
|
|
|
- message.append(nonce);
|
|
|
-
|
|
|
- byte[] bytes = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_SHA_256, lineConfig.channelSecret.getBytes()).doFinal(message.toString().getBytes());
|
|
|
-
|
|
|
- byte[] byteArray = Base64.encodeBase64(bytes);
|
|
|
-
|
|
|
- request.setHeader("X-LINE-Authorization", new String(byteArray));
|
|
|
-
|
|
|
- request.setEntity(new StringEntity(mapper.writeValueAsString(body), ContentType.APPLICATION_JSON));
|
|
|
+ setHeaderAndEntity(request, mapper.writeValueAsString(body));
|
|
|
|
|
|
response = client.execute(request, httpResponse ->
|
|
|
mapper.readValue(EntityUtils.toString(httpResponse.getEntity()), LinePayConfirmAPOD.class));
|
|
|
@@ -205,4 +191,42 @@ public class LinePay implements Serializable {
|
|
|
|
|
|
return response;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 決済完了(売上確定済み)された取引を返金します。
|
|
|
+ * @param transactionId
|
|
|
+ * @param refundAmount
|
|
|
+ */
|
|
|
+ public LinePayRefundAPOD payRefund(String transactionId, Long refundAmount) {
|
|
|
+ //
|
|
|
+ RefundBody body = new RefundBody();
|
|
|
+
|
|
|
+ body.setRefundAmount(refundAmount);
|
|
|
+
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+
|
|
|
+ MessageFormat form = new MessageFormat(lineConfig.confirmUrl);
|
|
|
+
|
|
|
+ String formatStr = form.format(new Object[] {transactionId});
|
|
|
+
|
|
|
+ LinePayRefundAPOD response = null;
|
|
|
+
|
|
|
+ try (CloseableHttpClient client = HttpClients.createDefault()) {
|
|
|
+
|
|
|
+ HttpPost request = new HttpPost(formatStr);
|
|
|
+
|
|
|
+ setHeaderAndEntity(request, mapper.writeValueAsString(body));
|
|
|
+
|
|
|
+ response = client.execute(request, httpResponse ->
|
|
|
+ mapper.readValue(EntityUtils.toString(httpResponse.getEntity()), LinePayRefundAPOD.class));
|
|
|
+
|
|
|
+ log.debug(mapper.writeValueAsString(response));
|
|
|
+
|
|
|
+ } catch (IOException | URISyntaxException e) {
|
|
|
+
|
|
|
+ log.error("line pay Refund API エラーが発生しました。", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ return response;
|
|
|
+ }
|
|
|
}
|