@@ -6,17 +6,109 @@ public interface PaylinkResponse {
66
77 record Paylink (
88 long id ,
9+ long templateId ,
910 double amount ,
10- String message ,
11- String url
11+ String msg ,
12+ String remittance ,
13+ PaylinkState state ,
14+ String url ,
15+ Customer customer ,
16+ Meta meta
1217 ) {
1318 public static Paylink fromJson (JSONObject json ) {
14- return new Paylink (
15- json .getLong ("id" ),
16- json .getDouble ("amount" ),
17- json .optString ("msg" ),
18- json .getString ("url" )
19- );
19+ long id = json .getLong ("id" );
20+ long templateId = json .optLong ("ct" );
21+ double amount = json .getDouble ("amount" );
22+ String msg = json .optString ("msg" );
23+ String remittance = json .optString ("ref" );
24+ String stateStr = json .optString ("state" , null );
25+ PaylinkState state = PaylinkState .parse (stateStr );
26+ String url = json .optString ("url" );
27+
28+ Customer customer = null ;
29+ if (json .has ("customer" )) {
30+ JSONObject customerJson = json .getJSONObject ("customer" );
31+ customer = new Customer ()
32+ .setEmail (customerJson .optString ("email" ))
33+ .setFirstname (customerJson .optString ("firstname" ))
34+ .setLastname (customerJson .optString ("lastname" ))
35+ .setStreet (customerJson .optString ("address" ))
36+ .setCity (customerJson .optString ("city" ))
37+ .setZip (customerJson .optString ("zip" ))
38+ .setCountry (customerJson .optString ("country" ))
39+ .setNumber (customerJson .optString ("customerNumber" ))
40+ .setLang (customerJson .optString ("l" ))
41+ .setMobile (customerJson .optString ("mobile" ))
42+ .setCompanyName (customerJson .optString ("companyName" ))
43+ .setCoc (customerJson .optString ("coc" ));
44+ }
45+
46+ Meta meta = null ;
47+ if (json .has ("meta" )) {
48+ meta = Meta .fromJson (json .getJSONObject ("meta" ));
49+ }
50+
51+ return new Paylink (id , templateId , amount , msg , remittance , state , url , customer , meta );
52+ }
53+ }
54+
55+ record Meta (
56+ boolean active ,
57+ String method ,
58+ String recurringId ,
59+ String expiry ,
60+ String type ,
61+ String invoice ,
62+ String sdd ,
63+ String tx ,
64+ String paymentMethod
65+ ) {
66+ public static Meta fromJson (JSONObject json ) {
67+ boolean active = json .optBoolean ("active" );
68+ String method = json .optString ("method" , null );
69+ String recurringId = json .optString ("recurringId" , null );
70+ String expiry = json .optString ("expiry" , null );
71+ String type = json .optString ("type" , null );
72+ String invoice = json .optString ("invoice" , null );
73+ String sdd = json .optString ("sdd" , null );
74+ String tx = json .optString ("tx" , null );
75+ String paymentMethod = json .optString ("paymentMethod" , null );
76+
77+ return new Meta (active , method , recurringId , expiry , type , invoice , sdd , tx , paymentMethod );
78+ }
79+ }
80+
81+
82+ enum PaylinkState {
83+ CREATED ("created" ),
84+ STARTED ("started" ),
85+ PENDING ("pending" ),
86+ DECLINED ("declined" ),
87+ PAID ("paid" ),
88+ EXPIRED ("expired" ),
89+ REFUNDED ("refunded" );
90+
91+ private final String id ;
92+
93+ PaylinkState (String id ) {
94+ this .id = id ;
95+ }
96+
97+ public String id () {
98+ return id ;
99+ }
100+
101+ public static PaylinkState parse (String state ) {
102+ if (state == null ) return PENDING ;
103+ return switch (state ) {
104+ case "created" -> CREATED ;
105+ case "started" -> STARTED ;
106+ case "declined" -> DECLINED ;
107+ case "paid" -> PAID ;
108+ case "expired" -> EXPIRED ;
109+ case "refunded" -> REFUNDED ;
110+ default -> PENDING ;
111+ };
20112 }
21113 }
22114}
0 commit comments