def _create_account_event_payload(self, event_type: str, include_pay_info: bool = False): """Return event payload for account.""" payload: Dict[str, any] = { 'specversion': '1.x-wip', 'type': event_type, 'source': f'https://api.pay.bcregistry.gov.bc.ca/v1/accounts/{self.auth_account_id}', 'id': f'{self.auth_account_id}', 'time': f'{datetime.now()}', 'datacontenttype': 'application/json', 'data': { 'accountId': self.auth_account_id, 'accountName': self.auth_account_name, 'padTosAcceptedBy': self.pad_tos_accepted_by } } if include_pay_info: payload['data']['paymentInfo'] = dict( bankInstitutionNumber=self.bank_number, bankTransitNumber=self.bank_branch_number, bankAccountNumber=mask(self.bank_account_number, current_app.config['MASK_LEN']), paymentStartDate=get_local_formatted_date( self.pad_activation_date)) return payload
def asdict(self, **kwargs): """Return the Account as a python dict.""" user: UserContext = kwargs['user'] account_schema = PaymentAccountSchema() d = account_schema.dump(self._dao) # Add cfs account values based on role and payment method. For system roles, return bank details. is_ob_or_pad = self.payment_method in ( PaymentMethod.PAD.value, PaymentMethod.ONLINE_BANKING.value) # to handle PAD 3 day period..UI needs bank details even if PAD is not activated is_future_pad = (self.payment_method == PaymentMethod.DRAWDOWN.value ) and (self._is_pad_in_pending_activation()) show_cfs_details = is_ob_or_pad or is_future_pad if show_cfs_details: cfs_account = { 'cfsAccountNumber': self.cfs_account, 'cfsPartyNumber': self.cfs_party, 'cfsSiteNumber': self.cfs_site, 'status': self.cfs_account_status } if user.is_system() or user.can_view_bank_info(): mask_len = 0 if not user.can_view_bank_account_number( ) else current_app.config['MASK_LEN'] cfs_account['bankAccountNumber'] = mask( self.bank_account_number, mask_len) cfs_account['bankInstitutionNumber'] = self.bank_number cfs_account['bankTransitNumber'] = self.bank_branch_number d['cfsAccount'] = cfs_account if is_future_pad: d['futurePaymentMethod'] = PaymentMethod.PAD.value return d