Exemple #1
0
def record_payment(order, config, amount=NOTSET, transaction_id=""):
    """Convert a pending payment into a real payment."""
    key = unicode(config.KEY.value)
    if amount == NOTSET:
        amount = order.balance
        
    log.debug("Recording %s payment of %s for %s", key, amount, order)
    payments = order.payments.filter(transaction_id__exact="PENDING", 
        payment__exact=key)
    ct = payments.count()
    if ct == 0:
        log.debug("No pending %s payments for %s", key, order)
        orderpayment = OrderPayment(order=order, amount=amount, payment=key,
            transaction_id=transaction_id)
    
    else:
        orderpayment = payments[0]
        orderpayment.amount = amount
        orderpayment.transaction_id = transaction_id

        if ct > 1:
            for payment in payments[1:len(payments)]:
                payment.transaction_id="ABORTED"
                payment.save()
            
    orderpayment.time_stamp = datetime.now()
    orderpayment.save()
    
    if order.paid_in_full:
        order.order_success()
    
    return orderpayment
Exemple #2
0
def record_payment(order, config, amount=NOTSET, transaction_id=""):
    """Convert a pending payment into a real payment."""
    key = unicode(config.KEY.value)
    if amount == NOTSET:
        amount = order.balance

    log.debug("Recording %s payment of %s for %s", key, amount, order)
    payments = order.payments.filter(transaction_id__exact="PENDING",
                                     payment__exact=key)
    ct = payments.count()
    if ct == 0:
        log.debug("No pending %s payments for %s", key, order)
        orderpayment = OrderPayment(order=order,
                                    amount=amount,
                                    payment=key,
                                    transaction_id=transaction_id)

    else:
        orderpayment = payments[0]
        orderpayment.amount = amount
        orderpayment.transaction_id = transaction_id

        if ct > 1:
            for payment in payments[1:len(payments)]:
                payment.transaction_id = "ABORTED"
                payment.save()

    orderpayment.time_stamp = datetime.now()
    orderpayment.save()

    if order.paid_in_full:
        order.order_success()

    return orderpayment
Exemple #3
0
def record_payment(order, config, amount=NOTSET, transaction_id=""):
    """Convert a pending payment into a real payment."""
    key = str(config.KEY.value)
    if amount == NOTSET:
        amount = order.balance

    log.debug("Recording %s payment of %s for %s", key, amount, order)
    payments = order.payments.filter(
        transaction_id__exact="PENDING", payment__exact=key
    )
    ct = payments.count()
    if ct == 0:
        log.debug("No pending %s payments for %s", key, order)

        try:
            exchange_rate = order.currency.exchange_rates.latest().rate
        except ExchangeRate.DoesNotExist:
            exchange_rate = Decimal("1.00")

        orderpayment = OrderPayment(
            order=order,
            amount=amount,
            exchange_rate=exchange_rate,
            payment=key,
            transaction_id=transaction_id,
        )

    else:
        orderpayment = payments[0]
        orderpayment.amount = amount
        orderpayment.transaction_id = transaction_id

        if ct > 1:
            for payment in payments[1 : len(payments)]:
                payment.transaction_id = "ABORTED"
                payment.save()

    orderpayment.time_stamp = datetime.now()
    orderpayment.save()

    if order.paid_in_full:
        order.order_success()

    return orderpayment
Exemple #4
0
def record_payment(order, config, amount=NOTSET, transaction_id=""):
    """Convert a pending payment into a real payment."""
    key = str(config.KEY.value)
    if amount == NOTSET:
        amount = order.balance

    log.debug("Recording %s payment of %s for %s", key, amount, order)
    payments = order.payments.filter(transaction_id__exact="PENDING",
                                     payment__exact=key)
    ct = payments.count()
    if ct == 0:
        log.debug("No pending %s payments for %s", key, order)

        try:
            exchange_rate = order.currency.exchange_rates.latest().rate
        except ExchangeRate.DoesNotExist:
            exchange_rate = Decimal("1.00")

        orderpayment = OrderPayment(
            order=order,
            amount=amount,
            exchange_rate=exchange_rate,
            payment=key,
            transaction_id=transaction_id,
        )

    else:
        orderpayment = payments[0]
        orderpayment.amount = amount
        orderpayment.transaction_id = transaction_id

        if ct > 1:
            for payment in payments[1:len(payments)]:
                payment.transaction_id = "ABORTED"
                payment.save()

    orderpayment.time_stamp = datetime.now()
    orderpayment.save()

    if order.paid_in_full:
        order.order_success()

    return orderpayment