@@ -83,6 +83,89 @@ public function getIdentifiers()
83
83
return $ this ->init ()->_identifiers ;
84
84
}
85
85
86
+ /**
87
+ * Get the user's preferred SMS number.
88
+ *
89
+ * @return string|null
90
+ */
91
+ public function getSmsNumber ()
92
+ {
93
+ $ this ->init ();
94
+ if ($ this ->data ->contact_info ->phone ) {
95
+ foreach ($ this ->data ->contact_info ->phone as $ phone ) {
96
+ if ($ phone ->preferred_sms ) {
97
+ return $ phone ->phone_number ;
98
+ }
99
+ }
100
+ }
101
+ return null ;
102
+ }
103
+
104
+ /**
105
+ * Remove the preferred SMS flag from any number.
106
+ */
107
+ public function unsetSmsNumber ()
108
+ {
109
+ $ this ->init ();
110
+ if ($ this ->data ->contact_info ->phone ) {
111
+ foreach ($ this ->data ->contact_info ->phone as $ phone ) {
112
+ if ($ phone ->preferred_sms ) {
113
+ $ phone ->preferred_sms = false ;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Set the user's preferred SMS number, creating a new internal mobile number if needed
121
+ * @param $number string The SMS-capable mobile phone number
122
+ */
123
+ public function setSmsNumber ($ number )
124
+ {
125
+ $ currentNumber = $ this ->getSmsNumber ();
126
+ if ($ number === $ currentNumber ) {
127
+ return ;
128
+ }
129
+ $ this ->unsetSmsNumber ();
130
+ $ updated = false ;
131
+ if ($ this ->data ->contact_info ->phone ) {
132
+ foreach ($ this ->data ->contact_info ->phone as $ phone ) {
133
+ if ($ phone ->phone_number === $ number ) {
134
+ $ phone ->preferred_sms = true ;
135
+ }
136
+ }
137
+ }
138
+ if (!$ updated ) {
139
+ $ this ->addSmsNumber ($ number );
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Add the user's preferred SMS number as a new internal mobile number.
145
+ * @param $number string The SMS-capable mobile phone number
146
+ */
147
+ public function addSmsNumber ($ number )
148
+ {
149
+ $ currentNumber = $ this ->getSmsNumber ();
150
+ if ($ currentNumber ) {
151
+ $ this ->unsetSmsNumber ();
152
+ }
153
+ $ phones = json_decode (json_encode ($ this ->data ->contact_info ->phone ), true );
154
+ $ phones [] = json_decode ('{"phone_number": ' .json_encode ($ number ).',"preferred":false,"preferred_sms":true,"segment_type":"Internal","phone_type":[{"value":"mobile","desc":"Mobile"}]} ' , true );
155
+ $ this ->data ->contact_info ->phone = json_decode (json_encode ($ phones ));
156
+ }
157
+
158
+ /**
159
+ * Save the user
160
+ *
161
+ * @return string The API response body
162
+ */
163
+ public function save ()
164
+ {
165
+ $ this ->init ();
166
+ return $ this ->client ->put ($ this ->url (), json_encode ($ this ->jsonSerialize ()));
167
+ }
168
+
86
169
/**
87
170
* Check if we have the full representation of our data object.
88
171
*
0 commit comments