Skip to content

Commit

Permalink
Fix bugs, prep for launch
Browse files Browse the repository at this point in the history
  • Loading branch information
schavery committed Feb 4, 2016
1 parent aaa2a9c commit c805d3c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
31 changes: 23 additions & 8 deletions AsyncSalesforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ private function get_donations() {
$query = 'SELECT
(SELECT
Id, Amount__c, Donation_Date__c,
Stripe_Status__c, Stripe_Id__c, In_Honor_Of__c
Stripe_Status__c, Stripe_Id__c,
In_Honor_Of__c, Referred_by__c
FROM Donations__r)
FROM
Contact
Expand Down Expand Up @@ -281,7 +282,8 @@ private function update_or_create_donation(&$info) {
}

if(strlen($dli['Referred_by__c']) > 0) {
$info['referral'] = $dli['Referred_by__c'];
$info['referral'] = sprintf("Referred by: %s\n",
$dli['Referred_by__c']);
}

} else {
Expand All @@ -300,10 +302,16 @@ private function update_or_create_donation(&$info) {
if(strlen($dli['In_Honor_Of__c']) > 0) {
$info['honor'] = sprintf("In Honor of: %s\n",
$dli['In_Honor_Of__c']);
} else {
// assuming that the referrer wont be set if there's
// no honor
$this->find_previous_donation_extras($info);
}

if(empty($info['honor'])) {
$this->find_previous_donation_honor($info);

if(strlen($dli['Referred_by__c']) > 0) {
$info['referral'] = sprintf("Referred by: %s\n",
$dli['Referred_by__c']);
}

$this->update_donation($info, $dli);
Expand All @@ -324,7 +332,7 @@ private function update_or_create_donation(&$info) {
}


private function find_previous_donation_honor(&$info) {
private function find_previous_donation_extras(&$info) {

if(isset($this->subscription)) {
$stripe = \SDF::make_stripe();
Expand All @@ -343,6 +351,15 @@ private function find_previous_donation_honor(&$info) {
if(strcmp($old_subscription, $this->subscription) === 0) {
$info['honor'] = sprintf("In Honor of: %s\n",
$dli['In_Honor_Of__c']);

// we should be pretty confident if this is the donation
// that was the first in the series, whatever referrer
// info was set there would be accurate
if(strlen($dli['Referred_by__c']) > 0) {
$info['referral'] = sprintf("Referred by: %s\n",
$dli['Referred_by__c']);
}

return;
}
}
Expand Down Expand Up @@ -414,7 +431,6 @@ private function send_email(&$info) {
}

// Alert email //////////////////////////////////////////////

$body = <<<EOF
A donation has been made!
Expand All @@ -424,8 +440,7 @@ private function send_email(&$info) {
Email: {$this->contact->Email}
Phone: {$this->contact->Phone}
Location: {$this->contact->MailingCity}, {$this->contact->MailingState}
Referred by: {$info['referral']}
{$info['honor']}
{$info['referral']}{$info['honor']}
Salesforce Link: https://na32.salesforce.com/{$this->contact->Id}
EOF;

Expand Down
2 changes: 2 additions & 0 deletions Salesforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ protected function upsert_contact() {
$response = self::create(array($this->contact), 'Contact');
}

$response = array_pop($response);

if(!$response->isSuccess()) {
throw new \Exception(sprintf('Contact %s not updated. %s',
$this->contact->Email, $response->getErrors()));
Expand Down
4 changes: 1 addition & 3 deletions UCSalesforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ private function merge_contact(&$info) {
}

// Every contact needs an 'Owner'
$this->contact->Owner = 'Shannon Farley';

if(!isset($this->contact->Board_Member_Contact_Owner__c)) {
$this->contact->Board_Member_Contact_Owner__c = 'Amanda Brock';
}
Expand Down Expand Up @@ -189,7 +187,7 @@ private function create_pending_li(&$info) {
$donation->Type__c = 'Membership';
$donation->Stripe_Status__c = 'Pending';
$donation->Stripe_Id__c = $info['stripe-id'];
$donation->Referred_by__c = parent::string_truncate($info['referral']);
$donation->Referred_by__c = parent::string_truncate($info['referral'], 255);

$donation->In_Honor_Of__c =
parent::string_truncate($info['inhonorof'], 64);
Expand Down
2 changes: 1 addition & 1 deletion sdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function sdf_parse() {
sprintf('Something went wrong, but we\'re not sure what.'
. ' <a href="mailto:%s?subject=Spark Donation Error" target="_blank">'
. 'Please get in contact</a> to make sure your donation went through.'
, $email);
, $email));
}

}
Expand Down

0 comments on commit c805d3c

Please sign in to comment.