From f441fe9b5e86a1211a7ef55c39c65f0de358e84a Mon Sep 17 00:00:00 2001 From: ycfxx Date: Thu, 23 Dec 2021 10:52:40 +0800 Subject: [PATCH 01/12] upgrade add shopify auth --- .../mappers/shopify/ShopifyStoreMapper.java | 18 +++ .../manage/mappers/system/MerchantMapper.java | 15 ++ .../ShopifyMerchantAuthApplication.java | 66 +++++++++ .../domain/entity/ShopifyAccessToken.java | 11 ++ .../entity/ShopifyPermissionBackParam.java | 18 +++ .../domain/entity/ShopifyPermissionURL.java | 11 ++ .../domain/service/ShopifyAuthService.java | 60 ++++++++ .../auth/web/ShopifyAuthController.java | 53 +++++++ .../command/ShopifyAccessTokenRequest.java | 17 +++ .../web/command/ShopifyPermissionRequest.java | 18 +++ .../config/ShopifyApplicationConfig.java | 30 ++++ .../store/domain/entity/ShopifyStore.java | 46 ++++++ .../store/domain/service/MerchantService.java | 21 +++ .../service/PaymentAppMerchantService.java | 21 +++ .../domain/service/ShopifyStoreService.java | 21 +++ .../service/impl/ShopifyStoreServiceImpl.java | 24 ++++ .../store/web/ShopifyStoreController.java | 29 ++++ src/main/resources/application-dev.yml | 2 +- src/main/resources/application.yml | 6 + .../templates/shopify/auth_back.html | 10 ++ src/main/ui/auth.html | 131 ++++++++++++++++++ src/main/ui/static/boot/shopify-auth-boot.js | 80 +++++++++++ src/main/ui/static/boot/shopifyMainApp.js | 27 ++++ .../static/shopify/auth/shopify.auth.back.js | 32 +++++ .../ui/static/shopify/auth/shopify.auth.js | 67 +++++++++ .../shopify/auth/templates/auth_root.html | 40 ++++++ .../shopify/auth/templates/shopify_auth.html | 42 ++++++ .../auth/templates/shopify_auth_back.html | 14 ++ .../shopify/auth/templates/shopify_login.html | 54 ++++++++ .../auth/templates/shopify_register.html | 31 +++++ .../service/ShopifyStoreServiceTest.java | 44 ++++++ 31 files changed, 1058 insertions(+), 1 deletion(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/system/MerchantMapper.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionBackParam.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionURL.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/service/ShopifyAuthService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/ShopifyAuthController.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyAccessTokenRequest.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyPermissionRequest.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/config/ShopifyApplicationConfig.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/PaymentAppMerchantService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java create mode 100644 src/main/resources/templates/shopify/auth_back.html create mode 100644 src/main/ui/auth.html create mode 100644 src/main/ui/static/boot/shopify-auth-boot.js create mode 100644 src/main/ui/static/boot/shopifyMainApp.js create mode 100644 src/main/ui/static/shopify/auth/shopify.auth.back.js create mode 100644 src/main/ui/static/shopify/auth/shopify.auth.js create mode 100644 src/main/ui/static/shopify/auth/templates/auth_root.html create mode 100644 src/main/ui/static/shopify/auth/templates/shopify_auth.html create mode 100644 src/main/ui/static/shopify/auth/templates/shopify_auth_back.html create mode 100644 src/main/ui/static/shopify/auth/templates/shopify_login.html create mode 100644 src/main/ui/static/shopify/auth/templates/shopify_register.html create mode 100644 src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java new file mode 100644 index 000000000..c18a3028c --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java @@ -0,0 +1,18 @@ +package au.com.royalpay.payment.manage.mappers.shopify; + +import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore; +import com.yixsoft.support.mybatis.autosql.annotations.AutoMapper; +import com.yixsoft.support.mybatis.autosql.annotations.AutoSql; +import com.yixsoft.support.mybatis.autosql.annotations.SqlType; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; + +@AutoMapper(tablename = "shopify_store", pkName = "id", keyGenerator = Jdbc3KeyGenerator.class) +public interface ShopifyStoreMapper { + + @AutoSql(SqlType.INSERT) + void insert(ShopifyStore shopifyStore); + + @AutoSql(SqlType.SELECT) + ShopifyStore selectByShop(@Param("shopify_shop") String shop); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/MerchantMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/MerchantMapper.java new file mode 100644 index 000000000..96c847260 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/MerchantMapper.java @@ -0,0 +1,15 @@ +package au.com.royalpay.payment.manage.mappers.system; + +import com.alibaba.fastjson.JSONObject; +import com.yixsoft.support.mybatis.autosql.annotations.AutoMapper; +import com.yixsoft.support.mybatis.autosql.annotations.AutoSql; +import com.yixsoft.support.mybatis.autosql.annotations.SqlType; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; + +@AutoMapper(tablename = "sys_clients", pkName = "client_id", keyGenerator = Jdbc3KeyGenerator.class) +public interface MerchantMapper { + + @AutoSql(SqlType.SELECT) + public JSONObject selectByLoginId(@Param("client_id") String loginId); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java new file mode 100644 index 000000000..93ca14369 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java @@ -0,0 +1,66 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.application; + +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyAccessToken; +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyPermissionURL; +import au.com.royalpay.payment.manage.shopify.auth.domain.service.ShopifyAuthService; +import au.com.royalpay.payment.manage.shopify.auth.web.command.ShopifyPermissionRequest; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore; +import au.com.royalpay.payment.manage.shopify.store.domain.service.ShopifyStoreService; +import au.com.royalpay.payment.manage.signin.beans.LoginInfo; +import au.com.royalpay.payment.manage.signin.core.SignInAccountService; +import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; +import com.alibaba.fastjson.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +@Component +public class ShopifyMerchantAuthApplication { + + private static final String redisPrefix = "shopify:accessToken:%s"; + + @Autowired + private StringRedisTemplate redisTemplate; + + @Autowired + private ShopifyAuthService shopifyAuthService; + + @Autowired + private ShopifyStoreService shopifyStoreService; + + @Autowired + private SignInAccountService signInAccountService; + + @Autowired + private SignInStatusManager signInStatusManager; + + /** + * 获取shopify店铺授权URL + * + * @param request 店铺信息 + * @return + */ + public ShopifyPermissionURL shopifyPermission(ShopifyPermissionRequest request) { + LoginInfo loginInfo = new LoginInfo(); + loginInfo.setLoginId(request.getLoginId()); + loginInfo.setPassword(request.getPassword()); + String statusKey = signInStatusManager.partnerSignIn(loginInfo); + JSONObject client = signInStatusManager.getCurrentClient(statusKey); + + shopifyStoreService.createShopifyStore(ShopifyStore.instanceOf(client, request.getShop())); + return shopifyAuthService.shopifyPermission(request); + } + + /** + * shopify商户授权 + * + * @param shop shopify商户标识 + * @param code 授权code + * @return + */ + public ShopifyAccessToken merchantOnboard(String shop, String code) { + ShopifyAccessToken accessToken = shopifyAuthService.getAccessToken(shop, code); + redisTemplate.boundValueOps(String.format(redisPrefix, shop)).set(accessToken.getAccess_token()); + return accessToken; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java new file mode 100644 index 000000000..a28858350 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java @@ -0,0 +1,11 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.entity; + +import lombok.Data; + +@Data +public class ShopifyAccessToken { + + private String access_token; + + private String scope; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionBackParam.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionBackParam.java new file mode 100644 index 000000000..034ff1e4c --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionBackParam.java @@ -0,0 +1,18 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.entity; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class ShopifyPermissionBackParam { + + @NotBlank(message = "code not blank") + private String code; + private String hmac; + private String host; + @NotBlank(message = "shop not blank") + private String shop; + private String state; + private String timestamp; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionURL.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionURL.java new file mode 100644 index 000000000..152161ef1 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyPermissionURL.java @@ -0,0 +1,11 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.entity; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class ShopifyPermissionURL { + + private String url; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/service/ShopifyAuthService.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/service/ShopifyAuthService.java new file mode 100644 index 000000000..1f88d2384 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/service/ShopifyAuthService.java @@ -0,0 +1,60 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.service; + +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyAccessToken; +import au.com.royalpay.payment.manage.shopify.auth.web.command.ShopifyAccessTokenRequest; +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyPermissionURL; +import au.com.royalpay.payment.manage.shopify.auth.web.command.ShopifyPermissionRequest; +import au.com.royalpay.payment.tools.env.PlatformEnvironment; +import au.com.royalpay.payment.tools.exceptions.ServerErrorException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; + +import java.util.Date; + +@Service +@Slf4j +public class ShopifyAuthService { + + @Value("${shopify.auth.apiKey}") + private String clientId; + + @Value("${shopify.auth.apiSecretKey}") + private String clientSecret; + + @Value("${shopify.auth.scope}") + private String scope; + + private static final String PERMISSION_URL = "https://%s/admin/oauth/authorize?client_id=%s&scope=%s&redirect_uri=%s&state=%s&grant_options[]=per-user"; + + private static final String ACCESS_TOKEN_URL = "https://%s/admin/oauth/access_token"; + + @Autowired + @Qualifier("shopifyRestTemplate") + private RestTemplate restTemplate; + + public ShopifyPermissionURL shopifyPermission(ShopifyPermissionRequest request) { + String redirectUri = PlatformEnvironment.getEnv().concatUrl("/shopify/auth/back"); + String permissionUrl = String.format(PERMISSION_URL, request.getShop(), clientId, scope, redirectUri, String.valueOf(new Date().getTime()).substring(0,10)); + return ShopifyPermissionURL.builder().url(permissionUrl).build(); + } + + public ShopifyAccessToken getAccessToken(String shop, String code) { + ShopifyAccessTokenRequest request = new ShopifyAccessTokenRequest(clientId, clientSecret, code); + ResponseEntity responseEntity; + try { + responseEntity = restTemplate.postForEntity(String.format(ACCESS_TOKEN_URL, shop), request, ShopifyAccessToken.class); + } catch (RestClientException e) { + log.error(String.format("Shopify merchant [%s] get access token error: %s", shop, e.getMessage())); + throw new ServerErrorException(e.getMessage()); + } + ShopifyAccessToken shopifyAccessToken = responseEntity.getBody(); + log.info(String.format("Shopify merchant [%s] access token: %s", shop, shopifyAccessToken)); + return shopifyAccessToken; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/ShopifyAuthController.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/ShopifyAuthController.java new file mode 100644 index 000000000..6599ccb05 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/ShopifyAuthController.java @@ -0,0 +1,53 @@ +package au.com.royalpay.payment.manage.shopify.auth.web; + +import au.com.royalpay.payment.manage.shopify.auth.domain.application.ShopifyMerchantAuthApplication; +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyAccessToken; +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyPermissionURL; +import au.com.royalpay.payment.manage.shopify.auth.web.command.ShopifyPermissionRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.ModelAndView; + +import javax.validation.Valid; + +/** + * shopify认证授权资源 + */ +@RestController +@RequestMapping(value = "/shopify/auth") +public class ShopifyAuthController { + + @Autowired + private ShopifyMerchantAuthApplication shopifyMerchantAuthApplication; + + /** + * 获取shopify店铺授权URL + * + * @param request 店铺信息 + * @return + */ + @PostMapping("/permission") + public ShopifyPermissionURL shopifyPermission(@RequestBody @Valid ShopifyPermissionRequest request) { + ShopifyPermissionURL shopifyPermissionURL = shopifyMerchantAuthApplication.shopifyPermission(request); + return shopifyPermissionURL; + } + + /** + * shopify授权回调接口 + * + * @return + */ + @GetMapping("/back") + public ModelAndView shopifyAuthBack(@RequestParam(value = "code") String code, + @RequestParam(name = "hmac", required = false) String hmac, + @RequestParam(name = "host", required = false) String host, + @RequestParam("shop") String shop, + @RequestParam(name = "state", required = false) String state, + @RequestParam(name = "timestamp", required = false) String timestamp) { + ShopifyAccessToken accessToken = shopifyMerchantAuthApplication.merchantOnboard(shop, code); + ModelAndView view = new ModelAndView("shopify/auth_back"); + view.addObject("accessToken",accessToken); + return view; + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyAccessTokenRequest.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyAccessTokenRequest.java new file mode 100644 index 000000000..3343a225e --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyAccessTokenRequest.java @@ -0,0 +1,17 @@ +package au.com.royalpay.payment.manage.shopify.auth.web.command; + +import lombok.Data; + +@Data +public class ShopifyAccessTokenRequest { + + private String client_id; + private String client_secret; + private String code; + + public ShopifyAccessTokenRequest(String clientId, String clientSecret, String code) { + this.client_id = clientId; + this.client_secret = clientSecret; + this.code = code; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyPermissionRequest.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyPermissionRequest.java new file mode 100644 index 000000000..494f17fca --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyPermissionRequest.java @@ -0,0 +1,18 @@ +package au.com.royalpay.payment.manage.shopify.auth.web.command; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class ShopifyPermissionRequest { + + @NotBlank(message = "Shop can not blank") + private String shop; + + @NotBlank(message = "Login Id can not blank") + private String loginId; + + @NotBlank(message = "Password can not blank") + private String password; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/config/ShopifyApplicationConfig.java b/src/main/java/au/com/royalpay/payment/manage/shopify/config/ShopifyApplicationConfig.java new file mode 100644 index 000000000..173b1d53f --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/config/ShopifyApplicationConfig.java @@ -0,0 +1,30 @@ +package au.com.royalpay.payment.manage.shopify.config; + +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; +import com.google.common.collect.ImmutableList; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.http.converter.ByteArrayHttpMessageConverter; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +import java.nio.charset.StandardCharsets; + +@Configuration +public class ShopifyApplicationConfig { + + @Bean + @Qualifier("shopifyRestTemplate") + public RestTemplate restTemplate() { + FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter(); + fastJsonHttpMessageConverter.setSupportedMediaTypes(ImmutableList.of(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN)); + return new RestTemplateBuilder() + .messageConverters(new ByteArrayHttpMessageConverter(), + new StringHttpMessageConverter(StandardCharsets.UTF_8), + fastJsonHttpMessageConverter) + .build(); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java new file mode 100644 index 000000000..de6e6bba7 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java @@ -0,0 +1,46 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.entity; + +import com.alibaba.fastjson.JSONObject; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Date; +import java.util.UUID; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ShopifyStore { + + private String id; + + private Integer clientId; + + private String clientMoniker; + + private String shopifyShop; + + private Date createTime; + + private String creator; + + private Date modifyTime; + + private String modifier; + + public static ShopifyStore instanceOf(JSONObject client, String shop) { + Integer clientId = client.getInteger("client_id"); + String clientMoniker = client.getString("client_moniker"); + return ShopifyStore.builder() + .id(UUID.randomUUID().toString()) + .clientId(clientId) + .clientMoniker(clientMoniker) + .shopifyShop(shop) + .createTime(new Date()) + .creator("shopify") + .modifyTime(new Date()).build(); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantService.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantService.java new file mode 100644 index 000000000..b7529fa43 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantService.java @@ -0,0 +1,21 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.service; + +import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper; +import com.alibaba.fastjson.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class MerchantService { + + @Autowired + private ClientAccountMapper clientAccountMapper; + + public Boolean existMerchant(String loginId) { + JSONObject account = clientAccountMapper.findByUsername(loginId); + if (account == null) { + return false; + } + return true; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/PaymentAppMerchantService.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/PaymentAppMerchantService.java new file mode 100644 index 000000000..6ec1a0255 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/PaymentAppMerchantService.java @@ -0,0 +1,21 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class PaymentAppMerchantService { + + @Autowired + private MerchantService merchantservice; + + /** + * 检查loginId的商户是否存在 + * + * @param loginId 商户用户标识 + * @return + */ + public Boolean existMerchant(String loginId) { + return merchantservice.existMerchant(loginId); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java new file mode 100644 index 000000000..55441447d --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java @@ -0,0 +1,21 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.service; + +import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore; + +public interface ShopifyStoreService { + + /** + * 关联shopify店铺 + * + * @param shopifyStore 店铺信息 + */ + void createShopifyStore(ShopifyStore shopifyStore); + + /** + * 根据shop获取shopify store + * + * @param shop 店铺标识 + * @return + */ + ShopifyStore getByShopifyShop(String shop); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java new file mode 100644 index 000000000..0d0ccd75a --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java @@ -0,0 +1,24 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.service.impl; + +import au.com.royalpay.payment.manage.mappers.shopify.ShopifyStoreMapper; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore; +import au.com.royalpay.payment.manage.shopify.store.domain.service.ShopifyStoreService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ShopifyStoreServiceImpl implements ShopifyStoreService { + + @Autowired + private ShopifyStoreMapper shopifyStoreMapper; + + @Override + public void createShopifyStore(ShopifyStore shopifyStore) { + shopifyStoreMapper.insert(shopifyStore); + } + + @Override + public ShopifyStore getByShopifyShop(String shop) { + return shopifyStoreMapper.selectByShop(shop); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java new file mode 100644 index 000000000..76813b27a --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java @@ -0,0 +1,29 @@ +package au.com.royalpay.payment.manage.shopify.store.web; + +import au.com.royalpay.payment.manage.shopify.store.domain.service.PaymentAppMerchantService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +/** + * shopify店铺资源 + */ +@RestController +@RequestMapping(value = "/shopify/store") +public class ShopifyStoreController { + + @Autowired + private PaymentAppMerchantService paymentAppMerchantService; + + /** + * 检查loginId的商户是否存在 + * + * @param loginId 商户用户标识 + */ + @GetMapping("/exist") + public Boolean validPaymentAppMerchant(@RequestParam("loginId") String loginId) { + return paymentAppMerchantService.existMerchant(loginId); + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 82aa7edc2..7180250b5 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -73,7 +73,7 @@ spring: app: run-tasks: false host: - main: http://dalong-au.dev.rpaygroup.com/ + main: https://1c6d-222-95-180-118.ngrok.io/ regions: au: http://dalong-au.dev.rpaygroup.com/ cn: http://dalong-au.dev.rpaygroup.com/ diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8e4176c97..16e76e99c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -174,5 +174,11 @@ logging: royalpay: payment: debug +shopify: + auth: + apiKey: 3bef8dabafd9db8c50f46ce73429f2ff + apiSecretKey: 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 + scope: write_orders,read_customers,write_payment_gateways,write_payment_sessions + diff --git a/src/main/resources/templates/shopify/auth_back.html b/src/main/resources/templates/shopify/auth_back.html new file mode 100644 index 000000000..cd6f8a9a7 --- /dev/null +++ b/src/main/resources/templates/shopify/auth_back.html @@ -0,0 +1,10 @@ + + + + + Title + + +
授权成功!
+ + \ No newline at end of file diff --git a/src/main/ui/auth.html b/src/main/ui/auth.html new file mode 100644 index 000000000..fb5650670 --- /dev/null +++ b/src/main/ui/auth.html @@ -0,0 +1,131 @@ + + + + + + RoyalPay + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+ + + diff --git a/src/main/ui/static/boot/shopify-auth-boot.js b/src/main/ui/static/boot/shopify-auth-boot.js new file mode 100644 index 000000000..cf66a288a --- /dev/null +++ b/src/main/ui/static/boot/shopify-auth-boot.js @@ -0,0 +1,80 @@ +/** + * Created by yixian on 2016-06-29. + */ +require.config({ + baseUrl: './', + waitSeconds: 90, + urlArgs: 'bust=' + new Date().getTime(), + paths: { + jquery: 'static/lib/jquery/jquery-2.1.4.min', + uiBootstrap: 'static/lib/angular-plugins/ui-bootstrap-tpls-1.2.4.min', + uiRouter: 'static/lib/angular-plugins/angular-ui-router.min', + angularChecklist: 'static/lib/angular-plugins/checklist-model', + angular: 'static/lib/angularjs/angular.min', + angularAnimate: 'static/lib/angularjs/angular-animate.min', + angularMessages: 'static/lib/angularjs/angular-messages.min', + angularSanitize: 'static/lib/angularjs/angular-sanitize.min', + angularLocale: 'static/lib/angularjs/angular-locale_zh-cn', + bootSwitch: 'static/lib/bootswitch/bootstrap-switch.min', + ngBootSwitch: 'static/lib/angular-plugins/angular-bootstrap-switch.min', + ngFileUpload: 'static/lib/ngfileupload/ng-file-upload.min', + holder: 'static/lib/holder/holder.min', + datetimePicker: 'static/lib/datetime-picker/datetime-picker.min', + colorpicker: 'static/lib/colorpicker/js/bootstrap-colorpicker-module.min', + qrcode: 'static/lib/jquery/jquery.qrcode.min', + sockjs: 'static/lib/websocket/sockjs.min', + stomp: 'static/lib/websocket/stomp.min', + uiSelect: 'static/lib/angular-plugins/select.min', + dragdrop: 'static/lib/angular-plugins/angular-drag-and-drop-lists.min', + echarts: 'static/lib/echarts/echarts.common.min', + angularEcharts: 'static/commons/angular-echarts', + decimal:'static/lib/decimal/decimal.min', + jstz: 'static/lib/timezone/jstz-1.0.4.min' + }, + shim: { + 'angular': {deps: ['jquery','decimal'], exports: 'angular'}, + 'angularLocale': ['angular'], + 'uiBootstrap': ['angular'], + 'uiRouter': ['angular'], + 'uiSelect': ['angular', 'css!static/lib/angular-plugins/select.min'], + 'angularAnimate': ['angular'], + 'angularMessages': ['angular'], + 'angularSanitize': ['angular'], + 'ngFileUpload': ['angular'], + 'angularChecklist': ['angular'], + 'datetimePicker': ['angular'], + 'ngBootSwitch': ['bootSwitch', 'angular'], + 'bootSwitch': ['jquery', 'css!static/lib/bootswitch/bootstrap-switch.min'], + 'qrcode': ['jquery'], + 'colorpicker': ['angular', 'css!static/lib/colorpicker/css/colorpicker.min'], + 'holder': ['jquery'], + 'dragdrop': ['angular'] + }, + map: { + '*': { + 'css': 'static/lib/css.min' + } + } +}); +var modules = [ + {path: 'static/boot/shopifyMainApp', module: 'shopifyMainApp'}, + {path: 'static/shopify/auth/shopify.auth', module: 'shopify.auth'}, + {path: 'static/shopify/auth/shopify.auth.back', module: 'shopify.auth.back'} +]; + +require(['angular', 'jquery'], function (angular, $) { + function boot() { + var paths = []; + var moduleNames = []; + angular.forEach(modules, function (mod) { + paths.push(mod.path); + moduleNames.push(mod.module); + }); + require(paths, function () { + angular.bootstrap(document.body, moduleNames) + }); + } + + boot(); + +}); diff --git a/src/main/ui/static/boot/shopifyMainApp.js b/src/main/ui/static/boot/shopifyMainApp.js new file mode 100644 index 000000000..21bd8244c --- /dev/null +++ b/src/main/ui/static/boot/shopifyMainApp.js @@ -0,0 +1,27 @@ + +define(['angular', 'angularSanitize', 'angularAnimate', 'angularMessages', 'uiRouter', 'uiBootstrap', 'ngFileUpload', 'sockjs', 'stomp'], function (angular) { + 'use strict'; + var app = angular.module('shopifyMainApp', ['ngSanitize', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ngFileUpload']); + app.config(['$urlRouterProvider', '$httpProvider','$locationProvider', function ($urlRouterProvider, $httpProvider, $locationProvider) { + $urlRouterProvider.otherwise('/shopify'); + /*$locationProvider.html5Mode({ + //设置为html5Mode(模式),当为false时为Hashbang模式 + enabled : true, + //是否需要加入base标签,这里设置为false,设置为true时,需在html的head配置标签 + requireBase : false + });*/ + if (!$httpProvider.defaults.headers.get) { + $httpProvider.defaults.headers.get = {}; + } + $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; + $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; + $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; + }]); + app.controller('ShopifyAppCtrl', ['$scope', '$rootScope', '$http', '$log', '$timeout', '$interval', '$q', '$uibModal', + function ($scope, $rootScope, $http, $log, $timeout, $interval, $q, $uibModal) { + + + + }]); + return app; +}); diff --git a/src/main/ui/static/shopify/auth/shopify.auth.back.js b/src/main/ui/static/shopify/auth/shopify.auth.back.js new file mode 100644 index 000000000..ad59b2a51 --- /dev/null +++ b/src/main/ui/static/shopify/auth/shopify.auth.back.js @@ -0,0 +1,32 @@ +define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { + 'use strict'; + var module = angular.module('shopify.auth.back', ['ui.router', 'ui.bootstrap']); + module.config(['$stateProvider', function ($stateProvider) { + $stateProvider.state('shopifyAuthBack', { + url: '/auth_back', + templateUrl: '/static/shopify/auth/templates/shopify_auth_back.html', + controller: 'ShopifyAuthBackController' + }); + }]); + module.controller('ShopifyAuthBackController',['$scope','$http','$location', function ($scope, $http, $location) { + var that = $scope; + that.getShopifyStorePermission = function () { + var params = { + code:$location.search().code, + hmac: $location.search().hmac, + host: $location.search().host, + shop: $location.search().shop, + state: $location.search().state, + timestamp: $location.search().timestamp + } + console.log("request data:",params) + $http.post("/shopify/auth/back",params).then(function (res) { + console.log("permission data:",res.data) + }) + } + that.getShopifyStorePermission() + + }]); + return module; + } +) \ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/shopify.auth.js b/src/main/ui/static/shopify/auth/shopify.auth.js new file mode 100644 index 000000000..2add776c0 --- /dev/null +++ b/src/main/ui/static/shopify/auth/shopify.auth.js @@ -0,0 +1,67 @@ +define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { + 'use strict'; + var module = angular.module('shopify.auth', ['ui.router', 'ui.bootstrap']); + module.config(['$stateProvider', function ($stateProvider) { + $stateProvider.state('shopify', { + url: '/shopify', + templateUrl: '/static/shopify/auth/templates/auth_root.html', + controller: 'ShopifyRootController' + }).state('shopify.auth', { + url: '/auth', + templateUrl: '/static/shopify/auth/templates/shopify_auth.html', + controller: 'ShopifyAuthController' + }).state('shopify.login', { + url: '/login', + templateUrl: '/static/shopify/auth/templates/shopify_login.html', + controller: 'ShopifyLoginController' + }).state('shopify.register', { + url: '/register', + templateUrl: '/static/shopify/auth/templates/shopify_register.html', + controller: 'ShopifyRegisterController' + }); + }]); + + module.controller('ShopifyRootController',['$scope','$http','$state',function ($scope, $http, $state) { + if ($state.is('shopify')) { + $state.go('shopify.auth') + } + }]) + + module.controller('ShopifyAuthController',['$scope','$http','$state', function ($scope, $http, $state) { + var that = $scope; + that.store = { + loginId: '' + } + that.validStoreLoginId = function () { + $http.get("/shopify/store/exist",{params: that.store}).then(function (res) { + if (res.data) { + $state.go('shopify.login', {userId: that.store.loginId}); + }else { + $state.go('shopify.register', {userId: that.store.loginId}); + } + }) + } + }]); + + module.controller('ShopifyLoginController',['$scope','$http','$state', function ($scope, $http, $state) { + var that = $scope; + that.model = { + shop: '', + loginId: '', + password: '' + } + that.activeShopifyMerchant = function () { + $http.post("/shopify/auth/permission",that.model).then(function (res) { + console.log("permissionUrl",res.data.url) + location.href = res.data.url + }) + } + }]); + + module.controller('ShopifyRegisterController',['$scope','$http','$state', function ($scope, $http, $state) { + + }]); + + return module; + } +) \ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/templates/auth_root.html b/src/main/ui/static/shopify/auth/templates/auth_root.html new file mode 100644 index 000000000..ccb6db5c9 --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/auth_root.html @@ -0,0 +1,40 @@ + + + + + Title + + + + +
+
+
+ +
+
+
+ +
+ +
+
+ ©2015-2021 RoyalPay. +
+
+ + \ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/templates/shopify_auth.html b/src/main/ui/static/shopify/auth/templates/shopify_auth.html new file mode 100644 index 000000000..e7fa3a881 --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_auth.html @@ -0,0 +1,42 @@ + + + + + Title + + + + +
+
+
+
+

+ Connect a RoyalPay account to start accepting payments on Shopify +

+ +

+ It's free to connect, whether you have an existing RoyalPay account or want to create a new one. +

+
+
+
+ +
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html b/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html new file mode 100644 index 000000000..959a46302 --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html @@ -0,0 +1,14 @@ + + + + + Title + + + +
+

auth back

+
+ + + \ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/templates/shopify_login.html b/src/main/ui/static/shopify/auth/templates/shopify_login.html new file mode 100644 index 000000000..6a4022f00 --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_login.html @@ -0,0 +1,54 @@ + + + + + Title + + + + +
+
+
+
+

+ Login +

+ +
+ +
+
+ +
+ +
+ + +
+ +
+ +

Example: geek-test-shop.myshopify.com

+
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/templates/shopify_register.html b/src/main/ui/static/shopify/auth/templates/shopify_register.html new file mode 100644 index 000000000..29541b3ca --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_register.html @@ -0,0 +1,31 @@ + + + + + Title + + + + +
+
+
+
+

+ Register +

+
+
+
+
+ + \ No newline at end of file diff --git a/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java new file mode 100644 index 000000000..f71bbc825 --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java @@ -0,0 +1,44 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.service; + +import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore; +import com.alibaba.fastjson.JSON; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Date; +import java.util.UUID; + +@Slf4j +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles({"dev", "alipay", "bestpay", "jd", "wechat", "rpay", "yeepay", "rppaysvc", "common", "alipayplusaps"}) +class ShopifyStoreServiceTest { + + @Autowired + private ShopifyStoreService shopifyStoreService; + + @Test + public void createShopifyStore() { + ShopifyStore shopifyStore = ShopifyStore.builder() + .id(UUID.randomUUID().toString()) + .clientId(00000001) + .clientMoniker("tttttt") + .shopifyShop("geek-test-shop.myshopify.com") + .createTime(new Date()) + .creator("shopify") + .modifyTime(new Date()).build(); + shopifyStoreService.createShopifyStore(shopifyStore); + } + + @Test + public void getByShopifyShop() { + ShopifyStore shopifyStore = shopifyStoreService.getByShopifyShop("geek-test-shop.myshopify.com"); + log.info(JSON.toJSONString(shopifyStore)); + } + +} \ No newline at end of file From ad4f78e1011ace327b8a6139260792397da7f08c Mon Sep 17 00:00:00 2001 From: ycfxx Date: Thu, 23 Dec 2021 13:22:51 +0800 Subject: [PATCH 02/12] upgrade add shopify auth --- .../mappers/shopify/ShopifyStoreMapper.java | 3 +++ .../ShopifyMerchantAuthApplication.java | 19 +++++++++++--- .../store/domain/entity/ShopifyStore.java | 2 ++ .../domain/service/ShopifyStoreService.java | 7 ++++++ .../service/impl/ShopifyStoreServiceImpl.java | 5 ++++ .../store/web/ShopifyStoreController.java | 17 ++++++++++--- .../command/CreateShopifyMerchantCommand.java | 16 ++++++++++++ .../web/command/PaymentAccountCommand.java | 11 ++++++++ .../web/command/PaymentMerchantCommand.java | 25 +++++++++++++++++++ .../service/ShopifyStoreServiceTest.java | 11 ++++++++ 10 files changed, 108 insertions(+), 8 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/CreateShopifyMerchantCommand.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentAccountCommand.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentMerchantCommand.java diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java index c18a3028c..985029eee 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java @@ -15,4 +15,7 @@ public interface ShopifyStoreMapper { @AutoSql(SqlType.SELECT) ShopifyStore selectByShop(@Param("shopify_shop") String shop); + + @AutoSql(SqlType.UPDATE) + void update(ShopifyStore shopifyStore); } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java index 93ca14369..c8458cef9 100644 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java @@ -14,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; +import java.util.Date; + @Component public class ShopifyMerchantAuthApplication { @@ -28,9 +30,6 @@ public class ShopifyMerchantAuthApplication { @Autowired private ShopifyStoreService shopifyStoreService; - @Autowired - private SignInAccountService signInAccountService; - @Autowired private SignInStatusManager signInStatusManager; @@ -47,7 +46,19 @@ public class ShopifyMerchantAuthApplication { String statusKey = signInStatusManager.partnerSignIn(loginInfo); JSONObject client = signInStatusManager.getCurrentClient(statusKey); - shopifyStoreService.createShopifyStore(ShopifyStore.instanceOf(client, request.getShop())); + ShopifyStore shopifyShop = shopifyStoreService.getByShopifyShop(request.getShop()); + + if (shopifyShop == null) { + shopifyStoreService.createShopifyStore(ShopifyStore.instanceOf(client, request.getShop())); + return shopifyAuthService.shopifyPermission(request); + } + + shopifyStoreService.modifyShopifyStore(shopifyShop + .setClientId(client.getInteger("client_id")) + .setClientMoniker(client.getString("client_moniker")) + .setModifyTime(new Date()) + .setModifier(request.getShop())); + return shopifyAuthService.shopifyPermission(request); } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java index de6e6bba7..4ef5252b4 100644 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java @@ -5,6 +5,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; import java.util.Date; import java.util.UUID; @@ -13,6 +14,7 @@ import java.util.UUID; @Builder @NoArgsConstructor @AllArgsConstructor +@Accessors(chain = true) public class ShopifyStore { private String id; diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java index 55441447d..320f7dc6b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java @@ -18,4 +18,11 @@ public interface ShopifyStoreService { * @return */ ShopifyStore getByShopifyShop(String shop); + + /** + * 变更shopify商户信息 + * + * @param shopifyStore 店铺信息 + */ + void modifyShopifyStore(ShopifyStore shopifyStore); } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java index 0d0ccd75a..15c68b7fc 100644 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java @@ -21,4 +21,9 @@ public class ShopifyStoreServiceImpl implements ShopifyStoreService { public ShopifyStore getByShopifyShop(String shop) { return shopifyStoreMapper.selectByShop(shop); } + + @Override + public void modifyShopifyStore(ShopifyStore shopifyStore) { + shopifyStoreMapper.update(shopifyStore); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java index 76813b27a..2c0bb9978 100644 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java @@ -1,11 +1,11 @@ package au.com.royalpay.payment.manage.shopify.store.web; import au.com.royalpay.payment.manage.shopify.store.domain.service.PaymentAppMerchantService; +import au.com.royalpay.payment.manage.shopify.store.web.command.CreateShopifyMerchantCommand; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; /** * shopify店铺资源 @@ -26,4 +26,13 @@ public class ShopifyStoreController { public Boolean validPaymentAppMerchant(@RequestParam("loginId") String loginId) { return paymentAppMerchantService.existMerchant(loginId); } + + /** + * shopify店铺报备 + * + * @param command 商户信息 + */ + @PostMapping("/register") + public void createMerchantWithShopify(@RequestBody @Valid CreateShopifyMerchantCommand command) { + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/CreateShopifyMerchantCommand.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/CreateShopifyMerchantCommand.java new file mode 100644 index 000000000..9bb26b36b --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/CreateShopifyMerchantCommand.java @@ -0,0 +1,16 @@ +package au.com.royalpay.payment.manage.shopify.store.web.command; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +@Data +public class CreateShopifyMerchantCommand { + + private PaymentMerchantCommand paymentMerchant; + + private PaymentAccountCommand paymentAccount; + + @NotBlank(message = "Shop can not blank") + private String shopifyShop; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentAccountCommand.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentAccountCommand.java new file mode 100644 index 000000000..6bd8a5471 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentAccountCommand.java @@ -0,0 +1,11 @@ +package au.com.royalpay.payment.manage.shopify.store.web.command; + +import lombok.Data; + +@Data +public class PaymentAccountCommand { + + private String loginId; + + private String password; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentMerchantCommand.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentMerchantCommand.java new file mode 100644 index 000000000..e88200aae --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentMerchantCommand.java @@ -0,0 +1,25 @@ +package au.com.royalpay.payment.manage.shopify.store.web.command; + +import lombok.Data; + +@Data +public class PaymentMerchantCommand { + + private String companyName; + + private String address; + + private String suburb; + + private String postcode; + + private String state; + + private String country; + + private String contactPerson; + + private String contactPhone; + + private String contactEmail; +} diff --git a/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java index f71bbc825..da506bc80 100644 --- a/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java +++ b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java @@ -41,4 +41,15 @@ class ShopifyStoreServiceTest { log.info(JSON.toJSONString(shopifyStore)); } + @Test + public void modifyShopifyStore() { + ShopifyStore shopifyStore = shopifyStoreService.getByShopifyShop("geek-test-shop.myshopify.com"); + + shopifyStoreService.modifyShopifyStore(shopifyStore + .setClientId(123) + .setClientMoniker("hello") + .setModifyTime(new Date()) + .setModifier("geek-test-shop.myshopify.com")); + } + } \ No newline at end of file From ea93441b537a14a9444657a86412eff365daa946 Mon Sep 17 00:00:00 2001 From: Todking Date: Thu, 23 Dec 2021 17:08:04 +0800 Subject: [PATCH 03/12] =?UTF-8?q?add=20shopify=E7=9A=84=E5=95=86=E6=88=B7?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/static/shopify/auth/shopify.auth.js | 174 +++++++++++++++++- .../auth/templates/shopify_register.html | 150 ++++++++++++++- 2 files changed, 310 insertions(+), 14 deletions(-) diff --git a/src/main/ui/static/shopify/auth/shopify.auth.js b/src/main/ui/static/shopify/auth/shopify.auth.js index 2add776c0..ef69b3cee 100644 --- a/src/main/ui/static/shopify/auth/shopify.auth.js +++ b/src/main/ui/static/shopify/auth/shopify.auth.js @@ -1,6 +1,6 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { 'use strict'; - var module = angular.module('shopify.auth', ['ui.router', 'ui.bootstrap']); + var module = angular.module('shopify.auth', ['ui.router', 'ui.bootstrap', 'ngMessages']); module.config(['$stateProvider', function ($stateProvider) { $stateProvider.state('shopify', { url: '/shopify', @@ -21,45 +21,199 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { }); }]); - module.controller('ShopifyRootController',['$scope','$http','$state',function ($scope, $http, $state) { + module.controller('ShopifyRootController', ['$scope', '$http', '$state', function ($scope, $http, $state) { if ($state.is('shopify')) { $state.go('shopify.auth') } }]) - module.controller('ShopifyAuthController',['$scope','$http','$state', function ($scope, $http, $state) { + module.controller('ShopifyAuthController', ['$scope', '$http', '$state', function ($scope, $http, $state) { var that = $scope; that.store = { loginId: '' } that.validStoreLoginId = function () { - $http.get("/shopify/store/exist",{params: that.store}).then(function (res) { + $http.get("/shopify/store/exist", {params: that.store}).then(function (res) { if (res.data) { $state.go('shopify.login', {userId: that.store.loginId}); - }else { + } else { $state.go('shopify.register', {userId: that.store.loginId}); } }) } }]); - module.controller('ShopifyLoginController',['$scope','$http','$state', function ($scope, $http, $state) { - var that = $scope; + module.controller('ShopifyLoginController', ['$scope', '$http', '$state', function ($scope, $http, $state) { + var that = $scope; that.model = { shop: '', loginId: '', password: '' } that.activeShopifyMerchant = function () { - $http.post("/shopify/auth/permission",that.model).then(function (res) { - console.log("permissionUrl",res.data.url) + $http.post("/shopify/auth/permission", that.model).then(function (res) { + console.log("permissionUrl", res.data.url) location.href = res.data.url }) } }]); - module.controller('ShopifyRegisterController',['$scope','$http','$state', function ($scope, $http, $state) { + module.controller('ShopifyRegisterController', ['$scope', '$http', '$state', function ($scope, $http, $state) { + var stateMap = [ + { + "label": "ACT", + "value": "ACT" + }, + { + "label": "NSW", + "value": "NSW" + }, + { + "label": "NT", + "value": "NT" + }, + { + "label": "QLD", + "value": "QLD" + }, + { + "label": "SA", + "value": "SA" + }, + { + "label": "TAS", + "value": "TAS" + }, + { + "label": "VIC", + "value": "VIC" + }, + { + "label": "WA", + "value": "WA" + } + ]; + var industryMap = [ + { + "label": "Shoes&Garments", + "value": "343" + }, + { + "label": "Comprehensive mall", + "value": "484" + }, + { + "label": "Food", + "value": "485" + }, + { + "label": "Cosmetics", + "value": "486" + }, + { + "label": "Maternal and infant", + "value": "487" + }, + { + "label": "Digital appliance", + "value": "488" + }, + { + "label": "Logistics", + "value": "489" + }, + { + "label": "Education Industry", + "value": "490" + }, + { + "label": "Hotel Industry", + "value": "491" + }, + { + "label": "Stationery/office supplies", + "value": "492" + }, + { + "label": "Air Ticket", + "value": "493" + }, + { + "label": "Other trade industry", + "value": "494" + }, { + "label": "Overseas Education", + "value": "528" + }, + { + "label": "Travel ticket", + "value": "529" + }, + { + "label": "Car rental", + "value": "530" + }, + { + "label": "International Conference", + "value": "531" + }, + { + "label": "Software", + "value": "532" + }, + { + "label": "Medical Service", + "value": "533" + } + ]; + $scope.states = angular.copy(stateMap); + $scope.industries = angular.copy(industryMap); + $scope.partner = {}; + $scope.saveForm = function (form) { + if (form.$invalid) { + angular.forEach(form, function (item, key) { + if (key.indexOf('$') < 0) { + item.$dirty = true; + } + }); + return; + } + if ($scope.partner.password != $scope.partner.password_again) { + $scope.resError = 'Inconsistent passwords'; + return; + } + $('#login-btn').attr('disabled', true); + const paymentMerchant = { + companyName: $scope.partner.companyName, + address: $scope.partner.address, + suburb: $scope.partner.suburb, + postcode: $scope.partner.postcode, + state: $scope.partner.state, + country: $scope.partner.country, + contactPerson: $scope.partner.contactPerson, + contactPhone: $scope.partner.contactPhone, + contactEmail: $scope.partner.contactEmail + } + const PaymentAccountCommand = { + loginId: $scope.partner.loginId, + password: $scope.partner.password + } + const param = { + paymentMerchant, + PaymentAccountCommand, + shopifyShop: $scope.partner.shopifyShop + } + console.log("参数:", param) + $http.post('shopify/store/register', param).then(function (resp) { + // alert("Registered merchant application has been submitted successfully"); + // location.href = 'partner_register_success.html'; + }, function (resp) { + alert(resp.data.message); + $scope.resError = resp.data.message; + $('#login-btn').attr('disabled', false); + }); + }; }]); return module; diff --git a/src/main/ui/static/shopify/auth/templates/shopify_register.html b/src/main/ui/static/shopify/auth/templates/shopify_register.html index 29541b3ca..1c86c1811 100644 --- a/src/main/ui/static/shopify/auth/templates/shopify_register.html +++ b/src/main/ui/static/shopify/auth/templates/shopify_register.html @@ -3,9 +3,13 @@ Title - + + + + + - -
授权成功!
+ + +
+
+
+ +
+
+
+ +
+
+
+
+

+ This authorization is successful! +

+
+
+
+
+ +
+
+ ©2015-2021 RoyalPay. +
+
\ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html b/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html index 959a46302..4cb2d20fa 100644 --- a/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html +++ b/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html @@ -3,12 +3,117 @@ Title + + +
+
+
+ +
+
+
-
-

auth back

+
+
+
+
+

+ This authorization is successful! +

+
+
+
+
+
+ ©2015-2021 RoyalPay. +
+
\ No newline at end of file From 7c190d0c34d243772887206b64673d4da75faf7a Mon Sep 17 00:00:00 2001 From: Todking Date: Tue, 11 Jan 2022 16:46:50 +0800 Subject: [PATCH 08/12] =?UTF-8?q?fix=20=E5=AF=BC=E5=87=BA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E5=AD=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/Impl/ApsNoticeClientsServiceImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/apsKYC/domain/service/Impl/ApsNoticeClientsServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/apsKYC/domain/service/Impl/ApsNoticeClientsServiceImpl.java index 4ea63c839..6c922510c 100644 --- a/src/main/java/au/com/royalpay/payment/manage/apsKYC/domain/service/Impl/ApsNoticeClientsServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/apsKYC/domain/service/Impl/ApsNoticeClientsServiceImpl.java @@ -87,10 +87,13 @@ public class ApsNoticeClientsServiceImpl implements ApsNoticeClientsService { try { ApsNotice apsNotice = apsNoticeMapper.getApsNoticesById(id); + + String fileName = apsNotice.getTitle() + "(" + df.format(new Date()) + ").xlsx"; + fileName = new String(fileName.getBytes("gbk"), "iso8859-1"); os = response.getOutputStream(); response.reset(); - response.setHeader("Content-disposition", "attachment; filename = " + URLEncoder.encode(fileName, "UTF-8")); + response.setHeader("Content-disposition", "attachment; filename = " + fileName); response.setContentType("application/octet-streem"); //创建表格工作空间 From 0d4f9a848f89b8f4be4b23d68338bff38d0a7fbc Mon Sep 17 00:00:00 2001 From: ycfxx Date: Wed, 12 Jan 2022 10:00:43 +0800 Subject: [PATCH 09/12] upgrade complete shopify OAuth --- src/main/resources/application.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6920778d7..5d2a85f93 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -177,8 +177,8 @@ logging: shopify: auth: - apiKey: 3bef8dabafd9db8c50f46ce73429f2ff - apiSecretKey: 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 + apiKey: 99e631dd0faa1076ceffae36cf91a93b + apiSecretKey: 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 scope: write_orders,read_customers,write_payment_gateways,write_payment_sessions From 480bc50442238900885e2b21ac7f44a3673646a9 Mon Sep 17 00:00:00 2001 From: ycfxx Date: Wed, 12 Jan 2022 16:39:00 +0800 Subject: [PATCH 10/12] upgrade shopify OAuth processing --- pom.xml | 5 ++ .../ShopifyMerchantAuthApplication.java | 27 ++++++++++- .../domain/entity/ShopifyAccessToken.java | 6 +++ .../graphqlclient/GraphqlRequestBody.java | 15 ++++++ .../PaymentsAppConfigureClient.java | 48 +++++++++++++++++++ .../PaymentsAppConfigureRequestBody.java | 16 +++++++ .../support/GraphqlSchemaReaderUtil.java | 11 +++++ src/main/resources/application.yml | 1 + .../graphql/paymentsAppConfigure.graphql | 8 ++++ .../templates/shopify/auth_back.html | 9 ++++ .../ui/static/shopify/auth/shopify.auth.js | 4 ++ .../shopify/auth/templates/shopify_auth.html | 13 +++-- .../PaymentsAppConfigureClientTest.java | 34 +++++++++++++ 13 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/GraphqlRequestBody.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClient.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureRequestBody.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/shopify/support/GraphqlSchemaReaderUtil.java create mode 100644 src/main/resources/graphql/paymentsAppConfigure.graphql create mode 100644 src/test/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClientTest.java diff --git a/pom.xml b/pom.xml index d692c8bf6..8682c5ddc 100644 --- a/pom.xml +++ b/pom.xml @@ -231,6 +231,11 @@ 0.1.55 + + org.springframework.boot + spring-boot-starter-webflux + + diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java index 08707668a..2731087dd 100644 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java @@ -2,6 +2,7 @@ package au.com.royalpay.payment.manage.shopify.auth.domain.application; import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyAccessToken; import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyPermissionURL; +import au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient.PaymentsAppConfigureClient; import au.com.royalpay.payment.manage.shopify.auth.domain.service.ShopifyAuthService; import au.com.royalpay.payment.manage.shopify.auth.web.command.ShopifyPermissionRequest; import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore; @@ -13,14 +14,26 @@ import au.com.royalpay.payment.manage.shopify.store.domain.service.ShopifyStoreS import au.com.royalpay.payment.manage.signin.beans.LoginInfo; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; import au.com.royalpay.payment.tools.exceptions.BadRequestException; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; +import java.io.IOException; import java.util.Date; +@Slf4j @Component public class ShopifyMerchantAuthApplication { + @Value("${shopify.version:2021-10}") + private String apiVersion; + + @Value("${shopify.auth.apiKey}") + private String apiKey; + + private static final String PAYMENT_SETTING_URL = "https://%s/services/payments_partners/gateways/%s/settings"; + @Autowired private ShopifyAuthService shopifyAuthService; @@ -36,6 +49,9 @@ public class ShopifyMerchantAuthApplication { @Autowired private MerchantService merchantService; + @Autowired + private PaymentsAppConfigureClient paymentsAppConfigureClient; + /** * 获取shopify店铺授权URL * @@ -81,6 +97,15 @@ public class ShopifyMerchantAuthApplication { throw new BadRequestException("Get access token error"); } shopifyStoreService.modifyShopifyStore(shopifyStore.setAccessToken(accessToken.getAccess_token()).setScope(accessToken.getScope())); - return accessToken; + + try { + paymentsAppConfigureClient.paymentsAppConfigure(shop, true, apiVersion); + } catch (IOException e) { + log.error(String.format("Shopify store [%s] payment app setting error: %s", shop, e.getMessage())); + throw new BadRequestException("Payment app setting error"); + } + + String redirectUrl = String.format(PAYMENT_SETTING_URL, shop, apiKey); + return accessToken.setRedirectUrl(redirectUrl); } } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java index a28858350..3e5f7e25d 100644 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java @@ -1,11 +1,17 @@ package au.com.royalpay.payment.manage.shopify.auth.domain.entity; import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; @Data +@Accessors(chain = true) +@NoArgsConstructor public class ShopifyAccessToken { private String access_token; private String scope; + + private String redirectUrl; } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/GraphqlRequestBody.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/GraphqlRequestBody.java new file mode 100644 index 000000000..b96930786 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/GraphqlRequestBody.java @@ -0,0 +1,15 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class GraphqlRequestBody { + private String query; + private Object variables; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClient.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClient.java new file mode 100644 index 000000000..943481c20 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClient.java @@ -0,0 +1,48 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient; + +import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore; +import au.com.royalpay.payment.manage.shopify.store.domain.service.ShopifyStoreService; +import au.com.royalpay.payment.manage.shopify.support.GraphqlSchemaReaderUtil; +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; + +import java.io.IOException; + +@Slf4j +@Component +public class PaymentsAppConfigureClient { + + private static final String url = "https://%s/payments_apps/api/%s/graphql.json"; + + @Autowired + private ShopifyStoreService shopifyStoreService; + + public void paymentsAppConfigure(String shopDomain, Boolean ready, String apiVersion) throws IOException { + + WebClient webClient = WebClient.builder().build(); + + GraphqlRequestBody graphQLRequestBody = new GraphqlRequestBody(); + + final String query = GraphqlSchemaReaderUtil.getSchemaFromFileName("paymentsAppConfigure"); + + graphQLRequestBody.setQuery(query); + PaymentsAppConfigureRequestBody requestBody = new PaymentsAppConfigureRequestBody(shopDomain, ready); + graphQLRequestBody.setVariables(requestBody); + + ShopifyStore shopifyStore = shopifyStoreService.getByShopifyShop(shopDomain); + JSONObject result = webClient + .post() + .uri(String.format(url, shopDomain, apiVersion)) + .header("X-Shopify-Access-Token", shopifyStore.getAccessToken()) + .bodyValue(graphQLRequestBody) + .retrieve() + .bodyToMono(JSONObject.class) + .block(); + + log.info(String.format("retrieve: [%s]", result.toString())); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureRequestBody.java b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureRequestBody.java new file mode 100644 index 000000000..a9ce7c90d --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureRequestBody.java @@ -0,0 +1,16 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient; + +import lombok.Data; + +@Data +public class PaymentsAppConfigureRequestBody { + + private String externalHandle; + + private boolean ready; + + public PaymentsAppConfigureRequestBody(String shopDomain, Boolean ready) { + this.externalHandle = shopDomain; + this.ready = ready; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/support/GraphqlSchemaReaderUtil.java b/src/main/java/au/com/royalpay/payment/manage/shopify/support/GraphqlSchemaReaderUtil.java new file mode 100644 index 000000000..6fdfe7c21 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/support/GraphqlSchemaReaderUtil.java @@ -0,0 +1,11 @@ +package au.com.royalpay.payment.manage.shopify.support; + +import java.io.IOException; + +public class GraphqlSchemaReaderUtil { + + public static String getSchemaFromFileName(final String filename) throws IOException { + return new String( + GraphqlSchemaReaderUtil.class.getClassLoader().getResourceAsStream("graphql/" + filename + ".graphql").readAllBytes()); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5d2a85f93..056979324 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -176,6 +176,7 @@ logging: payment: debug shopify: + apiVersion: 2022-01 auth: apiKey: 99e631dd0faa1076ceffae36cf91a93b apiSecretKey: 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 diff --git a/src/main/resources/graphql/paymentsAppConfigure.graphql b/src/main/resources/graphql/paymentsAppConfigure.graphql new file mode 100644 index 000000000..e6e0d32dc --- /dev/null +++ b/src/main/resources/graphql/paymentsAppConfigure.graphql @@ -0,0 +1,8 @@ +mutation PaymentsAppConfigure($externalHandle: String, $ready: Boolean!) { + paymentsAppConfigure(externalHandle: $externalHandle, ready: $ready) { + userErrors{ + field + message + } + } +} \ No newline at end of file diff --git a/src/main/resources/templates/shopify/auth_back.html b/src/main/resources/templates/shopify/auth_back.html index 5df9ad276..afe68c072 100644 --- a/src/main/resources/templates/shopify/auth_back.html +++ b/src/main/resources/templates/shopify/auth_back.html @@ -66,5 +66,14 @@ ©2015-2021 RoyalPay.
+ + + \ No newline at end of file diff --git a/src/main/ui/static/shopify/auth/shopify.auth.js b/src/main/ui/static/shopify/auth/shopify.auth.js index c9c577453..d3f97904a 100644 --- a/src/main/ui/static/shopify/auth/shopify.auth.js +++ b/src/main/ui/static/shopify/auth/shopify.auth.js @@ -48,6 +48,10 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { that.authDisable = false }) } + + that.registerMerchant = function () { + $state.go('shopify.register'); + } }]); module.controller('ShopifyLoginController', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) { diff --git a/src/main/ui/static/shopify/auth/templates/shopify_auth.html b/src/main/ui/static/shopify/auth/templates/shopify_auth.html index 53236e748..2573ea842 100644 --- a/src/main/ui/static/shopify/auth/templates/shopify_auth.html +++ b/src/main/ui/static/shopify/auth/templates/shopify_auth.html @@ -5,7 +5,7 @@ Title