Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Created December 17, 2018 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/3492aa16a827cc169a2a0736f2c69f51 to your computer and use it in GitHub Desktop.
Save steveosoule/3492aa16a827cc169a2a0736f2c69f51 to your computer and use it in GitHub Desktop.
Example mivaecommerce/api-sdk-php/examples/ListQueryExample.php
{
"json_url": "example.com/mm5/json.mvc",
"api_token": "abcdefghijlkmnopqrstuvqxyz123456",
"api_signature": "abcdefghijlkmnopqrstuvqxyz1234567890",
"store_code": "ABC",
"encryption_passphrase": "0123456789abcdef"
}
<?php
/*
* This file is part of the MerchantAPI package.
*
* (c) Miva Inc <https://www.miva.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* $Id: LoadOrdersExample.php 71893 2018-12-07 23:26:05Z gidriss $
*/
require_once( dirname( __FILE__ ).'/vendor/autoload.php');
$config = json_decode(file_get_contents('config.json'));
define('JSON_URL', $config->json_url);
define('API_TOKEN', $config->api_token);
define('API_SIGNATURE', $config->api_signature);
define('STORE_CODE', $config->store_code);
define('ENCRYPTION_PASSPHRASE', $config->encryption_passphrase);
use MerchantAPI\Client;
use MerchantAPI\ClientException;
use MerchantAPI\Request\OrderListLoadQuery;
/* Initialize our Client */
$client = new Client(JSON_URL, API_TOKEN, API_SIGNATURE, [
'require_timestamp' => true,
'signing_key_digest' => Client::SIGN_DIGEST_SHA256,
'default_store_code' => STORE_CODE,
'curl_options' => []
]);
/* Create a new Request object */
$orderListRequest = new OrderListLoadQuery();
/* include additional order information by including ondemandcolumns */
$orderListRequest->setOnDemandColumns([
'ship_method', // include the shipping method
'cust_login', // include the customers login
'cust_pw_email', // include the customers email address
'business_title', // include the customers business account title
'payment_module', // include the payment module information
'customer', // include the customer information
'items', // include the orders items
'charges', // include the orders charges
'coupons', // include the orders coupons
'discounts', // include the orders discounts
'payments' // include the orders payments
]);
$orderListRequest->addOnDemandColumn('notes'); // include the orders notes
/* Include all custom fields */
$orderListRequest->addOnDemandColumn('CustomField_Values:*');
/* Set the list sorting */
$orderListRequest->setSort('id', OrderListLoadQuery::SORT_DESCENDING);
/* If you wish to decrypt payment data, you must provide the passphrase used by your encryption key */
$orderListRequest->setPassphrase(ENCRYPTION_PASSPHRASE);
// FILTERS
$filters = $orderListRequest->filterExpression();
$filters->equal('id', '200000057')->orEqual('id', '200000056');
$orderListRequest->setFilters($filters);
/* Send the request for a response */
try {
$orderListResponse = $client->send($orderListRequest);
} catch(ClientException $e) {
printf("Error Executing OrderListLoadQuery Request: %s\r\n", $e->getMessage());
exit;
}
if (!$orderListResponse->isSuccess()) {
printf("OrderListLoadQuery Error: %s - %s\r\n", $orderListResponse->getErrorCode(), $orderListResponse->getErrorMessage());
exit;
}
foreach ($orderListResponse->getOrders() as $order) {
printf("Order ID %d With %d Items, %d Charges Total %s\r\n",
$order->getId(), $order->getItems()->count(), $order->getCharges()->count(),
$order->getFormattedTotal());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment