ZuoraService
ZuoraService is the main service for integration with Zuora REST API. It handles OAuth 2.0 authentication, API calls, and error handling.
Namespace
Dependencies
Illuminate\\Support\\Facades\\CacheIlluminate\\Support\\Facades\\HttpApp\\Exceptions\\ZuoraAuthenticationExceptionApp\\Exceptions\\ZuoraHttpException
Public methods
getAccessToken()
Obtains an OAuth 2.0 access token from Zuora, with automatic caching. Signature:$clientId(string|null): OAuth 2.0 Client ID$clientSecret(string|null): OAuth 2.0 Client Secret$baseUrl(string|null): Zuora API Base URL
string - Access token
Throws:
ZuoraAuthenticationException- If credentials are missing or invalid
- Cache key:
zuora_access_token_{md5(clientId.clientSecret)} - TTL: 3600 seconds (1 hour)
- Driver: Configured in
config/cache.php
- Check if token is in cache
- If cached, return cached token
- If not cached:
- POST
/oauth/tokenwith grant_type=client_credentials - Save token in cache
- Return token
- POST
listWorkflows()
Retrieves the list of workflows from Zuora with pagination. Signature:$clientId(string): OAuth 2.0 Client ID$clientSecret(string): OAuth 2.0 Client Secret$baseUrl(string): Zuora API Base URL (default:https://rest.zuora.com)$page(int): Page number (default: 1)$pageSize(int): Number of workflows per page (default: 12)
array - Array with keys:
data(array): Array of normalized workflowspagination(array|null): Pagination information
ZuoraHttpException- If the request fails
downloadWorkflow()
Downloads the complete JSON export of a specific workflow. Signature:$clientId(string): OAuth 2.0 Client ID$clientSecret(string): OAuth 2.0 Client Secret$baseUrl(string): Zuora API Base URL$workflowId(string|int): ID of workflow to download
array - Complete workflow JSON
Throws:
ZuoraHttpException- If the request fails
Private methods
normalizeWorkflow()
Normalizes workflow structure from Zuora API to consistent format. Signature:extractErrorMessage()
Extracts error message from a failed HTTP response. Signature:messageerrorerror_description- Fallback: complete body
throwHttpException()
Throws a formatted exception from a failed HTTP response. Signature:Exceptions
ZuoraAuthenticationException
Thrown when OAuth 2.0 authentication fails. Cases:- Missing credentials
- Invalid credentials
- Token generation failed
ZuoraHttpException
Thrown when a Zuora API call fails. Properties:statusCode(int): HTTP status codemessage(string): Error message