Exemplo n.º 1
0
def record_fxa_concerts_rsvp(email, is_firefox, campaign_id):
    sfmc.add_row('FxAccounts_Concert_RSVP', {
        'Email': email,
        'Firefox': is_firefox,
        'Campaign_ID': campaign_id,
        'RSVP_Time': gmttime(),
    })
Exemplo n.º 2
0
def process_donation_event(data):
    """Process a followup event on a donation"""
    etype = data['event_type']
    txn_id = data['transaction_id']
    status = data.get('status')
    statsd.incr('news.tasks.process_donation_event.{}'.format(etype))
    if status:
        statsd.incr('news.tasks.process_donation_event.{}.{}'.format(etype, status))

    if etype.startswith('charge.dispute.'):
        if status not in ['charge_refunded', 'won', 'lost']:
            # only care about the above statuses
            statsd.incr('news.tasks.process_donation_event.{}.IGNORED'.format(etype))
            return
    elif etype == 'charge.refunded':
        if status not in ['succeeded', 'failed', 'cancelled']:
            # don't care about pending statuses
            statsd.incr('news.tasks.process_donation_event.{}.IGNORED'.format(etype))
            return

    if 'reason' in data:
        reason_lost = data['reason']
    else:
        reason_lost = data['failure_code']

    try:
        # will raise a SalesforceMalformedRequest if not found
        sfdc.opportunity.update('PMT_Transaction_ID__c/{}'.format(txn_id), {
            'PMT_Type_Lost__c': etype,
            'PMT_Reason_Lost__c': reason_lost,
            'StageName': 'Closed Lost',
        })
    except sfapi.SalesforceMalformedRequest as e:
        # we don't know about this tx_id. Let someone know.
        do_notify = cache.add('donate-notify-{}'.format(txn_id), 1, 86400)
        if do_notify and settings.DONATE_UPDATE_FAIL_DE:
            sfmc.add_row(settings.DONATE_UPDATE_FAIL_DE, {
                'PMT_Transaction_ID__c': txn_id,
                'Payment_Type__c': etype,
                'PMT_Reason_Lost__c': reason_lost,
                'Error_Text': str(e)[:4000],
                'Date': gmttime(),
            })

        if do_notify and settings.DONATE_NOTIFY_EMAIL:
            # don't notify about a transaction more than once per day
            first_mail = cache.add('donate-notify-{}'.format(txn_id), 1, 86400)
            if first_mail:
                body = render_to_string('news/donation_notify_email.txt', {
                    'txn_id': txn_id,
                    'type_lost': etype,
                    'reason_lost': reason_lost,
                    'server_name': settings.STATSD_PREFIX,
                })
                send_mail('Donation Record Not Found', body,
                          '*****@*****.**', [settings.DONATE_NOTIFY_EMAIL])

        # retry
        raise
Exemplo n.º 3
0
def process_donation_event(data):
    """Process a followup event on a donation"""
    etype = data['event_type']
    txn_id = data['transaction_id']
    status = data.get('status')
    statsd.incr('news.tasks.process_donation_event.{}'.format(etype))
    if status:
        statsd.incr('news.tasks.process_donation_event.{}.{}'.format(etype, status))

    if etype.startswith('charge.dispute.'):
        if status not in ['charge_refunded', 'won', 'lost']:
            # only care about the above statuses
            statsd.incr('news.tasks.process_donation_event.{}.IGNORED'.format(etype))
            return
    elif etype == 'charge.refunded':
        if status not in ['succeeded', 'failed', 'cancelled']:
            # don't care about pending statuses
            statsd.incr('news.tasks.process_donation_event.{}.IGNORED'.format(etype))
            return

    if 'reason' in data:
        reason_lost = data['reason']
    else:
        reason_lost = data['failure_code']

    try:
        # will raise a SalesforceMalformedRequest if not found
        sfdc.opportunity.update('PMT_Transaction_ID__c/{}'.format(txn_id), {
            'PMT_Type_Lost__c': etype,
            'PMT_Reason_Lost__c': reason_lost,
            'StageName': 'Closed Lost',
        })
    except sfapi.SalesforceMalformedRequest as e:
        # we don't know about this tx_id. Let someone know.
        do_notify = cache.add('donate-notify-{}'.format(txn_id), 1, 86400)
        if do_notify and settings.DONATE_UPDATE_FAIL_DE:
            sfmc.add_row(settings.DONATE_UPDATE_FAIL_DE, {
                'PMT_Transaction_ID__c': txn_id,
                'Payment_Type__c': etype,
                'PMT_Reason_Lost__c': reason_lost,
                'Error_Text': str(e)[:4000],
                'Date': gmttime(),
            })

        if do_notify and settings.DONATE_NOTIFY_EMAIL:
            # don't notify about a transaction more than once per day
            first_mail = cache.add('donate-notify-{}'.format(txn_id), 1, 86400)
            if first_mail:
                body = render_to_string('news/donation_notify_email.txt', {
                    'txn_id': txn_id,
                    'type_lost': etype,
                    'reason_lost': reason_lost,
                    'server_name': settings.STATSD_PREFIX,
                })
                send_mail('Donation Record Not Found', body,
                          '*****@*****.**', [settings.DONATE_NOTIFY_EMAIL])

        # retry
        raise
Exemplo n.º 4
0
def record_fxa_concerts_rsvp(email, is_firefox, campaign_id):
    sfmc.add_row(
        'FxAccounts_Concert_RSVP', {
            'Email': email,
            'Firefox': is_firefox,
            'Campaign_ID': campaign_id,
            'RSVP_Time': gmttime(),
        })
Exemplo n.º 5
0
def record_fxa_concerts_rsvp(email, is_firefox, campaign_id):
    sfmc.add_row(
        "FxAccounts_Concert_RSVP",
        {
            "Email": email,
            "Firefox": is_firefox,
            "Campaign_ID": campaign_id,
            "RSVP_Time": gmttime(),
        },
    )
Exemplo n.º 6
0
def record_source_url(email, source_url, newsletter_id):
    if not source_url:
        source_url = '__NONE__'
    else:
        source_url = source_url[:1000]

    sfmc.add_row('NEWSLETTER_SOURCE_URLS', {
        'Email': email,
        'Signup_Source_URL__c': source_url,
        'Newsletter_Field_Name': newsletter_id,
        'Newsletter_Date': gmttime(),
    })
Exemplo n.º 7
0
def record_source_url(email, source_url, newsletter_id):
    if not source_url:
        source_url = '__NONE__'
    else:
        source_url = source_url[:1000]

    sfmc.add_row('NEWSLETTER_SOURCE_URLS', {
        'Email': email,
        'Signup_Source_URL__c': source_url,
        'Newsletter_Field_Name': newsletter_id,
        'Newsletter_Date': gmttime(),
    })
Exemplo n.º 8
0
def record_source_url(email, source_url, newsletter_id):
    if not source_url:
        source_url = "__NONE__"
    else:
        source_url = source_url[:1000]

    sfmc.add_row(
        "NEWSLETTER_SOURCE_URLS",
        {
            "Email": email,
            "Signup_Source_URL__c": source_url,
            "Newsletter_Field_Name": newsletter_id,
            "Newsletter_Date": gmttime(),
        },
    )
Exemplo n.º 9
0
def add_sms_user_optin(mobile_number):
    record = {'Phone': mobile_number, 'SubscriberKey': mobile_number}
    sfmc.add_row('Mobile_Subscribers', record)
Exemplo n.º 10
0
def add_sms_user_optin(mobile_number):
    record = {'Phone': mobile_number, 'SubscriberKey': mobile_number}
    sfmc.add_row('Mobile_Subscribers', record)
Exemplo n.º 11
0
def process_donation_event(data):
    """Process a followup event on a donation"""
    etype = data["event_type"]
    txn_id = data["transaction_id"]
    status = data.get("status")
    statsd.incr("news.tasks.process_donation_event.{}".format(etype))
    if status:
        statsd.incr("news.tasks.process_donation_event.{}.{}".format(etype, status))

    if etype.startswith("charge.dispute."):
        if status not in ["charge_refunded", "won", "lost"]:
            # only care about the above statuses
            statsd.incr("news.tasks.process_donation_event.{}.IGNORED".format(etype))
            return
    elif etype == "charge.refunded":
        if status not in ["succeeded", "failed", "cancelled"]:
            # don't care about pending statuses
            statsd.incr("news.tasks.process_donation_event.{}.IGNORED".format(etype))
            return

    if "reason" in data:
        reason_lost = data["reason"]
    else:
        reason_lost = data["failure_code"]

    try:
        # will raise a SalesforceMalformedRequest if not found
        sfdc.opportunity.update(
            "PMT_Transaction_ID__c/{}".format(txn_id),
            {
                "PMT_Type_Lost__c": etype,
                "PMT_Reason_Lost__c": reason_lost,
                "StageName": "Closed Lost",
            },
        )
    except sfapi.SalesforceMalformedRequest as e:
        statsd.incr("news.tasks.process_donation_event.not_found")
        with sentry_sdk.configure_scope() as scope:
            scope.set_tag("action", "ignored")
            sentry_sdk.capture_exception()
        # we don't know about this tx_id. Let someone know.
        do_notify = cache.add("donate-notify-{}".format(txn_id), 1, 86400)
        if do_notify and settings.DONATE_UPDATE_FAIL_DE:
            sfmc.add_row(
                settings.DONATE_UPDATE_FAIL_DE,
                {
                    "PMT_Transaction_ID__c": txn_id,
                    "Payment_Type__c": etype,
                    "PMT_Reason_Lost__c": reason_lost,
                    "Error_Text": str(e)[:4000],
                    "Date": gmttime(),
                },
            )

        if do_notify and settings.DONATE_NOTIFY_EMAIL:
            # don't notify about a transaction more than once per day
            first_mail = cache.add("donate-notify-{}".format(txn_id), 1, 86400)
            if first_mail:
                body = render_to_string(
                    "news/donation_notify_email.txt",
                    {
                        "txn_id": txn_id,
                        "type_lost": etype,
                        "reason_lost": reason_lost,
                        "server_name": settings.STATSD_PREFIX,
                    },
                )
                send_mail(
                    "Donation Record Not Found",
                    body,
                    "*****@*****.**",
                    [settings.DONATE_NOTIFY_EMAIL],
                )
Exemplo n.º 12
0
def add_sms_user_optin(mobile_number):
    record = {"Phone": mobile_number, "SubscriberKey": mobile_number}
    sfmc.add_row("Mobile_Subscribers", record)