Skip to content

Commit d1b270e

Browse files
committed
Missing event types added
Webhook with email added
1 parent c5a0afd commit d1b270e

File tree

5 files changed

+234
-186
lines changed

5 files changed

+234
-186
lines changed

Diff for: src/main/java/de/paymill/model/Subscription.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Subscription implements IPaymillObject {
1313
private Date canceledAt;
1414
private Date createdAt;
1515
private Date updatedAt;
16-
private Date nextCaptureAt;
16+
private String nextCaptureAt;
1717

1818
/**
1919
* @return the id
@@ -37,15 +37,14 @@ public Offer getOffer() {
3737
return offer;
3838
}
3939

40-
4140
/**
4241
* @param offer
4342
* the offer to set
4443
*/
4544
public void setOffer(Offer offer) {
4645
this.offer = offer;
4746
}
48-
47+
4948
/**
5049
* @return the cancelAtPeriodEnd
5150
*/
@@ -136,11 +135,11 @@ public void setUpdatedAt(Date updatedAt) {
136135
this.updatedAt = updatedAt;
137136
}
138137

139-
public Date getNextCaptureAt() {
138+
public String getNextCaptureAt() {
140139
return nextCaptureAt;
141140
}
142141

143-
public void setNextCaptureAt(Date nextCaptureAt) {
142+
public void setNextCaptureAt(String nextCaptureAt) {
144143
this.nextCaptureAt = nextCaptureAt;
145144
}
146145

@@ -167,7 +166,8 @@ public Payment getPayment() {
167166
}
168167

169168
/**
170-
* @param payment the payment to set
169+
* @param payment
170+
* the payment to set
171171
*/
172172
public void setPayment(Payment payment) {
173173
this.payment = payment;

Diff for: src/main/java/de/paymill/model/Webhook.java

+105-90
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,106 @@
1-
package de.paymill.model;
2-
3-
import java.net.URL;
4-
import java.util.Date;
5-
6-
public class Webhook implements IPaymillObject {
7-
public enum EventType {
8-
CHARGEBACK_EXECUTED, REFUND_SUCCEEDED, REFUND_FAILED, SUBSCRIPTION_SUCCEEDED, SUBSCRIPTION_FAILED, TRANSACTION_SUCCEEDED, TRANSACTION_FAILED;
9-
}
10-
11-
private String id;
12-
private URL url;
13-
private Date createdAt;
14-
private Date updatedAt;
15-
private EventType[] eventTypes;
16-
17-
/**
18-
* @return the id
19-
*/
20-
public String getId() {
21-
return id;
22-
}
23-
24-
/**
25-
* @param id
26-
* the id to set
27-
*/
28-
public void setId(String id) {
29-
this.id = id;
30-
}
31-
32-
/**
33-
* @return the callback-url
34-
*/
35-
public URL getUrl() {
36-
return url;
37-
}
38-
39-
/**
40-
* @param url
41-
* the callback-url
42-
*/
43-
public void setUrl(URL url) {
44-
this.url = url;
45-
}
46-
47-
/**
48-
* @return the createdAt
49-
*/
50-
public Date getCreatedAt() {
51-
return createdAt;
52-
}
53-
54-
/**
55-
* @param createdAt
56-
* the createdAt to set
57-
*/
58-
public void setCreatedAt(Date createdAt) {
59-
this.createdAt = createdAt;
60-
}
61-
62-
/**
63-
* @return the updatedAt
64-
*/
65-
public Date getUpdatedAt() {
66-
return updatedAt;
67-
}
68-
69-
/**
70-
* @param updatedAt
71-
* the updatedAt to set
72-
*/
73-
public void setUpdatedAt(Date updatedAt) {
74-
this.updatedAt = updatedAt;
75-
}
76-
77-
/**
78-
* @param eventTypes
79-
* the eventTypes to subscribe
80-
*/
81-
public void setEventTypes(EventType[] eventTypes) {
82-
this.eventTypes = eventTypes;
83-
}
84-
85-
/**
86-
* @return the event types
87-
*/
88-
public EventType[] getEventTypes() {
89-
return eventTypes;
90-
}
1+
package de.paymill.model;
2+
3+
import java.net.URL;
4+
import java.util.Date;
5+
6+
public class Webhook implements IPaymillObject {
7+
public enum EventType {
8+
CHARGEBACK_EXECUTED, REFUND_CREATED, REFUND_SUCCEEDED, REFUND_FAILED, SUBSCRIPTION_CREATED, SUBSCRIPTION_DELETED, SUBSCRIPTION_UPDATED, SUBSCRIPTION_SUCCEEDED, SUBSCRIPTION_FAILED, TRANSACTION_CREATED, TRANSACTION_SUCCEEDED, TRANSACTION_FAILED;
9+
}
10+
11+
private String id, email;
12+
private URL url;
13+
private Date createdAt;
14+
private Date updatedAt;
15+
private EventType[] eventTypes;
16+
17+
/**
18+
* @return the id
19+
*/
20+
public String getId() {
21+
return id;
22+
}
23+
24+
/**
25+
* @param id
26+
* the id to set
27+
*/
28+
public void setId(String id) {
29+
this.id = id;
30+
}
31+
32+
/**
33+
* @return the callback-url
34+
*/
35+
public URL getUrl() {
36+
return url;
37+
}
38+
39+
/**
40+
* @param url
41+
* the callback-url
42+
*/
43+
public void setUrl(URL url) {
44+
this.url = url;
45+
}
46+
47+
/**
48+
* @return the callback email
49+
*/
50+
public String getEmail() {
51+
return email;
52+
}
53+
54+
/**
55+
* @param email
56+
* the callback email
57+
*/
58+
public void setEmail(String email) {
59+
this.email = email;
60+
}
61+
62+
/**
63+
* @return the createdAt
64+
*/
65+
public Date getCreatedAt() {
66+
return createdAt;
67+
}
68+
69+
/**
70+
* @param createdAt
71+
* the createdAt to set
72+
*/
73+
public void setCreatedAt(Date createdAt) {
74+
this.createdAt = createdAt;
75+
}
76+
77+
/**
78+
* @return the updatedAt
79+
*/
80+
public Date getUpdatedAt() {
81+
return updatedAt;
82+
}
83+
84+
/**
85+
* @param updatedAt
86+
* the updatedAt to set
87+
*/
88+
public void setUpdatedAt(Date updatedAt) {
89+
this.updatedAt = updatedAt;
90+
}
91+
92+
/**
93+
* @param eventTypes
94+
* the eventTypes to subscribe
95+
*/
96+
public void setEventTypes(EventType[] eventTypes) {
97+
this.eventTypes = eventTypes;
98+
}
99+
100+
/**
101+
* @return the event types
102+
*/
103+
public EventType[] getEventTypes() {
104+
return eventTypes;
105+
}
91106
}

Diff for: src/main/java/de/paymill/service/WebhookService.java

+80-58
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,81 @@
1-
/**
2-
*
3-
*/
4-
package de.paymill.service;
5-
6-
import java.io.IOException;
7-
import java.io.InputStream;
8-
import java.net.URL;
9-
import java.util.HashMap;
10-
import java.util.Map;
11-
12-
import de.paymill.Paymill;
13-
import de.paymill.PaymillException;
14-
import de.paymill.model.Event;
15-
import de.paymill.model.Webhook;
16-
import de.paymill.model.Webhook.EventType;
17-
import de.paymill.net.HttpClient;
18-
19-
/**
20-
* @author df
21-
*
22-
*/
23-
public class WebhookService extends AbstractService<Webhook> {
24-
public WebhookService() {
25-
this(Paymill.getClient());
26-
}
27-
28-
public WebhookService(HttpClient client) {
29-
super("webhooks", Webhook.class, client);
30-
}
31-
32-
public Webhook create(Webhook obj) {
33-
return create(obj.getUrl(), obj.getEventTypes());
34-
}
35-
36-
/**
37-
* @param url the callback url that this webhook will call
38-
* @param eventTypes the event types to subscribe
39-
* @return the generated webhook
40-
*/
41-
public Webhook create(URL url, EventType... eventTypes) {
42-
if (url == null)
43-
throw new NullPointerException("url");
44-
if (eventTypes == null)
45-
throw new NullPointerException("eventTypes");
46-
Map<String, Object> params = new HashMap<String, Object>();
47-
params.put("url", url.toString());
48-
params.put("event_types", eventTypes);
49-
return client.post(resource, params, modelClass);
50-
}
51-
52-
public Event parse(InputStream inputStream) {
53-
try {
54-
return client.decode(inputStream, Event.class);
55-
} catch (IOException e) {
56-
throw new PaymillException("Failed to decode webhook event object from callback");
57-
}
58-
}
1+
/**
2+
*
3+
*/
4+
package de.paymill.service;
5+
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.net.URL;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
import de.paymill.Paymill;
13+
import de.paymill.PaymillException;
14+
import de.paymill.model.Event;
15+
import de.paymill.model.Webhook;
16+
import de.paymill.model.Webhook.EventType;
17+
import de.paymill.net.HttpClient;
18+
19+
/**
20+
* @author df
21+
*
22+
*/
23+
public class WebhookService extends AbstractService<Webhook> {
24+
public WebhookService() {
25+
this(Paymill.getClient());
26+
}
27+
28+
public WebhookService(HttpClient client) {
29+
super("webhooks", Webhook.class, client);
30+
}
31+
32+
public Webhook create(Webhook obj) {
33+
if ( obj.getUrl() != null ) {
34+
return create(obj.getUrl(), obj.getEventTypes());
35+
} else if ( obj.getEmail() != null ) {
36+
return create(obj.getEmail(), obj.getEventTypes());
37+
} else {
38+
throw new NullPointerException("url and email not set!");
39+
}
40+
}
41+
42+
/**
43+
* @param url the callback url that this webhook will call
44+
* @param eventTypes the event types to subscribe
45+
* @return the generated webhook
46+
*/
47+
public Webhook create(URL url, EventType... eventTypes) {
48+
if (url == null)
49+
throw new NullPointerException("url");
50+
if (eventTypes == null)
51+
throw new NullPointerException("eventTypes");
52+
Map<String, Object> params = new HashMap<String, Object>();
53+
params.put("url", url.toString());
54+
params.put("event_types", eventTypes);
55+
return client.post(resource, params, modelClass);
56+
}
57+
58+
/**
59+
* @param email the callback email that this webhook will call
60+
* @param eventTypes the event types to subscribe
61+
* @return the generated webhook
62+
*/
63+
public Webhook create(String email, EventType... eventTypes) {
64+
if (email == null)
65+
throw new NullPointerException("email");
66+
if (eventTypes == null)
67+
throw new NullPointerException("eventTypes");
68+
Map<String, Object> params = new HashMap<String, Object>();
69+
params.put("email", email);
70+
params.put("event_types", eventTypes);
71+
return client.post(resource, params, modelClass);
72+
}
73+
74+
public Event parse(InputStream inputStream) {
75+
try {
76+
return client.decode(inputStream, Event.class);
77+
} catch (IOException e) {
78+
throw new PaymillException("Failed to decode webhook event object from callback");
79+
}
80+
}
5981
}

0 commit comments

Comments
 (0)