Unity3D Android UCGame SDK Integration - 3. Payment, UPointCharge

 유니티3D 안드로이드에 중국 UCGame SDK 연동 초기화, 로그인 로그아웃 처리를 했었습니다. 이번에는 게임머니 결재부분과 U포인트 충전 처리를 정리합니다.


1. Payment

public void UCGamePayment_U(float fAmount) {
PaymentInfo pInfo = new PaymentInfo();
// 구매 요청 후 연속 충전 구매 가능 여부. 기본값 true
pInfo.setAllowContinuousPay(false);
// 충전 가능한 가격 == 0 이며 유저 마음대로 충전가능. != 0 이면 설정된 가격으로만 구매 가능.
pInfo.setAmount(fAmount);
// 충전 처리에 필요한 커스텀 충전 정보. 이 정보는 충전 처리 완료 후 UC 플랫폼에서 개발사 서버에 그대로 전달되는 값이다.
pInfo.setCustomInfo("custOrderId=PX299392#ip=111.22.333.44#...");

try {
// 충전 요청이 실패하면 아래의 callback은 실행되지 않고 아무런 메시지도 게임에 전달되지 않는다.
// 단지 충전 페이지에서 실패 정보를 출력해준다.
UCGameSDK.defaultSDK().pay(UnityPlayer.currentActivity
, pInfo, new UCCallbackListener<OrderInfo>() {

@Override
public void callback(int arg0, OrderInfo arg1) {
// TODO Auto-generated method stub
JSONObject jsonObj = new JSONObject();

switch(arg0) {
case UCGameSDKStatusCode.SUCCESS:
try {
// 오더 번호
jsonObj.put("orderId", arg1.getOrderId());
// 오더 가격
jsonObj.put("orderAmount", arg1.getOrderAmount());
// 충전 유형
jsonObj.put("payWayId", arg1.getPayWay());
// 충전 유형의 중국어 명칭
jsonObj.put("payWayName", arg1.getPayWayName());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d(LOG_TAG, "pay SUCCESS");
break;
case UCGameSDKStatusCode.NO_INIT:
Log.d(LOG_TAG, "pay NO_INIT");
break;
case UCGameSDKStatusCode.PAY_USER_EXIT:
// 유저가 충전 페이지 종료
Log.d(LOG_TAG, "pay PAY_USER_EXIT");
break;
default:
Log.d(LOG_TAG, "pay Error" + arg0);
break;
}
try {
jsonObj.put("resultCode", arg0);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UnityPlayer.UnitySendMessage("PluginUCGameManager", "UCGamePaymentResult_J", jsonObj.toString());
}
});

} catch( Exception e) {
e.printStackTrace();
Log.e(LOG_TAG, e.getMessage(), e);
}
}

 안드로이드 부분입니다.

 public void UCGamePayment(float fAmount)
 {
  curActivity.Call("UCGamePayment_U", fAmount);
 }

 void UCGamePaymentResult_J(string strResult)
 {
  JsonData jData = JsonMapper.ToObject(strResult);
  int iResult = Convert.ToInt32(jData["resultCode"].ToString());
  
  switch(iResult)
  {
  case 0:
   //  public static final int SUCCESS = 0;
   string strOrderId = jData["orderId"].ToString();
   string strOrderAmount = jData["orderAmount"].ToString();
   string strPayWay = jData["payWayId"].ToString();
   string strPayWayName = jData["payWayName"].ToString();
   SetLog("UCGame Pay Success" + strOrderId
    + " " + strOrderAmount
    + " " + strPayWay
    + " " + strPayWayName);
   break;
  case -10:
   //  public static final int NO_INIT = -10;
   SetLog("UCGame Pay No Init");
   break;
  case -500:
   //  public static final int PAY_USER_EXIT = -500;
   SetLog("UCGame Pay Cancel");
   break;
  default:
   SetLog("UCGame Pay Error" + iResult);
   break;
  }
 }
 PluginUCGameManager 컴포넌트입니다.

  fYpos += 50;
  if (GUI.Button (new Rect(0, fYpos, 100, 50), "Payment") == true)
  {
   float fAmount = 100.0f;
   PluginUCGameManager.GetInstance().UCGamePayment(fAmount);
  }
 TestGUI의 OnGUI 부분입니다.

 Payment를 눌렀을 때 화면입니다. 포인트가 충전이 되지 않아 더이상 진행하지 못하는 것 같네요.


2. UPoint 충전

public void UCGameUPointCharge_U() {
runOnUiThread(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub
try {
UCGameSDK.defaultSDK().uPointCharge(UnityPlayer.currentActivity, UC_SERVERID, new UCCallbackListener<String>() {

@Override
public void callback(int arg0, String arg1) {
// TODO Auto-generated method stub
JSONObject jsonObj = new JSONObject();

switch(arg0) {
case UCGameSDKStatusCode.NO_INIT:
Log.d(LOG_TAG, "UPointCharge NO_INIT");
break;
case UCGameSDKStatusCode.NO_LOGIN:
Log.d(LOG_TAG, "UPointCharge NO_LOGIN");
break;
case UCGameSDKStatusCode.SDK_CLOSE:
Log.d(LOG_TAG, "UPointCharge SDK_CLOSE");
break;
default:
Log.d(LOG_TAG, "UPointCharge Error" + arg0);
break;
}
try {
jsonObj.put("resultCode", arg0);
jsonObj.put("message", arg1);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

UnityPlayer.UnitySendMessage("PluginUCGameManager", "UCGameUPointChargeResult_J", jsonObj.toString());
}

});
} catch (UCCallbackListenerNullException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
 안드로이드 부분입니다.

 public void UCGameUPointCharge()
 {
  curActivity.Call("UCGameUPointCharge_U");
 }

 void UCGameUPointChargeResult_J(string strResult)
 {
  JsonData jData = JsonMapper.ToObject(strResult);
  int iResult = Convert.ToInt32(jData["resultCode"].ToString());
  string strMessage = jData["message"].ToString();
  
  switch(iResult)
  {
  case -10:
   //  public static final int NO_INIT = -10;
   break;
  case -11:
   //  public static final int NO_LOGIN = -11;
   break;
  case -701:
   //public static final int SDK_CLOSE = -701;
   break;
  default:
   break;
  }
  
  SetLog("UCGame UPoint " + strMessage);
 }
 PluginUCGameManager 컴포넌트 부분입니다.

  fYpos += 50;
  if (GUI.Button (new Rect(0, fYpos, 100, 50), "UPointCharge") == true)
  {
   PluginUCGameManager.GetInstance().UCGameUPointCharge();
  }
 TestGUI 부분입니다.

 U포인트 충전 페이지입니다.

 다음에는 UCGame SDK 연동 마지막으로 UC Game 플랫폼 메뉴를 호출하는 FloatButton 처리를 정리해보겠습니다.

댓글

이 블로그의 인기 게시물

'xxx.exe' 프로그램을 시작할 수 없습니다. 지정된 파일을 찾을 수 없습니다.

goorm IDE에서 node.js 프로젝트로 Hello World Simple Server 만들어 띄워보기

애드센스 수익을 웨스턴 유니온으로 수표대신 현금으로 지급 받아보자.