* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * */ class fielddayApi { private $apiurl = "http://api-dev.kidcircle.com"; private $apiversion = 'v2'; private $ProviderId; private $AuthKey; private $user_access_token; public static $CurlTimeout = 100; public static $DebugFile = 'php://output'; public static $debug = false; public static $SSLVerification = false; public static $PATCH = "PATCH"; public static $POST = "POST"; public static $GET = "GET"; public static $HEAD = "HEAD"; public static $OPTIONS = "OPTIONS"; public static $PUT = "PUT"; public static $DELETE = "DELETE"; function __construct() { global $fielddaySetting; if (isset($fielddaySetting['fieldday_api_endpoint']) && !empty($fielddaySetting['fieldday_api_endpoint'])) $this->apiurl = $fielddaySetting['fieldday_api_endpoint']; if (isset($fielddaySetting['fieldday_api_provider']) && !empty($fielddaySetting['fieldday_api_provider'])) { $this->ProviderId = $fielddaySetting['fieldday_api_provider']; } if (isset($fielddaySetting['fieldday_api_auth_key']) && !empty($fielddaySetting['fieldday_api_auth_key'])) { $this->AuthKey = $fielddaySetting['fieldday_api_auth_key']; } } /** * Set API version * * @param String $version version of the API default is v2 */ private function setVersion($version = 'v2') { $this->apiversion = $version; } /** * get purchase list of a parent for wordpress * @param string $userAuthKey parentn Auth ID * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function GetactivityRegistrations($queryOptions) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; /* set other imp data */ if (!array_key_exists('providerId', $queryOptions)) { $queryOptions['providerId'] = $this->ProviderId; } return $this->callApi( "wp/activityRegistrations", 'GET', $queryOptions, [], ['Authorization' => $accessToken] ); } /** * v2 place order/add kid to session for logged in user wordpress vendor * @param string $userAuthKey parent Auth ID * @param array $postData Order parameters * @throws ApiException on a non 2xx response * @return mixed */ public function PostactivityRegistrations($userAuthKey, $postData) { $this->setVersion(); return $this->callApi( "wp/activityRegistrations", 'POST', [], $postData, ['Authorization' => "Bearer " . $userAuthKey] ); } /** * login user with email from wordpress vendor * @param string $email user email address * @param array $password user password * @throws ApiException on a non 2xx response * @return mixed */ public function LoginWithEmail($email, $password) { $this->setVersion(); return $this->callApi( "wp/auth/email/login", 'POST', [], ['email' => $email, 'password' => $password] ); } /** * register user into fieldday * @param string $email user email address * @param array $password user password * @throws ApiException on a non 2xx response * @return mixed */ public function Registration($postData) { $this->setVersion(); return $this->callApi( "wp/auth/email/registration", 'POST', [], $postData ); } /** * login user with facebook * @param string $email user email address * @param array $password user password * @throws ApiException on a non 2xx response * @return mixed */ public function LoginWithFacebook($postData) { $this->setVersion(); return $this->callApi( "wp/auth/facebook", 'POST', [], $postData ); } /** * login user by google * @param string $email user email address * @param array $password user password * @throws ApiException on a non 2xx response * @return mixed */ public function LoginWithGoogle($postData) { $this->setVersion(); return $this->callApi( "wp/auth/google", 'POST', [], $postData ); } /** * get coupon detail with coupon ID * @param string $couponCode user email address * @throws ApiException on a non 2xx response * @return mixed */ public function GetCoupon($couponCode) { $this->setVersion(); return $this->callApi( "wp/coupons/{$couponCode}", 'GET' ); } /** * save kid insurance data into fieldday * @param array $postData Insurance Form data * @throws ApiException on a non 2xx response * @return mixed */ public function UpdateInsurance($postData) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi( "wp/insurance", 'POST', [], $postData, ['Authorization' => $accessToken] ); } /** * get medical and dental insurance details from wordpress vendor * @param array $queryOptions Insurance Form data * @throws ApiException on a non 2xx response * @return mixed */ public function GetInsurance($queryOptions = []) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi( "wp/insurance", 'GET', $queryOptions, [], ['Authorization' => $accessToken] ); } /** * get list of kids from wordpress vendor * @param array $queryOptions Query Parameters * @throws ApiException on a non 2xx response * @return mixed */ public function GetKids($queryOptions = []) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi( "wp/kids", 'GET', $queryOptions, [], ['Authorization' => $accessToken] ); } /** * add a kid from wordpress vendor * @param array $postData PostData * @throws ApiException on a non 2xx response * @return mixed */ public function AddKid($postData) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi( "wp/kids", 'POST', [], $postData, ['Authorization' => $accessToken, 'Content-Type' => 'multipart/form-data'] ); } /** * save medical forms for a kid * * @param array $postData PostData * @throws ApiException on a non 2xx response * @return mixed */ public function SaveMedicalForms($postData = []) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi( "wp/kids/medforms", 'POST', [], $postData, ['Authorization' => $accessToken] ); } /** * update a kid profile from wordpress vendor * @param String $kidId Kid Id * @param array $postData PostData * @throws ApiException on a non 2xx response * @return mixed */ public function UpdateKidProfile($kidId, $postData) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi( "wp/kids/{$kidId}", 'PUT', [], $postData, ['Authorization' => $accessToken, 'Content-Type' => 'multipart/form-data'] ); } /** * Delete a kid profile from fieldday * * @global array $KmUser * @param String $kidId * @return mixed response from fieldday API */ public function DeleteKidProfile($kidId) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi( "wp/kids/{$kidId}", 'DELETE', [], [], ['Authorization' => $accessToken] ); } /** * update a kid profile from wordpress vendor * @param String $kidId Kid Id * @param string $accessToken parent access token * @throws ApiException on a non 2xx response * @return mixed */ public function GetKidDetail($kidId, $accessToken = null) { $this->setVersion(); if (!$accessToken) { global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; } return $this->callApi( "wp/kids/{$kidId}", 'GET', [], [], ['Authorization' => $accessToken] ); } /** * get available payment options from wordpress app * @param Array $postData * @param Array $queryOptions * @throws ApiException on a non 2xx response * @return mixed */ public function PaymentOptions($postData = [], $queryOptions = []) { $this->setVersion('v3'); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; $postData['providerId'] = $this->ProviderId; return $this->callApi( "wp/paymentoptions", 'POST', $queryOptions, $postData, ['Authorization' => $accessToken] ); } /** * get terms of provider * @param Array $queryOptions * @throws ApiException on a non 2xx response * @return mixed */ public function getActivityProviderTerms($queryOptions = []) { $this->setVersion(); return $this->callApi( "wp/providers/{$this->ProviderId}/activityProviderTerms", 'GET', $queryOptions ); } /** * get terms of provider * @param Array $queryOptions * @throws ApiException on a non 2xx response * @return mixed */ public function getActivityProvider($queryOptions = []) { $this->setVersion(); return $this->callApi( "wp/providers/{$this->ProviderId}/activityProviders", 'GET', $queryOptions ); } /** * v2 place order/add kid to session from wordpress vendor * @param Array $postData Form data to register kid for a session * @throws ApiException on a non 2xx response * @return mixed */ public function activityRegistration($postData = []) { $this->setVersion(); return $this->callApi( "providers/{$this->ProviderId}/activityRegistrations", 'POST', [], $postData ); } /** * get sessions from a provider * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function GetProviderSessions($queryOptions = []) { $this->setVersion('v2'); $endpoint = "wp/providers/{$this->ProviderId}/activitySessions"; return $this->callApi($endpoint, 'GET', $queryOptions); } /** * v2 get details of session for wordpress vendor * @param String $sessionId Session Id * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function getActivitySession($sessionId, $queryOptions = []) { $this->setVersion(); $endpoint = "wp/providers/{$this->ProviderId}/activitySessions/{$sessionId}"; return $this->callApi($endpoint, 'GET', $queryOptions); } /** * v2 get details of session for wordpress vendor * @param String $sessionId Session Id * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function getActivitySessionDetail($sessionId, $queryOptions = []) { $this->setVersion('v2'); $endpoint = "wp/providers/{$this->ProviderId}/activitySessions/{$sessionId}/details"; return $this->callApi($endpoint, 'GET', $queryOptions); } /** * get gallery photos for wordpress vendor * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function galleryPhotos($queryOptions = []) { $this->setVersion(); $endpoint = "wp/providers/{$this->ProviderId}/galleryPhotos/gallery"; return $this->callApi($endpoint, 'GET', $queryOptions); } /** * get list of schools for wordpress vendor * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function getProviderSchools($queryOptions = []) { $this->setVersion(); $endpoint = "wp/providers/{$this->ProviderId}/schools/search"; return $this->callApi($endpoint, 'GET', $queryOptions); } /** * get the data of single school * @param string $schooldId * @param array $queryOptions * @return mixed Response */ public function getSchoolInfo($schooldId, $queryOptions = []) { $this->setVersion(); $endpoint = "wp/providers/{$this->ProviderId}/schools/search/{$schooldId}"; return $this->callApi($endpoint, 'GET', $queryOptions); } /** * get wordpress providers testimonials * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function getTestimonials($queryOptions = []) { $this->setVersion(); $endpoint = "wp/providers/{$this->ProviderId}/testimonials"; return $this->callApi($endpoint, 'GET', $queryOptions); } /** * get list of schools for wordpress vendor * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function getSchools($queryOptions = []) { $this->setVersion(); return $this->callApi("wp/schools/search", 'GET', $queryOptions); } /** * wp get users provider store credit summary * @param String $accessToken optional user access token * @param array $queryOptions parameters to be place in query URL * @throws ApiException on a non 2xx response * @return mixed */ public function getUserProviderCreditSummary($accessToken = null, $queryOptions = []) { $this->setVersion(); if (!$accessToken) { global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; } return $this->callApi("wp/userProviderCreditSummary/{$this->ProviderId}", 'GET', $queryOptions, [], ['Authorization' => $accessToken]); } /** * Change Password for User from wordpress vendor * @param array $postData FormData * @throws ApiException on a non 2xx response * @return mixed */ public function changePassword($postData = []) { $this->setVersion(); return $this->callApi("wp/userProviderCreditSummary/{$this->ProviderId}", 'PUT', [], $postData); } /** * Sends Reset Password Token To User * @param String $email user email address * @param String $redirectUri redirect url * @param String $vendorName vendor name * @throws ApiException on a non 2xx response * @return mixed */ public function getResetPasswordToken($email, $redirectUri = '', $vendorName = '') { $this->setVersion(); return $this->callApi("wp/users/getResetPasswordToken/{$email}", 'GET', ['redirectUri' => $redirectUri, 'vendorName' => $vendorName]); } /** * resend otp from wordpress * * @param String $countryCode Country code' * @param Int $phone user mobile number * @param String $accessToken user access token * @param String $sendingType call or sms * * @throws ApiException on a non 2xx response * @return mixed */ public function ResendOtp($countryCode, $phone, $accessToken, $sendingType = 'sms') { $this->setVersion(); return $this->callApi("wp/users/resendOTP", 'PUT', [], ['phone' => $phone, 'countryCode' => $countryCode, 'sendingType' => $sendingType], ['Authorization' => $accessToken]); } /** * resend otp from wordpress via email * * @param String $accessToken user access token * * @throws ApiException on a non 2xx response * @return mixed */ public function ResendOtpEmail($accessToken) { $this->setVersion(); return $this->callApi("wp/users/resendOTP/email", 'PUT', [], [], ['Authorization' => $accessToken]); } /** * verify otp from wordpress * @param Int $otpCode user one time password * @param String $accessToken user access token * * @throws ApiException on a non 2xx response * * @return mixed */ public function verifyOTP($otpCode, $accessToken) { $this->setVersion(); return $this->callApi("wp/users/verifyOTP", 'PUT', [], ['otpCode' => $otpCode], ['Authorization' => $accessToken]); } /** * verify otp from wordpress * @param Int $userId user Id * @param String $accessToken user access token * @throws ApiException on a non 2xx response * @return mixed */ public function getUser($userId, $accessToken = null) { $this->setVersion(); if (!$accessToken) { global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; } return $this->callApi("wp/users/{$userId}", 'GET', [], [], ['Authorization' => $accessToken]); } /** * verify otp from wordpress * @param Int $userId user Id * @param Array $postData FormData * @throws ApiException on a non 2xx response * @return mixed */ public function UpdateUser($userId, $postData) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/users/{$userId}", 'PUT', [], $postData, ['Authorization' => $accessToken, 'Content-Type' => 'multipart/form-data']); } /** * get the activity tag types of provider * @param Array $queryOptions FormData * @throws ApiException on a non 2xx response * @return mixed */ public function getActivityTagsCount($queryOptions = []) { $this->setVersion(); return $this->callApi("wp/providers/{$this->ProviderId}/activitySessions/activityTagsCount", 'GET', $queryOptions, []); } /** * calculate the price of single session * * @param Array $postData calculation API Data as POST request * @param type $queryOptions other filter parameters as GET request. * * @return Mixed returned response object */ public function calculateSessionPrice($postData, $queryOptions = []) { $this->setVersion('v3'); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; /* set other imp data */ $postData['providerId'] = $this->ProviderId; return $this->callApi( "wp/activityRegistrations/calculateamount", 'POST', $queryOptions, $postData, ['Authorization' => $accessToken, 'Content-Type' => 'application/json'] ); } /** * place order * * @param array $postData set of data to fieldday API * * @return mixed Response from fieldday API */ public function purchaseSession($postData) { $this->setVersion('v3'); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if ($accessToken) { /* call api for loggedin user */ $postData['providerId'] = $this->ProviderId; return $this->callApi( "wp/activityRegistrations", 'POST', [], $postData, ['Authorization' => $accessToken, 'Content-Type' => 'application/json'] ); } else { /* call api For guest User */ return $this->callApi( "wp/providers/{$this->ProviderId}/activityRegistrations", 'POST', [], $postData, ['Content-Type' => 'application/json'] ); } } /** * Wp user change password * * @return mixed Response from fieldday API */ public function wp_change_password($postData) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/users/changePassword", 'PUT', [], $postData, ['Authorization' => $accessToken, 'Content-Type' => ' application/json']); } /** * * @param array $queryOptions query parameters * * @return mixed Response from fieldday API */ public function getShoppingPackages($queryOptions = []) { $this->setVersion(); return $this->callApi("wp/providers/{$this->ProviderId}/providerShoppingPackages", 'GET', $queryOptions); } /** * purchase shoping package * * @global type $KmUser * @param type $postData * @return type */ public function purchaseShoppingPackage($postData) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if ($accessToken) { /* call api for loggedin user */ return $this->callApi( "wp/providerShoppingPackages/order", 'POST', [], $postData, ['Authorization' => $accessToken] ); } else { /* call api For guest User */ return $this->callApi( "wp/providers/{$this->ProviderId}/providerGivenStoreCredits/order", 'POST', [], $postData ); } } /** * get the user tax details from fieldday account * @global array $KmUser * @global array $fielddaySetting * @param type $queryOptions extra parameters like offset etc * @return mixed Response */ public function getTaxDetails($queryOptions = []) { $this->setVersion(); global $KmUser; global $fielddaySetting; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if (!array_key_exists('providerId', $queryOptions)) { $queryOptions['providerId'] = $this->ProviderId; } if(!array_key_exists('offset', $queryOptions)) { $queryOptions['offset'] = $fielddaySetting['offset']; } return $this->callApi( "wp/activityRegistrations/expenses/yearwise", 'GET', $queryOptions, [], ['Authorization' => $accessToken] ); } /** * get the user credit summary * @global array $KmUser * @param type $queryOptions query options * @return mixed Response */ public function userCreditSummary($queryOptions = []) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/userProviderCreditSummary/{$this->ProviderId}", 'GET', $queryOptions, [], ['Authorization' => $accessToken]); } /** * user credit statements * @global array $KmUser * @param array $queryOptions * @return Response */ public function userStoreCreditStatements($queryOptions = []) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; /* set other imp data */ if (!array_key_exists('providerId', $queryOptions)) { $queryOptions['providerId'] = $this->ProviderId; } if (!array_key_exists('isPerDayCredit', $queryOptions)) { $queryOptions['isPerDayCredit'] = 'true'; } return $this->callApi("wp/userStoreCreditStatements", 'GET', $queryOptions, [], ['Authorization' => $accessToken]); } /** * get featured session * @global array $fielddaySetting * @param type $queryOptions * * @return Response */ public function getFeaturedSession($queryOptions = []) { global $fielddaySetting; $this->setVersion('v3'); if(!array_key_exists('offset', $queryOptions)) { $queryOptions['offset'] = $fielddaySetting['offset']; } return $this->callApi("wp/providers/{$this->ProviderId}/activitySessions/list/home", 'GET', $queryOptions); } /** * get featured session * @global array $fielddaySetting * @param type $queryOptions * * @return Response */ public function getFeaturedActivities($queryOptions = []) { global $fielddaySetting; $this->setVersion('v3'); if(!array_key_exists('offset', $queryOptions)) { //$queryOptions['offset'] = $fielddaySetting['offset']; } return $this->callApi("wp/activities/{$this->ProviderId}", 'GET', $queryOptions); } /** * get packages * @global array $fielddaySetting * @param type $queryOptions * * @return Response */ public function getPackages($queryOptions = []) { global $fielddaySetting; $this->setVersion('v1'); return $this->callApi("wp/providers/{$this->ProviderId}/classPackages", 'GET', $queryOptions); } /** * * @global array $fielddaySetting * @param array $queryOptions * @return type Response */ public function homeSessionActivities($queryOptions = []) { global $fielddaySetting; $this->setVersion('v3'); if(!array_key_exists('offset', $queryOptions)) { $queryOptions['offset'] = $fielddaySetting['offset']; } return $this->callApi("wp/providers/{$this->ProviderId}/activities/list/home", 'GET', $queryOptions); } /** * claim store credit through Coupon code * @global array $KmUser * @param array $postData * @return Response */ public function clamimCoupon($postData) { $this->setVersion(); global $KmUser; $postData['providerId'] = $this->ProviderId; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/storeCredits/claim", 'POST', [], $postData, ['Authorization' => $accessToken]); } /** * make the provider donation * @global array $KmUser * @param array $postData * @return Response */ public function makeDonation($postData) { $this->setVersion(); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; /* set other imp data */ if (!array_key_exists('providerId', $postData)) { $postData['providerId'] = $this->ProviderId; } return $this->callApi( "wp/providerDonations", 'POST', [], $postData, ['Authorization' => $accessToken] ); } /** * get the provider testimonials * @param array $queryOptions * @return Response */ public function getProviderTestimonials($queryOptions = []) { $this->setVersion(); return $this->callApi("wp/providers/{$this->ProviderId}/testimonials", 'GET', $queryOptions); } /** * get all activities of provider * @param array $queryOptions * @return Response */ public function getProviderActivities($queryOptions = []) { $this->setVersion('v3'); return $this->callApi("wp/providers/{$this->ProviderId}/activities", 'GET', $queryOptions); } /** * get activity tags list * @param array $queryOptions * * @return Response activity tags */ public function getActivityTags($queryOptions = []) { $this->setVersion(); return $this->callApi("wp/activityTags?providerId={$this->ProviderId}", 'GET', $queryOptions); } /** * get gift card for a provider * @return Response */ public function getProviderGiftCards() { $this->setVersion('v1'); return $this->callApi("wp/providers/{$this->ProviderId}/giftCards", 'GET'); } /** * get single gift card for a provider * @return Response */ public function getProviderSingleGiftCard($giftCardid) { $this->setVersion('v1'); return $this->callApi("wp/providers/{$this->ProviderId}/giftCards/{$giftCardid}", 'GET'); } /** * get saved card of parent * @global array $KmUser * @return type */ public function getSavedCards() { $this->setVersion('v1'); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/parentPaymentDetails", 'GET', [], [], ['Authorization' => $accessToken]); } /** * get saved card of parent * @global array $KmUser * @return type */ public function saveNewCard($postData) { $this->setVersion('v1'); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if(!array_key_exists('isDefault', $postData)) { $postData['isDefault'] = "false"; } return $this->callApi("wp/parentPaymentDetails", 'POST', [], $postData, ['Authorization' => $accessToken]); } public function deleteSavedCard($cardId) { $this->setVersion('v1'); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/parentPaymentDetails/{$cardId}", 'DELETE', [], [], ['Authorization' => $accessToken]); } public function setCardAsDefault($cardId) { $this->setVersion('v1'); global $KmUser; $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/parentPaymentDetails/{$cardId}", 'PUT', [], [], ['Authorization' => $accessToken]); } public function getSavedCard($cardId) { $cards = $this->getSavedCards(); if($cards->statusCode === 200) { foreach ($cards->data as $key => $card) { if($card->_id == $cardId) { $cards->data = $card; } } } return $cards; } /** * get locations available for a provider * @param array $queryOptions * @return Response provider locations */ public function getProviderLocations($queryOptions = []) { $this->setVersion(); return $this->callApi("wp/providers/{$this->ProviderId}/providerLocations", 'GET', $queryOptions); } /** * * get membership subscription available for a provider * @param array $queryOptions * @return type Response */ public function homeMemberActivities($queryOptions = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); if (!array_key_exists('providerId', $queryOptions)) { $queryOptions['providerId'] = $this->ProviderId; } return $this->callApi("wp/memberships", 'GET', $queryOptions,[]); } /** * Purchase membership from parent app * @param array $postData API Post data * @return type Response */ public function membershipSubscriptionPurchase($postData = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); /*if (!array_key_exists('providerId', $queryOptions)) { $queryOptions['providerId'] = $this->ProviderId; }*/ $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("membershipSubscriptions/purchase", 'POST', [], $postData, ['Authorization' => $accessToken]); } /** * Purchase Package * @param array $postData API Post data * @return type Response */ public function PackagePurchase($postData = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if ($accessToken) { return $this->callApi("wp/activityRegistrations/classPackage/booking", 'POST', [], $postData, ['Authorization' => $accessToken]); } else { return $this->callApi("wp/activityRegistrations/classPackage/booking", 'POST', [], $postData); } } /** * Package Options * @param array $postData API Post data * @return type Response */ public function PackageOPtions($postData = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if ($accessToken) { return $this->callApi("wp/activityRegistrations/classPackage/calculation", 'POST', [], $postData, ['Authorization' => $accessToken]); } else { return $this->callApi("wp/activityRegistrations/classPackage/calculation", 'POST', [], $postData); } } /** * Events Calculation * @param array $postData API Post data * @return type Response */ public function EventsCalc($postData = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if ($accessToken) { return $this->callApi("wp/activityRegistrations/activityEvents/calculateamount", 'POST', [], $postData, ['Authorization' => $accessToken]); } else { return $this->callApi("wp/activityRegistrations/activityEvents/calculateamount", 'POST', [], $postData,['Authorization' =>'']); } } /** * Events Purchase * @param array $postData API Post data * @return type Response */ public function EventsPurchase($postData = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; if ($accessToken) { return $this->callApi("wp/activityRegistrations/activityEvents/booking", 'POST', [], $postData, ['Authorization' => $accessToken]); } else { $this->setVersion('v3'); return $this->callApi("wp/providers/{$this->ProviderId}/activityRegistrations/activityEvents/booking", 'POST', [], $postData); } } /** * Purchase giftCard * @param array $postData API Post data * @return type Response */ public function giftcardPurchase($postData = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/giftCards/purchase", 'POST', [], $postData, ['Authorization' => $accessToken]); } /** * Purchase giftCard for guest user * @param array $postData API Post data * @return type Response */ public function giftcardPurchaseGuest($postData = []) { global $fielddaySetting; global $KmUser; $this->setVersion('v1'); $accessToken = isset($KmUser->accessToken) ? $KmUser->accessToken : null; return $this->callApi("wp/{$this->ProviderId}/giftCards/purchase", 'POST', [], $postData, []); } /** * Make the HTTP call (Sync) * @param string $resourcePath path to method endpoint * @param string $method method to call * @param array $queryParams parameters to be place in query URL * @param array $postData parameters to be placed in POST body * @param array $headerParams parameters to be place in request header * @throws ApiException on a non 2xx response * @return mixed */ private function callApi($resourcePath, $method = 'GET', $queryParams = [], $postData = array(), array $headerParams = array()) { if (!array_key_exists('Authorization', $headerParams)) { $headerParams['Authorization'] = "Bearer " . $this->AuthKey; } elseif (!empty($headerParams['Authorization'])) { $headerParams['Authorization'] = "Bearer " . $headerParams['Authorization']; } // form data if (array_key_exists('Content-Type', $headerParams) && $headerParams['Content-Type'] == 'multipart/form-data') { // json model $boundary = wp_generate_password( 24 ); $headerParams['Content-Type'] = 'multipart/form-data; boundary=' . $boundary; $payload = ''; foreach ( $postData as $name => $value ) { if($name != 'file') { $payload .= '--' . $boundary; $payload .= "\r\n"; $payload .= 'Content-Disposition: form-data; name="' . $name .'"' . "\r\n\r\n"; $payload .= $value; $payload .= "\r\n"; }else { $local_file = $value['path']; $filename = $value['name']; if($local_file) { $payload .= '--' . $boundary; $payload .= "\r\n"; $payload .= 'Content-Disposition: form-data; name="' . $filename. '"; filename="' . basename( $local_file ) . '"' . "\r\n"; // $payload .= 'Content-Type: image/jpeg' . "\r\n"; $payload .= "\r\n"; $payload .= file_get_contents( $local_file ); $payload .= "\r\n"; } } } $payload .= '--' . $boundary . '--'; $postData = $payload; }else if(array_key_exists('Content-Type', $headerParams) && $headerParams['Content-Type'] == 'application/json') { $postData = json_encode($postData); } $url = $this->apiurl . "/" . $this->apiversion . "/" . $resourcePath; if (!empty($queryParams)) { $url = ($url . '?' . http_build_query($queryParams)); } $requestarg = [ 'headers' => $headerParams, 'timeout' => self::$CurlTimeout, 'body' => $postData ]; switch ($method) { case self::$POST: $api_response = wp_remote_post( $url, $requestarg ); break; case self::$PUT: $requestarg['method'] = "PUT"; $api_response = wp_remote_request($url, $requestarg); break; case self::$DELETE: $requestarg['method'] = "DELETE"; $api_response = wp_remote_request($url, $requestarg); break; case self::$GET: $api_response = wp_remote_get( $url, $requestarg ); break; default: break; } if ( is_wp_error( $api_response ) ) { return (object) array('message' => $api_response->get_error_message(), 'statusCode' => 404, 'headers' => ''); } $response = json_decode( $api_response['body'] ); $response->apiUrl = $url; if($response->statusCode >= 200 && $response->statusCode <= 299) { return $response; }else { $response->message = $response->message; $response->params = $requestarg; return $response; } } }