def add_recurring_donation(contact=None, form=None, customer=None, quarantine=False): """ This will add a recurring donation to Salesforce. """ if form["installment_period"] is None: raise Exception("installment_period must have a value") rdo = RDO(contact=contact) rdo.stripe_customer = customer["id"] rdo.campaign_id = form["campaign_id"] rdo.referral_id = form["referral_id"] rdo.description = "Texas Tribune Sustaining Membership" rdo.agreed_to_pay_fees = form["pay_fees_value"] rdo.encouraged_by = form["reason"] rdo.lead_source = "Stripe" rdo.amount = form.get("amount", 0) rdo.installments = None rdo.installment_period = form["installment_period"] rdo.open_ended_status = "Open" rdo.quarantined = quarantine apply_card_details(rdo=rdo, customer=customer) rdo.save() return rdo
def add_blast_subscription(form=None, customer=None): """ Adds a Blast subscription. Blast subscriptions are always recurring. They have two email addresses: one for billing and one for the newsletter subscription. """ form = clean(form) first_name = form["first_name"] last_name = form["last_name"] email = form["subscriber_email"] logging.info("----Getting contact...") contact = Contact.get_or_create(email=email, first_name=first_name, last_name=last_name) logging.info(contact) rdo = RDO(contact=contact) rdo.stripe_customer = customer["id"] rdo.campaign_id = form["campaign_id"] rdo.referral_id = form["referral_id"] rdo.lead_source = "Stripe" rdo.amount = form.get("amount", 0) rdo.agreed_to_pay_fees = form["pay_fees_value"] # Blast specific: rdo.installments = 0 rdo.description = "Blast Subscription" rdo.open_ended_status = "Open" if int(float(rdo.amount)) == 40: rdo.installment_period = "monthly" else: rdo.installment_period = "yearly" now = datetime.now(tz=ZONE).strftime("%Y-%m-%d %I:%M:%S %p %Z") rdo.name = f"{first_name} {last_name} - {now} - The Blast" rdo.type = "The Blast" rdo.billing_email = form["stripeEmail"] rdo.blast_subscription_email = form["subscriber_email"] logging.info("----Saving RDO....") apply_card_details(rdo=rdo, customer=customer) rdo.save() logging.info(rdo) # get opportunities opportunities = rdo.opportunities() today = datetime.now(tz=ZONE).strftime("%Y-%m-%d") opp = [ opportunity for opportunity in opportunities if opportunity.expected_giving_date == today ][0] try: charge(opp) except ChargeException: # TODO should we alert slack? Did not because we had no notifications here before. pass return True
def add_business_rdo(account=None, form=None, customer=None, quarantine=False): """ Adds a recurring business membership to Salesforce. """ if form["installment_period"] is None: raise Exception("installment_period must have a value") year = datetime.now(tz=ZONE).strftime("%Y") rdo = RDO(account=account) rdo.name = f"{year} Business {account.name} Recurring" rdo.type = "Business Membership" rdo.record_type_name = "Business Membership" rdo.stripe_customer = customer["id"] rdo.campaign_id = form["campaign_id"] rdo.referral_id = form["referral_id"] rdo.description = "Texas Tribune Business Membership" rdo.agreed_to_pay_fees = form["pay_fees_value"] rdo.encouraged_by = form["reason"] rdo.lead_source = "Stripe" rdo.amount = form.get("amount", 0) rdo.installments = None rdo.open_ended_status = "Open" rdo.installment_period = form["installment_period"] rdo.quarantined = quarantine apply_card_details(rdo=rdo, customer=customer) rdo.save() return rdo
def add_circle_membership(contact=None, form=None, customer=None): """ This will add Circle membership to Salesforce. """ if form["installment_period"] is None: raise Exception("installment_period must have a value") rdo = RDO(contact=contact) rdo.type = "Giving Circle" rdo.stripe_customer = customer["id"] rdo.campaign_id = form["campaign_id"] rdo.referral_id = form["referral_id"] rdo.description = "Texas Tribune Circle Membership" rdo.agreed_to_pay_fees = form["pay_fees_value"] rdo.encouraged_by = form["reason"] rdo.lead_source = "Stripe" rdo.amount = form.get("amount", 0) installment_period = form["installment_period"] if installment_period == "monthly": rdo.installments = 36 else: rdo.installments = 3 rdo.installment_period = installment_period rdo.open_ended_status = "None" apply_card_details(rdo=rdo, customer=customer) rdo.save() return rdo
def add_recurring_donation(contact=None, form=None, customer=None): """ This will add a recurring donation to Salesforce. Both Circle and regular. """ if form["installment_period"] is None: raise Exception("installment_period must have a value") rdo = RDO(contact=contact) rdo.stripe_customer = customer["id"] rdo.campaign_id = form["campaign_id"] rdo.referral_id = form["referral_id"] rdo.description = "Texas Tribune Sustaining Membership" rdo.agreed_to_pay_fees = form["pay_fees_value"] rdo.encouraged_by = form["reason"] rdo.lead_source = "Stripe" rdo.amount = form.get("amount", 0) installments = form["installments"] installment_period = form["installment_period"] rdo.installments = installments rdo.installment_period = installment_period if (installments == 3 or installments == 36) and (installment_period == "yearly" or installment_period == "monthly"): rdo.type = "Giving Circle" rdo.description = "Texas Tribune Circle Membership" rdo.open_ended_status = "None" else: rdo.open_ended_status = "Open" apply_card_details(rdo=rdo, customer=customer) rdo.save() return rdo
def test__format_slack(): opportunity = Opportunity(sf_connection=sf) opportunity.account_id = "0011700000BpR8PAAV" opportunity.amount = 9 opportunity.encouraged_by = "Because I love the Trib!" opportunity.name = "D C ([email protected])" opportunity.stripe_id = "cus_78MqJSBejMN9gn" opportunity.agreed_to_pay_fees = True opportunity.referral_id = "1234" opportunity.lead_source = "Stripe" opportunity.description = "The Texas Tribune Membership" opportunity.stripe_customer = "cus_78MqJSBejMN9gn" opportunity.campaign_id = "111111111111111" opportunity.campaign_name = "Test Campaign Name" no_campaign = Opportunity(sf_connection=sf) no_campaign.account_id = "0011700000BpR8PAAV" no_campaign.amount = 9 no_campaign.encouraged_by = "Because I love the Trib!" no_campaign.name = "D C ([email protected])" no_campaign.stripe_id = "cus_78MqJSBejMN9gn" no_campaign.agreed_to_pay_fees = True no_campaign.referral_id = "1234" no_campaign.lead_source = "Stripe" no_campaign.description = "The Texas Tribune Membership" no_campaign.stripe_customer = "cus_78MqJSBejMN9gn" rdo = RDO(sf_connection=sf) rdo.referral_id = "1234" rdo.encouraged_by = "Because I love the Trib!" rdo.lead_source = "Stripe" rdo.contact_id = "0031700000BHQzBAAX" rdo.installment_period = "yearly" rdo.stripe_customer = "cus_78MqJSBejMN9gn" rdo.amount = 100 rdo.name = "foo" rdo.installments = 3 rdo.open_ended_status = None rdo.description = "Texas Tribune Circle Membership" rdo.agreed_to_pay_fees = True rdo.type = "Giving Circle" rdo.campaign_id = "000000000000000" rdo.campaign_name = "Recurring Test Campaign Name" contact = Contact(sf_connection=sf) contact.email = "*****@*****.**" contact.first_name = "D" contact.last_name = "C" contact.lead_source = "Stripe" contact.work_email = "*****@*****.**" account = Account(sf_connection=sf) account.name = "Acme Inc." account.website = "http://acme.com" account.shipping_street = "Street" account.shipping_city = "Austin" account.shipping_postalcode = "78701" account.shipping_state = "TX" account.record_type_name = "Household" actual = construct_slack_message(account=account, rdo=rdo, opportunity=None, contact=None) expected = "Acme Inc. pledged $100 [yearly] (Because I love the Trib!) (Recurring Test Campaign Name)" assert actual == expected actual = construct_slack_message(account=None, rdo=rdo, opportunity=None, contact=contact) expected = "D C pledged $100 [yearly] (Because I love the Trib!) (Recurring Test Campaign Name)" assert actual == expected actual = construct_slack_message(account=None, rdo=None, opportunity=opportunity, contact=contact) expected = ( "D C pledged $9 [one-time] (Because I love the Trib!) (Test Campaign Name)" ) assert actual == expected actual = construct_slack_message(account=None, rdo=None, opportunity=no_campaign, contact=contact) expected = "D C pledged $9 [one-time] (Because I love the Trib!) " assert actual == expected