diff --git a/config/services.yaml b/config/services.yaml index 0a2888bc..57d46ba7 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -56,3 +56,11 @@ services: arguments: $em: "@doctrine.orm.entity_manager" $gmaps_api_key: "%env(GMAPS_API_KEY)%" + + App\Service\RisingTideGateway: + arguments: + $em: "@doctrine.orm.entity_manager" + $user: "%env(RT_USER)%" + $pass: "%env(RT_PASS)%" + $usage_type: "%env(RT_USAGE_TYPE)%" + $shortcode: "%env(RT_SHORTCODE)%" diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index de3e96f7..85016459 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -22,6 +22,7 @@ use App\Ramcar\TransactionOrigin; use App\Ramcar\TradeInType; use App\Service\InvoiceCreator; +use App\Service\RisingTideGateway; use App\Entity\MobileSession; use App\Entity\Customer; @@ -191,7 +192,7 @@ class APIController extends Controller return $res->getReturnResponse(); } - public function confirmNumber(Request $req) + public function confirmNumber(RisingTideGateway $rt, Request $req) { // check parameters $required_params = [ @@ -218,7 +219,9 @@ class APIController extends Controller ->setPhoneNumber($phone_number); $em->flush(); - // TODO: send sms to number + // send sms to number + $message = "Your Resq confirmation code is $code."; + $rt->sendSMS($phone_number, 'MOTOLITE', $message); // response return $res->getReturnResponse(); diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php new file mode 100644 index 00000000..ddfb2f79 --- /dev/null +++ b/src/Service/RisingTideGateway.php @@ -0,0 +1,68 @@ +em = $em; + $this->user = $user; + $this->pass = $pass; + $this->usage_type = $usage_type; + $this->shortcode = $shortcode; + } + + public function sendSMS($mobile_num, $mask, $message) + { + $headers = [ + 'Content-Type: application/vnd.net.wyrls.Document-v3+json' + ]; + + $date = new DateTime(); + $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); + + $data = [ + 'from' => $this->shortcode, + 'from_alias' => $mask, + 'to' => $mobile_num, + 'content_type' => 'text/plain', + 'body' => $message, + 'date' => $date_string, + 'usagetype' => $this->usage_type, + ]; + $data_json = json_encode($data); + + $userpwd = $this->user . ':' . $this->pass; + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, self::SERVER_URL); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + curl_setopt($curl, CURLOPT_VERBOSE, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($curl, CURLOPT_USERPWD, $userpwd); + $result = curl_exec($curl); + error_log('error_no - ' . curl_errno($curl)); + $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + error_log($http_code); + curl_close($curl); + + error_log($result); + } +}