<mvt:call>
#
In Miva Merchant’s template language, the <mvt:call>
tag is used to execute built-in system functions or user-defined functions. It allows you to invoke functions within the template code. Here’s a breakdown of how it works:
Parameters#
All parameters accept variables (g.url
) or strings which must be wrapped in single quotes.
Parameters | Description |
---|---|
ACTION | Required, specifies the fully qualified URL to be contacted, starting with http . |
METHOD | Required GET , POST , HEAD , XML , RAW , OPTIONS , PUT , DELETE , TRACE , or CONNECT . In most cases use GET for simple page retrieval and use POST when when transmitting field data. If not specified and METHOD is XML , POST will have content type text/xml . If not specified and METHOD is RAW , will have content type text/plain . |
CONTENT-TYPE | Optional, attribute available when the METHOD is XML or RAW . |
FIELDS | Optional, comma delimited list of variables value pairs sent to the URL when POST is used as the method. The values of the variables listed in the FIELDS attribute will then be passed in the header. |
FILES | Optional, contains variables whose values are filenames that will be uploaded to the URL specified in ACTION . |
CERTFILE | Optional, resolves to a location in the data directory containing a certificate or set of certificates. |
CERTTYPE | Optional, must be either PEM or ASN1 . |
CERTPASS | allows PEM-format certificates and/or private keys to be stored encrypted on disk. If specified, the value of CERTPASS is used to decrypt the certificate and/or private key in the file specified by CERTFILE . |
TIMEOUT | Optional, this value is used if it is smaller than the configured MvCONFIG_CALL_TIMEOUT value. |
HEADERS | Optional, the value in this attribute will be placed after the Empresa-generated HTTP headers, but before the CRLF separating the HTTP headers and the body of the HTTP request. |
PIN-ALGORITHM | [Requires 5.33 engine or above] Optional - PIN-ALGORITHM is either an empty string (which disables pinning), or an OpenSSL digest algorithm identifier, such as sha1 , md5 or sha256 . |
PIN-DIGEST | [Requires 5.33 engine or above] Optional - PIN-DIGEST is the binary “fingerprint” of the X509 certificate (as generated by X509_digest) |
The loop terminates when the entire document has been received, or when an (optional) is encountered. If is encountered, processing start back at the top continuing with the next item.
Function Response#
This function returns the response a single object at a time in a system variable called s.callvalue
. A common practice is to <mvt:eval>
this variable within the loop which will display the entire result.
Example#
JSON API call using 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>