Skip to content

Instantly share code, notes, and snippets.

@jwcobb
Last active September 2, 2015 19:53
Show Gist options
  • Save jwcobb/9ce71e3b88b8308e18fa to your computer and use it in GitHub Desktop.
Save jwcobb/9ce71e3b88b8308e18fa to your computer and use it in GitHub Desktop.
Hacky workaround for apparent Guzzle issue when uploading JSON body > 1MB
function uploadEticketsForAnOrder(array $array = [], $token, $secret)
{
$orderId = $array['order_id'];
$url = 'https://api.ticketevolution.com/v9/orders/' . $orderId . '/deliver_etickets';
$data_string = '{"etickets":' . json_encode($array['etickets']) . '}';
$stringToSign = 'POST ' . preg_replace('/https:\/\/|\?.*/', '', $url) . '?' . $data_string;
$signature = base64_encode(hash_hmac('sha256', $stringToSign, $secret, true));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'X-Token: ' . $token,
'X-Signature: ' . $signature,
'Expect:',
'Accept: application/json',
]);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
@jwcobb
Copy link
Author

jwcobb commented Sep 2, 2015

Example:

$item = new stdClass();
$item->item_id = $orderItem;
$item->eticket = base64_encode(file_get_contents('path-to-tickets.pdf'));

try {
    $result1 = uploadEticketsForAnOrder([
            'order_id' => $orderNumber,
            'etickets' => [$item]
        ],
        'TEVO_API_TOKEN',
        'TEVO_API_SECRET'
    );
    // var_dump($result1);
} catch (\Exception $e) {
    // Handle exception
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment