Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save steveosoule/3ed577918339bbd9ba68ff21f468bed3 to your computer and use it in GitHub Desktop.
Save steveosoule/3ed577918339bbd9ba68ff21f468bed3 to your computer and use it in GitHub Desktop.
Miva - JSON API mvt:call example with HMAC Signature
<mvt:comment>
Replace Access token and signature
</mvt:comment>
<mvt:assign name="g.endpoint" value ="'https://version9.mivamerchant.net/mm5/json.mvc'" />
<mvt:assign name="g.access_token" value ="''" />
<mvt:assign name="g.signature" value ="crypto_base64_decode('')" />
<mvt:assign name="g.timestamp" value="' \"Miva_Request_Timestamp\" : ' $ '\"' $ s.time_t $ '\",' " />
<mvt:comment>Replace Order Id with the new order you created</mvt:comment>
<mvt:assign name="g.json_data" value="'{' $ g.timestamp $ '
\"Store_Code\": \"beta\",
\"Function\": \"OrderList_Load_Query\",
\"Count\": \"1\",
\"Offset\": \"0\",
\"Filter\": [
{
\"name\": \"search\",
\"value\": [
{
\"field\": \"id\",
\"operator\": \"EQ\",
\"value\": \"200001\"
}
]
},
{
\"name\": \"ondemandcolumns\",
\"value\": [
\"payment_module\",
\"cust_pw_email\",
\"cust_login\",
\"ship_method\",
\"customer\",
\"items\",
\"charges\",
\"coupons\",
\"discounts\",
\"payments\",
\"notes\",
\"CustomField_Values:customfields:*\",
\"payment_data\"
]
}
]
}
'"/>
<mvt:assign name="l.ok" value="crypto_hmac_sha256(g.json_data,g.signature,'binary',g.hmac_response)" />
<mvt:assign name="g.b64encoded_hmac_response" value="crypto_base64_encode(g.hmac_response)" />
<mvt:assign name="g.headers" value="'X-Miva-API-Authorization: MIVA-HMAC-SHA256 ' $ g.access_token $ ':' $ g.b64encoded_hmac_response $ asciichar( 13 ) $ asciichar( 10 )" />
<mvt:call action="g.endpoint" method="'RAW'" headers="g.headers" content-type="'application/json'" fields="'g.json_data'">
<mvt:assign name="g.response" value="g.response $ s.callvalue" />
</mvt:call>
Order Load Response: <br>
<textarea rows="20" cols="200">
&mvt:global:response;
</textarea>
<br>
<br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment