def add_opportunity(contact=None, form=None, customer=None, quarantine=False): """ This will add a single donation to Salesforce. """ logging.info("----Adding opportunity...") opportunity = Opportunity(contact=contact) opportunity.amount = form.get("amount", 0) opportunity.stripe_customer = customer["id"] opportunity.campaign_id = form["campaign_id"] opportunity.referral_id = form["referral_id"] opportunity.description = "Texas Tribune Membership" opportunity.agreed_to_pay_fees = form["pay_fees_value"] opportunity.encouraged_by = form["reason"] opportunity.lead_source = "Stripe" opportunity.quarantined = quarantine customer = stripe.Customer.retrieve(customer["id"]) card = customer.sources.retrieve(customer.sources.data[0].id) year = card.exp_year month = card.exp_month day = calendar.monthrange(year, month)[1] opportunity.stripe_card_expiration = f"{year}-{month:02d}-{day:02d}" opportunity.stripe_card_brand = card.brand opportunity.stripe_card_last_4 = card.last4 opportunity.save() return opportunity
def test__format_opportunity(): opportunity = Opportunity(sf_connection=sf) opportunity.account_id = "0011700000BpR8PAAV" opportunity.amount = 9 opportunity.net_amount = 8 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" response = opportunity._format() expected = { "AccountId": "0011700000BpR8PAAV", "CampaignId": None, "Amount": "9.00", "CloseDate": today, "Encouraged_to_contribute_by__c": "Because I love the Trib!", "LeadSource": "Stripe", "Name": "D C ([email protected])", "RecordType": { "Name": "Membership" }, "StageName": "Pledged", "Stripe_Customer_ID__c": "cus_78MqJSBejMN9gn", "Referral_ID__c": "1234", "Description": "The Texas Tribune Membership", "Stripe_Agreed_to_pay_fees__c": True, "Type": "Single", "Stripe_Card__c": None, "Stripe_Transaction_ID__c": None, "npsp__Closed_Lost_Reason__c": None, "Stripe_Card_Brand__c": None, "Stripe_Card_Expiration__c": None, "Stripe_Card_Last_4__c": None, "Amazon_Order_Id__c": None, "Net_Amount__c": "8.00", "Donor_Selected_Amount__c": 0, "Quarantined__c": False, } assert response == expected
def add_business_opportunity(account=None, form=None, customer=None): """ Adds a single business membership to Salesforce. """ year = datetime.now(tz=ZONE).strftime("%Y") opportunity = Opportunity(account=account) opportunity.record_type_name = "Business Membership" opportunity.name = f"{year} Business {account.name} One time" opportunity.amount = form.get("amount", 0) opportunity.stripe_customer = customer["id"] opportunity.campaign_id = form["campaign_id"] opportunity.referral_id = form["referral_id"] opportunity.description = "Texas Tribune Business Membership" opportunity.agreed_to_pay_fees = form["pay_fees_value"] opportunity.encouraged_by = form["reason"] opportunity.lead_source = "Stripe" opportunity.save() return opportunity
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" 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" 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!)" 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!)" 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!)" assert actual == expected