1919public class QRCodeTest {
2020 private static String URL = String .format ("%s%s" , Xendit .Opt .getXenditURL (), "/qr_codes" );
2121 private static String TEST_ID = "test_id" ;
22- private static String TEST_EXTERNAL_ID = "test_external_id " ;
22+ private static String TEST_REFERENCE_ID = "test_reference_id " ;
2323 private static String TEST_QR_STRING = "this_is_qr_string" ;
24- private static String TEST_CALLBACK_URL = "https://callback.url" ;
2524 private static String TEST_QR_TYPE = QRCode .QRCodeType .DYNAMIC .toString ();
2625 private static String TEST_QR_STATUS = QRCode .QRCodeStatus .ACTIVE .toString ();
26+ private static String TEST_QR_CURRENCY = "IDR" ;
2727 private static Map <String , Object > PARAMS = new HashMap <>();
2828 private static Map <String , String > HEADERS = new HashMap <>();
2929 private static QRCode VALID_PAYMENT =
3030 QRCode .builder ()
3131 .id (TEST_ID )
32- .externalId (TEST_EXTERNAL_ID )
32+ .referenceId (TEST_REFERENCE_ID )
33+ .currency (TEST_QR_CURRENCY )
3334 .qrString (TEST_QR_STRING )
34- .callbackUrl (TEST_CALLBACK_URL )
3535 .status (TEST_QR_STATUS )
3636 .amount (10000 )
3737 .build ();
@@ -49,9 +49,9 @@ public void initMocks() {
4949 }
5050
5151 private void initCreateParams () {
52- PARAMS .put ("external_id " , TEST_EXTERNAL_ID );
52+ PARAMS .put ("reference_id " , TEST_REFERENCE_ID );
5353 PARAMS .put ("type" , TEST_QR_TYPE );
54- PARAMS .put ("callback_url " , TEST_CALLBACK_URL );
54+ PARAMS .put ("currency " , TEST_QR_CURRENCY );
5555 PARAMS .put ("amount" , 10000 );
5656 }
5757
@@ -60,14 +60,14 @@ public void createQRCode_Success_IfMethodCalledCorrectly() throws XenditExceptio
6060 initCreateParams ();
6161
6262 when (this .requestClient .request (
63- RequestResource .Method .POST , URL , PARAMS , opt .getApiKey (), QRCode .class ))
63+ RequestResource .Method .POST , URL , HEADERS , PARAMS , opt .getApiKey (), QRCode .class ))
6464 .thenReturn (VALID_PAYMENT );
6565 when (qrCodeClient .createQRCode (
66- TEST_EXTERNAL_ID , QRCode .QRCodeType .DYNAMIC , TEST_CALLBACK_URL , 10000 ))
66+ TEST_REFERENCE_ID , QRCode .QRCodeType .DYNAMIC , TEST_QR_CURRENCY , 10000 ))
6767 .thenReturn (VALID_PAYMENT );
6868 QRCode qrCode =
6969 qrCodeClient .createQRCode (
70- TEST_EXTERNAL_ID , QRCode .QRCodeType .DYNAMIC , TEST_CALLBACK_URL , 10000 );
70+ TEST_REFERENCE_ID , QRCode .QRCodeType .DYNAMIC , TEST_QR_CURRENCY , 10000 );
7171
7272 assertEquals (qrCode , VALID_PAYMENT );
7373 }
@@ -77,12 +77,7 @@ public void createQRCode_Success_IfParamsIsValid() throws XenditException {
7777 initCreateParams ();
7878
7979 when (this .requestClient .request (
80- RequestResource .Method .POST ,
81- URL ,
82- new HashMap <>(),
83- PARAMS ,
84- opt .getApiKey (),
85- QRCode .class ))
80+ RequestResource .Method .POST , URL , HEADERS , PARAMS , opt .getApiKey (), QRCode .class ))
8681 .thenReturn (VALID_PAYMENT );
8782 when (qrCodeClient .createQRCode (PARAMS )).thenReturn (VALID_PAYMENT );
8883 QRCode qrCode = qrCodeClient .createQRCode (PARAMS );
@@ -96,12 +91,7 @@ public void createQRCode_ThrowsException_IfParamsIsInvalid() throws XenditExcept
9691 PARAMS .put ("type" , "NOT_DYNAMIC" );
9792
9893 when (this .requestClient .request (
99- RequestResource .Method .POST ,
100- URL ,
101- new HashMap <>(),
102- PARAMS ,
103- opt .getApiKey (),
104- QRCode .class ))
94+ RequestResource .Method .POST , URL , HEADERS , PARAMS , opt .getApiKey (), QRCode .class ))
10595 .thenThrow (new XenditException ("QR Code type is invalid" ));
10696 when (qrCodeClient .createQRCode (PARAMS ))
10797 .thenThrow (new XenditException ("QR Code type is invalid" ));
@@ -114,8 +104,17 @@ public void createQRCode_Success_WithHeaderProvided() throws XenditException {
114104 initCreateParams ();
115105 HEADERS .put ("for-user-id" , "user-id" );
116106
107+ Map <String , String > RequestHeaders = new HashMap <>();
108+ RequestHeaders .put ("for-user-id" , "user-id" );
109+ RequestHeaders .put ("api-version" , "2022-07-31" );
110+
117111 when (this .requestClient .request (
118- RequestResource .Method .POST , URL , HEADERS , PARAMS , opt .getApiKey (), QRCode .class ))
112+ RequestResource .Method .POST ,
113+ URL ,
114+ RequestHeaders ,
115+ PARAMS ,
116+ opt .getApiKey (),
117+ QRCode .class ))
119118 .thenReturn (VALID_PAYMENT );
120119 when (qrCodeClient .createQRCode (HEADERS , PARAMS )).thenReturn (VALID_PAYMENT );
121120
@@ -126,27 +125,60 @@ public void createQRCode_Success_WithHeaderProvided() throws XenditException {
126125
127126 @ Test
128127 public void GetQRCode_Success_WithExternalId () throws XenditException {
129- String url = String .format ("%s/%s" , URL , TEST_EXTERNAL_ID );
128+ String url = String .format ("%s/%s" , URL , TEST_REFERENCE_ID );
130129
131130 when (this .requestClient .request (
132131 RequestResource .Method .GET , url , null , opt .getApiKey (), QRCode .class ))
133132 .thenReturn (VALID_PAYMENT );
134- when (qrCodeClient .getQRCode (TEST_EXTERNAL_ID )).thenReturn (VALID_PAYMENT );
135- QRCode qrCode = qrCodeClient .getQRCode (TEST_EXTERNAL_ID );
133+ when (qrCodeClient .getQRCode (TEST_REFERENCE_ID )).thenReturn (VALID_PAYMENT );
134+ QRCode qrCode = qrCodeClient .getQRCode (TEST_REFERENCE_ID );
136135
137136 assertEquals (qrCode , VALID_PAYMENT );
138137 }
139138
140139 @ Test (expected = XenditException .class )
141140 public void GetQRCode_ThrowsException_OnExternalIDNotFound () throws XenditException {
142- String NOT_VALID_EXTERNAL_ID = "not_valid_external_id " ;
143- String url = String .format ("%s/%s" , URL , NOT_VALID_EXTERNAL_ID );
141+ String NOT_VALID_REFERENCE_ID = "not_valid_reference_id " ;
142+ String url = String .format ("%s/%s" , URL , NOT_VALID_REFERENCE_ID );
144143
145144 when (this .requestClient .request (
146145 RequestResource .Method .GET , url , null , opt .getApiKey (), QRCode .class ))
147146 .thenThrow (new XenditException ("not found" ));
148- when (qrCodeClient .getQRCode (NOT_VALID_EXTERNAL_ID )).thenThrow (new XenditException ("not found" ));
147+ when (qrCodeClient .getQRCode (NOT_VALID_REFERENCE_ID ))
148+ .thenThrow (new XenditException ("not found" ));
149+
150+ qrCodeClient .getQRCode (NOT_VALID_REFERENCE_ID );
151+ }
152+
153+ @ Test
154+ public void GetQRCode_Success_WithQRId () throws XenditException {
155+ String url = String .format ("%s/%s" , URL , TEST_ID );
156+
157+ Map <String , String > headers = new HashMap <>();
158+ headers .put ("api-version" , "2022-07-31" );
159+
160+ when (this .requestClient .request (
161+ RequestResource .Method .GET , url , headers , null , opt .getApiKey (), QRCode .class ))
162+ .thenReturn (VALID_PAYMENT );
163+ when (qrCodeClient .getQRCodeByQRId (TEST_ID )).thenReturn (VALID_PAYMENT );
164+ QRCode qrCode = qrCodeClient .getQRCodeByQRId (TEST_ID );
165+
166+ assertEquals (qrCode , VALID_PAYMENT );
167+ }
168+
169+ @ Test (expected = XenditException .class )
170+ public void GetQRCode_ThrowsException_OnReferenceIDNotFound () throws XenditException {
171+ String NOT_VALID_QR_ID = "not_valid_qr_id" ;
172+ String url = String .format ("%s/%s" , URL , NOT_VALID_QR_ID );
173+
174+ Map <String , String > headers = new HashMap <>();
175+ headers .put ("api-version" , "2022-07-31" );
176+
177+ when (this .requestClient .request (
178+ RequestResource .Method .GET , url , headers , null , opt .getApiKey (), QRCode .class ))
179+ .thenThrow (new XenditException ("not found" ));
180+ when (qrCodeClient .getQRCodeByQRId (NOT_VALID_QR_ID )).thenThrow (new XenditException ("not found" ));
149181
150- qrCodeClient .getQRCode ( NOT_VALID_EXTERNAL_ID );
182+ qrCodeClient .getQRCodeByQRId ( NOT_VALID_QR_ID );
151183 }
152184}
0 commit comments