I am able to create order using square(v2/locations/location_id/orders)api and getting order id. But I am not able to get this order details and also how I can see this created order on square dashboard? please help me.
I am using the below method for doing it:
public CreateOrderResponse createOrder(String locationId, CreateOrderRequest body) throws ApiException {
Object localVarPostBody = body;
// verify the required parameter 'locationId' is set
if (locationId == null) {
throw new ApiException(400, "Missing the required parameter 'locationId' when calling createOrder");
}
// verify the required parameter 'body' is set
if (body == null) {
throw new ApiException(400, "Missing the required parameter 'body' when calling createOrder");
}
// create path and map variables
String localVarPath = "/v2/locations/{location_id}/orders".replaceAll("\\{" + "location_id" + "\\}",
apiClient.escapeString(locationId.toString()));
// query params
List<Pair> localVarQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = { "application/json" };
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = { "application/json" };
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { "oauth2" };
GenericType<CreateOrderResponse> localVarReturnType = new GenericType<CreateOrderResponse>() {
};
CompleteResponse<CreateOrderResponse> completeResponse = (CompleteResponse<CreateOrderResponse>) apiClient
.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams,
localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames,
localVarReturnType);
return completeResponse.getData();
}
Thanks
The orders endpoint is only for creating itemized orders for e-commerce transactions. You won't see them anywhere until you charge them, and then you'll see the itemizations for the order in your dashboard with the transaction.
Related
I have 2 applications communicating via grps.
When I try to send a span context, I always get null in extracted.
Map<String, String> tracingMetadata = new HashMap<>();
tracingMetadata.put("trace-id", traceId);
tracingMetadata.put("span-id", spanId);
SpanContext extracted = tracer.extract(Format.Builtin.TEXT_MAP, new TextMapAdapter(tracingMetadata));
Therefore, I send it via metadata in ClientIntercaptor like that.
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
#Override
public void start(Listener<RespT> responseListener, Metadata headers) {
headers.put(Metadata.Key.of("trace-id", Metadata.ASCII_STRING_MARSHALLER), traceId);
headers.put(Metadata.Key.of("span-id", Metadata.ASCII_STRING_MARSHALLER), spanId);
...
When I try to create a context span from this data, it either talks about incompatible types, or context doesn't change. In pre and after equal context.
private void injectParentContext(Span span) {
final String traceId = HeadersServerInterceptor.getTraceIdHeader();
final String spanId = HeadersServerInterceptor.getSpanIdHeader();
final Map<String, String> contextValues = new HashMap<>();
contextValues.put("x-b3-trace-id", traceId);
contextValues.put("x-b3-spanid", spanId);
final SpanContext pre=span.context();
tracer.inject(span.context(), Format.Builtin.TEXT_MAP, new TextMapAdapter(contextValues));
final SpanContext after= span.context();
}
I tried different Format.Builtin and Adapter, nothing works.
What am I doing wrong?
I have Request by status = PENDING_PAYMENT,DONE, I want to split by comma with java spring to search
data by find to repository.
how can I resolved this?
#Override
public Map<String, Object> getAllOrderDetails(String status, String productName, String page, String limit) {
Map<String, Object> result = new HashMap<>();
String[] statusSplit = status.split(",");
OrderStatus os = OrderStatus.valueOf(status.toUpperCase());
List<Order> orders = orderRepo.findByStatus(os);
if(orders == null){
throw new NonexistentEntityException(ErrCode.ERR_UNKNOWN, "Order not listed");
}
List<OrderResult> order = new ArrayList<>();
// order = serviceDataList.getOrderDetails(o);
result.put("order", order);
return result;
}
This is the sql script that I have used to create the necessary classes :
CREATE CLASS ProductSummary;
CREATE PROPERTY ProductSummary.name STRING (NOTNULL, MANDATORY TRUE);
CREATE PROPERTY ProductSummary.modelNumber LONG (NOTNULL, MANDATORY TRUE);
ALTER CLASS ProductSummary STRICTMODE TRUE;
CREATE CLASS PricingSummary;
CREATE PROPERTY PricingSummary.price LONG (NOTNULL, MANDATORY TRUE);
CREATE PROPERTY PricingSummary.discount LONG (NOTNULL, MANDATORY TRUE);
ALTER CLASS PricingSummary STRICTMODE TRUE;
CREATE CLASS TotalSummary EXTENDS V;
CREATE PROPERTY TotalSummary.projectLink LINK Project (NOTNULL, MANDATORY TRUE);
CREATE PROPERTY TotalSummary.productSummaries EMBEDDEDLIST ProductSummary;
CREATE PROPERTY TotalSummary.pricingSummaries EMBEDDEDLIST PricingSummary;
ALTER CLASS TotalSummary STRICTMODE TRUE;
CREATE INDEX TotalSummary_projectLink_idx ON TotalSummary (projectLink) UNIQUE;
I am trying to insert some values into my TotalSummary class, where I also need to insert some values into the EmbeddedList for pricingSummaries and productSummaries.
public TotalSummary create(final TotalSummary totalSummary) {
final Long projectId = 1;
final StatementBuilder builder = new StatementBuilder();
final StringBuilder query = new StringBuilder();
final List<Map<?, ?>> productSummaries = totalSummary.getProductSummaries().stream()
.map(ProductSummary::toMap)
.collect(Collectors.toList());
final List<Map<?, ?>> pricingSummaries = totalSummary.getPricingSummaries().stream()
.map(PricingSummary::toMap)
.collect(Collectors.toList());
builder.addAttribute("projectLink = (SELECT FROM project WHERE id = ?)", projectId);
if ( ! productSummaries.isEmpty()) {
builder.addAttribute("productSummaries = ?", productSummaries);
}
if ( ! pricingSummaries.isEmpty()) {
builder.addAttribute("pricingSummaries = ?", pricingSummaries);
}
try {
insert(TotalSummary.class.getSimpleName(), builder.attributes(), statement -> {
builder.init(statement);
return statement;
});
} catch (final UncategorizedSQLException e) {
throw new ConstraintViolationException(totalSummary, ExceptionUtils.getRootCauseMessage(e), e);
}
return assertNotNull(findById(projectId));
}
This is the utility method that I am using to build the insert query :
protected String insert(final String vertex, final String fieldValuePairs, final PreparedStatementInitializer initializer) {
final String sql = "INSERT INTO " + vertex + " SET " + fieldValuePairs + " RETURN #rid";
return executeStatement(sql, initializer);
}
The toMap methods to convert the List<ProductSummary> to List<Map<?,?>>
**ProductSummary**
public Map<String, Object> toMap() {
final Map<String, Object> ret = new HashMap<>();
ret.put("name", name);
ret.put("model number", Long.valueOf(modelNumber));
return ret;
}
The toMap methods to convert the List<PricingSummary> to List<Map<?,?>>
**PricingSummary**
public Map<String, Object> toMap() {
final Map<String, Object> ret = new HashMap<>();
ret.put("price", Long.valueOf(price));
ret.put("discount", Long.valueOf(discount));
return ret;
}
I am getting the following exception when I execute the code
Constraint violation for: TotalSummary#58f79eeb[recordId=<null>,customProperties=[]]. Reason: OValidationException: The field 'TotalSummary.productSummaries' has been declared as EMBEDDEDLIST but an incompatible type is used.
Things that I have already tried :
I have tried to covert to list to json format before adding it to
the builder like so new Gson().toJson(pricingSummaries);
Converted the pricingSummaries and productSummaries toArray().
You defined the summaries as EMBEDDEDLIST ProductSummary but you are passing lists of maps as values.
Try to create real ProductSummary objects instead eg.
OElement ret = db.newEmbeddedElement("ProductSummary");
ret.setProperty("price", Long.valueOf(price));
ret.setProperty("discount", Long.valueOf(discount));
Below is my test method.
#Test
public void testSaveUserPreference() throws Exception {
final long userId = 1L;
final String category = "category";
final UserPreference userPreference = createMockedUserPreference(userId, category);
final UserPreferenceDTO userPreferenceDTO = createMockedUserPreferenceDTO(userId, category);
final Date lastAccessed = userPreference.getLastAccessedDate();
userPreferenceDTO.setLastAccessedDate(lastAccessed);
//override the convert method to control the object being "saved"
final UserPreference document = new UserPreference();
new MockUp<UserPreferenceUtils>() {
#Mock
UserPreference convertFromDTO(UserPreferenceDTO dto) {
document.setUserId(userPreference.getUserId());
document.setCategory(userPreference.getCategory());
document.setProperties(userPreference.getProperties());
return document;
}
};
new Expectations() {{
component.getUserPreference(userId, category);
returns(userPreference);
component.saveUserPreference(userPreference);
returns(userPreference);
}};
UserPreferenceDTO actual = service.savePreference(userPreferenceDTO);
assertNotNull(actual);
assertEquals(userPreference.getUserId(), actual.getUserId());
assertEquals(userPreference.getCategory(), actual.getCategory());
assertEquals(userPreference.getProperties(), actual.getProperties());
assertNotNull(actual.getCreatedDate());
assertTrue(lastAccessed.before(actual.getLastAccessedDate()));
}
Below is the service method in which I am facing the error.
#Transactional
public UserPreferenceDTO savePreference(UserPreferenceDTO userPreference) {
UserPreference preference = UserPreferenceUtils.convertFromDTO(userPreference);
UserPreference existingPreference = userPreferenceComponent.getUserPreference(userPreference.getUserId(), userPreference.getCategory());
if(existingPreference!=null && !CollectionUtils.isEmpty(existingPreference.getProperties())) {
Map<String,Object> report = (Map<String, Object>) preference.getProperties().get("favoriteFilters");
Map<String,Object> existingRep = (Map<String, Object>) existingPreference.getProperties().get("favoriteFilters");
existingRep.putAll(report);
existingPreference.getProperties().put("favoriteFilters",existingRep);
} else {
existingPreference = preference;
}
if (existingPreference.getCreatedDate() == null) {
existingPreference.setCreatedDate(new Date());
}
existingPreference.setLastAccessedDate(new Date());
UserPreferenceDTO savedPreference = UserPreferenceUtils.convertFromDocument(userPreferenceComponent.saveUserPreference(existingPreference));
return savedPreference;
}
When calling the save method in the second last line, it is giving this error.
mockit.internal.UnexpectedInvocation: Parameter "userPreference" of com.curaspan.platformsupportservice.components.preference.UserPreferenceComponent#saveUserPreference(com.curaspan.platformsupportservice.mongo.document.UserPreference userPreference) expected com.curaspan.platformsupportservice.mongo.document.UserPreference#3d3fcdb0, got com.curaspan.platformsupportservice.mongo.document.UserPreference#636be97c
The userPreference object in the Expectation and the actual method is not matching, though I have all the parameters same. Is there anything I am missing out?
I'm trying to migrate an old project to Retrofit library and this project has quite tricky API. So I have a query template like this:
#GET(value = "products/search")
Single<ProductSearchResponse> productSearch();
And I have to add some parameters here of following template:
filter[attributeId]=attributeValueId
For example:
products/search?filter[1]=10&filter[1]=11&filter[2]=20&filter[2]=21
That's how API works and I can't change it. I know that we can pass a list as a parameter, like this:
#Query("filter") List<Integer> attributeValueIds
But how can I also set parameter's name dynamically?
You can use an arrayList! Something like the code below.
#GET(value = "products/search")
Single<ProductSearchResponse> productSearch(
#Query("status") List<Integer> status
);
ArrayList<Integer> queryStatus = new ArrayList<>();
queryStatus.add(0);
queryStatus.add(1);
queryStatus.add(2);
productService.productSearch(queryStatus);
Your url will be like that -> {url}?status=0&status=1&status=2
Thanks to the link, posted by #ILLIA DEREVIANKO (https://github.com/square/retrofit/issues/1324), I've managed to solve the problem with this class:
public class ProxyRetrofitQueryMap extends HashMap<String, Object> {
public ProxyRetrofitQueryMap(Map<String, Object> m) {
super(m);
}
#Override
public Set<Entry<String, Object>> entrySet() {
Set<Entry<String, Object>> originSet = super.entrySet();
Set<Entry<String, Object>> newSet = new HashSet<>();
for (Entry<String, Object> entry : originSet) {
String entryKey = entry.getKey();
if (entryKey == null) {
throw new IllegalArgumentException("Query map contained null key.");
}
Object entryValue = entry.getValue();
if (entryValue == null) {
throw new IllegalArgumentException(
"Query map contained null value for key '" + entryKey + "'.");
}
else if(entryValue instanceof List) {
for(Object arrayValue:(List)entryValue) {
if (arrayValue != null) { // Skip null values
Entry<String, Object> newEntry = new AbstractMap.SimpleEntry<>(entryKey, arrayValue);
newSet.add(newEntry);
}
}
}
else {
Entry<String, Object> newEntry = new AbstractMap.SimpleEntry<>(entryKey, entryValue);
newSet.add(newEntry);
}
}
return newSet;
}
}
With this we can just use a map, where key is a unique parameter name and value is a List of Strings, that are values for this parameter. Something like this:
ProxyRetrofitQueryMap map = new ProxyRetrofitQueryMap();
List<String> values1 = new ArrayList<>();
values1.add("10");
values1.add("11");
map.put("filter[1]", values1);
List<String> values2 = new ArrayList<>();
values1.add("20");
values1.add("21");
map.put("filter[2]", values2);
You can use #QueryMap annotation like this:
public interface NewsService() {
#GET("/news")
Call<List<News>> getNews(
#QueryMap Map<String, String> options
);
}
Map<String, String> data = new HashMap<>();
data.put("author", "Marcus");
data.put("page", String.valueOf(2));
...
newsService.getNews(data);
More details: https://futurestud.io/tutorials/retrofit-2-add-multiple-query-parameter-with-querymap