Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing metadata to scheduled charge #153

Merged
merged 12 commits into from
Jul 17, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"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": {
"object": "scheduled_charge",
"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": [
{
"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": [
"2017-06-02",
"2017-07-02",
"2017-08-02",
"2017-09-02",
"2017-10-02",
"2017-11-02",
"2017-12-02",
"2018-01-02",
"2018-02-02",
"2018-03-02",
"2018-04-02"
],
"created_at": "2017-04-27T09:10:11Z"
}
7 changes: 7 additions & 0 deletions src/main/java/co/omise/models/schedules/ChargeSchedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public static class Params extends co.omise.models.Params {
@JsonProperty
private String description;

@JsonProperty
private Map<String, Object> metadata;

public Params amount(long amount) {
this.amount = amount;
return this;
Expand All @@ -116,5 +119,9 @@ public Params description(String description) {
this.description = description;
return this;
}
public Params metadata(Map<String, Object> metadata) {
this.metadata = metadata;
return this;
}
}
}
10 changes: 7 additions & 3 deletions src/test/java/co/omise/live/LiveScheduleRequestTest.java
danfowler marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand Down Expand Up @@ -75,7 +77,8 @@ public void testLiveScheduleGet() throws IOException, OmiseException {
.build();

Customer customer = client.sendRequest(customerRequest);

Map<String, Object> metadata = new HashMap<>();
metadata.put("testKey","testData");
Request<Schedule> scheduleRequest = new Schedule.CreateRequestBuilder()
.every(1)
.period(SchedulePeriod.Week)
Expand All @@ -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);

Expand Down
15 changes: 14 additions & 1 deletion src/test/java/co/omise/requests/ScheduleRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
AnasNaouchi marked this conversation as resolved.
Show resolved Hide resolved
Map<String, Object> 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
Expand All @@ -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<String, Object> metadata = new HashMap<>();
metadata.put("testKey", "testData");

Request<Schedule> request = new Schedule.CreateRequestBuilder()
.every(1)
.period(SchedulePeriod.Month)
Expand All @@ -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);
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"currency":"thb",
"description":"Monthly membership fee",
"customer":"cust_test_55bb3hkywglfyyachha",
"card":"card_test_55bb3fhl3tc1wr9d51d"
"card":"card_test_55bb3fhl3tc1wr9d51d",
"metadata": {
danfowler marked this conversation as resolved.
Show resolved Hide resolved
"testKey": "testData"
}
},
"occurrences":{
"object":"list",
Expand Down Expand Up @@ -61,4 +64,4 @@
"2018-04-02"
],
"created_at":"2017-04-27T09:10:11Z"
}
}
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -60,5 +61,5 @@
"2018-03-02",
"2018-04-02"
],
"created_at":"2017-04-27T09:10:11Z"
}
"created_at": "2017-04-27T09:10:11Z"
}
Loading