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);
|
|
||||||
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -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,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,11 +1,20 @@
|
|||||||
package au.com.royalpay.payment.manage.shopify.store.web.command;
|
package au.com.royalpay.payment.manage.shopify.store.web.command;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
public class PaymentAccountCommand {
|
public class PaymentAccountCommand {
|
||||||
|
|
||||||
|
@NotBlank(message = "LoginId can not blank")
|
||||||
private String loginId;
|
private String loginId;
|
||||||
|
|
||||||
|
@NotBlank(message = "Password can not blank")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
@NotBlank(message = "Confirm password can not blank")
|
||||||
|
private String confirmPassword;
|
||||||
}
|
}
|
||||||
|
@ -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,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…
Reference in new issue