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 index 0b4efc35b..83cba5cd7 100644 --- 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 @@ -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; } + + } diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyMerchantApplyInfo.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyMerchantApplyInfo.java new file mode 100644 index 000000000..965202243 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/entity/ShopifyMerchantApplyInfo.java @@ -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; + + +} 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 index 0e943d543..8c6c4b101 100644 --- 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 @@ -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; diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/event/ShopifyStoreCreatedEvent.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/event/ShopifyStoreCreatedEvent.java new file mode 100644 index 000000000..e3d83a12e --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/event/ShopifyStoreCreatedEvent.java @@ -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; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/listener/ShopifyStoreCreatedListener.java b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/listener/ShopifyStoreCreatedListener.java new file mode 100644 index 000000000..2e978cbc0 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/shopify/store/domain/listener/ShopifyStoreCreatedListener.java @@ -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(); + } + } +} diff --git a/src/main/resources/templates/mail/shopify_merchant_application.html b/src/main/resources/templates/mail/shopify_merchant_application.html new file mode 100644 index 000000000..73e96627b --- /dev/null +++ b/src/main/resources/templates/mail/shopify_merchant_application.html @@ -0,0 +1,22 @@ + + +
Registration application from Shopify store:
+
+
Partner Code:
+
Company Name:
+
Address:
+
Suburb:
+
State:
+
Country:
+
Contact Person:
+
Contact Phone:
+
Contact Email:
+
Shopify Store Host:
+
+
+
Please deal with it in time!
+
+

+
+
       
+ \ No newline at end of file diff --git a/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/listener/ShopifyStoreCreatedListenerTest.java b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/listener/ShopifyStoreCreatedListenerTest.java new file mode 100644 index 000000000..268063fb6 --- /dev/null +++ b/src/test/java/au/com/royalpay/payment/manage/shopify/store/domain/listener/ShopifyStoreCreatedListenerTest.java @@ -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); + } +} \ No newline at end of file