11package kr .co .bootpay .valid ;
22
3+ import android .app .AlertDialog ;
4+ import android .content .Context ;
5+ import android .content .DialogInterface ;
6+ import android .content .Intent ;
37import android .os .Build ;
48
59import java .util .Arrays ;
1115import kr .co .bootpay .model .Request ;
1216
1317public class ValidRequest {
14- public static Request validUXAvailablePG (Request request ) {
18+ public static Request validUXAvailablePG (Context context , Request request ) {
1519 UX ux = request .getUX ();
16- if (PGAvailable .isUXPGDefault (ux )) return validPGDialog (request );
17- if (PGAvailable .isUXPGSubscript (ux )) return validPGSubscript (request );
18- else if (PGAvailable .isUXBootpayApi (ux )) return validPGDialog (request );
19- else if (PGAvailable .isUXApp2App (ux )) return validBootpayUX (request );
20+ if (PGAvailable .isUXPGDefault (ux )) return validPGDialog (context , request );
21+ if (PGAvailable .isUXPGSubscript (ux )) return validPGSubscript (context , request );
22+ else if (PGAvailable .isUXBootpayApi (ux )) return validPGDialog (context , request );
23+ else if (PGAvailable .isUXApp2App (ux )) return validBootpayUX (context , request );
2024 return request ;
2125 }
2226
23- private static Request validPGDialog (Request request ) {
27+ private static Request validPGDialog (Context context , Request request ) {
2428 if (request .getPG ().length () == 0 ) return request ; // 통합결제창
2529 if (request .getMethods () != null && request .getMethods ().size () > 0 ) return request ; // 통합결제창
2630
@@ -36,15 +40,22 @@ private static Request validPGDialog(Request request) {
3640 break ;
3741 }
3842 }
39- if (!contain ) throw new IllegalStateException (request .getPG () + "'s " + request .getMethod () + " is not supported" );
43+ if (!contain ) {
44+ final String string = request .getPG () + "'s " + request .getMethod () + " is not supported" ;
45+ errorDialog (context , string );
46+ }
4047 }
4148 return request ;
4249 }
4350
44- private static Request validPGSubscript (Request request ) {
51+ private static Request validPGSubscript (Context context , Request request ) {
4552 if ("nicepay" .equals (request .getPG ().toLowerCase ())) throw new IllegalStateException (request .getPG () + " 정기결제는 클라이언트 UI 연동방식이 아닌, REST API를 통해 진행해주셔야 합니다." );
4653 List <String > rebill = Arrays .asList ("card_rebill" , "phone_rebill" );
47- if (!rebill .contains (request .getMethod ())) throw new IllegalStateException (request .getMethod () + " is not supported in " + request .getUX ());
54+ if (!rebill .contains (request .getMethod ())) {
55+ final String string = request .getMethod () + " is not supported in " + request .getUX () + ". select in " + rebill .toString ();
56+ errorDialog (context , string );
57+ }
58+
4859 List <Method > methodList = PGAvailable .getDefaultMethods (request );
4960 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
5061 boolean contain = false ;
@@ -55,12 +66,15 @@ private static Request validPGSubscript(Request request) {
5566 break ;
5667 }
5768 }
58- if (!contain ) throw new IllegalStateException (request .getPG () + "'s " + request .getMethod () + " is not supported" );
69+ if (!contain ) {
70+ final String string = request .getPG () + "'s " + request .getMethod () + " is not supported" ;
71+ errorDialog (context , string );
72+ }
5973 }
6074 return request ;
6175 }
6276
63- private static Request validBootpayUX (Request request ) {
77+ private static Request validBootpayUX (Context context , Request request ) {
6478 List <PG > pgList = PGAvailable .getBootpayUX (request );
6579 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
6680 boolean contain = false ;
@@ -70,8 +84,28 @@ private static Request validBootpayUX(Request request) {
7084 break ;
7185 }
7286 }
73- if (!contain ) throw new IllegalStateException (request .getUX () + "'s " + request .getPG () + " is not supported" );
87+
88+ if (!contain ) {
89+ final String string = request .getPG () + "'s " + request .getMethod () + " is not supported" ;
90+ errorDialog (context , string );
91+ }
7492 }
7593 return request ;
7694 }
95+
96+ private static void errorDialog (Context context , final String msg ) {
97+ // 친절히 알려주자
98+ new AlertDialog .Builder (context )
99+ .setTitle ("Bootpay Android Dev Error" )
100+ .setMessage (msg )
101+ .setCancelable (true )
102+ .setPositiveButton ("종료" ,
103+ new DialogInterface .OnClickListener () {
104+ public void onClick (
105+ DialogInterface dialog , int id ) {
106+ // 프로그램을 종료한다
107+ throw new IllegalStateException (msg );
108+ }
109+ }).create ().show ();
110+ }
77111}
0 commit comments