Example #1
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 #2
0
def auth_transaction(amount, user, payid, thing, test = None):
    # use negative pay_ids to identify freebies, coupons, or anything
    # that doesn't require a CC.
    if payid < 0:
        trans_id = -thing._id
        # update previous freebie transactions if we can
        try:
            bid = Bid.one(thing_id = thing._id,
                          pay_id = payid)
            bid.bid = amount
            bid.auth()
        except NotFound:
            bid = Bid._new(trans_id, user, payid, thing._id, amount)
        return bid.transaction

    elif int(payid) in PayID.get_ids(user):
        order = Order(invoiceNumber = "%dT%d" % (user._id, thing._id))
        success, res = _make_transaction(ProfileTransAuthOnly,
                                         amount, user, payid,
                                         order = order, test = test)
        if success:
            Bid._new(res.trans_id, user, payid, thing._id, amount)
            return res.trans_id
        elif res is None:
            # we are in test mode!
            return auth_transaction(amount, user, -1, thing, test = test)
        # duplicate transaction, which is bad, but not horrible.  Log
        # the transaction id, creating a new bid if necessary. 
        elif (res.response_code, res.response_reason_code) == (3,11):
            try:
                Bid.one(res.trans_id)
            except NotFound:
                Bid._new(res.trans_id, user, payid, thing._id, amount)
            return res.trans_id
Example #3
0
def auth_transaction(amount, user, payment_method_id, link, campaign_id):
    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)

    try:
        transaction_id = api.create_authorization_hold(profile_id,
                                                       payment_method_id,
                                                       amount, invoice,
                                                       request.ip)
    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:
        return None, e.message

    bid = Bid._new(transaction_id, user, payment_method_id, link._id, amount,
                   campaign_id)
    return transaction_id, None
Example #4
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 #5
0
def auth_transaction(amount, user, payment_method_id, link, campaign_id):
    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)

    try:
        transaction_id = api.create_authorization_hold(
            profile_id, payment_method_id, amount, invoice, request.ip)
    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:
        return None, e.message

    bid = Bid._new(transaction_id, user, payment_method_id, link._id, amount,
                   campaign_id)
    return transaction_id, None
Example #6
0
def auth_transaction(amount, user, payid, thing, campaign, test=None):
    # use negative pay_ids to identify freebies, coupons, or anything
    # that doesn't require a CC.
    if payid < 0:
        trans_id = -thing._id
        # update previous freebie transactions if we can
        try:
            bid = Bid.one(thing_id=thing._id,
                          transaction=trans_id,
                          campaign=campaign)
            bid.bid = amount
            bid.auth()
        except NotFound:
            bid = Bid._new(trans_id, user, payid, thing._id, amount, campaign)
        return bid.transaction, ""

    elif int(payid) in PayID.get_ids(user):
        order = Order(invoiceNumber="T%dC%d" % (thing._id, campaign))
        success, res = _make_transaction(ProfileTransAuthOnly,
                                         amount,
                                         user,
                                         payid,
                                         order=order,
                                         test=test)
        if success:
            if test:
                return auth_transaction(amount,
                                        user,
                                        -1,
                                        thing,
                                        campaign,
                                        test=test)
            else:
                Bid._new(res.trans_id, user, payid, thing._id, amount,
                         campaign)
                return res.trans_id, ""
        elif res is None:
            # we are in test mode!
            return auth_transaction(amount, user, -1, thing, test=test)
        # duplicate transaction, which is bad, but not horrible.  Log
        # the transaction id, creating a new bid if necessary.
        elif res.trans_id and (res.response_code,
                               res.response_reason_code) == (3, 11):
            g.log.error("Authorize.net duplicate trans %d on campaign %d" %
                        (res.trans_id, campaign))
            try:
                Bid.one(res.trans_id, campaign=campaign)
            except NotFound:
                Bid._new(res.trans_id, user, payid, thing._id, amount,
                         campaign)
        return res.trans_id, res.response_reason_text
Example #7
0
def refund_transaction(amount, user, trans_id, test=None):
    bid = Bid.one(trans_id)
    if trans_id > 0:
        # create a new bid to identify the refund
        success, res = _make_transaction(ProfileTransRefund, amount, user, bid.pay_id, trans_id=trans_id, test=test)
        if success:
            bid = Bid._new(res.trans_id, user, -1, bid.thing_id, amount)
            bid.refund()
            return bool(res.trans_id)
Example #8
0
def auth_freebie_transaction(amount, user, link, campaign_id):
    transaction_id = -link._id

    try:
        # attempt to update existing freebie transaction
        bid = Bid.one(thing_id=link._id, transaction=transaction_id, campaign=campaign_id)
    except NotFound:
        bid = Bid._new(transaction_id, user, FREEBIE_PAYMENT_METHOD_ID, link._id, amount, campaign_id)
    else:
        bid.bid = amount
        bid.auth()

    return transaction_id, ""
Example #9
0
def auth_transaction(amount, user, payid, thing, campaign):
    # use negative pay_ids to identify freebies, coupons, or anything
    # that doesn't require a CC.
    if payid < 0:
        trans_id = -thing._id
        # update previous freebie transactions if we can
        try:
            bid = Bid.one(thing_id=thing._id,
                          transaction=trans_id,
                          campaign=campaign)
            bid.bid = amount
            bid.auth()
        except NotFound:
            bid = Bid._new(trans_id, user, payid, thing._id, amount, campaign)
        return bid.transaction, ""

    elif int(payid) in PayID.get_ids(user):
        order = Order(invoiceNumber="T%dC%d" % (thing._id, campaign))
        success, res = _make_transaction(
            ProfileTransAuthOnly, amount, user, payid, order=order,
            include_request_ip=True)

        if success:
            Bid._new(res.trans_id, user, payid, thing._id, amount, campaign)
            return res.trans_id, ""

        elif (res.trans_id and
              (res.response_code, res.response_reason_code) == (3, 11)):
            # duplicate transaction, which is bad, but not horrible.  Log
            # the transaction id, creating a new bid if necessary.
            g.log.error("Authorize.net duplicate trans %d on campaign %d" % 
                        (res.trans_id, campaign))
            try:
                Bid.one(res.trans_id, campaign=campaign)
            except NotFound:
                Bid._new(res.trans_id, user, payid, thing._id, amount, campaign)

        return res.trans_id, res.response_reason_text
Example #10
0
def auth_freebie_transaction(amount, user, link, campaign_id):
    transaction_id = -link._id

    try:
        # attempt to update existing freebie transaction
        bid = Bid.one(thing_id=link._id,
                      transaction=transaction_id,
                      campaign=campaign_id)
    except NotFound:
        bid = Bid._new(transaction_id, user, FREEBIE_PAYMENT_METHOD_ID,
                       link._id, amount, campaign_id)
    else:
        bid.bid = amount
        bid.auth()

    return transaction_id, ""