diff --git a/src/main/java/co/omise/models/schedules/ChargeSchedule.java b/src/main/java/co/omise/models/schedules/ChargeSchedule.java index fc95e087..c255e402 100644 --- a/src/main/java/co/omise/models/schedules/ChargeSchedule.java +++ b/src/main/java/co/omise/models/schedules/ChargeSchedule.java @@ -92,6 +92,9 @@ public static class Params extends co.omise.models.Params { @JsonProperty private String description; + @JsonProperty + private Map metadata; + public Params amount(long amount) { this.amount = amount; return this; @@ -116,5 +119,9 @@ public Params description(String description) { this.description = description; return this; } + public Params metadata(Map metadata) { + this.metadata = metadata; + return this; + } } } \ No newline at end of file diff --git a/src/test/java/co/omise/live/LiveScheduleRequestTest.java b/src/test/java/co/omise/live/LiveScheduleRequestTest.java index 1b217b72..f74de16e 100644 --- a/src/test/java/co/omise/live/LiveScheduleRequestTest.java +++ b/src/test/java/co/omise/live/LiveScheduleRequestTest.java @@ -11,6 +11,8 @@ import org.junit.Test; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import static org.junit.Assert.*; @@ -75,7 +77,8 @@ public void testLiveScheduleGet() throws IOException, OmiseException { .build(); Customer customer = client.sendRequest(customerRequest); - + Map metadata = new HashMap<>(); + metadata.put("testKey","testData"); Request scheduleRequest = new Schedule.CreateRequestBuilder() .every(1) .period(SchedulePeriod.Week) @@ -85,8 +88,9 @@ public void testLiveScheduleGet() throws IOException, OmiseException { .customer(customer.getId()) .amount(2000) .currency("THB") - .description("Monthly membership fee")) - .build(); + .description("Monthly membership fee") + .metadata(metadata) + ).build(); Schedule createdSchedule = client.sendRequest(scheduleRequest); diff --git a/src/test/java/co/omise/requests/ScheduleRequestTest.java b/src/test/java/co/omise/requests/ScheduleRequestTest.java index b2d0ddae..01405c1a 100644 --- a/src/test/java/co/omise/requests/ScheduleRequestTest.java +++ b/src/test/java/co/omise/requests/ScheduleRequestTest.java @@ -9,6 +9,8 @@ import org.junit.Test; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; public class ScheduleRequestTest extends RequestTest { @@ -28,12 +30,16 @@ public void testGet() throws IOException, OmiseException { Schedule schedule = requester.sendRequest(request); assertRequested("GET", "/schedules/" + SCHEDULE_ID, 200); + // Create the map with "testKey" and "testData" to validate metadata + Map expectedMetadata = new HashMap<>(); + expectedMetadata.put("testKey", "testData"); assertEquals(SCHEDULE_ID, schedule.getId()); assertEquals(ScheduleStatus.Running, schedule.getStatus()); assertEquals(1, schedule.getEvery()); assertEquals(SchedulePeriod.Month, schedule.getPeriod()); assertEquals(11, schedule.getNextOccurrencesOn().size()); + assertEquals(expectedMetadata, schedule.getCharge().getMetadata()); } @Test @@ -48,6 +54,10 @@ public void testList() throws IOException, OmiseException { @Test public void testCreate() throws IOException, OmiseException { + // Create the map with "testKey" and "testData" to create metadata + Map metadata = new HashMap<>(); + metadata.put("testKey", "testData"); + Request request = new Schedule.CreateRequestBuilder() .every(1) .period(SchedulePeriod.Month) @@ -57,7 +67,9 @@ public void testCreate() throws IOException, OmiseException { .charge(new ChargeSchedule.Params() .customer("cust_test_55bb3hkywglfyyachha") .amount(88800) - .description("Monthly membership fee")) + .description("Monthly membership fee") + .metadata(metadata) + ) .build(); Schedule schedule = requester.sendRequest(request); @@ -68,6 +80,7 @@ public void testCreate() throws IOException, OmiseException { assertEquals(1, schedule.getEvery()); assertEquals(SchedulePeriod.Month, schedule.getPeriod()); assertEquals(11, schedule.getNextOccurrencesOn().size()); + assertEquals(metadata, schedule.getCharge().getMetadata()); } @Test diff --git a/src/test/resources/testdata/fixtures/api.omise.co/schedules-post.json b/src/test/resources/testdata/fixtures/api.omise.co/schedules-post.json index f8eeda3a..ead164b7 100644 --- a/src/test/resources/testdata/fixtures/api.omise.co/schedules-post.json +++ b/src/test/resources/testdata/fixtures/api.omise.co/schedules-post.json @@ -20,7 +20,10 @@ "currency":"thb", "description":"Monthly membership fee", "customer":"cust_test_55bb3hkywglfyyachha", - "card":"card_test_55bb3fhl3tc1wr9d51d" + "card":"card_test_55bb3fhl3tc1wr9d51d", + "metadata": { + "testKey": "testData" + } }, "occurrences":{ "object":"list", @@ -61,4 +64,4 @@ "2018-04-02" ], "created_at":"2017-04-27T09:10:11Z" -} \ No newline at end of file +} diff --git a/src/test/resources/testdata/fixtures/api.omise.co/schedules/schd_test_57s33hm9fg1pzcqihxs-get.json b/src/test/resources/testdata/fixtures/api.omise.co/schedules/schd_test_57s33hm9fg1pzcqihxs-get.json index 0d7d923d..12634bb0 100644 --- a/src/test/resources/testdata/fixtures/api.omise.co/schedules/schd_test_57s33hm9fg1pzcqihxs-get.json +++ b/src/test/resources/testdata/fixtures/api.omise.co/schedules/schd_test_57s33hm9fg1pzcqihxs-get.json @@ -1,53 +1,54 @@ { - "object":"schedule", - "id":"schd_test_57s33hm9fg1pzcqihxs", - "livemode":false, - "location":"/schedules/schd_test_57s33hm9fg1pzcqihxs", - "status":"running", - "every":1, - "period":"month", - "on":{ - "days_of_month":[ - 2 - ] + "object": "schedule", + "id": "schd_test_57s33hm9fg1pzcqihxs", + "livemode": false, + "location": "/schedules/schd_test_57s33hm9fg1pzcqihxs", + "status": "running", + "every": 1, + "period": "month", + "on": { + "days_of_month": [2] }, - "in_words":"Every 1 month(s) on the 2nd", - "start_on":"2017-04-27", - "end_on":"2018-04-27", - "charge":{ + "in_words": "Every 1 month(s) on the 2nd", + "start_on": "2017-04-27", + "end_on": "2018-04-27", + "charge": { "object": "scheduled_charge", - "amount":88800, - "currency":"thb", - "description":"Monthly membership fee", - "customer":"cust_test_55bb3hkywglfyyachha", - "card":"card_test_55bb3fhl3tc1wr9d51d" + "amount": 88800, + "currency": "thb", + "description": "Monthly membership fee", + "customer": "cust_test_55bb3hkywglfyyachha", + "card": "card_test_55bb3fhl3tc1wr9d51d", + "metadata": { + "testKey": "testData" + } }, - "occurrences":{ - "object":"list", - "from":"1970-01-01T00:00:00+00:00", - "to":"2017-05-16T11:30:41+00:00", - "offset":0, - "limit":20, - "total":1, - "order":null, - "location":"/schedules/schd_test_57s33hm9fg1pzcqihxs/occurrences", - "data":[ + "occurrences": { + "object": "list", + "from": "1970-01-01T00:00:00+00:00", + "to": "2017-05-16T11:30:41+00:00", + "offset": 0, + "limit": 20, + "total": 1, + "order": null, + "location": "/schedules/schd_test_57s33hm9fg1pzcqihxs/occurrences", + "data": [ { - "object":"occurrence", - "id":"occu_test_57s33hmja9t3fs4wmop", - "location":"/occurrences/occu_test_57s33hmja9t3fs4wmop", - "schedule":"schd_test_57s33hm9fg1pzcqihxs", - "schedule_date":"2017-05-02", - "retry_date":null, - "processed_at":"2017-05-02T01:30:00Z", - "status":"successful", - "message":null, - "result":"chrg_test_57tx012c753e2pzawzy", - "created_at":"2017-04-27T09:10:11Z" + "object": "occurrence", + "id": "occu_test_57s33hmja9t3fs4wmop", + "location": "/occurrences/occu_test_57s33hmja9t3fs4wmop", + "schedule": "schd_test_57s33hm9fg1pzcqihxs", + "schedule_date": "2017-05-02", + "retry_date": null, + "processed_at": "2017-05-02T01:30:00Z", + "status": "successful", + "message": null, + "result": "chrg_test_57tx012c753e2pzawzy", + "created_at": "2017-04-27T09:10:11Z" } ] }, - "next_occurrences_on":[ + "next_occurrences_on": [ "2017-06-02", "2017-07-02", "2017-08-02", @@ -60,5 +61,5 @@ "2018-03-02", "2018-04-02" ], - "created_at":"2017-04-27T09:10:11Z" -} \ No newline at end of file + "created_at": "2017-04-27T09:10:11Z" +}