parent
ba26e017bc
commit
5da0ab76b3
@ -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;
|
||||
|
||||
|
||||
}
|
@ -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,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…
Reference in new issue