httpResponse = Unirest.get(url)
56 | .header(acceptEncodingHeader, "application/json")
57 | .header(authorizationHeader, "Bearer " + secreteKey)
58 | .asJson();
59 |
60 | statusCode = httpResponse.getStatus();
61 | return httpResponse.getBody().toString();
62 | }
63 |
64 | @Override
65 | public int getStatusCode() {
66 | return statusCode;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/docs/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Generated Documentation (Untitled)
7 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | JavaScript is disabled on your browser.
70 |
71 | Frame Alert
72 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/docs/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/src/main/java/com/yaphet/chapa/model/PostData.java:
--------------------------------------------------------------------------------
1 | package com.yaphet.chapa.model;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | import java.math.BigDecimal;
6 |
7 | /**
8 | * The PostData class is an object representation of JSON form data
9 | * that will be posted to Chapa API.
10 | */
11 | public class PostData {
12 |
13 | private BigDecimal amount;
14 | private String currency;
15 | private String email;
16 | @SerializedName("first_name")
17 | private String firstName;
18 | @SerializedName("last_name")
19 | private String lastName;
20 | @SerializedName("tx_ref")
21 | private String txRef;
22 | @SerializedName("callback_url")
23 | private String callbackUrl;
24 | @SerializedName("return_url")
25 | private String returnUrl;
26 | @SerializedName("subaccounts[id]")
27 | private String subAccountId;
28 | private Customization customization;
29 |
30 | public BigDecimal getAmount() {
31 | return amount;
32 | }
33 |
34 | public PostData setAmount(BigDecimal amount) {
35 | this.amount = amount;
36 | return this;
37 | }
38 |
39 | public String getCurrency() {
40 | return currency;
41 | }
42 |
43 | public PostData setCurrency(String currency) {
44 | this.currency = currency;
45 | return this;
46 | }
47 |
48 | public String getEmail() {
49 | return email;
50 | }
51 |
52 | public PostData setEmail(String email) {
53 | this.email = email;
54 | return this;
55 | }
56 |
57 | public String getFirstName() {
58 | return firstName;
59 | }
60 |
61 | public PostData setFirstName(String firstName) {
62 | this.firstName = firstName;
63 | return this;
64 | }
65 |
66 | public String getLastName() {
67 | return lastName;
68 | }
69 |
70 | public PostData setLastName(String lastName) {
71 | this.lastName = lastName;
72 | return this;
73 | }
74 |
75 | public String getTxRef() {
76 | return txRef;
77 | }
78 |
79 | public PostData setTxRef(String txRef) {
80 | this.txRef = txRef;
81 | return this;
82 | }
83 |
84 | public String getCallbackUrl() {
85 | return callbackUrl;
86 | }
87 |
88 | public PostData setCallbackUrl(String callbackUrl) {
89 | this.callbackUrl = callbackUrl;
90 | return this;
91 | }
92 |
93 | public String getReturnUrl() {
94 | return returnUrl;
95 | }
96 |
97 | public PostData setReturnUrl(String returnUrl) {
98 | this.returnUrl = returnUrl;
99 | return this;
100 | }
101 |
102 | public String getSubAccountId() {
103 | return subAccountId;
104 | }
105 |
106 | public PostData setSubAccountId(String subAccountId) {
107 | this.subAccountId = subAccountId;
108 | return this;
109 | }
110 |
111 | public Customization getCustomization() {
112 | return customization;
113 | }
114 |
115 | public PostData setCustomization(Customization customization) {
116 | this.customization = customization;
117 | return this;
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/docs/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Deprecated List
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
75 |
76 |
93 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/docs/constant-values.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Constant Field Values
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
75 |
76 |
93 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/docs/serialized-form.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Serialized Form
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
74 |
88 |
89 |
106 |
107 |
108 | Prev
109 | Next
110 |
111 |
115 |
118 |
119 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
78 |
79 |
Class Hierarchy
80 |
81 | java.lang.Object
82 |
83 | com.yaphet.chapa.Chapa
84 |
85 |
86 |
87 |
88 |
89 |
106 |
107 |
108 | Prev
109 | Next
110 |
111 |
115 |
118 |
119 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/docs/overview-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Overview
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
102 |
103 |
120 |
121 |
122 | Prev
123 | Next
124 |
125 |
129 |
132 |
133 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/utility/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.utility Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
78 |
79 |
Class Hierarchy
80 |
81 | java.lang.Object
82 |
86 |
87 |
88 |
89 |
90 |
107 |
108 |
109 | Prev
110 | Next
111 |
112 |
116 |
119 |
120 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
74 |
75 |
76 |
77 |
78 | Class Summary
79 |
80 | Class
81 | Description
82 |
83 |
84 |
85 | Chapa
86 |
87 | The Chapa class is responsible for making GET and POST request to Chapa API to initialize
88 | a transaction, verify a transaction and create a sub account.
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
114 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/exception/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.exception Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
78 |
79 |
Class Hierarchy
80 |
81 | java.lang.Object
82 |
83 | java.lang.Throwable (implements java.io.Serializable)
84 |
85 | java.lang.Exception
86 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
114 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/docs/index-files/index-5.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | E-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
E
75 |
76 | extractBanks(String) - Static method in class com.yaphet.chapa.utility.Util
77 |
78 |
79 |
A B C D E G I J L N P R S U V
80 |
81 |
98 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/docs/index-files/index-10.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | N-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
N
75 |
76 | notNullAndEmpty(String) - Static method in class com.yaphet.chapa.utility.Util
77 |
78 |
79 |
A B C D E G I J L N P R S U V
80 |
81 |
98 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/exception/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.exception
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
74 |
75 |
76 |
77 |
78 | Exception Summary
79 |
80 | Exception
81 | Description
82 |
83 |
84 |
85 | ChapaException
86 |
87 | A ChapaException is thrown to signal a problem during SDK execution.
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
113 |
140 |
141 |
142 |
143 |
--------------------------------------------------------------------------------
/docs/index-files/index-1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | A-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
A
75 |
76 | asString() - Method in class com.yaphet.chapa.model.ResponseData
77 |
78 |
79 |
80 |
81 |
A B C D E G I J L N P R S U V
82 |
83 |
100 |
127 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/client/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.client Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
78 |
79 |
Class Hierarchy
80 |
81 | java.lang.Object
82 |
85 |
86 |
87 |
Interface Hierarchy
88 |
91 |
92 |
93 |
110 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/utility/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.utility
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
74 |
75 |
76 |
77 |
78 | Class Summary
79 |
80 | Class
81 | Description
82 |
83 |
84 |
85 | LocalDateTimeDeserializer
86 |
87 | Custom deserializer for LocalDateTime objects.
88 |
89 |
90 |
91 | Util
92 |
93 | The
Util class serves as a helper class for the main
Chapa class.
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
119 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/src/main/java/com/yaphet/chapa/utility/Util.java:
--------------------------------------------------------------------------------
1 | package com.yaphet.chapa.utility;
2 |
3 | import java.lang.reflect.Type;
4 | import java.math.BigDecimal;
5 | import java.time.Clock;
6 | import java.time.LocalDateTime;
7 | import java.time.format.DateTimeFormatter;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.UUID;
11 |
12 | import com.google.gson.Gson;
13 | import com.google.gson.JsonObject;
14 | import com.google.gson.reflect.TypeToken;
15 | import com.yaphet.chapa.model.*;
16 |
17 | /**
18 | * The Util class serves as a helper class for the main {@link com.yaphet.chapa.Chapa} class.
19 | */
20 | public class Util {
21 |
22 | private static final Clock CLOCK = Clock.systemDefaultZone();
23 | private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd-MM-yy-HH-mm-ss");
24 | private final static Gson JSON_MAPPER = new Gson();
25 |
26 | /**
27 | * @param jsonData A json string to be mapped to a {@link PostData} object.
28 | * @return A {@link PostData} object which contains post fields of the
29 | * provided JSON data.
30 | */
31 | public static PostData jsonToPostData(String jsonData) {
32 | if (!notNullAndEmpty(jsonData)) {
33 | throw new IllegalArgumentException("Can't map null or empty json to PostData object");
34 | }
35 |
36 | Map newMap = jsonToMap(jsonData);
37 | JsonObject jsonObject = JSON_MAPPER.fromJson(jsonData, JsonObject.class);
38 | Type bankListType = new TypeToken>() {}.getType();
39 | Map customizations = JSON_MAPPER.fromJson(jsonObject.get("customizations"), bankListType);
40 | Customization customization = new Customization()
41 | .setTitle(customizations.get("customization[title]"))
42 | .setTitle(customizations.get("customization[description]"))
43 | .setTitle(customizations.get("customization[logo]"))
44 | ;
45 | return new PostData()
46 | .setAmount(new BigDecimal(String.valueOf(newMap.get("amount"))))
47 | .setCurrency(newMap.get("currency"))
48 | .setEmail(newMap.get("email"))
49 | .setFirstName(newMap.get("first_name"))
50 | .setLastName(newMap.get("last_name"))
51 | .setTxRef(newMap.get("tx_ref"))
52 | .setCallbackUrl(newMap.get("callback_url"))
53 | .setCustomization(customization);
54 | }
55 |
56 | /**
57 | * @param jsonData A json string to be mapped to a {@link SubAccount} object.
58 | * @return A {@link SubAccount} object which contains post fields of the
59 | * provided JSON data.
60 | */
61 | public static SubAccount jsonToSubAccount(String jsonData) {
62 | if (!notNullAndEmpty(jsonData)) {
63 | throw new IllegalArgumentException("Can't map null or empty json to SubAccount object");
64 | }
65 |
66 | return JSON_MAPPER.fromJson(jsonData, SubAccount.class);
67 | }
68 |
69 | /**
70 | * @param jsonData a json string to be mapped to a Map object.
71 | * @return A Map object which contains post fields of the provided
72 | * JSON data.
73 | */
74 | public static Map jsonToMap(String jsonData) {
75 | return JSON_MAPPER.fromJson(jsonData, Map.class);
76 | }
77 |
78 | /**
79 | * @param jsonData a json string to be mapped to an {@link InitializeResponseData} object.
80 | * @return An {@link InitializeResponseData} object which contains response fields of the provided
81 | * JSON data.
82 | */
83 | public static InitializeResponseData jsonToInitializeResponseData(String jsonData) {
84 | return JSON_MAPPER.fromJson(jsonData, InitializeResponseData.class);
85 | }
86 |
87 | /**
88 | * @param jsonData a json string to be mapped to a {@link VerifyResponseData} object.
89 | * @return A {@link VerifyResponseData} object which contains response fields of the provided
90 | * JSON data.
91 | */
92 | public static VerifyResponseData jsonToVerifyResponseData(String jsonData) {
93 | return JSON_MAPPER.fromJson(jsonData, VerifyResponseData.class);
94 | }
95 |
96 | /**
97 | * @param jsonData a json string to be mapped to a {@link SubAccountResponseData} object.
98 | * @return A {@link SubAccountResponseData} object which contains response fields of the provided
99 | * JSON data.
100 | */
101 | public static SubAccountResponseData jsonToSubAccountResponseData(String jsonData) {
102 | return JSON_MAPPER.fromJson(jsonData, SubAccountResponseData.class);
103 | }
104 |
105 | /**
106 | * @param jsonData a json string to be mapped to a list of {@link Bank} objects.
107 | * @return A list of {@link Bank} objects each containing details of a bank.
108 | */
109 | public static List extractBanks(String jsonData) {
110 | JsonObject jsonObject = JSON_MAPPER.fromJson(jsonData, JsonObject.class);
111 | Type bankListType = new TypeToken>() {}.getType();
112 |
113 | return JSON_MAPPER.fromJson(jsonObject.get("data"), bankListType);
114 | }
115 |
116 | /**
117 | * @return A random string followed by the current date/time value (dd-MM-yy-HH-mm-ss).
118 | */
119 | public static String generateToken() {
120 | final LocalDateTime now = LocalDateTime.now(CLOCK);
121 | return UUID.randomUUID().toString().substring(0, 8) + "_" + FORMATTER.format(now);
122 | }
123 |
124 | public static boolean notNullAndEmpty(String value) {
125 | return value != null && !value.isEmpty();
126 | }
127 |
128 | public static boolean is2xxSuccessful(int statucCode) {
129 | return (statucCode / 100) == 2;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/docs/index-files/index-14.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | U-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
U
75 |
76 | Util - Class in com.yaphet.chapa.utility
77 |
78 | The
Util class serves as a helper class for the main
Chapa class.
79 |
80 | Util() - Constructor for class com.yaphet.chapa.utility.Util
81 |
82 |
83 |
A B C D E G I J L N P R S U V
84 |
85 |
102 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/docs/index-files/index-9.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | L-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
L
75 |
76 | LocalDateTimeDeserializer - Class in com.yaphet.chapa.utility
77 |
78 | Custom deserializer for LocalDateTime objects.
79 |
80 | LocalDateTimeDeserializer() - Constructor for class com.yaphet.chapa.utility.LocalDateTimeDeserializer
81 |
82 |
83 |
A B C D E G I J L N P R S U V
84 |
85 |
102 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/docs/index-files/index-2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | B-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
B
75 |
76 | Bank - Class in com.yaphet.chapa.model
77 |
78 | Bank() - Constructor for class com.yaphet.chapa.model.Bank
79 |
80 | banks() - Method in class com.yaphet.chapa.Chapa
81 |
82 |
83 |
A B C D E G I J L N P R S U V
84 |
85 |
102 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/docs/index-files/index-12.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | R-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
R
75 |
76 | ResponseData - Class in com.yaphet.chapa.model
77 |
78 | The ResponseData class is an abstract class that
79 | represents the response data from Chapa API.
80 |
81 | ResponseData() - Constructor for class com.yaphet.chapa.model.ResponseData
82 |
83 | ResponseData(String, String, String, int) - Constructor for class com.yaphet.chapa.model.ResponseData
84 |
85 |
86 |
A B C D E G I J L N P R S U V
87 |
88 |
105 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/client/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.client
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
74 |
75 |
76 |
77 |
78 | Interface Summary
79 |
80 | Interface
81 | Description
82 |
83 |
84 |
85 | ChapaClient
86 |
87 | A client to interact with Chapa API.
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | Class Summary
96 |
97 | Class
98 | Description
99 |
100 |
101 |
102 | ChapaClientImpl
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
130 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/src/main/java/com/yaphet/chapa/model/VerifyResponseData.java:
--------------------------------------------------------------------------------
1 | package com.yaphet.chapa.model;
2 |
3 | import com.google.gson.annotations.JsonAdapter;
4 | import com.google.gson.annotations.SerializedName;
5 | import com.yaphet.chapa.utility.LocalDateTimeDeserializer;
6 |
7 | import java.math.BigDecimal;
8 | import java.time.LocalDateTime;
9 |
10 | public class VerifyResponseData extends ResponseData {
11 |
12 | private Data data;
13 |
14 | public VerifyResponseData() {
15 | }
16 |
17 | public VerifyResponseData(String rawJson, String message, String status, int statusCode, Data data) {
18 | super(rawJson, message, status, statusCode);
19 | this.data = data;
20 | }
21 |
22 | public VerifyResponseData setMessage(String message) {
23 | return (VerifyResponseData) super.setMessage(message);
24 | }
25 |
26 | public VerifyResponseData setStatus(String status) {
27 | return (VerifyResponseData) super.setStatus(status);
28 | }
29 |
30 | public VerifyResponseData setStatusCode(int statusCode) {
31 | return (VerifyResponseData) super.setStatusCode(statusCode);
32 | }
33 |
34 | public VerifyResponseData setRawJson(String rawJson) {
35 | return (VerifyResponseData) super.setRawJson(rawJson);
36 | }
37 |
38 | public VerifyResponseData setData(Data data) {
39 | this.data = data;
40 | return this;
41 | }
42 |
43 | public Data getData() {
44 | return data;
45 | }
46 |
47 | public static class Data {
48 |
49 | @SerializedName("first_name")
50 | private String firstName;
51 | @SerializedName("last_name")
52 | private String lastName;
53 | private String email;
54 | private String currency;
55 | private BigDecimal amount;
56 | private BigDecimal charge;
57 | private String mode;
58 | private String method;
59 | private String type;
60 | private String status;
61 | private String reference;
62 | @SerializedName("tx_ref")
63 | private String txRef;
64 | private Customization customization;
65 | private String meta;
66 | @SerializedName("created_at")
67 | @JsonAdapter(LocalDateTimeDeserializer.class)
68 | private LocalDateTime createdAt;
69 | @SerializedName("updated_at")
70 | @JsonAdapter(LocalDateTimeDeserializer.class)
71 | private LocalDateTime updatedAt;
72 |
73 | @SerializedName("first_name")
74 | public String getFirstName() {
75 | return firstName;
76 | }
77 |
78 | public VerifyResponseData.Data setFirstName(String firstName) {
79 | this.firstName = firstName;
80 | return this;
81 | }
82 |
83 | public String getLastName() {
84 | return lastName;
85 | }
86 |
87 | public VerifyResponseData.Data setLastName(String lastName) {
88 | this.lastName = lastName;
89 | return this;
90 | }
91 |
92 | public String getEmail() {
93 | return email;
94 | }
95 |
96 | public VerifyResponseData.Data setEmail(String email) {
97 | this.email = email;
98 | return this;
99 | }
100 |
101 | public String getCurrency() {
102 | return currency;
103 | }
104 |
105 | public VerifyResponseData.Data setCurrency(String currency) {
106 | this.currency = currency;
107 | return this;
108 | }
109 |
110 | public BigDecimal getAmount() {
111 | return amount;
112 | }
113 |
114 | public VerifyResponseData.Data setAmount(BigDecimal amount) {
115 | this.amount = amount;
116 | return this;
117 | }
118 |
119 | public BigDecimal getCharge() {
120 | return charge;
121 | }
122 |
123 | public VerifyResponseData.Data setCharge(BigDecimal charge) {
124 | this.charge = charge;
125 | return this;
126 | }
127 |
128 | public String getMode() {
129 | return mode;
130 | }
131 |
132 | public VerifyResponseData.Data setMode(String mode) {
133 | this.mode = mode;
134 | return this;
135 | }
136 |
137 | public String getMethod() {
138 | return method;
139 | }
140 |
141 | public VerifyResponseData.Data setMethod(String method) {
142 | this.method = method;
143 | return this;
144 | }
145 |
146 | public String getType() {
147 | return type;
148 | }
149 |
150 | public VerifyResponseData.Data setType(String type) {
151 | this.type = type;
152 | return this;
153 | }
154 |
155 | public String getStatus() {
156 | return status;
157 | }
158 |
159 | public VerifyResponseData.Data setStatus(String status) {
160 | this.status = status;
161 | return this;
162 | }
163 |
164 | public String getReference() {
165 | return reference;
166 | }
167 |
168 | public VerifyResponseData.Data setReference(String reference) {
169 | this.reference = reference;
170 | return this;
171 | }
172 |
173 | public String getTxRef() {
174 | return txRef;
175 | }
176 |
177 | public VerifyResponseData.Data setTxRef(String txRef) {
178 | this.txRef = txRef;
179 | return this;
180 | }
181 |
182 | public Customization getCustomization() {
183 | return customization;
184 | }
185 |
186 | public VerifyResponseData.Data setCustomization(Customization customization) {
187 | this.customization = customization;
188 | return this;
189 | }
190 |
191 | public String getMeta() {
192 | return meta;
193 | }
194 |
195 | public VerifyResponseData.Data setMeta(String meta) {
196 | this.meta = meta;
197 | return this;
198 | }
199 |
200 | public LocalDateTime getCreatedAt() {
201 | return createdAt;
202 | }
203 |
204 | public VerifyResponseData.Data setCreatedAt(LocalDateTime createdAt) {
205 | this.createdAt = createdAt;
206 | return this;
207 | }
208 |
209 | public LocalDateTime getUpdatedAt() {
210 | return updatedAt;
211 | }
212 |
213 | public VerifyResponseData.Data setUpdatedAt(LocalDateTime updatedAt) {
214 | this.updatedAt = updatedAt;
215 | return this;
216 | }
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/docs/index-files/index-4.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | D-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
D
75 |
76 | Data() - Constructor for class com.yaphet.chapa.model.InitializeResponseData.Data
77 |
78 | Data() - Constructor for class com.yaphet.chapa.model.SubAccountResponseData.Data
79 |
80 | Data() - Constructor for class com.yaphet.chapa.model.VerifyResponseData.Data
81 |
82 | deserialize(JsonElement, Type, JsonDeserializationContext) - Method in class com.yaphet.chapa.utility.LocalDateTimeDeserializer
83 |
84 |
85 |
A B C D E G I J L N P R S U V
86 |
87 |
104 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/docs/index-files/index-8.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | J-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
J
75 |
76 | jsonToInitializeResponseData(String) - Static method in class com.yaphet.chapa.utility.Util
77 |
78 | jsonToMap(String) - Static method in class com.yaphet.chapa.utility.Util
79 |
80 | jsonToPostData(String) - Static method in class com.yaphet.chapa.utility.Util
81 |
82 | jsonToSubAccount(String) - Static method in class com.yaphet.chapa.utility.Util
83 |
84 | jsonToSubAccountResponseData(String) - Static method in class com.yaphet.chapa.utility.Util
85 |
86 | jsonToVerifyResponseData(String) - Static method in class com.yaphet.chapa.utility.Util
87 |
88 |
89 |
A B C D E G I J L N P R S U V
90 |
91 |
108 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/docs/index-files/index-11.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | P-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
P
75 |
76 | post(String, Map<String, Object>, String) - Method in interface com.yaphet.chapa.client.ChapaClient
77 |
78 | post(String, String, String) - Method in interface com.yaphet.chapa.client.ChapaClient
79 |
80 | post(String, Map<String, Object>, String) - Method in class com.yaphet.chapa.client.ChapaClientImpl
81 |
82 | post(String, String, String) - Method in class com.yaphet.chapa.client.ChapaClientImpl
83 |
84 | PostData - Class in com.yaphet.chapa.model
85 |
86 | The PostData class is an object representation of JSON form data
87 | that will be posted to Chapa API.
88 |
89 | PostData() - Constructor for class com.yaphet.chapa.model.PostData
90 |
91 |
92 |
A B C D E G I J L N P R S U V
93 |
94 |
111 |
138 |
139 |
140 |
141 |
--------------------------------------------------------------------------------
/docs/index-files/index-15.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | V-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
V
75 |
76 | valueOf(String) - Static method in enum com.yaphet.chapa.model.SplitType
77 |
78 | Returns the enum constant of this type with the specified name.
79 |
80 | values() - Static method in enum com.yaphet.chapa.model.SplitType
81 |
82 | Returns an array containing the constants of this enum type, in
83 | the order they are declared.
84 |
85 | verify(String) - Method in class com.yaphet.chapa.Chapa
86 |
87 | VerifyResponseData - Class in com.yaphet.chapa.model
88 |
89 | VerifyResponseData() - Constructor for class com.yaphet.chapa.model.VerifyResponseData
90 |
91 | VerifyResponseData(String, String, String, int, VerifyResponseData.Data) - Constructor for class com.yaphet.chapa.model.VerifyResponseData
92 |
93 | VerifyResponseData.Data - Class in com.yaphet.chapa.model
94 |
95 |
96 |
A B C D E G I J L N P R S U V
97 |
98 |
115 |
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/docs/index-files/index-7.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | I-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 | A B C D E G I J L N P R S U V
72 |
73 |
74 |
I
75 |
76 | initialize(PostData) - Method in class com.yaphet.chapa.Chapa
77 |
78 | This method is used to initialize payment in Chapa.
79 |
80 | initialize(String) - Method in class com.yaphet.chapa.Chapa
81 |
82 | This method is used to initialize payment in Chapa.
83 |
84 | InitializeResponseData - Class in com.yaphet.chapa.model
85 |
86 | InitializeResponseData() - Constructor for class com.yaphet.chapa.model.InitializeResponseData
87 |
88 | InitializeResponseData(String, String, String, int, InitializeResponseData.Data) - Constructor for class com.yaphet.chapa.model.InitializeResponseData
89 |
90 | InitializeResponseData.Data - Class in com.yaphet.chapa.model
91 |
92 | is2xxSuccessful(int) - Static method in class com.yaphet.chapa.utility.Util
93 |
94 |
95 |
A B C D E G I J L N P R S U V
96 |
97 |
114 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/model/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.model Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
78 |
79 |
Class Hierarchy
80 |
81 | java.lang.Object
82 |
98 |
99 |
100 |
Enum Hierarchy
101 |
102 | java.lang.Object
103 |
104 | java.lang.Enum<E> (implements java.lang.Comparable<T>, java.io.Serializable)
105 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
131 |
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ```
2 | ,-----. ,--. ,--.
3 | ' .--./ | ,---. ,--,--. ,---. ,--,--. ,-----. | | ,--,--. ,--. ,--. ,--,--.
4 | | | | .-. | ' ,-. | | .-. | ' ,-. | '-----' ,--. | | ' ,-. | \ `' / ' ,-. |
5 | ' '--'\ | | | | \ '-' | | '-' ' \ '-' | | '-' / \ '-' | \ / \ '-' |
6 | `-----' `--' `--' `--`--' | |-' `--`--' `-----' `--`--' `--' `--`--'
7 | ```
8 |
9 | [](https://github.com/yaphet17/chapa-java/actions/workflows/maven.yml/) [](https://maven-badges.herokuapp.com/maven-central/io.github.yaphet17/Chapa) [](https://opensource.org/licenses/MIT)
10 |
11 | Unofficial Java SDK for Chapa Payment Gateway.
12 |
13 | ## What's new in this version
14 | - You no longer need to deal with `JSON` or `Map` responses. You can just treat response data as a Java object using specific response classes for each request type (e.g. payment initialization, payment verification).
15 | - Better exception handling. The SDK will throw the newly added `ChapaException` on failed requests to Chapa API.
16 | - Bug fixes and design improvements.
17 | - Well-tested and documented code. Check out the Javadoc [here](https://yaphet17.github.io/chapa-java/).
18 |
19 | ## Table of Contents
20 | 1. [Documentation](#documentation)
21 | 2. [Installation](#installation)
22 | 3. [Usage](#usage)
23 | 4. [Javadoc](https://yaphet17.github.io/chapa-java/)
24 | 5. [Contribution](#contribution)
25 | 6. [Example](#example)
26 | 7. [License](#license)
27 |
28 | ## Documentation
29 | Visit official [Chapa's API Documentation](https://developer.chapa.co/docs)
30 | ## Installation
31 | Add the below maven dependency to your `pom.xml` file.
32 | ```xml
33 |
34 | io.github.yaphet17
35 | Chapa
36 | 1.2.2
37 |
38 | ```
39 | Or add the below gradle dependency to your `build.gradle` file.
40 | ```groovy
41 | implementation 'io.github.yaphet17:Chapa:1.2.2'
42 | ```
43 |
44 | ## Usage
45 |
46 | Instantiate a `Chapa` class.
47 | ```java
48 | Chapa chapa = new Chapa("your-secrete-key");
49 | ```
50 | Or if you want to use your own implementation of `ChapaClient` interface.
51 | ```java
52 | Chapa chapa = new Chapa("your-secrete-key", new MyCustomChapaClient());
53 | ```
54 | Note: `MyCustomChapaClient` must implement `ChapaClient` interface.
55 |
56 | To initialize a transaction, you can specify your information by either using our `PostData` class.
57 |
58 | Note: Starting from version 1.1.0 you have to specify customization fields as a `Map` object.
59 |
60 | ```java
61 | Customization customization = new Customization()
62 | .setTitle("E-commerce")
63 | .setDescription("It is time to pay")
64 | .setLogo("https://mylogo.com/log.png");
65 | PostData postData = new PostData()
66 | .setAmount(new BigDecimal("100"))
67 | .setCurrency("ETB")
68 | .setFirstName("Abebe")
69 | .setLastName("Bikila")
70 | .setEmail("abebe@bikila")
71 | .setTxRef(Util.generateToken())
72 | .setCallbackUrl("https://chapa.co")
73 | .setReturnUrl("https://chapa.co")
74 | .setSubAccountId("testSubAccountId")
75 | .setCustomization(customization);
76 | ```
77 | Or, you can use a string JSON data.
78 | ```java
79 | String formData = " { " +
80 | "'amount': '100', " +
81 | "'currency': 'ETB'," +
82 | "'email': 'abebe@bikila.com'," +
83 | "'first_name': 'Abebe'," +
84 | "'last_name': 'Bikila'," +
85 | "'tx_ref': 'tx-myecommerce12345'," +
86 | "'callback_url': 'https://chapa.co'," +
87 | "'subaccount[id]': 'ACCT_xxxxxxxxx'," +
88 | "'customizations':{" +
89 | " 'customization[title]':'E-commerce'," +
90 | " 'customization[description]':'It is time to pay'," +
91 | " 'customization[logo]':'https://mylogo.com/log.png'" +
92 | " }" +
93 | " }";
94 | ```
95 | Initialize payment
96 | ```java
97 | InitializeResponseData responseData = chapa.initialize(postData);
98 | // Get the response message
99 | System.out.println(responseData.getMessage());
100 | // Get the checkout URL from the response JSON
101 | System.out.println(responseData.getData().getCheckOutUrl());
102 | // Get the raw response JSON
103 | System.out.println(responseData.getRawJson());
104 | ```
105 | Verify payment
106 | ```java
107 | // Get the verification response data
108 | VerifyResponseData verifyResponseData = chapa.verify("tx-myecommerce12345");
109 | ```
110 | Get the list of banks
111 | ```java
112 | List banks = chapa.getBanks();
113 | ```
114 | To create a subaccount, you can specify your information by either using our `Subaccount` class.
115 | ```java
116 | SubAccount subAccount = new SubAccount()
117 | .setBusinessName("Abebe Suq")
118 | .setAccountName("Abebe Bikila")
119 | .setAccountNumber("0123456789")
120 | .setBankCode("96e41186-29ba-4e30-b013-2ca36d7e7025")
121 | .setSplitType(SplitType.PERCENTAGE)
122 | .setSplitValue(0.2);
123 | ```
124 | Or, you can use a string JSON data.
125 | ```java
126 | String subAccount = " { " +
127 | "'business_name': 'Abebe Suq', " +
128 | "'account_name': 'Abebe Bikila'," +
129 | "'account_number': '0123456789'," +
130 | "'bank_code': '96e41186-29ba-4e30-b013-2ca36d7e7025'," +
131 | "'split_type': 'percentage'," +
132 | "'split_value': '0.2'" +
133 | " }";
134 | ```
135 | Create subaccount
136 | ```java
137 | SubAccountResponseData subAccountResponseData = chapa.createSubAccount(subAccount);
138 | // Get SubAccount id from the response JSOn
139 | System.out.println(subAccountResponseData.getData().getSubAccountId());
140 | ```
141 | ## Example
142 | ```java
143 | import java.math.BigDecimal;
144 | import java.util.HashMap;
145 | import java.util.List;
146 | import java.util.Map;
147 |
148 | import io.github.yaphet17.chapa.Chapa;
149 | import io.github.yaphet17.chapa.PostData;
150 | import io.github.yaphet17.chapa.SubAccount;
151 | import io.github.yaphet17.chapa.SplitType;
152 | import io.github.yaphet17.chapa.Bank;
153 |
154 | public class ChapaExample {
155 |
156 | public static void main(String[] args) {
157 | Chapa chapa = new Chapa("your-secrete-key");
158 |
159 | Customization customization = new Customization()
160 | .setTitle("E-commerce")
161 | .setDescription("It is time to pay")
162 | .setLogo("https://mylogo.com/log.png");
163 |
164 | PostData postData = new PostData()
165 | .setAmount(new BigDecimal("100"))
166 | .setCurrency("ETB")
167 | .setFirstName("Abebe")
168 | .setLastName("Bikila")
169 | .setEmail("abebe@bikila")
170 | .setTxRef(Util.generateToken())
171 | .setCallbackUrl("https://chapa.co")
172 | .setReturnUrl("https://chapa.co")
173 | .setSubAccountId("testSubAccountId")
174 | .setCustomization(customization);
175 |
176 | SubAccount subAccount = new SubAccount()
177 | .setBusinessName("Abebe Suq")
178 | .setAccountName("Abebe Bikila")
179 | .setAccountNumber("0123456789")
180 | .setBankCode("96e41186-29ba-4e30-b013-2ca36d7e7025")
181 | .setSplitType(SplitType.PERCENTAGE)
182 | .setSplitValue(0.2);
183 |
184 |
185 | InitializeResponseData responseData = chapa.initialize(postData);
186 | VerifyResponseData verifyResponseData = chapa.verify("tx-myecommerce12345");
187 | SubAccountResponseData subAccountResponseData = chapa.createSubAccount(subAccount);
188 |
189 | }
190 | }
191 | ```
192 | ## Contribution
193 | If you find any bugs or have any suggestions, please feel free to open an issue or pull request.
194 |
195 | ## License
196 | This open-source library is licensed under the terms of the MIT License.
197 |
198 | Enjoy!
199 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | 4.0.0
6 |
7 | io.github.yaphet17
8 | Chapa
9 | 1.3.0-SNAPSHOT
10 | jar
11 |
12 | Chapa
13 | Java package for Chapa Payment Gateway
14 | https://github.com/yaphet17/chapa-java
15 |
16 |
17 | Yafet Berhanu
18 | yafetberhanu3@gmail.com
19 |
20 |
21 |
22 |
23 | scm:git:git://github.com/yaphet17/chapa-java.git
24 | scm:git:ssh://github.com:yaphet17/chapa-java.git
25 | http://github.com/yapht17/chapa-java/tree/main
26 |
27 |
28 |
29 | UTF-8
30 | 1.7
31 | 1.7
32 | 2.2.27
33 |
34 |
35 |
36 |
37 | com.mashape.unirest
38 | unirest-java
39 | 1.4.9
40 |
41 |
42 | com.google.code.gson
43 | gson
44 | 2.8.9
45 |
46 |
47 | org.junit.jupiter
48 | junit-jupiter
49 | 5.9.0
50 | test
51 |
52 |
53 | org.mockito
54 | mockito-junit-jupiter
55 | 4.6.1
56 | test
57 |
58 |
59 | org.mockito
60 | mockito-inline
61 | 3.8.0
62 | test
63 |
64 |
65 | org.skyscreamer
66 | jsonassert
67 | 1.5.0
68 | test
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | maven-clean-plugin
78 | 3.1.0
79 |
80 |
81 |
82 | maven-resources-plugin
83 | 3.0.2
84 |
85 |
86 | maven-compiler-plugin
87 | 3.8.0
88 |
89 |
90 | maven-surefire-plugin
91 | 2.22.1
92 |
93 |
94 | maven-jar-plugin
95 | 3.0.2
96 |
97 |
98 | maven-install-plugin
99 | 2.5.2
100 |
101 |
102 | maven-deploy-plugin
103 | 2.8.2
104 |
105 |
106 |
107 | maven-site-plugin
108 | 3.7.1
109 |
110 |
111 | maven-project-info-reports-plugin
112 | 3.0.0
113 |
114 |
115 |
116 |
117 |
118 | org.apache.maven.plugins
119 | maven-source-plugin
120 | 3.2.0
121 |
122 |
123 | attach-sources
124 |
125 | jar-no-fork
126 |
127 |
128 |
129 |
130 |
131 | org.apache.maven.plugins
132 | maven-gpg-plugin
133 | 3.0.1
134 |
135 |
136 | sign-artifacts
137 | verify
138 |
139 | sign
140 |
141 |
142 |
143 |
144 |
145 | org.apache.maven.plugins
146 | maven-javadoc-plugin
147 | 3.2.0
148 |
149 |
150 | attach-javadocs
151 |
152 | jar
153 |
154 |
155 |
156 |
157 | 8
158 |
159 |
160 |
161 | org.apache.maven.plugins
162 | maven-compiler-plugin
163 |
164 | 8
165 | 8
166 |
167 |
168 |
169 | org.sonatype.plugins
170 | nexus-staging-maven-plugin
171 | 1.6.13
172 | true
173 |
174 | ossrh
175 | https://s01.oss.sonatype.org/
176 | true
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 | MIT License
185 | http://www.opensource.org/licenses/mit-license.php
186 |
187 |
188 |
189 |
190 |
191 | ossrh
192 | https://s01.oss.sonatype.org/content/repositories/snapshots
193 |
194 |
195 | ossrh
196 | https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
197 |
198 |
199 |
200 |
201 |
202 |
--------------------------------------------------------------------------------
/docs/com/yaphet/chapa/model/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.yaphet.chapa.model
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
43 |
70 |
71 |
74 |
75 |
76 |
77 |
136 |
137 |
138 |
139 | Enum Summary
140 |
141 | Enum
142 | Description
143 |
144 |
145 |
146 | SplitType
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
172 |
199 |
200 |
201 |
202 |
--------------------------------------------------------------------------------