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/system/MerchantMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/MerchantMapper.java deleted file mode 100644 index 96c847260..000000000 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/MerchantMapper.java +++ /dev/null @@ -1,15 +0,0 @@ -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/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index 371013012..93300643f 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 @@ -595,7 +595,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; } @@ -6799,7 +6803,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 index c8458cef9..08707668a 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 @@ -5,13 +5,15 @@ import au.com.royalpay.payment.manage.shopify.auth.domain.entity.ShopifyPermissi 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.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; -import com.alibaba.fastjson.JSONObject; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; import java.util.Date; @@ -19,11 +21,6 @@ import java.util.Date; @Component public class ShopifyMerchantAuthApplication { - private static final String redisPrefix = "shopify:accessToken:%s"; - - @Autowired - private StringRedisTemplate redisTemplate; - @Autowired private ShopifyAuthService shopifyAuthService; @@ -33,6 +30,12 @@ public class ShopifyMerchantAuthApplication { @Autowired private SignInStatusManager signInStatusManager; + @Autowired + private MerchantAccountService merchantAccountService; + + @Autowired + private MerchantService merchantService; + /** * 获取shopify店铺授权URL * @@ -43,19 +46,21 @@ public class ShopifyMerchantAuthApplication { LoginInfo loginInfo = new LoginInfo(); loginInfo.setLoginId(request.getLoginId()); loginInfo.setPassword(request.getPassword()); - String statusKey = signInStatusManager.partnerSignIn(loginInfo); - JSONObject client = signInStatusManager.getCurrentClient(statusKey); - ShopifyStore shopifyShop = shopifyStoreService.getByShopifyShop(request.getShop()); + 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(client, request.getShop())); + shopifyStoreService.createShopifyStore(ShopifyStore.instanceOf(simpleMerchantAccount, simpleMerchant, request.getShop())); return shopifyAuthService.shopifyPermission(request); } shopifyStoreService.modifyShopifyStore(shopifyShop - .setClientId(client.getInteger("client_id")) - .setClientMoniker(client.getString("client_moniker")) + .setClientId(simpleMerchantAccount.getClientId()) + .setClientMoniker(simpleMerchant.getClientMoniker()) .setModifyTime(new Date()) .setModifier(request.getShop())); @@ -71,7 +76,11 @@ public class ShopifyMerchantAuthApplication { */ public ShopifyAccessToken merchantOnboard(String shop, String code) { ShopifyAccessToken accessToken = shopifyAuthService.getAccessToken(shop, code); - redisTemplate.boundValueOps(String.format(redisPrefix, shop)).set(accessToken.getAccess_token()); + 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())); return accessToken; } } 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 index 494f17fca..aaeb585a2 100644 --- 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 @@ -1,10 +1,17 @@ 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") @@ -15,4 +22,12 @@ public class ShopifyPermissionRequest { @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/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..b4c52c85f --- /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; + + /** + * 检查loginId的商户是否存在 + * + * @param loginId 商户用户标识 + * @return + */ + public Boolean existMerchant(String loginId) { + return merchantservice.existMerchant(loginId); + } + + /** + * 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 index 4ef5252b4..871e725e6 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 @@ -1,6 +1,5 @@ package au.com.royalpay.payment.manage.shopify.store.domain.entity; -import com.alibaba.fastjson.JSONObject; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -33,16 +32,18 @@ public class ShopifyStore { private String modifier; - public static ShopifyStore instanceOf(JSONObject client, String shop) { - Integer clientId = client.getInteger("client_id"); - String clientMoniker = client.getString("client_moniker"); + private String accessToken; + + private String scope; + + public static ShopifyStore instanceOf(SimpleMerchantAccount merchantAccount, SimpleMerchant simpleMerchant, String shop) { return ShopifyStore.builder() .id(UUID.randomUUID().toString()) - .clientId(clientId) - .clientMoniker(clientMoniker) + .clientId(merchantAccount.getClientId()) + .clientMoniker(simpleMerchant.getClientMoniker()) .shopifyShop(shop) .createTime(new Date()) - .creator("shopify") + .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 index b7529fa43..5aa5e2461 100644 --- 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 @@ -1,16 +1,30 @@ 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.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; + public Boolean existMerchant(String loginId) { JSONObject account = clientAccountMapper.findByUsername(loginId); if (account == null) { @@ -18,4 +32,21 @@ public class MerchantService { } 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/PaymentAppMerchantService.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/PaymentAppMerchantService.java deleted file mode 100644 index 6ec1a0255..000000000 --- a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/service/PaymentAppMerchantService.java +++ /dev/null @@ -1,21 +0,0 @@ -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/web/ShopifyStoreController.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/web/ShopifyStoreController.java index 2c0bb9978..2d976ff18 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,6 +1,7 @@ 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.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.*; @@ -15,7 +16,7 @@ import javax.validation.Valid; public class ShopifyStoreController { @Autowired - private PaymentAppMerchantService paymentAppMerchantService; + private ShopifyStoreApplication shopifyStoreApplication; /** * 检查loginId的商户是否存在 @@ -24,15 +25,17 @@ public class ShopifyStoreController { */ @GetMapping("/exist") public Boolean validPaymentAppMerchant(@RequestParam("loginId") String loginId) { - return paymentAppMerchantService.existMerchant(loginId); + return shopifyStoreApplication.existMerchant(loginId); } /** * shopify店铺报备 * * @param command 商户信息 + * @Return 店铺授权链接 */ @PostMapping("/register") - public void createMerchantWithShopify(@RequestBody @Valid CreateShopifyMerchantCommand command) { + 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 index 9bb26b36b..c4311a72d 100644 --- 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 @@ -1,10 +1,12 @@ 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; 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 index 6bd8a5471..1c729cebe 100644 --- 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 @@ -1,11 +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 index e88200aae..5a1134914 100644 --- 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 @@ -1,8 +1,10 @@ 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; 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/ui/static/shopify/auth/shopify.auth.js b/src/main/ui/static/shopify/auth/shopify.auth.js index ef69b3cee..2f791e0c8 100644 --- a/src/main/ui/static/shopify/auth/shopify.auth.js +++ b/src/main/ui/static/shopify/auth/shopify.auth.js @@ -13,10 +13,12 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { }).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' }); }]); @@ -32,33 +34,44 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { that.store = { loginId: '' } + 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', {userId: that.store.loginId}); } else { $state.go('shopify.register', {userId: that.store.loginId}); } + },function (error) { + that.resError = error.data.message; + that.authDisable = false }) } }]); - module.controller('ShopifyLoginController', ['$scope', '$http', '$state', function ($scope, $http, $state) { + module.controller('ShopifyLoginController', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) { var that = $scope; that.model = { shop: '', - loginId: '', + loginId: $stateParams.userId, 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', '$state', function ($scope, $http, $state) { + module.controller('ShopifyRegisterController', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) { + var that = $scope var stateMap = [ { "label": "ACT", @@ -166,10 +179,13 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { "value": "533" } ]; - $scope.states = angular.copy(stateMap); - $scope.industries = angular.copy(industryMap); - $scope.partner = {}; - $scope.saveForm = function (form) { + that.states = angular.copy(stateMap); + that.industries = angular.copy(industryMap); + that.partner = { + loginId: $stateParams.userId + }; + that.registerDisable = false + that.saveForm = function (form) { if (form.$invalid) { angular.forEach(form, function (item, key) { if (key.indexOf('$') < 0) { @@ -178,40 +194,37 @@ define(['angular', 'uiRouter', 'uiBootstrap'], function (angular) { }); return; } - if ($scope.partner.password != $scope.partner.password_again) { - $scope.resError = 'Inconsistent passwords'; + if (that.partner.password != that.partner.password_again) { + that.resError = 'Inconsistent passwords'; return; } - $('#login-btn').attr('disabled', true); - + that.registerDisable = 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 + 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 PaymentAccountCommand = { - loginId: $scope.partner.loginId, - password: $scope.partner.password + const paymentAccount = { + loginId: that.partner.loginId, + password: that.partner.password, + confirmPassword: that.partner.password_again } const param = { paymentMerchant, - PaymentAccountCommand, - shopifyShop: $scope.partner.shopifyShop + paymentAccount, + shopifyShop: that.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); + location.href = resp.data.url + }, function (error) { + that.resError = error.data.message; + that.registerDisable = false }); }; }]); 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 e7fa3a881..638a11b0c 100644 --- a/src/main/ui/static/shopify/auth/templates/shopify_auth.html +++ b/src/main/ui/static/shopify/auth/templates/shopify_auth.html @@ -32,7 +32,7 @@
- + diff --git a/src/main/ui/static/shopify/auth/templates/shopify_login.html b/src/main/ui/static/shopify/auth/templates/shopify_login.html index 6a4022f00..aa526c7a4 100644 --- a/src/main/ui/static/shopify/auth/templates/shopify_login.html +++ b/src/main/ui/static/shopify/auth/templates/shopify_login.html @@ -32,11 +32,6 @@
-
@@ -44,7 +39,11 @@

Example: geek-test-shop.myshopify.com

- + +
+

{{resError}}

+
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 1c86c1811..8fcb9bd8d 100644 --- a/src/main/ui/static/shopify/auth/templates/shopify_register.html +++ b/src/main/ui/static/shopify/auth/templates/shopify_register.html @@ -3,11 +3,6 @@ Title - - - - -