add shopify register email

master
ycfxx 3 years ago
parent ba26e017bc
commit 5da0ab76b3

@ -6,16 +6,19 @@ import au.com.royalpay.payment.manage.shopify.auth.web.command.ShopifyPermission
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.event.ShopifyStoreCreatedEvent;
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.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ShopifyStoreApplication {
public class ShopifyStoreApplication implements ApplicationEventPublisherAware {
@Autowired
private MerchantService merchantservice;
@ -29,6 +32,13 @@ public class ShopifyStoreApplication {
@Autowired
private ShopifyMerchantAuthApplication shopifyMerchantAuthApplication;
private ApplicationEventPublisher eventPublisher;
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.eventPublisher = applicationEventPublisher;
}
/**
* partnerCode
*
@ -54,6 +64,12 @@ public class ShopifyStoreApplication {
MerchantAccountRequest accountRequest = MerchantAccountRequest.instanceOf(command, simpleMerchant);
merchantAccountService.createAccount(accountRequest);
return shopifyMerchantAuthApplication.shopifyPermission(ShopifyPermissionRequest.instanceOf(command));
ShopifyPermissionURL shopifyPermissionURL = shopifyMerchantAuthApplication.shopifyPermission(ShopifyPermissionRequest.instanceOf(command));
this.eventPublisher.publishEvent(new ShopifyStoreCreatedEvent(this,simpleMerchant,command,accountRequest));
return shopifyPermissionURL;
}
}

@ -0,0 +1,37 @@
package au.com.royalpay.payment.manage.shopify.store.domain.entity;
import lombok.Builder;
import lombok.Data;
@Data
@Builder
public class ShopifyMerchantApplyInfo {
private int clientId;
private String clientMoniker;
private String shopifyShop;
private String contactPerson;
private String contactPhone;
private String contactEmail;
private String displayName;
private String companyName;
private String address;
private String suburb;
private String postcode;
private String state;
private String country;
}

@ -1,12 +1,14 @@
package au.com.royalpay.payment.manage.shopify.store.domain.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SimpleMerchant {
private Integer clientId;
private String clientMoniker;

@ -0,0 +1,35 @@
package au.com.royalpay.payment.manage.shopify.store.domain.event;
import au.com.royalpay.payment.manage.shopify.store.domain.application.ShopifyStoreApplication;
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.web.command.CreateShopifyMerchantCommand;
import org.springframework.context.ApplicationEvent;
public class ShopifyStoreCreatedEvent extends ApplicationEvent {
private SimpleMerchant simpleMerchant;
private CreateShopifyMerchantCommand command;
private MerchantAccountRequest accountRequest;
public ShopifyStoreCreatedEvent(ShopifyStoreApplication source, SimpleMerchant simpleMerchant, CreateShopifyMerchantCommand command, MerchantAccountRequest accountRequest) {
super(source);
this.simpleMerchant = simpleMerchant;
this.command = command;
this.accountRequest = accountRequest;
}
public SimpleMerchant getSimpleMerchant() {
return simpleMerchant;
}
public CreateShopifyMerchantCommand getCommand() {
return command;
}
public MerchantAccountRequest getAccountRequest() {
return accountRequest;
}
}

@ -0,0 +1,63 @@
package au.com.royalpay.payment.manage.shopify.store.domain.listener;
import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyMerchantApplyInfo;
import au.com.royalpay.payment.manage.shopify.store.domain.event.ShopifyStoreCreatedEvent;
import au.com.royalpay.payment.manage.shopify.store.web.command.PaymentMerchantCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.URISyntaxException;
@Slf4j
@Component
public class ShopifyStoreCreatedListener {
@Resource
private MailService mailService;
@Resource
private SpringTemplateEngine thymeleaf;
private static final String consignee = "info@royalpay.com.au";
@Async
@EventListener
public void onShopifyStoreCreated(ShopifyStoreCreatedEvent event) {
PaymentMerchantCommand paymentMerchant = event.getCommand().getPaymentMerchant();
ShopifyMerchantApplyInfo applyInfo = ShopifyMerchantApplyInfo.builder()
.clientId(event.getSimpleMerchant().getClientId())
.clientMoniker(event.getSimpleMerchant().getClientMoniker())
.contactEmail(event.getAccountRequest().getContactEmail())
.contactPhone(event.getAccountRequest().getContactPhone())
.contactPerson(paymentMerchant.getContactPerson())
.address(paymentMerchant.getAddress())
.shopifyShop(event.getCommand().getShopifyShop())
.displayName(event.getAccountRequest().getDisplayName())
.companyName(paymentMerchant.getCompanyName())
.suburb(paymentMerchant.getSuburb())
.state(paymentMerchant.getState())
.country(paymentMerchant.getCountry())
.postcode(paymentMerchant.getPostcode())
.build();
Context ctx = new Context();
ctx.setVariable("applyInfo", applyInfo);
final String content = thymeleaf.process("mail/shopify_merchant_application.html", ctx);
try {
mailService.sendEmail("Shopify merchant application", consignee, "", content);
} catch (URISyntaxException e) {
log.error(e.getMessage());
e.printStackTrace();
} catch (IOException e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
}

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<div style="margin:0;">Registration application from Shopify store</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div style="margin:0;">Partner Code:<span th:text="${applyInfo.clientMoniker}"></span></div>
<div style="margin:0;">Company Name:<span th:text="${applyInfo.companyName}"></span></div>
<div style="margin:0;">Address:<span th:text="${applyInfo.address}"></span></div>
<div style="margin:0;">Suburb:<span th:text="${applyInfo.suburb}"></span></div>
<div style="margin:0;">State:<span th:text="${applyInfo.state}"></span></div>
<div style="margin:0;">Country:<span th:text="${applyInfo.country}"></span></div>
<div style="margin:0;">Contact Person:<span th:text="${applyInfo.contactPerson}"></span></div>
<div style="margin:0;">Contact Phone:<span th:text="${applyInfo.contactPhone}"></span></div>
<div style="margin:0;">Contact Email:<span th:text="${applyInfo.contactEmail}"></span></div>
<div style="margin:0;">Shopify Store Host:<span th:text="${applyInfo.shopifyShop}"></span></div>
</blockquote>
<div></div>
<div>Please deal with it in time</div>
<blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;">
<div style="margin:0;"><br/></div>
</blockquote>
<div style="margin:0;">&nbsp; &nbsp; &nbsp; &nbsp;</div>
</html>

@ -0,0 +1,51 @@
package au.com.royalpay.payment.manage.shopify.store.domain.listener;
import au.com.royalpay.payment.manage.shopify.store.domain.application.ShopifyStoreApplication;
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.event.ShopifyStoreCreatedEvent;
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 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 ShopifyStoreCreatedListenerTest {
@Autowired
private ShopifyStoreCreatedListener shopifyStoreCreatedListener;
@Test
public void shopifyStoreRegisterTest() {
SimpleMerchant simpleMerchant = SimpleMerchant.builder().clientId(00001).clientMoniker("test").build();
PaymentMerchantCommand paymentMerchantCommand = new PaymentMerchantCommand()
.setCompanyName("test company ltd")
.setAddress("test address")
.setSuburb("test suburb")
.setState("test state")
.setCountry("test country")
.setContactPerson("test contact person")
.setContactPhone("test contact phone")
.setContactEmail("test contact email");
PaymentAccountCommand paymentAccountCommand = new PaymentAccountCommand()
.setLoginId("test login id")
.setPassword("test password")
.setConfirmPassword("test confirm password");
CreateShopifyMerchantCommand command = new CreateShopifyMerchantCommand().setShopifyShop("test.myshop.com").setPaymentMerchant(paymentMerchantCommand).setPaymentAccount(paymentAccountCommand);
ShopifyStoreCreatedEvent event = new ShopifyStoreCreatedEvent(new ShopifyStoreApplication(), simpleMerchant, command, MerchantAccountRequest.instanceOf(command, simpleMerchant));
shopifyStoreCreatedListener.onShopifyStoreCreated(event);
}
}
Loading…
Cancel
Save