parent
12de9f4856
commit
2f9635d4a0
@ -0,0 +1,34 @@
|
||||
package au.com.royalpay.payment.manage.shopify.auth.domain.manage;
|
||||
|
||||
import au.com.royalpay.payment.manage.mappers.shopify.ShopifyStoreMapper;
|
||||
import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore;
|
||||
import au.com.royalpay.shopify.config.ShopifyAuthProvider;
|
||||
import au.com.royalpay.shopify.entity.ShopifyAccessToken;
|
||||
import au.com.royalpay.shopify.service.ShopifyAuthService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ShopifyManageService {
|
||||
|
||||
private final ShopifyAuthProvider shopifyAuthProvider;
|
||||
private final ShopifyAuthService shopifyAuthService;
|
||||
private final ShopifyStoreMapper shopifyStoreMapper;
|
||||
|
||||
public ShopifyManageService(ShopifyAuthProvider shopifyAuthProvider, ShopifyAuthService shopifyAuthService, ShopifyStoreMapper shopifyStoreMapper) {
|
||||
this.shopifyAuthProvider = shopifyAuthProvider;
|
||||
this.shopifyAuthService = shopifyAuthService;
|
||||
this.shopifyStoreMapper = shopifyStoreMapper;
|
||||
}
|
||||
|
||||
public void rotateAccessToken(String newSecret, String refreshToken) {
|
||||
shopifyAuthProvider.addSecret(newSecret);
|
||||
shopifyStoreMapper.listAvailableStores().parallelStream().filter(store -> !store.getTokenSecret().equalsIgnoreCase(newSecret))
|
||||
.forEach(store -> rotateStoreAccessToken(store, refreshToken));
|
||||
shopifyAuthProvider.activateSecret(newSecret);
|
||||
}
|
||||
|
||||
public void rotateStoreAccessToken(ShopifyStore store, String refreshToken) {
|
||||
ShopifyAccessToken newToken = shopifyAuthService.rotateAccessToken(store.storeName(), refreshToken, store.getAccessToken());
|
||||
shopifyStoreMapper.update(ShopifyStore.builder().id(store.getId()).accessToken(newToken.getAccess_token()).tokenSecret(newToken.getSecret()).build());
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package au.com.royalpay.payment.manage.shopify.store.domain.entity;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ShopifyStoreTest {
|
||||
|
||||
@Test
|
||||
void storeName() {
|
||||
ShopifyStore store = ShopifyStore.builder()
|
||||
.shopifyShop("test-store-nicks-4.myshopify.com")
|
||||
.build();
|
||||
Assertions.assertEquals(store.storeName(), "test-store-nicks-4", "storename match");
|
||||
}
|
||||
}
|
Loading…
Reference in new issue