Skip to content

Commit

Permalink
Merge pull request #5 from RonAbarbanel/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeTowers authored Apr 5, 2024
2 parents d5e5a18 + 50c0fd4 commit 1ebf751
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/DonorPerfect.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,42 @@ protected function callInternal(array $params)
if (strlen(static::$baseUrl . $relativeUrl) > 8000) {
throw new Exception('The DonorPerfect API call exceeds the maximum length permitted (8000 characters)');
}
// Create filters to remove any credentials from the response
$pattern = [
'/(apikey=)([^&]*)/',
'/(pass=)([^&]*)/'
];
$replacement = [
'${1}**APIKEY**',
'${1}**PASSWORD**'
];
// Make the request
$response = (string) $this->client->request('GET', $relativeUrl)->getBody();
try{
$response = (string) $this->client->request('GET', $relativeUrl)->getBody();
}
catch(Exception $e){
// Conceal any credentials in the error to prevent them from being displayed in output
$error = $e->getMessage();
$error = preg_replace($pattern, $replacement, $error);
throw new Exception($error);
}

// Fix values with invalid unescaped XML values
$response = preg_replace('|(?Umsi)(value=\'DATE:.*\\R*\')|', 'value=\'\'', $response);

// Turn the response into a usable PHP array
$response = json_decode(json_encode(simplexml_load_string($response)), true);

// Handle error messages
if (array_key_exists('error', $response)) {
// conceal any credentials in the error to prevent them from being displayed in output
$response['error'] = preg_replace($pattern, $replacement, $response['error']);
throw new Exception($response['error']);
} elseif (isset($response['field']['@attributes']['value']) && $response['field']['@attributes']['value'] === 'false') {
throw new Exception($response['field']['@attributes']['reason']);
// conceal any credentials in the error to prevent them from being displayed in output
$error = $response['field']['@attributes']['reason'];
$error = preg_replace($pattern, $replacement, $error);
throw new Exception($error);
}

// Handle empty responses
Expand Down Expand Up @@ -448,7 +470,7 @@ public static function prepareParams($data, $params)
}

// Handle a param not being included in the data
if (!isset($data[$param])) {
if (!isset($data[$param]) || $data[$param] === '') {
$return[$param] = null;
continue;
}
Expand Down Expand Up @@ -793,6 +815,7 @@ public function dp_savegift($data)
'currency' => ['string', 3], // If you use the multi-currency feature, enter appropriate code value per your currency field – e.g; 'USD', 'CAD', etc.
'receipt_delivery_g' => ['string', 1], // This field sets receipt delivery preference for the specified gift. Supply one of the following single letter code values: • N = do not acknowledge • E = email • B = email and letter • L = letter
'acknowledgepref' => ['string', 3], // Used in Canadian DonorPerfect systems to indicate official receipt acknowledgement preference code: • 1AR – Acknowledge/Receipt • 2AD – Acknowledge / Do Not Receipt • 3DD – Do Not Acknowledge / Do Not Receipt
'rcpt_type' => ['string', 1], // C for consolidated or I for individual or NULL for unset
]));
}

Expand Down Expand Up @@ -924,7 +947,7 @@ public function dp_saveaddress($data)
'mobile_phone' => ['string', 40], //
'address3' => ['string', 100], //
'address4' => ['string', 100], //
'ukcountry' => ['string', 100], //
'ukcounty' => ['string', 100], //
'org_rec' => ['string', 1], // Enter 'Y' to check the Org Rec field (indicating an organizational record) or 'N' to leave it unchecked to indicate an individual record.
]));
}
Expand Down Expand Up @@ -966,12 +989,17 @@ public function dp_savecode($data)
return $this->call('dp_savecode', static::prepareParams($data, [
'field_name' => ['string', 20], // Enter the name of an existing field type from the DPCODES table
'code' => ['string', 30], // Enter the new CODE value
'description' => ['string', 100], // Enter the description value that will appear in drop-down selection values
'description' => ['string', 100], // Enter the description value that will appear in drop-down selection values
'original_code' => ['string', 20], // Enter NULL unless you are updating an existing code. In that case, set this field to the current (before update) value of the CODE
'code_date' => ['date'], // Enter NULL
'mcat_hi' => ['money'], // Enter NULL
'mcat_lo' => ['money'], // Enter NULL
'mcat_gl' => ['string', 1], // Enter NULL
'reciprocal' => null,
'mailed' => null,
'printing' => null,
'other' => null,
'goal' => null,
'acct_num' => ['string', 30], // Enter NULL
'campaign' => ['string', 30], // Enter NULL
'solicit_code' => ['string', 30], // Enter NULL
Expand Down Expand Up @@ -1063,7 +1091,7 @@ public function mergemultivalues($data)
return $this->call('mergemultivalues', static::prepareParams($data, [
'matchingid' => ['numeric'], // Specify the desired donor_id
'fieldname' => ['string', 20], // Enter the name of the checkbox field name.
'valuestring' => ['string', 20], // Enter any CODE values to be set. Separate with commas. Any code values not specified will be unset (unchecked).
'valuestring' => ['string', 7000], // Enter any CODE values to be set. Separate with commas (max 20 chars per code). Any code values not specified will be unset (unchecked).
'debug' => ['numeric'], // Specification of this field is optional but if you want to return the list of checkbox fields and the values in them after running this command then add debug=1 as a parameter to this API call. If a code was previously set but was not specified in your mergemultivalues API call then it will show as a DeletedCode value. If a value was not previously set but was specified in your API call, then it will show as an InsertedCode.
]));
}
Expand Down

0 comments on commit 1ebf751

Please sign in to comment.