Exemplo n.º 1
0
def succeed_paid_out(vas_name, tx, payer_id, amount):
    event_id = bookkeeping(EventType.TRANSFER_OUT, tx.sn, payer_id, vas_name,
                           amount)
    transit_transaction_state(tx.id, PaymentTxState.CREATED,
                              PaymentTxState.PAID_OUT, event_id)

    # real payer
    add_tx_user(tx.id, user_roles.from_user(payer_id))
Exemplo n.º 2
0
def handle_succeed_refund(vas_name, payment_record, refund_record):
    refund_amount = refund_record.amount

    # 直付和担保付的不同操作
    if payment_record.type == PaymentType.DIRECT:
        event_id = bookkeeping(EventType.TRANSFER_OUT, refund_record.sn,
                               refund_record.payee_id, vas_name, refund_amount)
    elif payment_record.type == PaymentType.GUARANTEE:
        secure_user_id = get_system_account_user_id(SECURE_USER_NAME)
        event_id = bookkeeping(EventType.TRANSFER_OUT_FROZEN, refund_record.sn,
                               secure_user_id, vas_name, refund_amount)
    else:
        logger.warn('bad payment type: [{0}]'.format(payment_record.type))
        return

    refund_tx = refund_record.tx
    transit_transaction_state(refund_tx.id, refund_tx.state,
                              RefundTxState.SUCCESS, event_id)

    payment_record.add_refund(refund_record, event_id)
Exemplo n.º 3
0
def _succeed_refund_in(vas_name, payment_tx, refund_record):
    """处理被退款人的事务"""
    refund_amount = refund_record.amount
    from_user_role = payment_tx.get_role(UserRole.FROM)
    if from_user_role is None:
        raise BizError('payment tx error: should has from role user.')
    event_id = bookkeeping(EventType.TRANSFER_IN, refund_record.sn,
                           from_user_role.user_id, vas_name, refund_amount)
    transit_transaction_state(refund_record.tx_id, RefundTxState.CREATED,
                              RefundTxState.REFUNDED_IN, event_id)

    add_tx_user(refund_record.tx_id,
                user_roles.to_user(from_user_role.user_id))
Exemplo n.º 4
0
def succeed_payment(vas_name,
                    tx,
                    payment_record,
                    state=PaymentTxState.SUCCESS,
                    bk=None):
    payee_id = payment_record.payee_id
    amount = payment_record.real_amount
    if not in_to_pay_state(tx.state):
        raise TransactionStateError(msg='state error: [{0}]'.format(tx.state))

    if amount == 0:
        # 不用记账
        event_id = None
    else:
        event_id = bk(tx.sn, amount) if bk else bookkeeping(
            EventType.TRANSFER_IN, tx.sn, payee_id, vas_name, amount)
    transit_transaction_state(tx.id, tx.state, state, event_id)
Exemplo n.º 5
0
def handle_duplicate_pay(vas_name, vas_sn, tx, prepaid_record):
    """处理充值时的重复支付"""
    event_id = bookkeeping(EventType.TRANSFER_IN, tx.source_sn,
                           prepaid_record.to_id, vas_name,
                           prepaid_record.amount)
    # 交易总金额增加
    tx.amount += prepaid_record.amount
    db.session.add(tx)

    # 不改变状态,只是添加一条关联event
    transit_transaction_state(prepaid_record.tx_id, tx.state, tx.state,
                              event_id)

    # 添加一条重复支付记录
    duplicate_payment_record = DuplicatedPaymentRecord(
        tx_id=tx.id,
        sn=tx.sn,
        event_id=event_id,
        vas_name=vas_name,
        vas_sn=vas_sn,
        source=TransactionType.PREPAID)
    db.session.add(duplicate_payment_record)
Exemplo n.º 6
0
def _success_withdraw(tx, withdraw_record):
    from_user_id = withdraw_record.from_user_id
    fee = withdraw_record.fee
    actual_amount = withdraw_record.actual_amount

    event_ids = []
    if fee > 0:
        from api_x.zyt.vas.pattern import transfer_frozen
        from api_x.zyt.user_mapping import get_lvye_corp_account_user_id
        from api_x.constant import LVYE_WITHDRAW_FEE_USER_NAME
        lvye_withdraw_fee_user_id = get_lvye_corp_account_user_id(
            LVYE_WITHDRAW_FEE_USER_NAME)
        # 手续费转账
        event_ids.extend(
            transfer_frozen(tx.sn, from_user_id, lvye_withdraw_fee_user_id,
                            fee))
    # 提现金额转出
    event_id = bookkeeping(EventType.TRANSFER_OUT_FROZEN, tx.sn, from_user_id,
                           tx.vas_name, actual_amount)
    event_ids.append(event_id)

    transit_transaction_state(tx.id, WithdrawTxState.PROCESSING,
                              WithdrawTxState.SUCCESS, event_ids)
Exemplo n.º 7
0
 def bk(sn, amount):
     secure_user_id = get_system_account_user_id(SECURE_USER_NAME)
     return bookkeeping(EventType.TRANSFER_IN_FROZEN, sn, secure_user_id,
                        vas_name, amount)
Exemplo n.º 8
0
def succeed_prepaid(vas_name, tx, prepaid_record):
    event_id = bookkeeping(EventType.TRANSFER_IN, tx.sn, prepaid_record.to_id,
                           vas_name, prepaid_record.amount)
    transit_transaction_state(tx.id, tx.state, PrepaidTxState.SUCCESS,
                              event_id)