Skip to content

Commit d2e5736

Browse files
vadzim-vysdzinad
authored andcommitted
added payment methods parameters
1 parent 02ae0e1 commit d2e5736

10 files changed

Lines changed: 253 additions & 8 deletions

File tree

services-directions-models/src/main/java/com/mapbox/api/directions/v5/DirectionsCriteria.java

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,86 @@ public final class DirectionsCriteria {
314314
@SuppressWarnings("checkstyle:javadocvariable")
315315
public static final int TRAFFIC_TENDENCY_RAPIDLY_DECREASING_CONGESTION = 5;
316316

317+
/*
318+
* Used in Japan for all payments other than transponder such as ETC or ETCX.
319+
*/
320+
@SuppressWarnings("checkstyle:javadocvariable")
321+
public static final String PAYMENT_METHOD_GENERAL = "general";
322+
323+
/*
324+
* A transponder in any country, for any transponder system (e.g. EZ-PASS, Peach Pass).
325+
*/
326+
@SuppressWarnings("checkstyle:javadocvariable")
327+
public static final String PAYMENT_METHOD_ETC = "etc";
328+
329+
/*
330+
* A transponder only used for several specific roads in Japan.
331+
*/
332+
@SuppressWarnings("checkstyle:javadocvariable")
333+
public static final String PAYMENT_METHOD_ETCX = "etcx";
334+
335+
/*
336+
* Payment can be done in cash (coins or notes) of the locally common currency.
337+
*/
338+
@SuppressWarnings("checkstyle:javadocvariable")
339+
public static final String PAYMENT_METHOD_CASH = "cash";
340+
341+
/*
342+
* Exact cash payment or tokens at a toll structure.
343+
* Tokens are pre-purchased coins used to pay toll.
344+
*/
345+
@SuppressWarnings("checkstyle:javadocvariable")
346+
public static final String PAYMENT_METHOD_EXACT_CASH = "exact_cash";
347+
348+
/*
349+
* Payment can be done by coins.
350+
*/
351+
@SuppressWarnings("checkstyle:javadocvariable")
352+
public static final String PAYMENT_METHOD_COINS = "coins";
353+
354+
/*
355+
* Payment can be done by notes (paper money).
356+
*/
357+
@SuppressWarnings("checkstyle:javadocvariable")
358+
public static final String PAYMENT_METHOD_NOTES = "notes";
359+
360+
/*
361+
* Payment can be done with common debit cards.
362+
*/
363+
@SuppressWarnings("checkstyle:javadocvariable")
364+
public static final String PAYMENT_METHOD_DEBIT_CARD = "debit_card";
365+
366+
/*
367+
* A pre-purchased pass or subscription.
368+
*/
369+
@SuppressWarnings("checkstyle:javadocvariable")
370+
public static final String PAYMENT_METHOD_PASS_CARD = "pass_card";
371+
372+
/*
373+
* Payment can be done with common credit cards.
374+
*/
375+
@SuppressWarnings("checkstyle:javadocvariable")
376+
public static final String PAYMENT_METHOD_CREDIT_CARD = "credit_card";
377+
378+
/*
379+
* Automatic monitor of vehicles that enter the toll road without a transponder.
380+
*/
381+
@SuppressWarnings("checkstyle:javadocvariable")
382+
public static final String PAYMENT_METHOD_VIDEO = "video";
383+
384+
/*
385+
* Generic tag for any cryptocurrency.
386+
*/
387+
@SuppressWarnings("checkstyle:javadocvariable")
388+
public static final String PAYMENT_METHOD_CRYPTOCURRENCIES = "cryptocurrencies";
389+
390+
/*
391+
* Payment possible via phone or other personal device's app
392+
* (e.g. Bluetooth, barcode, CR code, etc.).
393+
*/
394+
@SuppressWarnings("checkstyle:javadocvariable")
395+
public static final String PAYMENT_METHOD_APPS = "apps";
396+
317397
private DirectionsCriteria() {
318398
//not called
319399
}
@@ -481,4 +561,27 @@ private DirectionsCriteria() {
481561
})
482562
public @interface TrafficTendencyCriteria {
483563
}
564+
565+
/*
566+
* Retention policy for the various payment methods.
567+
*/
568+
@SuppressWarnings("checkstyle:javadoctype")
569+
@Retention(RetentionPolicy.CLASS)
570+
@StringDef({
571+
PAYMENT_METHOD_GENERAL,
572+
PAYMENT_METHOD_ETC,
573+
PAYMENT_METHOD_ETCX,
574+
PAYMENT_METHOD_CASH,
575+
PAYMENT_METHOD_EXACT_CASH,
576+
PAYMENT_METHOD_COINS,
577+
PAYMENT_METHOD_NOTES,
578+
PAYMENT_METHOD_DEBIT_CARD,
579+
PAYMENT_METHOD_PASS_CARD,
580+
PAYMENT_METHOD_CREDIT_CARD,
581+
PAYMENT_METHOD_VIDEO,
582+
PAYMENT_METHOD_CRYPTOCURRENCIES,
583+
PAYMENT_METHOD_APPS,
584+
})
585+
public @interface PaymentMethodsCriteria {
586+
}
484587
}

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/IntersectionLanes.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.mapbox.api.directions.v5.models;
22

33
import androidx.annotation.Nullable;
4-
54
import com.google.auto.value.AutoValue;
65
import com.google.gson.Gson;
76
import com.google.gson.GsonBuilder;
@@ -81,6 +80,16 @@ public static Builder builder() {
8180
@Nullable
8281
public abstract List<String> indications();
8382

83+
/*
84+
* Available payment methods for the line.
85+
* @return A list of strings where each value
86+
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
87+
*/
88+
@SuppressWarnings("checkstyle:javadocmethod")
89+
@Nullable
90+
@SerializedName("payment_methods")
91+
public abstract List<String> paymentMethods();
92+
8493
/**
8594
* Convert the current {@link IntersectionLanes} to its builder holding the currently assigned
8695
* values. This allows you to modify a single property and then rebuild the object resulting in
@@ -167,6 +176,14 @@ public abstract static class Builder extends DirectionsJsonObject.Builder<Builde
167176
*/
168177
public abstract Builder indications(@Nullable List<String> indications);
169178

179+
/*
180+
* Set available payment methods for the line.
181+
* @param paymentMethods is a list of strings where each value
182+
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
183+
*/
184+
@SuppressWarnings("checkstyle:javadocmethod")
185+
public abstract Builder paymentMethods(@Nullable List<String> paymentMethods);
186+
170187
/**
171188
* Build a new {@link IntersectionLanes} object.
172189
*

services-directions-models/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,29 @@ public List<Boolean> snappingIncludeStaticClosuresList() {
909909
@Nullable
910910
public abstract Boolean metadata();
911911

912+
/*
913+
* Enables filtering the route and lane by payment methods. Default is no filtering.
914+
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
915+
* @return a comma separated string where each value
916+
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
917+
*/
918+
@SuppressWarnings("checkstyle:javadocmethod")
919+
@SerializedName("payment_methods")
920+
@Nullable
921+
public abstract String paymentMethods();
922+
923+
/*
924+
* Enables filtering the route and lane by payment methods. Default is no filtering.
925+
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
926+
* @return a list of strings where each value
927+
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
928+
*/
929+
@SuppressWarnings("checkstyle:javadocmethod")
930+
@Nullable
931+
public List<String> paymentMethodsList() {
932+
return ParseUtils.parseToStrings(paymentMethods(), ",");
933+
}
934+
912935
/**
913936
* Gson type adapter for parsing Gson to this class.
914937
*
@@ -1045,6 +1068,7 @@ public URL toUrl(@NonNull String accessToken) {
10451068
appendQueryParameter(sb, "compute_toll_cost", computeTollCost());
10461069
appendQueryParameter(sb, "waypoints_per_route", waypointsPerRoute());
10471070
appendQueryParameter(sb, "metadata", metadata());
1071+
appendQueryParameter(sb, "payment_methods", paymentMethods());
10481072

10491073
Map<String, SerializableJsonElement> unrecognized = unrecognized();
10501074
if (unrecognized != null) {
@@ -2090,6 +2114,31 @@ public Builder unrecognizedProperties(@Nullable Map<String, String> unrecognized
20902114
return unrecognized(null);
20912115
}
20922116

2117+
/*
2118+
* Enables filtering the route and lane by payment methods. Default is no filtering.
2119+
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
2120+
* @param paymentMethods is a comma separated string where each value
2121+
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
2122+
* @return this builder
2123+
*/
2124+
@SuppressWarnings("checkstyle:javadocmethod")
2125+
@NonNull
2126+
public abstract Builder paymentMethods(@Nullable String paymentMethods);
2127+
2128+
/*
2129+
* Enables filtering the route and lane by payment methods. Default is no filtering.
2130+
* Available payment methods match {@link DirectionsCriteria.PaymentMethodsCriteria}
2131+
* @param paymentMethods is a list of strings where each value
2132+
* matches {@link DirectionsCriteria.PaymentMethodsCriteria}
2133+
* @return this builder
2134+
*/
2135+
@SuppressWarnings("checkstyle:javadocmethod")
2136+
@NonNull
2137+
public Builder paymentMethodsList(@Nullable List<String> paymentMethods) {
2138+
String result = FormatUtils.join(",", paymentMethods);
2139+
return paymentMethods(result);
2140+
}
2141+
20932142
/**
20942143
* Builds the object.
20952144
*

services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/IntersectionLanesTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotNull;
55

6+
import com.mapbox.api.directions.v5.DirectionsCriteria;
67
import com.mapbox.core.TestUtils;
78
import org.junit.Test;
89

910
import java.util.ArrayList;
1011
import java.util.Arrays;
1112
import java.util.Collections;
13+
import java.util.List;
1214

1315
public class IntersectionLanesTest extends TestUtils {
1416

@@ -71,4 +73,19 @@ public void testFromJson_validIndication() {
7173

7274
assertEquals(intersectionLanes, intersectionLanesFromJson);
7375
}
76+
77+
@Test
78+
public void testFromJson_etcAndGeneralPayment() {
79+
IntersectionLanes intersectionLanes = IntersectionLanes.builder()
80+
.paymentMethods(Arrays.asList(
81+
DirectionsCriteria.PAYMENT_METHOD_GENERAL,
82+
DirectionsCriteria.PAYMENT_METHOD_ETC
83+
))
84+
.build();
85+
86+
String jsonString = "{\"payment_methods\": [\"general\", \"etc\"]}";
87+
IntersectionLanes intersectionLanesFromJson = IntersectionLanes.fromJson(jsonString);
88+
89+
assertEquals(intersectionLanes, intersectionLanesFromJson);
90+
}
7491
}

services-directions-models/src/test/java/com/mapbox/api/directions/v5/models/RouteOptionsTest.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static com.google.gson.JsonParser.parseString;
2525
import static com.mapbox.api.directions.v5.utils.Asserts.assertContains;
2626
import static com.mapbox.api.directions.v5.utils.Asserts.assertContainsExactCount;
27+
import static com.mapbox.api.directions.v5.utils.Asserts.assertDoesNotContain;
2728
import static com.mapbox.api.directions.v5.utils.Asserts.assertNoDuplicatedParameters;
2829
import static org.junit.Assert.assertEquals;
2930
import static org.junit.Assert.assertFalse;
@@ -37,7 +38,7 @@ public class RouteOptionsTest extends TestUtils {
3738
*/
3839
private static final String ROUTE_OPTIONS_JSON = "route_options_v5.json";
3940
private static final String ROUTE_OPTIONS_URL =
40-
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&snapping_include_static_closures=true%3B%3Bfalse&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&max_weight=2.9&compute_toll_cost=true&waypoints_per_route=true&metadata=true";
41+
"https://api.mapbox.com/directions/v5/mapbox/driving/-122.4003312,37.7736941;-122.4187529,37.7689715;-122.4255172,37.7775835?access_token=pk.token&geometries=polyline6&alternatives=false&overview=full&radiuses=%3Bunlimited%3B5.1&steps=true&avoid_maneuver_radius=200.0&bearings=0%2C90%3B90%2C0%3B&layers=-42%3B%3B0&continue_straight=false&annotations=congestion%2Cdistance%2Cduration&language=ru&roundabout_exits=false&voice_instructions=true&banner_instructions=true&voice_units=metric&exclude=toll%2Cferry%2Cpoint%2811.0+-22.0%29&include=hot%2Chov2&approaches=%3Bcurb%3B&waypoints=0%3B1%3B2&waypoint_names=%3BSerangoon+Garden+Market+%26+Food+Centre%3BFunky+%26nAmE*&waypoint_targets=%3B12.2%2C21.2%3B&enable_refresh=true&walking_speed=5.11&walkway_bias=-0.2&alley_bias=0.75&snapping_include_closures=%3Bfalse%3Btrue&snapping_include_static_closures=true%3B%3Bfalse&arrive_by=2021-01-01%27T%2701%3A01&depart_at=2021-02-02%27T%2702%3A02&max_height=1.5&max_width=1.4&max_weight=2.9&compute_toll_cost=true&waypoints_per_route=true&metadata=true&payment_methods=general";
4142
private static final String ACCESS_TOKEN = "pk.token";
4243

4344
private final String optionsJson = loadJsonFixture(ROUTE_OPTIONS_JSON);
@@ -1011,6 +1012,45 @@ public void emptyExcludeObjectsCleansUpExcludes() {
10111012
assertNull(routeOptions.exclude());
10121013
}
10131014

1015+
@Test
1016+
public void etcPaymentMethod() {
1017+
RouteOptions routeOptions = routeOptions().toBuilder()
1018+
.paymentMethodsList(Arrays.asList(DirectionsCriteria.PAYMENT_METHOD_ETC))
1019+
.build();
1020+
String query = routeOptions.toUrl("test").getQuery();
1021+
1022+
assertEquals("etc", routeOptions.paymentMethods());
1023+
assertContains(query, "payment_methods=etc");
1024+
}
1025+
1026+
@Test
1027+
public void generalAndEtcPaymentsMethod() {
1028+
List<String> paymentMethods = Arrays.asList(
1029+
DirectionsCriteria.PAYMENT_METHOD_ETC,
1030+
DirectionsCriteria.PAYMENT_METHOD_GENERAL
1031+
);
1032+
RouteOptions routeOptions = routeOptions().toBuilder()
1033+
.paymentMethodsList(paymentMethods)
1034+
.build();
1035+
String query = routeOptions.toUrl("test").getQuery();
1036+
1037+
assertEquals("etc,general", routeOptions.paymentMethods());
1038+
assertEquals(paymentMethods, routeOptions.paymentMethodsList());
1039+
assertContains(query, "payment_methods=etc%2Cgeneral");
1040+
}
1041+
1042+
@Test
1043+
public void emptyPaymentMethodsList() {
1044+
RouteOptions routeOptions = routeOptions().toBuilder()
1045+
.paymentMethodsList(Collections.<String>emptyList())
1046+
.build();
1047+
String query = routeOptions.toUrl("test").getQuery();
1048+
1049+
assertNull(routeOptions.paymentMethods());
1050+
assertNull(routeOptions.paymentMethodsList());
1051+
assertDoesNotContain(query, "payment_methods");
1052+
}
1053+
10141054
/**
10151055
* Fills up all the options using string variants. Values need ot be equal to the ones in {@link #optionsJson}.
10161056
*/
@@ -1061,6 +1101,7 @@ private RouteOptions routeOptions() {
10611101
.metadata(true)
10621102
.computeTollCost(true)
10631103
.waypointsPerRoute(true)
1104+
.paymentMethods(DirectionsCriteria.PAYMENT_METHOD_GENERAL)
10641105
.build();
10651106
}
10661107

@@ -1168,6 +1209,7 @@ private RouteOptions routeOptionsList() {
11681209
.metadata(true)
11691210
.computeTollCost(true)
11701211
.waypointsPerRoute(true)
1212+
.paymentMethodsList(Arrays.asList(DirectionsCriteria.PAYMENT_METHOD_GENERAL))
11711213
.build();
11721214
}
11731215
}

services-directions-models/src/test/resources/route_options_v5.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@
3737
"enable_refresh": true,
3838
"metadata": true,
3939
"waypoints_per_route": true,
40-
"compute_toll_cost": true
40+
"compute_toll_cost": true,
41+
"payment_methods": "general"
4142
}

services-directions/src/main/java/com/mapbox/api/directions/v5/DirectionsService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ Call<DirectionsResponse> getCall(
102102
@Query("max_weight") Double maxWeight,
103103
@Query("compute_toll_cost") Boolean computeTollCost,
104104
@Query("waypoints_per_route") Boolean waypointsPerRoute,
105-
@Query("metadata") Boolean metadata
105+
@Query("metadata") Boolean metadata,
106+
@Query("payment_methods") String paymentMethods
106107
);
107108

108109
/**
@@ -191,6 +192,7 @@ Call<DirectionsResponse> postCall(
191192
@Field("max_weight") Double maxWeight,
192193
@Field("compute_toll_cost") Boolean computeTollCost,
193194
@Field("waypoints_per_route") Boolean waypointsPerRoute,
194-
@Field("metadata") Boolean metadata
195+
@Field("metadata") Boolean metadata,
196+
@Field("payment_methods") String paymentMethods
195197
);
196198
}

services-directions/src/main/java/com/mapbox/api/directions/v5/MapboxDirections.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ private Call<DirectionsResponse> get() {
111111
routeOptions().maxWeight(),
112112
routeOptions().computeTollCost(),
113113
routeOptions().waypointsPerRoute(),
114-
routeOptions().metadata()
114+
routeOptions().metadata(),
115+
routeOptions().paymentMethods()
115116
);
116117
}
117118

@@ -156,7 +157,8 @@ private Call<DirectionsResponse> post() {
156157
routeOptions().maxWeight(),
157158
routeOptions().computeTollCost(),
158159
routeOptions().waypointsPerRoute(),
159-
routeOptions().metadata()
160+
routeOptions().metadata(),
161+
routeOptions().paymentMethods()
160162
);
161163
}
162164

0 commit comments

Comments
 (0)