Beispiel #1
0
 def __update_vault_state(self, status):
     user_did, app_did = check_auth()
     self.get_checked_vault(user_did)
     col_filter = {VAULT_SERVICE_DID: user_did}
     doc = {VAULT_SERVICE_DID: user_did,
            VAULT_SERVICE_MODIFY_TIME: datetime.utcnow().timestamp(),
            VAULT_SERVICE_STATE: status}
     cli.update_one_origin(DID_INFO_DB_NAME, VAULT_SERVICE_COL, col_filter, {"$set": doc})
 def get_receipt_info(self, order_id):
     user_did, app_did = check_auth()
     order = self._check_param_order_id(user_did, order_id)
     receipt = cli.find_one_origin(DID_INFO_DB_NAME, COL_RECEIPTS,
                                   {COL_RECEIPTS_ORDER_ID: order_id}, throw_exception=False)
     if not receipt:
         raise ReceiptNotFoundException(msg='Receipt can not be found by order_id.')
     return self._get_receipt_vo(order, receipt)
 def run_script(self, script_name):
     json_data = request.get_json(force=True, silent=True)
     Script.validate_run_data(json_data)
     user_did, app_did = check_auth()
     return Script(script_name,
                   json_data,
                   user_did,
                   app_did,
                   scripting=self,
                   is_ipfs=self.is_ipfs).execute()
    def pay_order(self, order_id, json_body):
        user_did, app_did = check_auth()
        vault = self._get_vault_subscription().get_checked_vault(user_did)

        order, transaction_id, paid_did = self._check_pay_order_params(user_did, order_id, json_body)

        receipt = self._create_receipt(user_did, order, transaction_id, paid_did)
        self._update_order_status(str(order['_id']), COL_ORDERS_STATUS_PAID)
        self._get_vault_subscription().upgrade_vault_plan(user_did, vault, order[COL_ORDERS_PRICING_NAME])
        return self._get_receipt_vo(order, receipt)
Beispiel #5
0
 def unsubscribe(self):
     user_did, app_did = check_auth()
     document = self.get_checked_vault(user_did, throw_exception=False)
     if not document:
         # INFO: do not raise here.
         return
     delete_user_vault_data(user_did)
     cli.remove_database(user_did, app_did)
     self.payment.archive_orders(user_did)
     cli.delete_one_origin(DID_INFO_DB_NAME, VAULT_SERVICE_COL, {VAULT_SERVICE_DID: user_did}, is_check_exist=False)
 def run_script_url(self, script_name, target_did, target_app_did, params):
     json_data = {'params': params}
     if target_did and target_app_did:
         json_data['context'] = {
             'target_did': target_did,
             'target_app_did': target_app_did
         }
     Script.validate_run_data(json_data)
     user_did, app_did = check_auth()
     return Script(script_name,
                   json_data,
                   user_did,
                   app_did,
                   scripting=self,
                   is_ipfs=self.is_ipfs).execute()
    def get_orders(self, subscription, order_id):
        _, _ = check_auth()
        if subscription not in ('vault', 'backup'):
            raise InvalidParameterException(msg=f'Invalid subscription: {subscription}.')

        col_filter = {}
        if subscription:
            col_filter[COL_ORDERS_SUBSCRIPTION] = subscription
        if order_id:
            col_filter[COL_RECEIPTS_ORDER_ID] = order_id
        orders = cli.find_many_origin(DID_INFO_DB_NAME, COL_ORDERS, col_filter, throw_exception=False)
        if not orders:
            raise OrderNotFoundException(msg='Can not get the matched orders.')
        return {'orders': list(map(lambda o: {'order_id': str(o['_id']),
                                              COL_ORDERS_SUBSCRIPTION: o[COL_ORDERS_SUBSCRIPTION],
                                              COL_ORDERS_PRICING_NAME: o[COL_ORDERS_PRICING_NAME],
                                              COL_ORDERS_ELA_AMOUNT: o[COL_ORDERS_ELA_AMOUNT],
                                              COL_ORDERS_ELA_ADDRESS: o[COL_ORDERS_ELA_ADDRESS],
                                              COL_ORDERS_PROOF: o[COL_ORDERS_PROOF],
                                              COL_ORDERS_STATUS: o[COL_ORDERS_STATUS],
                                              CREATE_TIME: int(o[CREATE_TIME])}, orders))}
 def get_version(self):
     _, _ = check_auth()
     return {'version': self._get_vault_subscription().get_price_plans_version()}
Beispiel #9
0
 def get_info(self):
     user_did, app_did = check_auth()
     doc = self.get_checked_vault(user_did)
     return self.__get_vault_info(doc)
Beispiel #10
0
 def subscribe(self):
     user_did, app_did = check_auth()
     self.get_checked_vault(user_did, is_not_exist_raise=False)
     return self.__get_vault_info(self.create_vault(user_did, self.get_price_plan('vault', 'Free')))