Example #1
0
def refund_transaction(user, campaign_id, link_id, amount, transaction_id,
                       references):
    bid = Bid.one(transaction=transaction_id, campaign=campaign_id)
    if transaction_id < 0:
        bid.refund(amount)
        return True, None

    references['pay_id'] = bid.pay_id

    profile_id = CustomerID.get_id(user._id)
    try:
        authorize_response = api.refund_transaction(
            customer_id=profile_id,
            payment_profile_id=bid.pay_id,
            amount=amount,
            transaction_id=transaction_id,
        )
        AuthorizeTransaction._new(authorize_response, **references)
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return False, e.message

    bid.refund(amount)
    return True, None
Example #2
0
def charge_transaction(user, campaign_id, link_id, transaction_id, references):
    bid = Bid.one(transaction=transaction_id, campaign=campaign_id)
    if bid.is_charged():
        return True, None

    if transaction_id < 0:
        bid.charged()
        return True, None

    references['pay_id'] = bid.pay_id

    profile_id = CustomerID.get_id(user._id)
    try:
        authorize_response = api.capture_authorization_hold(
            customer_id=profile_id,
            payment_profile_id=bid.pay_id,
            amount=bid.bid,
            transaction_id=transaction_id,
        )
        AuthorizeTransaction._new(authorize_response, **references)
    except api.AuthorizationHoldNotFound:
        # authorization hold has expired
        bid.void()
        return False, api.TRANSACTION_NOT_FOUND
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return False, e.message

    bid.charged()
    return True, None
Example #3
0
def auth_transaction(user, campaign_id, link_id, amount, payment_method_id,
                     references):
    if payment_method_id not in PayID.get_ids(user._id):
        return None, "invalid payment method"

    profile_id = CustomerID.get_id(user._id)
    invoice = "T%dC%d" % (link_id, campaign_id)

    references['pay_id'] = payment_method_id

    try:
        authorize_response = api.create_authorization_hold(
            profile_id, payment_method_id, amount, invoice, request.ip)
        AuthorizeTransaction._new(authorize_response, **references)
    except api.DuplicateTransactionError as e:
        transaction_id = e.transaction_id
        try:
            bid = Bid.one(transaction_id, campaign=campaign_id)
        except NotFound:
            bid = Bid._new(transaction_id, user, payment_method_id, link_id,
                           amount, campaign_id)
        g.log.error("%s on campaign %d" % (e.message, campaign_id))
        return transaction_id, None
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return None, e.message

    bid = Bid._new(authorize_response.trans_id, user, payment_method_id,
                   link_id, amount, campaign_id)
    return authorize_response.trans_id, None
Example #4
0
def charge_transaction(user, campaign_id, link_id, transaction_id, references):
    bid = Bid.one(transaction=transaction_id, campaign=campaign_id)
    if bid.is_charged():
        return True, None

    if transaction_id < 0:
        bid.charged()
        return True, None

    references["pay_id"] = bid.pay_id

    profile_id = CustomerID.get_id(user._id)
    try:
        authorize_response = api.capture_authorization_hold(
            customer_id=profile_id, payment_profile_id=bid.pay_id, amount=bid.bid, transaction_id=transaction_id
        )
        AuthorizeTransaction._new(authorize_response, **references)
    except api.AuthorizationHoldNotFound:
        # authorization hold has expired
        bid.void()
        return False, api.TRANSACTION_NOT_FOUND
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return False, e.message

    bid.charged()
    return True, None
Example #5
0
def auth_transaction(user, campaign_id, link_id, amount, payment_method_id, references):
    if payment_method_id not in PayID.get_ids(user._id):
        return None, "invalid payment method"

    profile_id = CustomerID.get_id(user._id)
    invoice = "T%dC%d" % (link_id, campaign_id)

    references["pay_id"] = payment_method_id

    try:
        authorize_response = api.create_authorization_hold(profile_id, payment_method_id, amount, invoice, request.ip)
        AuthorizeTransaction._new(authorize_response, **references)
    except api.DuplicateTransactionError as e:
        transaction_id = e.transaction_id
        try:
            bid = Bid.one(transaction_id, campaign=campaign_id)
        except NotFound:
            bid = Bid._new(transaction_id, user, payment_method_id, link_id, amount, campaign_id)
        g.log.error("%s on campaign %d" % (e.message, campaign_id))
        return transaction_id, None
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return None, e.message

    bid = Bid._new(authorize_response.trans_id, user, payment_method_id, link_id, amount, campaign_id)
    return authorize_response.trans_id, None
Example #6
0
def void_transaction(user, campaign_id, link_id, transaction_id, references):
    bid = Bid.one(transaction=transaction_id, campaign=campaign_id)

    if transaction_id <= 0:
        bid.void()
        return True, None

    references["pay_id"] = bid.pay_id

    profile_id = CustomerID.get_id(user._id)
    try:
        authorize_response = api.void_authorization_hold(profile_id, bid.pay_id, transaction_id)
        AuthorizeTransaction._new(authorize_response, **references)
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return False, e.message

    bid.void()
    return True, None
Example #7
0
def void_transaction(user, campaign_id, link_id, transaction_id, references):
    bid = Bid.one(transaction=transaction_id, campaign=campaign_id)

    if transaction_id <= 0:
        bid.void()
        return True, None

    references['pay_id'] = bid.pay_id

    profile_id = CustomerID.get_id(user._id)
    try:
        authorize_response = api.void_authorization_hold(
            profile_id, bid.pay_id, transaction_id)
        AuthorizeTransaction._new(authorize_response, **references)
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return False, e.message

    bid.void()
    return True, None
Example #8
0
def refund_transaction(user, campaign_id, link_id, amount, transaction_id, references):
    bid = Bid.one(transaction=transaction_id, campaign=campaign_id)
    if transaction_id < 0:
        bid.refund(amount)
        return True, None

    references["pay_id"] = bid.pay_id

    profile_id = CustomerID.get_id(user._id)
    try:
        authorize_response = api.refund_transaction(
            customer_id=profile_id, payment_profile_id=bid.pay_id, amount=amount, transaction_id=transaction_id
        )
        AuthorizeTransaction._new(authorize_response, **references)
    except api.TransactionError as e:
        authorize_response = e.authorize_response
        AuthorizeTransaction._new(authorize_response, **references)
        return False, e.message

    bid.refund(amount)
    return True, None