add complete shopify OAuth

master
ycfxx 4 years ago
parent ea93441b53
commit 9de6d1e469

@ -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);
}

@ -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);
}

@ -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);
}

@ -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;
}

@ -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;
/**
* shopifyURL
*
@ -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;
}
}

@ -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();
}
}

@ -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);
}
/**
* shopifyshopify
*
* @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));
}
}

@ -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();
}
}

@ -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();
}
}

@ -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;
}

@ -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();
}
}

@ -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;
}

@ -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;
}

@ -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);
}
}

@ -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<JSONObject> 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);
}
}

@ -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);
}
}

@ -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);
}
}

@ -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;

@ -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;
}

@ -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;

@ -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;
}
}

@ -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;
}
/**
* beanIdSpring
* @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<T> className) {
return applicationContext.getBean(className);
}
}

@ -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)) {

@ -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
});
};
}]);

@ -32,7 +32,7 @@
<div class="form-group form-group-lg">
<input class="form-control input-lg" id="exampleInputEmail" placeholder="Login ID" ng-model="store.loginId">
</div>
<button class="btn btn-warning btn-lg btn-block" ng-click="validStoreLoginId()">Next</button>
<button class="btn btn-warning btn-lg btn-block" ng-disabled="authDisable" ng-click="validStoreLoginId()">Next</button>
</form>
</div>
</div>

@ -32,11 +32,6 @@
</div>
<div class="form-group form-group-lg">
<!-- <div class="input-group">
<span class="input-group-addon">
<i class="glyphicon glyphicon-eye-open"></i>
</span>
</div>-->
<input type="password" class="form-control" id="exampleInputPassword" placeholder="Password" ng-model="model.password">
</div>
@ -44,7 +39,11 @@
<input class="form-control input-lg" id="shopifyShop" placeholder="Shop" ng-model="model.shop">
<p class="help-block">Example: geek-test-shop.myshopify.com</p>
</div>
<button class="btn btn-warning btn-lg btn-block m-t-40" ng-click="activeShopifyMerchant()">Log In</button>
<button class="btn btn-warning btn-lg btn-block m-t-40" ng-disabled="loginDisable" ng-click="activeShopifyMerchant()">Log In</button>
<div>
<p ng-if="resError" style="padding: 6px 12px;font-size: 14px;"
class="small text-danger">{{resError}}</p>
</div>
</form>
</div>
</div>

@ -3,11 +3,6 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="../../../../static/lib/jquery/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="../../../../static/lib/angularjs/angular.min.js"></script>
<script type="text/javascript" src="../../../../static/lib/angularjs/angular-messages.js"></script>
<script type="text/javascript" src="../../../../static/lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../../../static/lib/blocs.min.js"></script>
<style>
.col-centered {
float: none;
@ -58,7 +53,6 @@
</div>
</div>
<div class="form-group has-feedback"
ng-class="{'has-error':partnerForm.shopifyShop.$invalid && partnerForm.shopifyShop.$dirty}">
<input type="text" class="form-control" ng-model="partner.shopifyShop" name="shopifyShop"
@ -155,8 +149,8 @@
</div>
<div class="row">
<div class="col-xs-12 margin-bottom">
<button type="button" id="login-btn" class="btn btn-success btn-block btn-flat"
ng-click="saveForm(partnerForm)">Submit
<button type="button" id="login-btn" class="btn btn-warning btn-block btn-flat btn-lg"
ng-disabled="registerDisable" ng-click="saveForm(partnerForm)">Submit
</button>
<div>
<p ng-if="resError" style="padding: 6px 12px;font-size: 14px;"

@ -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));
}
}
Loading…
Cancel
Save