Skip to content

Commit 1ebf751

Browse files
authored
Merge pull request #5 from RonAbarbanel/develop
2 parents d5e5a18 + 50c0fd4 commit 1ebf751

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

src/DonorPerfect.php

+35-7
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,42 @@ protected function callInternal(array $params)
125125
if (strlen(static::$baseUrl . $relativeUrl) > 8000) {
126126
throw new Exception('The DonorPerfect API call exceeds the maximum length permitted (8000 characters)');
127127
}
128+
// Create filters to remove any credentials from the response
129+
$pattern = [
130+
'/(apikey=)([^&]*)/',
131+
'/(pass=)([^&]*)/'
132+
];
133+
$replacement = [
134+
'${1}**APIKEY**',
135+
'${1}**PASSWORD**'
136+
];
128137
// Make the request
129-
$response = (string) $this->client->request('GET', $relativeUrl)->getBody();
138+
try{
139+
$response = (string) $this->client->request('GET', $relativeUrl)->getBody();
140+
}
141+
catch(Exception $e){
142+
// Conceal any credentials in the error to prevent them from being displayed in output
143+
$error = $e->getMessage();
144+
$error = preg_replace($pattern, $replacement, $error);
145+
throw new Exception($error);
146+
}
130147

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

134151
// Turn the response into a usable PHP array
135152
$response = json_decode(json_encode(simplexml_load_string($response)), true);
136-
153+
137154
// Handle error messages
138155
if (array_key_exists('error', $response)) {
156+
// conceal any credentials in the error to prevent them from being displayed in output
157+
$response['error'] = preg_replace($pattern, $replacement, $response['error']);
139158
throw new Exception($response['error']);
140159
} elseif (isset($response['field']['@attributes']['value']) && $response['field']['@attributes']['value'] === 'false') {
141-
throw new Exception($response['field']['@attributes']['reason']);
160+
// conceal any credentials in the error to prevent them from being displayed in output
161+
$error = $response['field']['@attributes']['reason'];
162+
$error = preg_replace($pattern, $replacement, $error);
163+
throw new Exception($error);
142164
}
143165

144166
// Handle empty responses
@@ -448,7 +470,7 @@ public static function prepareParams($data, $params)
448470
}
449471

450472
// Handle a param not being included in the data
451-
if (!isset($data[$param])) {
473+
if (!isset($data[$param]) || $data[$param] === '') {
452474
$return[$param] = null;
453475
continue;
454476
}
@@ -793,6 +815,7 @@ public function dp_savegift($data)
793815
'currency' => ['string', 3], // If you use the multi-currency feature, enter appropriate code value per your currency field – e.g; 'USD', 'CAD', etc.
794816
'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
795817
'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
818+
'rcpt_type' => ['string', 1], // C for consolidated or I for individual or NULL for unset
796819
]));
797820
}
798821

@@ -924,7 +947,7 @@ public function dp_saveaddress($data)
924947
'mobile_phone' => ['string', 40], //
925948
'address3' => ['string', 100], //
926949
'address4' => ['string', 100], //
927-
'ukcountry' => ['string', 100], //
950+
'ukcounty' => ['string', 100], //
928951
'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.
929952
]));
930953
}
@@ -966,12 +989,17 @@ public function dp_savecode($data)
966989
return $this->call('dp_savecode', static::prepareParams($data, [
967990
'field_name' => ['string', 20], // Enter the name of an existing field type from the DPCODES table
968991
'code' => ['string', 30], // Enter the new CODE value
969-
'description' => ['string', 100], // Enter the description value that will appear in drop-down selection values
992+
'description' => ['string', 100], // Enter the description value that will appear in drop-down selection values
970993
'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
971994
'code_date' => ['date'], // Enter NULL
972995
'mcat_hi' => ['money'], // Enter NULL
973996
'mcat_lo' => ['money'], // Enter NULL
974997
'mcat_gl' => ['string', 1], // Enter NULL
998+
'reciprocal' => null,
999+
'mailed' => null,
1000+
'printing' => null,
1001+
'other' => null,
1002+
'goal' => null,
9751003
'acct_num' => ['string', 30], // Enter NULL
9761004
'campaign' => ['string', 30], // Enter NULL
9771005
'solicit_code' => ['string', 30], // Enter NULL
@@ -1063,7 +1091,7 @@ public function mergemultivalues($data)
10631091
return $this->call('mergemultivalues', static::prepareParams($data, [
10641092
'matchingid' => ['numeric'], // Specify the desired donor_id
10651093
'fieldname' => ['string', 20], // Enter the name of the checkbox field name.
1066-
'valuestring' => ['string', 20], // Enter any CODE values to be set. Separate with commas. Any code values not specified will be unset (unchecked).
1094+
'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).
10671095
'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.
10681096
]));
10691097
}

0 commit comments

Comments
 (0)