| 
					
				 | 
			
			
				@@ -57,6 +57,8 @@ class InAppPurchaseView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return self.vsees_notifications(request) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         elif operation == 'serverNotifications':  # App Store服务器通知 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return self.server_notifications(request) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        elif operation == 'putRefundOrder':  # App Store服务器通知 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return self.put_refund_order(request) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         token_code, user_id, response = CommonService.verify_token_get_user_id(request_dict, request) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if token_code != 0: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return response.json(token_code) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -191,6 +193,9 @@ class InAppPurchaseView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         pay_result_url = CommonService.get_payment_status_url(lang, 'fail') 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         return response.json(0, {'url': pay_result_url}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    return response.json(173, "内购套餐未分配") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             # 设备开通云存 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             now_time = int(time.time()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             uid_bucket_id = cls.enable_cloud(channel, now_time, order_id, store_qs, uid) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -607,44 +612,19 @@ class InAppPurchaseView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 decoded_transaction_information = signed_data_verifier.verify_and_decode_signed_transaction( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     decoded_payload.data.signedTransactionInfo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 transaction_id = decoded_transaction_information.transactionId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                app_account_token = decoded_transaction_information.appAccountToken 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if not app_account_token: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    app_account_token = "" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 orders_qs = Order_Model.objects.filter(transaction_id=transaction_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if not orders_qs.exists(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     return HttpResponse(status=400) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 orderID = orders_qs[0].orderID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                unused_uid_meal_qs = Unused_Uid_Meal.objects.filter(order_id=orderID) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                uid_bucket_qs = UID_Bucket.objects.filter(orderId=orderID, endTime__gt=int(time.time())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if unused_uid_meal_qs.exists(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    consumptionStatus = ConsumptionStatus.NOT_CONSUMED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    deliveryStatus = DeliveryStatus.DELIVERED_AND_WORKING_PROPERLY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                elif uid_bucket_qs.exists(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    consumptionStatus = ConsumptionStatus.PARTIALLY_CONSUMED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    deliveryStatus = DeliveryStatus.DELIVERED_AND_WORKING_PROPERLY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                elif UID_Bucket.objects.filter(orderId=orderID, endTime__lt=int(time.time())): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    consumptionStatus = ConsumptionStatus.FULLY_CONSUMED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    deliveryStatus = DeliveryStatus.DELIVERED_AND_WORKING_PROPERLY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    consumptionStatus = ConsumptionStatus.UNDECLARED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    deliveryStatus = DeliveryStatus.DID_NOT_DELIVER_FOR_OTHER_REASON 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                in_app_refund_qs = InAppRefund.objects.filter(transaction_id=transaction_id).exists() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                refundPreference = RefundPreference.PREFER_DECLINE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if in_app_refund_qs.exists(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if in_app_refund_qs[0].refund_preference == 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        refundPreference = RefundPreference.PREFER_GRANT 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                consumption_request = ConsumptionRequest( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    customerConsented=True, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    consumptionStatus=consumptionStatus, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    platform=Platform.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    sampleContentProvided=True, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    deliveryStatus=deliveryStatus, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    appAccountToken="", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    accountTenure=AccountTenure.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    playTime=PlayTime.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    lifetimeDollarsRefunded=LifetimeDollarsRefunded.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    lifetimeDollarsPurchased=LifetimeDollarsPurchased.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    userStatus=UserStatus.ACTIVE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    refundPreference=refundPreference, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                client.send_consumption_data(transaction_id, consumption_request) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                uid = orders_qs[0].UID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                now_time = int(time.time()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                put_time = now_time + 11.5 * 60 * 60 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                InAppRefund.objects.create(transaction_id=transaction_id, orderID=orderID, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                           uid=uid, app_type=app_type, created_time=now_time, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                           updated_time=now_time, put_time=put_time, app_account_token=app_account_token) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 return HttpResponse(status=200) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             elif str(decoded_payload.rawNotificationType) == "DID_CHANGE_RENEWAL_STATUS": 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -823,3 +803,58 @@ class InAppPurchaseView(View): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     status_code = eur_response.status_code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return HttpResponse(status=status_code) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @staticmethod 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    def put_refund_order(response): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        put_time = int(time.time()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        in_app_refund_qs = InAppRefund.objects.filter(refund_progress=0, put_time__lt=put_time) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for in_app_refund in in_app_refund_qs: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            transaction_id = in_app_refund.transaction_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            app_type = in_app_refund.app_type 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if app_type == 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                bundle_id = "com.ansjer.zccloud" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            elif app_type == 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                bundle_id = "com.ansjer.zccloud" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return response.json(0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            in_app_purchase_obj = InAppPurchase(bundle_id=bundle_id) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            # AppStoreServerAPIClient 用于查询交易信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            client = in_app_purchase_obj.client 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            orderID = in_app_refund.orderID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            app_account_token = in_app_refund.app_account_token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            unused_uid_meal_qs = Unused_Uid_Meal.objects.filter(order_id=orderID) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            uid_bucket_qs = UID_Bucket.objects.filter(orderId=orderID, endTime__gt=int(time.time())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if unused_uid_meal_qs.exists(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                consumptionStatus = ConsumptionStatus.NOT_CONSUMED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                deliveryStatus = DeliveryStatus.DELIVERED_AND_WORKING_PROPERLY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            elif uid_bucket_qs.exists(): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                consumptionStatus = ConsumptionStatus.PARTIALLY_CONSUMED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                deliveryStatus = DeliveryStatus.DELIVERED_AND_WORKING_PROPERLY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            elif UID_Bucket.objects.filter(orderId=orderID, endTime__lt=int(time.time())): 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                consumptionStatus = ConsumptionStatus.FULLY_CONSUMED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                deliveryStatus = DeliveryStatus.DELIVERED_AND_WORKING_PROPERLY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                consumptionStatus = ConsumptionStatus.UNDECLARED 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                deliveryStatus = DeliveryStatus.DID_NOT_DELIVER_FOR_OTHER_REASON 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if in_app_refund.refund_preference == 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                refundPreference = RefundPreference.PREFER_GRANT 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            else: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                refundPreference = RefundPreference.PREFER_DECLINE 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            consumption_request = ConsumptionRequest( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                customerConsented=True, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                consumptionStatus=consumptionStatus, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                platform=Platform.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sampleContentProvided=True, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                deliveryStatus=deliveryStatus, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                appAccountToken=app_account_token, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                accountTenure=AccountTenure.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                playTime=PlayTime.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                lifetimeDollarsRefunded=LifetimeDollarsRefunded.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                lifetimeDollarsPurchased=LifetimeDollarsPurchased.UNDECLARED, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                userStatus=UserStatus.ACTIVE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                refundPreference=refundPreference, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            client.send_consumption_data(transaction_id, consumption_request) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return response.json(0) 
			 |