コード例 #1
0
ファイル: promote.py プロジェクト: kevinrose/diggit
def auth_paid_promo(thing, user, pay_id, bid):
    """
    promotes a promotion from 'unpaid' to 'unseen'.  
    
    In the case that bid already exists on the current promotion, the
    previous transaction is voided and repalced with the new bid.
    """
    if thing.promote_status == STATUS.finished:
        return
    elif (thing.promote_status > STATUS.unpaid and
          thing.promote_trans_id):
        # void the existing transaction
        authorize.void_transaction(user, thing.promote_trans_id)

    # create a new transaction and update the bid
    trans_id = authorize.auth_transaction(bid, user, pay_id, thing)
    thing.promote_bid = bid
    
    if trans_id is not None:
        # we won't reset to unseen if already approved and the payment went ok
        promotion_log(thing, "updated payment and/or bid: SUCCESS")
        if trans_id < 0:
            promotion_log(thing, "FREEBIE")
        thing.promote_status = max(thing.promote_status, STATUS.unseen)
        thing.promote_trans_id = trans_id
    else:
        # something bad happend.  
        promotion_log(thing, "updated payment and/or bid: FAILED")    
        thing.promore_status = STATUS.unpaid
        thing.promote_trans_id = 0
    PromoteDates.update_bid(thing)
    # commit last to guarantee consistency
    thing._commit()
    emailer.promo_bid(thing)
    return bool(trans_id)
コード例 #2
0
def auth_campaign(link, campaign, user, pay_id=None, freebie=False):
    """
    Authorizes (but doesn't charge) a bid with authorize.net.
    Args:
    - link: promoted link
    - campaign: campaign to be authorized
    - user: Account obj of the user doing the auth (usually the currently
        logged in user)
    - pay_id: customer payment profile id to use for this transaction. (One
        user can have more than one payment profile if, for instance, they have
        more than one credit card on file.) Set pay_id to -1 for freebies.

    Returns: (True, "") if successful or (False, error_msg) if not. 
    """
    void_campaign(link, campaign, reason='changed_payment')

    if freebie:
        trans_id, reason = authorize.auth_freebie_transaction(
            campaign.bid, user, link, campaign._id)
    else:
        trans_id, reason = authorize.auth_transaction(campaign.bid, user,
                                                      pay_id, link,
                                                      campaign._id)

    if trans_id and not reason:
        text = ('updated payment and/or bid for campaign %s: '
                'SUCCESS (trans_id: %d, amt: %0.2f)' %
                (campaign._id, trans_id, campaign.bid))
        PromotionLog.add(link, text)
        if trans_id < 0:
            PromotionLog.add(link, 'FREEBIE (campaign: %s)' % campaign._id)

        if trans_id:
            if is_finished(link):
                # When a finished promo gets a new paid campaign it doesn't
                # need to go through approval again and is marked accepted
                new_status = PROMOTE_STATUS.accepted
            else:
                new_status = max(PROMOTE_STATUS.unseen, link.promote_status)
        else:
            new_status = max(PROMOTE_STATUS.unpaid, link.promote_status)
        update_promote_status(link, new_status)

        if user and (user._id == link.author_id) and trans_id > 0:
            emailer.promo_bid(link, campaign.bid, campaign.start_date)

    else:
        text = ("updated payment and/or bid for campaign %s: FAILED ('%s')" %
                (campaign._id, reason))
        PromotionLog.add(link, text)
        trans_id = 0

    campaign.trans_id = trans_id
    campaign._commit()

    return bool(trans_id), reason
コード例 #3
0
ファイル: promote.py プロジェクト: freekrai/reddit
def auth_campaign(link, index, user, pay_id):
    """
    for setting up a campaign as a real bid with authorize.net
    """
    with g.make_lock(campaign_lock(link)):
        campaigns = getattr(link, "campaigns", {}).copy()
        if index in campaigns:
            # void any existing campaign
            void_campaign(link, index, user)

            sd, ed, bid, sr, trans_id = campaigns[index]
            # create a new transaction and update the bid
            test = 1 if g.debug else None
            trans_id, reason = authorize.auth_transaction(bid, user,
                                                          pay_id, link,
                                                          index,
                                                          test = test)
            if not reason and trans_id is not None and int(trans_id) != 0:
                promotion_log(link, "updated payment and/or bid for campaign %s: "
                              "SUCCESS (trans_id: %d, amt: %0.2f)"
                              % (index, trans_id, bid))
                if trans_id < 0:
                    promotion_log(link, "FREEBIE (campaign: %s)" % index)

                set_status(link,
                           max(STATUS.unseen if trans_id else STATUS.unpaid,
                               link.promote_status))
                # notify of campaign creation
                # update the query queue
                if user._id == link.author_id and trans_id > 0:
                    emailer.promo_bid(link, bid, sd)
            
            else:
                # something bad happend.
                promotion_log(link, "updated payment and/or bid for campaign %s: FAILED ('%s')" 
                              % (index, reason))
                trans_id = 0

            campaigns[index] = sd, ed, bid, sr, trans_id
            link.campaigns = {}
            link.campaigns = campaigns
            link._commit()

            # dual-write update to campaign Thing
            campaign = PromoCampaign._byID(index)
            if campaign:
                if trans_id > 0:
                    campaign.mark_paid(trans_id)
                elif trans_id < 0:
                    campaign.mark_freebie(trans_id)
                else:
                    campaign.mark_payment_error(reason)
                campaign._commit()

            return bool(trans_id), reason
        return False, ""
コード例 #4
0
ファイル: promote.py プロジェクト: pra85/reddit
def auth_campaign(link, campaign, user, pay_id=None, freebie=False):
    """
    Authorizes (but doesn't charge) a bid with authorize.net.
    Args:
    - link: promoted link
    - campaign: campaign to be authorized
    - user: Account obj of the user doing the auth (usually the currently
        logged in user)
    - pay_id: customer payment profile id to use for this transaction. (One
        user can have more than one payment profile if, for instance, they have
        more than one credit card on file.) Set pay_id to -1 for freebies.

    Returns: (True, "") if successful or (False, error_msg) if not. 
    """
    void_campaign(link, campaign, reason='changed_payment')

    if freebie:
        trans_id, reason = authorize.auth_freebie_transaction(
            campaign.bid, user, link, campaign._id)
    else:
        trans_id, reason = authorize.auth_transaction(
            campaign.bid, user, pay_id, link, campaign._id)

    if trans_id and not reason:
        text = ('updated payment and/or bid for campaign %s: '
                'SUCCESS (trans_id: %d, amt: %0.2f)' % (campaign._id, trans_id,
                                                        campaign.bid))
        PromotionLog.add(link, text)
        if trans_id < 0:
            PromotionLog.add(link, 'FREEBIE (campaign: %s)' % campaign._id)

        if trans_id:
            if is_finished(link):
                # When a finished promo gets a new paid campaign it doesn't
                # need to go through approval again and is marked accepted
                new_status = PROMOTE_STATUS.accepted
            else:
                new_status = max(PROMOTE_STATUS.unseen, link.promote_status)
        else:
            new_status = max(PROMOTE_STATUS.unpaid, link.promote_status)
        update_promote_status(link, new_status)

        if user and (user._id == link.author_id) and trans_id > 0:
            emailer.promo_bid(link, campaign.bid, campaign.start_date)

    else:
        text = ("updated payment and/or bid for campaign %s: FAILED ('%s')"
                % (campaign._id, reason))
        PromotionLog.add(link, text)
        trans_id = 0

    campaign.trans_id = trans_id
    campaign._commit()

    return bool(trans_id), reason
コード例 #5
0
ファイル: promote.py プロジェクト: topwinner/reddit
def auth_campaign(link, campaign_id, user, pay_id):
    """
    Authorizes (but doesn't charge) a bid with authorize.net.
    Args:
    - link: promoted link
    - campaign_id: long id of the campaign on link to be authorized
    - user: Account obj of the user doing the auth (usually the currently
        logged in user)
    - pay_id: customer payment profile id to use for this transaction. (One
        user can have more than one payment profile if, for instance, they have
        more than one credit card on file.) Set pay_id to -1 for freebies.

    Returns: (True, "") if successful or (False, error_msg) if not. 
    """
    try:
        campaign = PromoCampaign._byID(campaign_id, data=True)
    except NotFound:
        g.log.error("Ignoring attempt to auth non-existent campaign: %d" % 
                    campaign_id)
        return False, "Campaign not found."

    void_campaign(link, campaign_id)
    test = 1 if g.debug else None
    trans_id, reason = authorize.auth_transaction(campaign.bid, user, pay_id,
                                                  link, campaign_id, test=test)

    if trans_id and not reason:
        text = ('updated payment and/or bid for campaign %s: '
                'SUCCESS (trans_id: %d, amt: %0.2f)' % (campaign_id, trans_id,
                                                        campaign.bid))
        PromotionLog.add(link, text)
        if trans_id < 0:
            PromotionLog.add(link, 'FREEBIE (campaign: %s)' % campaign_id)

        set_status(link,
                   max(STATUS.unseen if trans_id else STATUS.unpaid,
                       link.promote_status))
        # notify of campaign creation
        # update the query queue
        if user and (user._id == link.author_id) and trans_id > 0:
            emailer.promo_bid(link, campaign.bid, campaign.start_date)
    
    else:
        # something bad happend.
        text = ("updated payment and/or bid for campaign %s: FAILED ('%s')"
                % (campaign_id, reason))
        PromotionLog.add(link, text)
        trans_id = 0

    campaign.trans_id = trans_id
    campaign._commit()

    return bool(trans_id), reason
コード例 #6
0
def auth_campaign(link, campaign, user, pay_id):
    """
    Authorizes (but doesn't charge) a bid with authorize.net.
    Args:
    - link: promoted link
    - campaign: campaign to be authorized
    - user: Account obj of the user doing the auth (usually the currently
        logged in user)
    - pay_id: customer payment profile id to use for this transaction. (One
        user can have more than one payment profile if, for instance, they have
        more than one credit card on file.) Set pay_id to -1 for freebies.

    Returns: (True, "") if successful or (False, error_msg) if not. 
    """
    void_campaign(link, campaign)
    test = 1 if g.debug else None
    trans_id, reason = authorize.auth_transaction(campaign.bid,
                                                  user,
                                                  pay_id,
                                                  link,
                                                  campaign._id,
                                                  test=test)

    if trans_id and not reason:
        text = ('updated payment and/or bid for campaign %s: '
                'SUCCESS (trans_id: %d, amt: %0.2f)' %
                (campaign._id, trans_id, campaign.bid))
        PromotionLog.add(link, text)
        if trans_id < 0:
            PromotionLog.add(link, 'FREEBIE (campaign: %s)' % campaign._id)

        if trans_id:
            new_status = max(PROMOTE_STATUS.unseen, link.promote_status)
        else:
            new_status = max(PROMOTE_STATUS.unpaid, link.promote_status)
        set_promote_status(link, new_status)
        # notify of campaign creation
        # update the query queue
        if user and (user._id == link.author_id) and trans_id > 0:
            emailer.promo_bid(link, campaign.bid, campaign.start_date)

    else:
        # something bad happend.
        text = ("updated payment and/or bid for campaign %s: FAILED ('%s')" %
                (campaign._id, reason))
        PromotionLog.add(link, text)
        trans_id = 0

    campaign.trans_id = trans_id
    campaign._commit()

    return bool(trans_id), reason
コード例 #7
0
ファイル: promote.py プロジェクト: saferadar/coderaid-reddit
def auth_campaign(link, index, user, pay_id):
    """
    for setting up a campaign as a real bid with authorize.net
    """
    with g.make_lock(campaign_lock(link)):
        campaigns = getattr(link, "campaigns", {}).copy()
        if index in campaigns:
            # void any existing campaign
            void_campaign(link, index, user)

            sd, ed, bid, sr, trans_id = campaigns[index]
            # create a new transaction and update the bid
            test = 1 if g.debug else None
            trans_id, reason = authorize.auth_transaction(bid,
                                                          user,
                                                          pay_id,
                                                          link,
                                                          index,
                                                          test=test)
            if not reason and trans_id is not None and int(trans_id) != 0:
                promotion_log(
                    link, "updated payment and/or bid: "
                    "SUCCESS (id: %s)" % trans_id)
                if trans_id < 0:
                    promotion_log(link, "FREEBIE")

                set_status(
                    link,
                    max(STATUS.unseen if trans_id else STATUS.unpaid,
                        link.promote_status))
                # notify of campaign creation
                # update the query queue
                if user._id == link.author_id and trans_id > 0:
                    emailer.promo_bid(link, bid, sd)

            else:
                # something bad happend.
                promotion_log(
                    link, "updated payment and/or bid: FAILED ('%s')" % reason)
                trans_id = 0

            campaigns[index] = sd, ed, bid, sr, trans_id
            link.campaigns = {}
            link.campaigns = campaigns
            link._commit()

            return bool(trans_id), reason
        return False, ""
コード例 #8
0
ファイル: promote.py プロジェクト: Kingofhearts102/reddit
def auth_campaign(link, campaign, user, pay_id):
    """
    Authorizes (but doesn't charge) a bid with authorize.net.
    Args:
    - link: promoted link
    - campaign: campaign to be authorized
    - user: Account obj of the user doing the auth (usually the currently
        logged in user)
    - pay_id: customer payment profile id to use for this transaction. (One
        user can have more than one payment profile if, for instance, they have
        more than one credit card on file.) Set pay_id to -1 for freebies.

    Returns: (True, "") if successful or (False, error_msg) if not. 
    """
    void_campaign(link, campaign)
    test = 1 if g.debug else None
    trans_id, reason = authorize.auth_transaction(campaign.bid, user, pay_id, link, campaign._id, test=test)

    if trans_id and not reason:
        text = "updated payment and/or bid for campaign %s: " "SUCCESS (trans_id: %d, amt: %0.2f)" % (
            campaign._id,
            trans_id,
            campaign.bid,
        )
        PromotionLog.add(link, text)
        if trans_id < 0:
            PromotionLog.add(link, "FREEBIE (campaign: %s)" % campaign._id)

        if trans_id:
            new_status = max(PROMOTE_STATUS.unseen, link.promote_status)
        else:
            new_status = max(PROMOTE_STATUS.unpaid, link.promote_status)
        set_promote_status(link, new_status)
        # notify of campaign creation
        # update the query queue
        if user and (user._id == link.author_id) and trans_id > 0:
            emailer.promo_bid(link, campaign.bid, campaign.start_date)

    else:
        # something bad happend.
        text = "updated payment and/or bid for campaign %s: FAILED ('%s')" % (campaign._id, reason)
        PromotionLog.add(link, text)
        trans_id = 0

    campaign.trans_id = trans_id
    campaign._commit()

    return bool(trans_id), reason
コード例 #9
0
ファイル: promote.py プロジェクト: jianbin91/reddit
def auth_campaign(link, campaign_id, user, pay_id):
    """
    Authorizes (but doesn't charge) a bid with authorize.net.
    Args:
    - link: promoted link
    - campaign_id: long id of the campaign on link to be authorized
    - user: Account obj of the user doing the auth (usually the currently
        logged in user)
    - pay_id: customer payment profile id to use for this transaction. (One
        user can have more than one payment profile if, for instance, they have
        more than one credit card on file.) Set pay_id to -1 for freebies.

    Returns: (True, "") if successful or (False, error_msg) if not. 
    """
    try:
        campaign = PromoCampaign._byID(campaign_id, data=True)
    except NotFound:
        g.log.error("Ignoring attempt to auth non-existent campaign: %d" % campaign_id)
        return False, "Campaign not found."

    void_campaign(link, campaign_id)
    test = 1 if g.debug else None
    trans_id, reason = authorize.auth_transaction(campaign.bid, user, pay_id, link, campaign_id, test=test)

    if trans_id and not reason:
        promotion_log(
            link,
            "updated payment and/or bid for campaign %s: "
            "SUCCESS (trans_id: %d, amt: %0.2f)" % (campaign_id, trans_id, campaign.bid),
        )
        if trans_id < 0:
            promotion_log(link, "FREEBIE (campaign: %s)" % campaign_id)

        set_status(link, max(STATUS.unseen if trans_id else STATUS.unpaid, link.promote_status))
        # notify of campaign creation
        # update the query queue
        if user and (user._id == link.author_id) and trans_id > 0:
            emailer.promo_bid(link, campaign.bid, campaign.start_date)

    else:
        # something bad happend.
        promotion_log(link, "updated payment and/or bid for campaign %s: FAILED ('%s')" % (campaign_id, reason))
        trans_id = 0

    campaign.trans_id = trans_id
    campaign._commit()

    # dual-write update to link attribute in case we need to roll back
    with g.make_lock("promo_campaign", campaign_lock(link)):
        campaigns = getattr(link, "campaigns", {}).copy()
        if campaign_id in campaigns:
            campaigns[campaign_id] = (
                campaign.start_date,
                campaign.end_date,
                campaign.bid,
                campaign.sr_name,
                campaign.trans_id,
            )
            link.campaigns = {}
            link.campaigns = campaigns
            link._commit()

    return bool(trans_id), reason
コード例 #10
0
ファイル: promote.py プロジェクト: nod3x/reddit
def auth_campaign(link, campaign_id, user, pay_id):
    """
    Authorizes (but doesn't charge) a bid with authorize.net.
    Args:
    - link: promoted link
    - campaign_id: long id of the campaign on link to be authorized
    - user: Account obj of the user doing the auth (usually the currently
        logged in user)
    - pay_id: customer payment profile id to use for this transaction. (One
        user can have more than one payment profile if, for instance, they have
        more than one credit card on file.) Set pay_id to -1 for freebies.

    Returns: (True, "") if successful or (False, error_msg) if not. 
    """
    try:
        campaign = PromoCampaign._byID(campaign_id, data=True)
    except NotFound:
        g.log.error("Ignoring attempt to auth non-existent campaign: %d" %
                    campaign_id)
        return False, "Campaign not found."

    void_campaign(link, campaign_id)
    test = 1 if g.debug else None
    trans_id, reason = authorize.auth_transaction(campaign.bid,
                                                  user,
                                                  pay_id,
                                                  link,
                                                  campaign_id,
                                                  test=test)

    if trans_id and not reason:
        promotion_log(
            link, "updated payment and/or bid for campaign %s: "
            "SUCCESS (trans_id: %d, amt: %0.2f)" %
            (campaign_id, trans_id, campaign.bid))
        if trans_id < 0:
            promotion_log(link, "FREEBIE (campaign: %s)" % campaign_id)

        set_status(
            link,
            max(STATUS.unseen if trans_id else STATUS.unpaid,
                link.promote_status))
        # notify of campaign creation
        # update the query queue
        if user and (user._id == link.author_id) and trans_id > 0:
            emailer.promo_bid(link, campaign.bid, campaign.start_date)

    else:
        # something bad happend.
        promotion_log(
            link, "updated payment and/or bid for campaign %s: FAILED ('%s')" %
            (campaign_id, reason))
        trans_id = 0

    campaign.trans_id = trans_id
    campaign._commit()

    # dual-write update to link attribute in case we need to roll back
    with g.make_lock("promo_campaign", campaign_lock(link)):
        campaigns = getattr(link, "campaigns", {}).copy()
        if campaign_id in campaigns:
            campaigns[campaign_id] = (campaign.start_date, campaign.end_date,
                                      campaign.bid, campaign.sr_name,
                                      campaign.trans_id)
            link.campaigns = {}
            link.campaigns = campaigns
            link._commit()

    return bool(trans_id), reason