MediaWiki fundraising/REL1_35
CiviproxyConnect.php
Go to the documentation of this file.
1<?php
2
4
5 // These refer to the names (keys in an array) of available actual site and api keys
6 // that CiviProxy may use when it connects to Civi.
7 // Note: coordinate with config.php for Civiproxy.
8 const SITE_KEY_KEY = 'SITE_KEY';
9 const API_KEY_KEY = 'API_KEY';
10
11 public static function getEmailPreferences( $checksum, $contact_id ) {
12 global $wgDonationInterfaceCiviproxyURLBase;
13
14 $client = new GuzzleHttp\Client();
15
16 try {
17 $resp = $client->get(
18 "$wgDonationInterfaceCiviproxyURLBase/rest.php",
19 [ 'query' => [
20 'entity' => 'civiproxy',
21 'action' => 'getpreferences',
22 'key' => self::SITE_KEY_KEY,
23 'api_key' => self::API_KEY_KEY,
24 'version' => '3',
25 'json' => '1',
26 'checksum' => $checksum,
27 'contact_id' => $contact_id
28 ],
29 'verify' => false
30 ]
31 );
32
33 $rawResp = $resp->getBody()->getContents();
34 $resp = json_decode( $rawResp, true );
35
36 if ( !$resp ) {
37 throw new RuntimeException( "Invalid JSON from CiviProxy for id $contact_id" );
38 }
39
40 return [
41 'country' => $resp[ 'country' ] ?? null,
42 'sendEmail' => $resp[ 'is_opt_in' ] ?? null,
43 'email' => $resp[ 'email' ],
44 'first_name' => $resp[ 'first_name' ],
45 'preferred_language' => $resp[ 'preferred_language' ] ?? null,
46 'is_error' => ( $resp[ 'is_error' ] === 1 ),
47 'error_message' => $resp[ 'error_message' ] ?? null
48 ];
49
50 } catch ( Exception $e ) {
52 'CiviproxyConnector', true, false, '', null );
53
54 $logger->error( "contact id: $contact_id, " . $e->getMessage() );
55 return [
56 'is_error' => true,
57 'error_message' => $e->getMessage()
58 ];
59 }
60 }
61}
static getEmailPreferences( $checksum, $contact_id)
static getLoggerFromParams( $identifier, $useSyslog, $debug, $suffix, $prefixer)