Download the PHP package quickbooks/payments-sdk without Composer
On this page you can find all versions of the php package quickbooks/payments-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download quickbooks/payments-sdk
More information about quickbooks/payments-sdk
Files in quickbooks/payments-sdk
Package payments-sdk
Short Description The Official PHP SDK for QuickBooks Online Payments API
License Apache-2.0
Homepage http://developer.intuit.com
Informations about the package payments-sdk
QuickBooks Payments PHP SDK
This SDK is designed to facilitate developers using the QuickBooks Payments API by providing a set of methods that make it easier to work with. It supports the following operations:
- Standard OAuth 2.0 and OpenID Connect protocols
- Interceptors for logging and error handling
- Standard Payments API endpoints with requests/response handling
If you have not used the QuickBooks Payments API before, please go to our docs at: https://developer.intuit.com/app/developer/qbpayments/docs/get-started
Requirements
- PHP 7.2.0 and later.
- App for QuickBooks Online Payments API.
Composer
You can install the package via Composer. Run the following command:
If you encounter a problem during composer installation, try to update composer first:
and see if specifying a version resolves the issue, example:
To use the package, use Composer's autoload:
Manual Installation
If you do not wish to use Composer, you can download the latest release. Then, to use the package, include the config.php
file.
Dependencies
The following extensions are required in order to work properly:
If you specify the Guzzle client, then Guzzle is also required.
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.
Getting Started
To begin using the Payments SDK, the first step is to create the PaymentClient. The minimum required properties are access_token
and environment
. The access_token
is the OAuth 2.0 token to access the API, the environment
is defining the base url for the API endpoint. This can be either sandbox
or production
. If you do not provide these two properties, the PaymentClient
will still be created, however, it will not be able to make any Payments API calls.
Once the Payment Client is created, you can start making API calls to the Payments API endpoints. Simple usage looks like:
If the request is made successfully, then the getBody()
function will return the casted object. The above example will return the following $responseCharge
object from $response->getBody()
:
Each casted object will have the same property names as stated in our API reference: https://developer.intuit.com/app/developer/qbpayments/docs/api/resources/all-entities/charges page,
A call could fail for reasons such as an expired token, server outrage, or invalid request body. You can check this by using $response->failed()
. Check with our Response Interface for a list of supported operations to diagnose a failed request.
OAuth support
Developers can use this library to handle the OAuth 2.0 protocol. It supports:
- Generating the Authorization URL
generateAuthCodeURL(string $scope, string $userDefinedState = "state") : string
- Getting the OAuth 2.0 Bearer Token
createRequestToExchange(string $code) : RequestInterface
- Getting User Info
createRequestForUserInfo(string $accessToken) : RequestInterface
- Refreshing the OAuth 2.0 Token
createRequestToRefresh(string $refreshToken) : RequestInterface
- Revoking the OAuth 2.0 Token
createRequestToRevoke(string $token)
- Migrating tokens from OAuth 1.0 to OAuth 2.0
createRequestToMigrateToken(string $consumerKey, string $consumerSecret, string $oauth1AccessToken, string $oauth1TokenSecret, string $scopes) : RequestInterface
In order to use OAuth 2.0, developers will need to create two objects
- OAuth2Authenticator : used to create OAuth 2.0 related request
- PaymentClient: used to send OAuth 2.0 related request
The Payments SDK does not provide any parsing support for parsing the OAuth 2.0 response. Since the response for OAuth 2.0 requests are always in JSON format, a simple json_decode($response->getBody(), true)
will work.
Example:
Operations
The PHP Payments SDK supports all six Payments endpoints: BankAccounts
, Cards
, Charges
, EChecks
, Tokens
, Transactions
. These can be found in our QuickBooks Payments API Explorer.
To construct the body for each API endpoint, developers will need to first construct the body of the request in array format, then use the Operations
's buildFrom
method to convert the array to an object.
For example, to convert an array representation of a card to a $card object, use:
All supported operations
are availble here: Operations
Once the object is created, you can use it to send the request. The function names of all the endpoints are derived from the API reference. For example, to create a card, you should use:
If you want to provide a custom Request-Id for the request, use:
otherwise, a system generated random request ID will be provided.
To check a list of available functions, refer here: API endpoints operations
Interceptors
Interceptors are used to intercept requests and responses. It can be used to log a request or response. This can be used as a retry mechanism for issues such as connection timeouts or token expirations.
The default interceptors provided in this SDK are:
- StackTraceLoggerInterceptor: Similar to log4j, it will log the stack trace to a log file. The StackTraceLoggerIntercepto will log everything to one error log.
- RequestResponseLoggerInterceptor: It will log the complete request and response that was sent and received each time. It will hide the OAuth 2.0 token. The RequestResponseLoggerInterceptor will record each request in a file, and each response in a file.
- ExceptionOnErrorInterceptor: It will throw an exception if the request failed.
Based on the need, you can define your own interceptors to intercept requests and responses by inheriting the InterceptorInterface
:
- To change the request sent to the Payments API, define your
before(RequestInterface &$request, PaymentClient $client)
method. - To change the response received, define your
after(ResponseInterface &$response, PaymentClient $client)
method. - To intercept the unaltered request and response, define your
intercept(RequestInterface $request, ResponseInterface $response, PaymentClient $client)
method.
In order to add an interceptor to the client, use:
To delete an interceptor by its name, use:
Example: To enable file storage for each acutal request and response sent by the SDK:
To enable logging of each transaction sent by the SDK:
Error Handling
By default, each $response
object has a failed()
method to determine if a request was made successfully. A successful request is defined by having a status code of 200/201. Any other status code will cause the $response->failed()
method to return true. If a request failed, you can use our supported diagnose function to find out more information.
Questions
If you find any bugs for the SDK, or want to request for a feature, create a support ticket at https://help.developer.intuit.com/s/ or send us a pull request. Contributions are always welcomed!