1. Go to this page and download the library: Download easypost/easypost-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
easypost / easypost-php example snippets
# Require the autoloader (when using composer - recommended):
# will
function customFunction($args)
{
// Pass your code here, data about the request/response is contained within `$args`.
echo "Received a request with the status code of: " . $args['http_status'];
}
$client = new \EasyPost\EasyPostClient(getenv('EASYPOST_API_KEY'));
$client->subscribeToResponseHook('customFunction');
// Make your API calls here, your customFunction will trigger once a response is received
use EasyPost\Test\mocking\MockingUtility;
use EasyPost\Test\mocking\MockRequest;
use EasyPost\Test\mocking\MockRequestMatchRule;
use EasyPost\Test\mocking\MockRequestResponseInfo;
// create a mocking utility with a list of mock request-response pairs
$mockingUtility = new MockingUtility(
new MockRequest(
new MockRequestMatchRule(
// HTTP method and regex pattern for the URL must both pass for the request to match
'post',
'/v2\\/bank_accounts\\/\\S*\\/charges$/'
),
new MockRequestResponseInfo(
// HTTP status code and body to return when this request is matched
200,
'{}'
)
),
... // more mock requests
);
// create a new client with the mocking utility
$client = new EasyPostClient("some_key", Constants::TIMEOUT, Constants::API_BASE, $mockUtility);
// use the client as normal
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.