public static O_E_INSERT_IN_APP_BILLING_BY_GOOGLE Execute(I_E_INSERT_IN_APP_BILLING_BY_GOOGLE input, long userNo) { if (input == null || string.IsNullOrEmpty(input.ProductID)) { ErrorHandler.OccurException(RowCode.Invalid_InputValue); } // Check ProductID valid if (!InAppPurchase.TryGetInAppPurchase(input.ProductID, out var inAppProduct) || inAppProduct.StoreType != StoreType.GooglePlay) { ErrorHandler.OccurException(RowCode.Invalid_Product_Id); } // Check DB PoseGlobalDB.Procedures.P_INSERT_IN_APP_BILLING.Output db_output; using (var P_INSERT_IN_APP_BILLING = new PoseGlobalDB.Procedures.P_INSERT_IN_APP_BILLING()) { P_INSERT_IN_APP_BILLING.SetInput(new PoseGlobalDB.Procedures.P_INSERT_IN_APP_BILLING.Input { UserNo = userNo, ProductID = input.ProductID, PurchaseState = PosePurchaseStateType.Canceled.ToString(), StoreType = StoreType.GooglePlay.ToString(), CurrentTime = DateTime.UtcNow, }); db_output = P_INSERT_IN_APP_BILLING.OnQuery(); if (P_INSERT_IN_APP_BILLING.EntityStatus != null || db_output.Result != 0) { ErrorHandler.OccurException(RowCode.DB_Failed_Insert_Billing); } } return(new O_E_INSERT_IN_APP_BILLING_BY_GOOGLE { BillingPayload = db_output.TransNo.ToString(), }); }
public static async Task <O_E_CHECK_MEMBERSHIP_BY_GOOGLE> Execute(I_E_CHECK_MEMBERSHIP_BY_GOOGLE input, long userNo, int serviceRoleType) { PoseBillingResult billingResult = null; //////////////////////////////////////////////////// /// 프로모션 유저 만료 처리 /////////////////////////////////////////////////// if (serviceRoleType == (int)ServiceRoleType.Promotion) { billingResult = new PoseBillingResult() { MemberRoleType = MemberRoleType.Regular, RoleExpireTime = DateTime.UtcNow, }; // Update DB bool db_output_promo; using (var P_UPDATE_USER_ROLE = new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE()) { P_UPDATE_USER_ROLE.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE.Input { UserNo = userNo, LinkedTransNo = 0, RoleType = billingResult.MemberRoleType.ToString(), RoleExpireTime = billingResult.RoleExpireTime, CurrentTime = DateTime.UtcNow, }); db_output_promo = P_UPDATE_USER_ROLE.OnQuery(); if (P_UPDATE_USER_ROLE.EntityStatus != null || db_output_promo == false) { ErrorHandler.OccurException(RowCode.DB_User_Role_Update_Failed); } } // Refrash PoseToken billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType promoServiceRoleType); billingResult.PoseToken = PoseCredentials.CreateToken(userNo, promoServiceRoleType); return(new O_E_CHECK_MEMBERSHIP_BY_GOOGLE { BillingResult = billingResult, }); } //////////////////////////////////////////////////// /// 결제 유저 멤버십 처리 /////////////////////////////////////////////////// // Check DB PoseGlobalDB.Procedures.P_SELECT_LINKED_BILLING.Output db_output; using (var P_SELECT_LINKED_BILLING = new PoseGlobalDB.Procedures.P_SELECT_LINKED_BILLING()) { P_SELECT_LINKED_BILLING.SetInput(userNo); db_output = P_SELECT_LINKED_BILLING.OnQuery(); if (P_SELECT_LINKED_BILLING.EntityStatus != null || db_output.Result != 0) { ErrorHandler.OccurException(RowCode.P_SELECT_LINKED_BILLING + db_output.Result); } } // Check ProductID valid if (!InAppPurchase.TryGetInAppPurchase(db_output.InAppBilling.product_id, out var inAppPurchase) || inAppPurchase.StoreType != StoreType.GooglePlay) { Log4Net.WriteLog($"Invalid Google ProudctId, UserNo: {userNo}, productId: {db_output.InAppBilling.product_id}", Log4Net.Level.ERROR); ErrorHandler.OccurException(RowCode.Invalid_Product_Id); } long linkedTransNo = 0; if (inAppPurchase.PurchaseType == InAppPurchaseType.InAppProduct) { linkedTransNo = db_output.UserRole.linked_trans_no; billingResult = new PoseBillingResult(); billingResult.MemberRoleType = inAppPurchase.OfferRoleType; billingResult.RoleExpireTime = db_output.UserRole.expire_time; billingResult.ProductId = db_output.InAppBilling.product_id; billingResult.PurchaseStateType = db_output.UserRole.expire_time > DateTime.UtcNow ? PosePurchaseStateType.Purchased : PosePurchaseStateType.Unknown; } else if (inAppPurchase.PurchaseType == InAppPurchaseType.Subscription) { var process_ret = await P_E_UPDATE_IN_APP_BILLING_BY_GOOGLE.SubscriptionProcess(inAppPurchase, input.AppPackageName, db_output.InAppBilling.purchase_token); billingResult = process_ret.BillingResult; linkedTransNo = process_ret.Payload; } // 회원등급 심사 if (billingResult.PurchaseStateType != PosePurchaseStateType.Purchased && billingResult.PurchaseStateType != PosePurchaseStateType.Grace) // 결제 유예기간.. { billingResult.MemberRoleType = MemberRoleType.Regular; linkedTransNo = 0; } // Update DB bool db_output2; using (var P_UPDATE_USER_ROLE = new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE()) { P_UPDATE_USER_ROLE.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_USER_ROLE.Input { UserNo = userNo, LinkedTransNo = linkedTransNo, RoleType = billingResult.MemberRoleType.ToString(), RoleExpireTime = billingResult.RoleExpireTime, CurrentTime = DateTime.UtcNow, }); db_output2 = P_UPDATE_USER_ROLE.OnQuery(); if (P_UPDATE_USER_ROLE.EntityStatus != null || db_output2 == false) { ErrorHandler.OccurException(RowCode.DB_User_Role_Update_Failed); } } // Refrash PoseToken billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType convertedServiceRoleType); billingResult.PoseToken = PoseCredentials.CreateToken(userNo, convertedServiceRoleType); return(new O_E_CHECK_MEMBERSHIP_BY_GOOGLE { BillingResult = billingResult, }); }
public static async Task <O_E_UPDATE_IN_APP_BILLING_BY_GOOGLE> Execute(I_E_UPDATE_IN_APP_BILLING_BY_GOOGLE input, long userNo) { if (input == null || string.IsNullOrEmpty(input.ProductID) || string.IsNullOrEmpty(input.AppPackageName) || string.IsNullOrEmpty(input.PurchaseToken)) { ErrorHandler.OccurException(RowCode.Invalid_InputValue); } // Check ProductID valid if (!InAppPurchase.TryGetInAppPurchase(input.ProductID, out var inAppPurchase) || inAppPurchase.StoreType != StoreType.GooglePlay) { Log4Net.WriteLog($"Invalid Google ProudctId, UserNo: {userNo}, productId: {input.ProductID}", Log4Net.Level.ERROR); ErrorHandler.OccurException(RowCode.Invalid_Product_Id); } PoseBillingResult billingResult = null; long trasNo = 0; string orderId = string.Empty; switch (inAppPurchase.PurchaseType) { case InAppPurchaseType.InAppProduct: // 소비성 상품 { var process_ret = await InAppProductProcess(inAppPurchase, input.AppPackageName, input.PurchaseToken); billingResult = process_ret.BillingResult; trasNo = process_ret.Payload; orderId = process_ret.OrderId; } break; case InAppPurchaseType.Subscription: // 구독 상품 { var process_ret = await SubscriptionProcess(inAppPurchase, input.AppPackageName, input.PurchaseToken); billingResult = process_ret.BillingResult; trasNo = process_ret.Payload; orderId = process_ret.OrderId; } break; } // 유효하지않은 PurchaseToken if (billingResult == null) { Log4Net.WriteLog($"Google PurchaseToken is Invalid, UserNo: {userNo}, productId: {input.ProductID}, purchaseToken: {input.PurchaseToken}", Log4Net.Level.ERROR); ErrorHandler.OccurException(RowCode.Invalid_Google_Receipt); } if (billingResult.PurchaseStateType == PosePurchaseStateType.Purchased) { // DB Process PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING.Output db_output; using (var P_UPDATE_IN_APP_BILLING = new PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING()) { P_UPDATE_IN_APP_BILLING.SetInput(new PoseGlobalDB.Procedures.P_UPDATE_IN_APP_BILLING.Input { UserNo = userNo, TransNo = trasNo, PurchaseState = PosePurchaseStateType.Purchased.ToString(), PurchaseToken = input.PurchaseToken, OrderId = orderId, RoleType = billingResult.MemberRoleType.ToString(), RoleExpireTime = billingResult.RoleExpireTime, CurrentTime = DateTime.UtcNow, }); db_output = P_UPDATE_IN_APP_BILLING.OnQuery(); if (P_UPDATE_IN_APP_BILLING.EntityStatus != null || db_output.Result != 0) { ErrorHandler.OccurException(RowCode.P_UPDATE_IN_APP_BILLING + db_output.Result); } } // Refrash PoseToken billingResult.MemberRoleType.ToString().TryParseEnum(out ServiceRoleType serviceRoleType); billingResult.PoseToken = PoseCredentials.CreateToken(userNo, serviceRoleType); } return(new O_E_UPDATE_IN_APP_BILLING_BY_GOOGLE { BillingResult = billingResult, }); }