diff --git a/pom.xml b/pom.xml index 90ccade81..bc9200a4b 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 manage - 2.4.5 + 2.4.6 UTF-8 2.4.0 @@ -232,6 +232,11 @@ 0.1.55 + + org.springframework.boot + spring-boot-starter-webflux + + 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"); //创建表格工作空间 diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/MerchantAccountMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/MerchantAccountMapper.java new file mode 100644 index 000000000..414778280 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/MerchantAccountMapper.java @@ -0,0 +1,19 @@ +package au.com.royalpay.payment.manage.mappers.shopify; + +import au.com.royalpay.payment.manage.shopify.store.domain.entity.MerchantAccountRequest; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.SimpleMerchantAccount; +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_accounts", pkName = "account_id", keyGenerator = Jdbc3KeyGenerator.class) +public interface MerchantAccountMapper { + + @AutoSql(SqlType.INSERT) + void insert(MerchantAccountRequest accountRequest); + + @AutoSql(SqlType.SELECT) + SimpleMerchantAccount selectByUsername(@Param("username") String username); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/MerchantMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/MerchantMapper.java new file mode 100644 index 000000000..071d6b16f --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/MerchantMapper.java @@ -0,0 +1,24 @@ +package au.com.royalpay.payment.manage.mappers.shopify; + +import au.com.royalpay.payment.manage.shopify.store.domain.entity.MerchantRequest; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.SimpleMerchant; +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) + SimpleMerchant selectByClientId(@Param("client_id") Integer clientId); + + @AutoSql(SqlType.SELECT) + SimpleMerchant selectByMoniker(@Param("client_moniker") String clientMoniker); + + @AutoSql(SqlType.INSERT) + void insert(MerchantRequest merchantRequest); + + +} 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..985029eee --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/shopify/ShopifyStoreMapper.java @@ -0,0 +1,21 @@ +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); + + @AutoSql(SqlType.UPDATE) + void update(ShopifyStore shopifyStore); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index 2dcb969b5..01f19c7d3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -400,7 +400,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid } @Override - @Cacheable(value = ":app_client_info_moniker:", key = "#clientMoniker") + @Cacheable(value = ":app_client_info_moniker:", key = "#clientMoniker",unless="#result == null") public JSONObject getClientInfoByMoniker(String clientMoniker) { return clientMapper.findClientByMonikerAll(clientMoniker); } @@ -622,7 +622,11 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid client.put("has_children", !children.isEmpty()); } assert client != null; - client.putAll(clientConfigService.find(clientId)); + + JSONObject clientConfig = clientConfigService.find(clientId); + if(clientConfig !=null) { + client.putAll(clientConfig); + } return client; } @@ -6826,7 +6830,9 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid partner.put("lessComplianceFiles", signInAccountService.checkAuthFileStatus(partner.getJSONObject("client")).getBoolean("client_less_file")); } JSONObject clientConfig = clientConfigMapper.find(client.getIntValue("client_id")); - partner.put("geek_shop_status", clientConfig.getBooleanValue("geek_shop_status")); + if(clientConfig !=null) { + partner.put("geek_shop_status", clientConfig.getBooleanValue("geek_shop_status")); + } return partner; } 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..2731087dd --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/application/ShopifyMerchantAuthApplication.java @@ -0,0 +1,111 @@ +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; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.SimpleMerchant; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.SimpleMerchantAccount; +import au.com.royalpay.payment.manage.shopify.store.domain.service.MerchantAccountService; +import au.com.royalpay.payment.manage.shopify.store.domain.service.MerchantService; +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.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; + + @Autowired + private ShopifyStoreService shopifyStoreService; + + @Autowired + private SignInStatusManager signInStatusManager; + + @Autowired + private MerchantAccountService merchantAccountService; + + @Autowired + private MerchantService merchantService; + + @Autowired + private PaymentsAppConfigureClient paymentsAppConfigureClient; + + /** + * 获取shopify店铺授权URL + * + * @param request 店铺信息 + * @return + */ + public ShopifyPermissionURL shopifyPermission(ShopifyPermissionRequest request) { + LoginInfo loginInfo = new LoginInfo(); + loginInfo.setLoginId(request.getLoginId()); + loginInfo.setPassword(request.getPassword()); + + signInStatusManager.partnerSignIn(loginInfo); + SimpleMerchantAccount simpleMerchantAccount = merchantAccountService.getByUsername(request.getLoginId()); + + SimpleMerchant simpleMerchant = merchantService.getByClientId(simpleMerchantAccount.getClientId()); + + ShopifyStore shopifyShop = shopifyStoreService.getByShopifyShop(request.getShop()); + if (shopifyShop == null) { + shopifyStoreService.createShopifyStore(ShopifyStore.instanceOf(simpleMerchantAccount, simpleMerchant, request.getShop())); + return shopifyAuthService.shopifyPermission(request); + } + + shopifyStoreService.modifyShopifyStore(shopifyShop + .setClientId(simpleMerchantAccount.getClientId()) + .setClientMoniker(simpleMerchant.getClientMoniker()) + .setModifyTime(new Date()) + .setModifier(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); + ShopifyStore shopifyStore = shopifyStoreService.getByShopifyShop(shop); + if (shopifyStore == null) { + throw new BadRequestException("Get access token error"); + } + shopifyStoreService.modifyShopifyStore(shopifyStore.setAccessToken(accessToken.getAccess_token()).setScope(accessToken.getScope())); + + 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 new file mode 100644 index 000000000..3e5f7e25d --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/domain/entity/ShopifyAccessToken.java @@ -0,0 +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/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/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/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..aaeb585a2 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/auth/web/command/ShopifyPermissionRequest.java @@ -0,0 +1,33 @@ +package au.com.royalpay.payment.manage.shopify.auth.web.command; + +import au.com.royalpay.payment.manage.shopify.store.web.command.CreateShopifyMerchantCommand; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +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; + + public static ShopifyPermissionRequest instanceOf(CreateShopifyMerchantCommand command) { + return ShopifyPermissionRequest.builder() + .loginId(command.getPaymentAccount().getLoginId()) + .password(command.getPaymentAccount().getPassword()) + .shop(command.getShopifyShop()) + .build(); + } +} 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/application/ShopifyStoreApplication.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/application/ShopifyStoreApplication.java new file mode 100644 index 000000000..0b4efc35b --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/application/ShopifyStoreApplication.java @@ -0,0 +1,59 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.application; + +import au.com.royalpay.payment.manage.shopify.auth.domain.application.ShopifyMerchantAuthApplication; +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.manage.shopify.store.domain.context.MerchantCreateContext; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.MerchantAccountRequest; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.SimpleMerchant; +import au.com.royalpay.payment.manage.shopify.store.domain.service.MerchantAccountService; +import au.com.royalpay.payment.manage.shopify.store.domain.service.MerchantService; +import au.com.royalpay.payment.manage.shopify.store.web.command.CreateShopifyMerchantCommand; +import au.com.royalpay.payment.manage.shopify.support.PlatformMerchantProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class ShopifyStoreApplication { + + @Autowired + private MerchantService merchantservice; + + @Autowired + private MerchantAccountService merchantAccountService; + + @Autowired + private PlatformMerchantProvider platformMerchantProvider; + + @Autowired + private ShopifyMerchantAuthApplication shopifyMerchantAuthApplication; + + /** + * 检查partnerCode的商户是否存在 + * + * @param partnerCode 商户用户标识 + * @return + */ + public Boolean existMerchant(String partnerCode) { + return merchantservice.existMerchant(partnerCode); + } + + /** + * shopify店铺报备、获取shopify店铺授权 + * + * @param command 报备信息 + * @return 授权链接 + */ + @Transactional + public ShopifyPermissionURL register(CreateShopifyMerchantCommand command) { + + MerchantCreateContext merchantCreateContext = new MerchantCreateContext(platformMerchantProvider, command); + SimpleMerchant simpleMerchant = merchantservice.createMerchant(merchantCreateContext); + + MerchantAccountRequest accountRequest = MerchantAccountRequest.instanceOf(command, simpleMerchant); + merchantAccountService.createAccount(accountRequest); + + return shopifyMerchantAuthApplication.shopifyPermission(ShopifyPermissionRequest.instanceOf(command)); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/context/MerchantCreateContext.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/context/MerchantCreateContext.java new file mode 100644 index 000000000..03077d564 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/context/MerchantCreateContext.java @@ -0,0 +1,53 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.context; + +import au.com.royalpay.payment.manage.shopify.store.domain.entity.MerchantRequest; +import au.com.royalpay.payment.manage.shopify.store.web.command.PaymentAccountCommand; +import au.com.royalpay.payment.manage.shopify.support.PlatformMerchantProvider; +import au.com.royalpay.payment.manage.shopify.store.web.command.CreateShopifyMerchantCommand; +import au.com.royalpay.payment.manage.shopify.store.web.command.PaymentMerchantCommand; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; + +import java.util.Date; + +public class MerchantCreateContext { + + private PlatformMerchantProvider platformMerchantProvider; + + private CreateShopifyMerchantCommand command; + + public MerchantCreateContext(PlatformMerchantProvider platformMerchantProvider, CreateShopifyMerchantCommand command) { + this.platformMerchantProvider = platformMerchantProvider; + this.command = command; + } + + public String contactPhone() { + return command.getPaymentMerchant().getContactPhone(); + } + + public MerchantRequest genRequest() { + PaymentAccountCommand paymentAccount = command.getPaymentAccount(); + if (!paymentAccount.getPassword().equals(paymentAccount.getConfirmPassword())) { + throw new BadRequestException("Inconsistent passwords"); + } + PaymentMerchantCommand paymentMerchant = command.getPaymentMerchant(); + return MerchantRequest.builder() + .clientMoniker(platformMerchantProvider.generateClientMoniker()) + .companyName(paymentMerchant.getCompanyName()) + .shortName(paymentMerchant.getCompanyName()) + .industry("331") + .address(paymentMerchant.getAddress()) + .suburb(paymentMerchant.getSuburb()) + .postcode(paymentMerchant.getPostcode()) + .state(paymentMerchant.getState()) + .country("AUS") + .contactPerson(paymentMerchant.getContactPerson()) + .companyPhone(paymentMerchant.getContactPhone()) + .contactPhone(paymentMerchant.getContactPhone()) + .contactEmail(paymentMerchant.getContactEmail()) + .creator("shopify store") + .createTime(new Date()) + .approveResult(1) + .approveTime(new Date()) + .build(); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/MerchantAccountRequest.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/MerchantAccountRequest.java new file mode 100644 index 000000000..af8a8e8b9 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/MerchantAccountRequest.java @@ -0,0 +1,58 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.entity; + +import au.com.royalpay.payment.manage.shopify.store.web.command.CreateShopifyMerchantCommand; +import au.com.royalpay.payment.manage.shopify.store.web.command.PaymentAccountCommand; +import au.com.royalpay.payment.manage.shopify.store.web.command.PaymentMerchantCommand; +import au.com.royalpay.payment.tools.utils.PasswordUtils; +import lombok.Builder; +import lombok.Data; + +import java.util.Date; +import java.util.UUID; + +@Data +@Builder +public class MerchantAccountRequest { + + private String accountId; + + private Integer clientId; + + private String username; + + private String passwordHash; + + private String salt; + + private String passwordAes; + + private String contactPhone; + + private String contactEmail; + + private String displayName; + + private String creator; + + private Date createTime; + + public static MerchantAccountRequest instanceOf(CreateShopifyMerchantCommand command, SimpleMerchant simpleMerchant) { + PaymentMerchantCommand paymentMerchant = command.getPaymentMerchant(); + PaymentAccountCommand paymentAccount = command.getPaymentAccount(); + String salt = PasswordUtils.newSalt(); + String hashPwd = PasswordUtils.hashPwd(paymentAccount.getPassword(), salt); + return MerchantAccountRequest.builder() + .accountId(UUID.randomUUID().toString()) + .clientId(simpleMerchant.getClientId()) + .username(paymentAccount.getLoginId()) + .salt(salt) + .passwordHash(hashPwd) + .passwordAes(PasswordUtils.encryptAESPwd(paymentAccount.getPassword())) + .contactPhone(paymentMerchant.getContactPhone()) + .contactEmail(paymentMerchant.getContactEmail()) + .displayName(paymentAccount.getLoginId()) + .creator("shopify store") + .createTime(new Date()) + .build(); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/MerchantRequest.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/MerchantRequest.java new file mode 100644 index 000000000..96703a394 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/MerchantRequest.java @@ -0,0 +1,48 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.entity; + +import lombok.Builder; +import lombok.Data; + +import java.util.Date; + +@Data +@Builder +public class MerchantRequest { + + private Integer clientId; + + private String clientMoniker; + + private String companyName; + + private String shortName; + + private String industry; + + private String address; + + private String suburb; + + private String postcode; + + private String state; + + private String country; + + private String contactPerson; + + private String companyPhone; + + private String contactPhone; + + private String contactEmail; + + private String creator; + + private Date createTime; + + private Integer approveResult; + + private Date approveTime; + +} 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..871e725e6 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyStore.java @@ -0,0 +1,49 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.util.Date; +import java.util.UUID; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +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; + + private String accessToken; + + private String scope; + + public static ShopifyStore instanceOf(SimpleMerchantAccount merchantAccount, SimpleMerchant simpleMerchant, String shop) { + return ShopifyStore.builder() + .id(UUID.randomUUID().toString()) + .clientId(merchantAccount.getClientId()) + .clientMoniker(simpleMerchant.getClientMoniker()) + .shopifyShop(shop) + .createTime(new Date()) + .creator("shopify store") + .modifyTime(new Date()).build(); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/SimpleMerchant.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/SimpleMerchant.java new file mode 100644 index 000000000..0e943d543 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/SimpleMerchant.java @@ -0,0 +1,13 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SimpleMerchant { + private Integer clientId; + private String clientMoniker; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/SimpleMerchantAccount.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/SimpleMerchantAccount.java new file mode 100644 index 000000000..a017a0876 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/SimpleMerchantAccount.java @@ -0,0 +1,15 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.entity; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SimpleMerchantAccount { + + private String username; + + private Integer clientId; +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantAccountService.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantAccountService.java new file mode 100644 index 000000000..d88fd5d3d --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantAccountService.java @@ -0,0 +1,22 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.service; + +import au.com.royalpay.payment.manage.mappers.shopify.MerchantAccountMapper; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.MerchantAccountRequest; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.SimpleMerchantAccount; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class MerchantAccountService { + + @Autowired + private MerchantAccountMapper merchantAccountMapper; + + public void createAccount(MerchantAccountRequest accountRequest) { + merchantAccountMapper.insert(accountRequest); + } + + public SimpleMerchantAccount getByUsername(String username) { + return merchantAccountMapper.selectByUsername(username); + } +} 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..17f1c2e40 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/MerchantService.java @@ -0,0 +1,56 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.service; + +import au.com.royalpay.payment.manage.management.sysconfig.core.impls.PermissionPartnerManagerImpl; +import au.com.royalpay.payment.manage.mappers.shopify.MerchantMapper; +import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper; +import au.com.royalpay.payment.manage.merchants.core.ClientManager; +import au.com.royalpay.payment.manage.shopify.store.domain.context.MerchantCreateContext; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.MerchantRequest; +import au.com.royalpay.payment.manage.shopify.store.domain.entity.SimpleMerchant; +import au.com.royalpay.payment.tools.exceptions.ForbiddenException; +import com.alibaba.fastjson.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class MerchantService { + + @Autowired + private ClientAccountMapper clientAccountMapper; + + @Autowired + private MerchantMapper merchantMapper; + + @Autowired + private PermissionPartnerManagerImpl permissionPartnerManager; + + @Autowired + private ClientManager clientManager; + + public Boolean existMerchant(String partnerCode) { + JSONObject clientInfo = clientManager.getClientInfoByMoniker(partnerCode); + if (clientInfo == null) { + return false; + } + return true; + } + + public SimpleMerchant createMerchant(MerchantCreateContext merchantCreateContext) { + List account = clientAccountMapper.findByPhone(merchantCreateContext.contactPhone(), "+61"); + if (account != null && !account.isEmpty()) { + throw new ForbiddenException("The user name has been registered"); + } + + MerchantRequest merchantRequest = merchantCreateContext.genRequest(); + merchantMapper.insert(merchantRequest); + SimpleMerchant simpleMerchant = merchantMapper.selectByMoniker(merchantRequest.getClientMoniker()); + permissionPartnerManager.permissionClientModuleSave(simpleMerchant.getClientId(), simpleMerchant.getClientMoniker()); + return simpleMerchant; + } + + public SimpleMerchant getByClientId(Integer clientId) { + return merchantMapper.selectByClientId(clientId); + } +} 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..320f7dc6b --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreService.java @@ -0,0 +1,28 @@ +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); + + /** + * 变更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 new file mode 100644 index 000000000..15c68b7fc --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/impl/ShopifyStoreServiceImpl.java @@ -0,0 +1,29 @@ +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); + } + + @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 new file mode 100644 index 000000000..22bbb1bc4 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java @@ -0,0 +1,41 @@ +package au.com.royalpay.payment.manage.shopify.store.web; + +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyPermissionURL; +import au.com.royalpay.payment.manage.shopify.store.domain.application.ShopifyStoreApplication; +import au.com.royalpay.payment.manage.shopify.store.web.command.CreateShopifyMerchantCommand; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +/** + * shopify店铺资源 + */ +@RestController +@RequestMapping(value = "/shopify/store") +public class ShopifyStoreController { + + @Autowired + private ShopifyStoreApplication shopifyStoreApplication; + + /** + * 检查loginId的商户是否存在 + * + * @param partnerCode 商户标识 + */ + @GetMapping("/exist") + public Boolean validPaymentAppMerchant(@RequestParam("partnerCode") String partnerCode) { + return shopifyStoreApplication.existMerchant(partnerCode); + } + + /** + * shopify店铺报备 + * + * @param command 商户信息 + * @Return 店铺授权链接 + */ + @PostMapping("/register") + public ShopifyPermissionURL createMerchantWithShopify(@RequestBody @Valid CreateShopifyMerchantCommand command) { + return shopifyStoreApplication.register(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..c4311a72d --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/CreateShopifyMerchantCommand.java @@ -0,0 +1,18 @@ +package au.com.royalpay.payment.manage.shopify.store.web.command; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; + +@Data +@Accessors(chain = true) +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..1c729cebe --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentAccountCommand.java @@ -0,0 +1,20 @@ +package au.com.royalpay.payment.manage.shopify.store.web.command; + +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotBlank; + +@Data +@Accessors(chain = true) +public class PaymentAccountCommand { + + @NotBlank(message = "LoginId can not blank") + private String loginId; + + @NotBlank(message = "Password can not blank") + private String password; + + @NotBlank(message = "Confirm password can not blank") + private String confirmPassword; +} 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..5a1134914 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/command/PaymentMerchantCommand.java @@ -0,0 +1,27 @@ +package au.com.royalpay.payment.manage.shopify.store.web.command; + +import lombok.Data; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +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/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/java/au/com/royalpay/payment/manage/shopify/support/PlatformMerchantProvider.java b/src/main/java/au/com/royalpay/payment/manage/shopify/support/PlatformMerchantProvider.java new file mode 100644 index 000000000..c5b03a888 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/support/PlatformMerchantProvider.java @@ -0,0 +1,24 @@ +package au.com.royalpay.payment.manage.shopify.support; + +import au.com.royalpay.payment.manage.mappers.system.ClientMapper; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.RandomStringUtils; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +public class PlatformMerchantProvider { + + @Resource + private ClientMapper clientMapper; + + public String generateClientMoniker() { + String clientMoniker = RandomStringUtils.random(4, true, true).toUpperCase(); + JSONObject client = clientMapper.findClientByMoniker(clientMoniker); + if (client != null) { + generateClientMoniker(); + } + return clientMoniker; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/support/SpringContextUtil.java b/src/main/java/au/com/royalpay/payment/manage/shopify/support/SpringContextUtil.java new file mode 100644 index 000000000..a1ded1209 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/support/SpringContextUtil.java @@ -0,0 +1,37 @@ +package au.com.royalpay.payment.manage.shopify.support; + +import org.apache.poi.ss.formula.functions.T; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; + +public class SpringContextUtil { + + // Spring应用上下文环境 + private static ApplicationContext applicationContext; + + /** + * 实现ApplicationContextAware接口的回调方法,设置上下文环境 + */ + public static void setApplicationContext(ApplicationContext applicationContext)throws BeansException { + SpringContextUtil.applicationContext = applicationContext; + } + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + /** + * 根据beanId返回Spring中的实例 + * @Date 2019-08-07 17:36 + * @param + * @return + **/ + public static Object getBean(String beanId) throws BeansException { + return applicationContext.getBean(beanId); + } + + public static Object getBean(Class className) { + return applicationContext.getBean(className); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java index 97c8f62c9..da79a3709 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java @@ -173,7 +173,10 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati if (client == null) { throw new ForbiddenException("用户不存在或已禁用"); } - client.putAll(clientConfigService.find(client_id)); + JSONObject clientConfig = clientConfigService.find(client_id); + if (clientConfig !=null) { + client.putAll(clientConfig); + } client = clientInfoWithNoSecretInfo(client); client.put("client_less_file", false); if ((client.getIntValue("approve_result") == 2 || client.getIntValue("open_status") == 10 || client.getIntValue("approve_result") == 1 || client.getIntValue("open_status") == 5)) { 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 593ac4ebe..6f3e95999 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,7 +11,8 @@ spring: host: 127.0.0.1 port: 6379 thymeleaf: - mode: HTML + mode: LEGACYHTML5 + cache: false jetty: threadPool: maxThreads: 1000 @@ -175,5 +176,12 @@ logging: royalpay: payment: debug +shopify: + apiVersion: 2022-01 + auth: + apiKey: 99e631dd0faa1076ceffae36cf91a93b + apiSecretKey: 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 + scope: write_orders,read_customers,write_payment_gateways,write_payment_sessions + 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 new file mode 100644 index 000000000..afe68c072 --- /dev/null +++ b/src/main/resources/templates/shopify/auth_back.html @@ -0,0 +1,79 @@ + + + + + Auth + + + + + + + +
+
+
+ +
+
+
+ +
+
+
+
+

+ This authorization is successful! +

+
+
+
+
+ +
+
+ ©2015-2021 RoyalPay. +
+
+ + + + + \ 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/images/shopify/Alipay.png b/src/main/ui/static/images/shopify/Alipay.png new file mode 100644 index 000000000..cc9489f30 Binary files /dev/null and b/src/main/ui/static/images/shopify/Alipay.png differ diff --git a/src/main/ui/static/images/shopify/WeChat.png b/src/main/ui/static/images/shopify/WeChat.png new file mode 100644 index 000000000..c0abd5fc0 Binary files /dev/null and b/src/main/ui/static/images/shopify/WeChat.png differ diff --git a/src/main/ui/static/images/shopify/unionpay.png b/src/main/ui/static/images/shopify/unionpay.png new file mode 100644 index 000000000..f6bb83bbf Binary files /dev/null and b/src/main/ui/static/images/shopify/unionpay.png differ diff --git a/src/main/ui/static/images/shopify/unipay.png b/src/main/ui/static/images/shopify/unipay.png new file mode 100644 index 000000000..730ec1bee Binary files /dev/null and b/src/main/ui/static/images/shopify/unipay.png differ diff --git a/src/main/ui/static/images/shopify/wechat_pay.png b/src/main/ui/static/images/shopify/wechat_pay.png new file mode 100644 index 000000000..907eeb35f Binary files /dev/null and b/src/main/ui/static/images/shopify/wechat_pay.png differ 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..d3f97904a --- /dev/null +++ b/src/main/ui/static/shopify/auth/shopify.auth.js @@ -0,0 +1,239 @@ +define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { + 'use strict'; + var module = angular.module('shopify.auth', ['ui.router', 'ui.bootstrap', 'ngMessages']); + 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', + params: {'userId': null}, + controller: 'ShopifyLoginController' + }).state('shopify.register', { + url: '/register', + templateUrl: '/static/shopify/auth/templates/shopify_register.html', + params: {'userId': null}, + 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 = { + partnerCode: '' + } + that.authDisable = false + that.validStoreLoginId = function () { + that.authDisable = true + $http.get("/shopify/store/exist", {params: that.store}).then(function (res) { + if (res.data) { + $state.go('shopify.login', {partnerCode: that.store.partnerCode}); + } else { + $state.go('shopify.register', {partnerCode: that.store.partnerCode}); + } + },function (error) { + that.resError = error.data.message; + that.authDisable = false + }) + } + + that.registerMerchant = function () { + $state.go('shopify.register'); + } + }]); + + module.controller('ShopifyLoginController', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) { + var that = $scope; + that.model = { + shop: '', + partnerCode: $stateParams.partnerCode, + loginId: '', + password: '' + } + that.loginDisable = false + that.activeShopifyMerchant = function () { + that.loginDisable = true + $http.post("/shopify/auth/permission", that.model).then(function (res) { + console.log("permissionUrl", res.data.url) + location.href = res.data.url + },function (error) { + that.resError = error.data.message; + that.loginDisable = false + }) + } + }]); + + module.controller('ShopifyRegisterController', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) { + var that = $scope + 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" + } + ]; + that.states = angular.copy(stateMap); + that.industries = angular.copy(industryMap); + that.partner = { + partnerCode: $stateParams.partnerCode + }; + that.registerDisable = false + that.saveForm = function (form) { + if (form.$invalid) { + angular.forEach(form, function (item, key) { + if (key.indexOf('$') < 0) { + item.$dirty = true; + } + }); + return; + } + if (that.partner.password != that.partner.password_again) { + that.resError = 'Inconsistent passwords'; + return; + } + that.registerDisable = true + const paymentMerchant = { + companyName: that.partner.companyName, + address: that.partner.address, + suburb: that.partner.suburb, + postcode: that.partner.postcode, + state: that.partner.state, + country: that.partner.country, + contactPerson: that.partner.contactPerson, + contactPhone: that.partner.contactPhone, + contactEmail: that.partner.contactEmail + } + const paymentAccount = { + loginId: that.partner.loginId, + password: that.partner.password, + confirmPassword: that.partner.password_again + } + const param = { + paymentMerchant, + paymentAccount, + shopifyShop: that.partner.shopifyShop + } + $http.post('shopify/store/register', param).then(function (resp) { + location.href = resp.data.url + }, function (error) { + that.resError = error.data.message; + that.registerDisable = false + }); + }; + }]); + + 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..2573ea842 --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_auth.html @@ -0,0 +1,49 @@ + + + + + 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. +

+
+
+
+ +
+ +
+
+ + Not a RoyalPay merchant yet, please register + +
+
+
+
+ + \ 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..4cb2d20fa --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_auth_back.html @@ -0,0 +1,119 @@ + + + + + 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_login.html b/src/main/ui/static/shopify/auth/templates/shopify_login.html new file mode 100644 index 000000000..aa526c7a4 --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_login.html @@ -0,0 +1,53 @@ + + + + + Title + + + + +
+
+
+
+

+ Login +

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

Example: geek-test-shop.myshopify.com

+
+ +
+

{{resError}}

+
+
+
+
+
+
+ + \ 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..8fcb9bd8d --- /dev/null +++ b/src/main/ui/static/shopify/auth/templates/shopify_register.html @@ -0,0 +1,167 @@ + + + + + Title + + + +
+
+
+
+

+ Register +

+
+
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +

Example: geek-test-shop.myshopify.com

+
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+ +
+ +
+

Required Field

+
+
+
+ +
+

Required Field

+
+
+
+
+ +
+

{{resError}}

+
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/test/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClientTest.java b/src/test/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClientTest.java new file mode 100644 index 000000000..ca80ed4ce --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/shopify/auth/domain/graphqlclient/PaymentsAppConfigureClientTest.java @@ -0,0 +1,34 @@ +package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient; + +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.io.IOException; + +@Slf4j +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles({"dev", "alipay", "bestpay", "jd", "wechat", "rpay", "yeepay", "rppaysvc", "common", "alipayplusaps"}) +class PaymentsAppConfigureClientTest { + + @Autowired + private PaymentsAppConfigureClient paymentsAppConfigureClient; + + @Test + public void paymentsAppConfigureClientTest() { + + try { + paymentsAppConfigureClient.paymentsAppConfigure("geek-test-shop.myshopify.com", true, "2022-01"); + } catch (IOException e) { + log.error(String.format("PaymentsAppConfigure error: [%s]", e.getMessage())); + e.printStackTrace(); + } + + } + +} \ No newline at end of file diff --git a/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/application/ShopifyStoreApplicationTest.java b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/application/ShopifyStoreApplicationTest.java new file mode 100644 index 000000000..800559bf8 --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/application/ShopifyStoreApplicationTest.java @@ -0,0 +1,52 @@ +package au.com.royalpay.payment.manage.shopify.store.domain.application; + +import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyPermissionURL; +import au.com.royalpay.payment.manage.shopify.store.web.command.CreateShopifyMerchantCommand; +import au.com.royalpay.payment.manage.shopify.store.web.command.PaymentAccountCommand; +import au.com.royalpay.payment.manage.shopify.store.web.command.PaymentMerchantCommand; +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; + +@Slf4j +@RunWith(SpringRunner.class) +@SpringBootTest +@ActiveProfiles({"dev", "alipay", "bestpay", "jd", "wechat", "rpay", "yeepay", "rppaysvc", "common", "alipayplusaps"}) +class ShopifyStoreApplicationTest { + + @Autowired + private ShopifyStoreApplication shopifyStoreApplication; + + @Test + public void register() { + CreateShopifyMerchantCommand command = new CreateShopifyMerchantCommand(); + + PaymentMerchantCommand paymentMerchantCommand = new PaymentMerchantCommand(); + paymentMerchantCommand + .setAddress("address") + .setCompanyName("company name") + .setContactEmail("contact email") + .setContactPerson("contact person") + .setContactPhone("18014724505") + .setCountry("AUS") + .setPostcode("post code") + .setState("state") + .setSuburb("suburb") + .setContactEmail("ycfxx521@163.com"); + + PaymentAccountCommand accountCommand = new PaymentAccountCommand(); + accountCommand.setLoginId("alanfeng").setPassword("123456"); + + command.setPaymentMerchant(paymentMerchantCommand) + .setPaymentAccount(accountCommand) + .setShopifyShop("demo.myshopify.com"); + + ShopifyPermissionURL shopifyPermissionURL = shopifyStoreApplication.register(command); + log.warn(JSON.toJSONString(shopifyPermissionURL)); + } +} \ 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..da506bc80 --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/service/ShopifyStoreServiceTest.java @@ -0,0 +1,55 @@ +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)); + } + + @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 diff --git a/uidocker/conf.d/default.conf b/uidocker/conf.d/default.conf index bad9a1de7..9b7c46d4e 100644 --- a/uidocker/conf.d/default.conf +++ b/uidocker/conf.d/default.conf @@ -164,6 +164,22 @@ server { } + location /api/payment/v1.0/shopify { + proxy_pass http://rppaycenter; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_set_header Host $host; + + + proxy_read_timeout 300s; + + } + location /partner/cashiers/payment { proxy_pass http://rppaycenter;