|
|
@ -8,6 +8,7 @@ import au.com.royalpay.payment.manage.shopify.auth.domain.service.ShopifyRequest
|
|
|
|
import au.com.royalpay.payment.manage.shopify.support.ShopifyEndpoint;
|
|
|
|
import au.com.royalpay.payment.manage.shopify.support.ShopifyEndpoint;
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.http.server.ServletServerHttpRequest;
|
|
|
|
import org.springframework.http.server.ServletServerHttpRequest;
|
|
|
@ -41,7 +42,10 @@ public class ShopifyAuthTemplateController {
|
|
|
|
@GetMapping("/auth")
|
|
|
|
@GetMapping("/auth")
|
|
|
|
@ShopifyEndpoint
|
|
|
|
@ShopifyEndpoint
|
|
|
|
public String shopifyStorePermission(@RequestParam(value = "shop", required = false) String shop,
|
|
|
|
public String shopifyStorePermission(@RequestParam(value = "shop", required = false) String shop,
|
|
|
|
@RequestParam("hmac") String hmac, HttpServletRequest request) {
|
|
|
|
@RequestParam(value = "hmac", required = false) String hmac, HttpServletRequest request) {
|
|
|
|
|
|
|
|
if (StringUtils.isAnyEmpty(shop, hmac)) {
|
|
|
|
|
|
|
|
throw new BadRequestException("Parameter shop&hmac are required");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!Pattern.matches("^[a-zA-Z0-9][a-zA-Z0-9\\-]*\\.myshopify\\.com", shop)) {
|
|
|
|
if (!Pattern.matches("^[a-zA-Z0-9][a-zA-Z0-9\\-]*\\.myshopify\\.com", shop)) {
|
|
|
|
throw new BadRequestException("Parameter shop is invalid.");
|
|
|
|
throw new BadRequestException("Parameter shop is invalid.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -67,12 +71,15 @@ public class ShopifyAuthTemplateController {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GetMapping("/auth/back")
|
|
|
|
@GetMapping("/auth/back")
|
|
|
|
@ShopifyEndpoint
|
|
|
|
@ShopifyEndpoint
|
|
|
|
public String shopifyStoreAuthRedirect(@RequestParam("code") String code,
|
|
|
|
public String shopifyStoreAuthRedirect(@RequestParam(value = "code", required = false) String code,
|
|
|
|
@RequestParam("hmac") String hmac,
|
|
|
|
@RequestParam(value = "hmac", required = false) String hmac,
|
|
|
|
@RequestParam("host") String host,
|
|
|
|
@RequestParam(value = "host", required = false) String host,
|
|
|
|
@RequestParam("state") String state,
|
|
|
|
@RequestParam(value = "state", required = false) String state,
|
|
|
|
@RequestParam("shop") String shop,
|
|
|
|
@RequestParam(value = "shop", required = false) String shop,
|
|
|
|
@RequestParam("timestamp") String timestamp) {
|
|
|
|
@RequestParam(value = "timestamp", required = false) String timestamp) {
|
|
|
|
|
|
|
|
if (StringUtils.isAnyEmpty(shop, hmac, host, state, shop, timestamp)) {
|
|
|
|
|
|
|
|
throw new BadRequestException("Parameter shop,hmac,host,state,shop,timestamp are required");
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!Pattern.matches("^[a-zA-Z0-9][a-zA-Z0-9\\-]*\\.myshopify\\.com", shop)) {
|
|
|
|
if (!Pattern.matches("^[a-zA-Z0-9][a-zA-Z0-9\\-]*\\.myshopify\\.com", shop)) {
|
|
|
|
throw new ShopifyRequestVerifyException("Parameter shop is invalid.");
|
|
|
|
throw new ShopifyRequestVerifyException("Parameter shop is invalid.");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -90,7 +97,7 @@ public class ShopifyAuthTemplateController {
|
|
|
|
.shop(shop)
|
|
|
|
.shop(shop)
|
|
|
|
.timestamp(timestamp)
|
|
|
|
.timestamp(timestamp)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
if (!shopifyRequestValidator.valid(shopifyCommonParameter)) {
|
|
|
|
if (Boolean.FALSE.equals(shopifyRequestValidator.valid(shopifyCommonParameter))) {
|
|
|
|
throw new ShopifyRequestVerifyException("This request parameters is invalid");
|
|
|
|
throw new ShopifyRequestVerifyException("This request parameters is invalid");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|