parent
0d4f9a848f
commit
480bc50442
@ -1,11 +1,17 @@
|
|||||||
package au.com.royalpay.payment.manage.shopify.auth.domain.entity;
|
package au.com.royalpay.payment.manage.shopify.auth.domain.entity;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@NoArgsConstructor
|
||||||
public class ShopifyAccessToken {
|
public class ShopifyAccessToken {
|
||||||
|
|
||||||
private String access_token;
|
private String access_token;
|
||||||
|
|
||||||
private String scope;
|
private String scope;
|
||||||
|
|
||||||
|
private String redirectUrl;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class GraphqlRequestBody {
|
||||||
|
private String query;
|
||||||
|
private Object variables;
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient;
|
||||||
|
|
||||||
|
import au.com.royalpay.payment.manage.shopify.store.domain.entity.ShopifyStore;
|
||||||
|
import au.com.royalpay.payment.manage.shopify.store.domain.service.ShopifyStoreService;
|
||||||
|
import au.com.royalpay.payment.manage.shopify.support.GraphqlSchemaReaderUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.reactive.function.client.WebClient;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class PaymentsAppConfigureClient {
|
||||||
|
|
||||||
|
private static final String url = "https://%s/payments_apps/api/%s/graphql.json";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopifyStoreService shopifyStoreService;
|
||||||
|
|
||||||
|
public void paymentsAppConfigure(String shopDomain, Boolean ready, String apiVersion) throws IOException {
|
||||||
|
|
||||||
|
WebClient webClient = WebClient.builder().build();
|
||||||
|
|
||||||
|
GraphqlRequestBody graphQLRequestBody = new GraphqlRequestBody();
|
||||||
|
|
||||||
|
final String query = GraphqlSchemaReaderUtil.getSchemaFromFileName("paymentsAppConfigure");
|
||||||
|
|
||||||
|
graphQLRequestBody.setQuery(query);
|
||||||
|
PaymentsAppConfigureRequestBody requestBody = new PaymentsAppConfigureRequestBody(shopDomain, ready);
|
||||||
|
graphQLRequestBody.setVariables(requestBody);
|
||||||
|
|
||||||
|
ShopifyStore shopifyStore = shopifyStoreService.getByShopifyShop(shopDomain);
|
||||||
|
JSONObject result = webClient
|
||||||
|
.post()
|
||||||
|
.uri(String.format(url, shopDomain, apiVersion))
|
||||||
|
.header("X-Shopify-Access-Token", shopifyStore.getAccessToken())
|
||||||
|
.bodyValue(graphQLRequestBody)
|
||||||
|
.retrieve()
|
||||||
|
.bodyToMono(JSONObject.class)
|
||||||
|
.block();
|
||||||
|
|
||||||
|
log.info(String.format("retrieve: [%s]", result.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PaymentsAppConfigureRequestBody {
|
||||||
|
|
||||||
|
private String externalHandle;
|
||||||
|
|
||||||
|
private boolean ready;
|
||||||
|
|
||||||
|
public PaymentsAppConfigureRequestBody(String shopDomain, Boolean ready) {
|
||||||
|
this.externalHandle = shopDomain;
|
||||||
|
this.ready = ready;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package au.com.royalpay.payment.manage.shopify.support;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class GraphqlSchemaReaderUtil {
|
||||||
|
|
||||||
|
public static String getSchemaFromFileName(final String filename) throws IOException {
|
||||||
|
return new String(
|
||||||
|
GraphqlSchemaReaderUtil.class.getClassLoader().getResourceAsStream("graphql/" + filename + ".graphql").readAllBytes());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
mutation PaymentsAppConfigure($externalHandle: String, $ready: Boolean!) {
|
||||||
|
paymentsAppConfigure(externalHandle: $externalHandle, ready: $ready) {
|
||||||
|
userErrors{
|
||||||
|
field
|
||||||
|
message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package au.com.royalpay.payment.manage.shopify.auth.domain.graphqlclient;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@ActiveProfiles({"dev", "alipay", "bestpay", "jd", "wechat", "rpay", "yeepay", "rppaysvc", "common", "alipayplusaps"})
|
||||||
|
class PaymentsAppConfigureClientTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PaymentsAppConfigureClient paymentsAppConfigureClient;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void paymentsAppConfigureClientTest() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
paymentsAppConfigureClient.paymentsAppConfigure("geek-test-shop.myshopify.com", true, "2022-01");
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(String.format("PaymentsAppConfigure error: [%s]", e.getMessage()));
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue