Showing posts with label addcrn. Show all posts
Showing posts with label addcrn. Show all posts

Wednesday, March 26, 2014

Create/edit crn for nab transact

/**
* crn is the key of the token payment system of NAB transact.
* It must be a unique key against one account.
* And must be less than 20 characters length.
* Can contains a-z, A-Z, 0-9, space, underscore.
* To edit existing customer in NAB account, please 
* find the block '<actionType>addcrn</actionType>' in xml below
* and replace 'addcrn' with 'editcrn' and please provide 
* a valid crn existing against provided merchant account.
*/


<?php
/* TEST MERCHANT ID=XYZ0010 */
/* TEST PASSWORD=abcd1234 */
/* Replace this parameters when using in real transaction */
$nabXml = "<NABTransactMessage>
    <MerchantInfo>
        <merchantID>XYZ0010</merchantID>
        <password>abcd1234</password>
    </MerchantInfo>
    <RequestType>Periodic</RequestType>
    <Periodic>
        <PeriodicList count='1'>
            <PeriodicItem ID='1'>
                <actionType>addcrn</actionType>
                <periodicType>5</periodicType>
                <crn>ABDNK3D389D</crn>
                <CreditCardInfo>
                    <cardNumber>4444333322221111</cardNumber>
                    <expiryDate>01/15</expiryDate>
                </CreditCardInfo>
            </PeriodicItem>
        </PeriodicList>
    </Periodic>
</NABTransactMessage>";
/* LIVE URL=https://transact.nab.com.au/xmlapi/periodic */
$result = makeCurlCall(
    "https://transact.nab.com.au/xmlapidemo/periodic", /* CURL URL */
    "POST", /* CURL CALL METHOD */
    array( /* CURL HEADERS */
        "Content-Type: text/xml; charset=utf-8",
        "Accept: text/xml",
        "Pragma: no-cache",
        "Content_length: ".strlen(trim($nabXml))
    ),
    null, /* CURL GET PARAMETERS */
    $nabXml /* CURL POST PARAMETERS AS XML */
);
header('Content-type: text/xml');
echo $result["response"];
function makeCurlCall($url, $method = "GET", $headers = null, $gets = null, $posts = null) {
    $ch = curl_init();
    if($gets != null)
    {
        $url.="?".(http_build_query($gets));
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    if($posts != null)
    {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $posts);
    }
    if($method == "POST") {
        curl_setopt($ch, CURLOPT_POST, true);
    } else if($method == "PUT") {
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
    } else if($method == "HEAD") {
        curl_setopt($ch, CURLOPT_NOBODY, true);
    }
    if($headers != null && is_array($headers))
    {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }
    $response = curl_exec($ch);
    $code = curl_getinfo($ch,CURLINFO_HTTP_CODE);

    curl_close($ch);
    return array(
        "code" => $code,
        "response" => $response
    );
}
?>

And valid output would be like this:

<NABTransactMessage>
    <MessageInfo>
        <messageID/>
        <messageTimestamp>20142603215200606000+660</messageTimestamp>
        <apiVersion/>
    </MessageInfo>
    <MerchantInfo>
        <merchantID>XYZ0010</merchantID>
    </MerchantInfo>
    <Status>
        <statusCode>0</statusCode>
        <statusDescription>Normal</statusDescription>
    </Status>
    <RequestType>Periodic</RequestType>
    <Periodic>
        <PeriodicList count="1">
            <PeriodicItem ID="1">
                <actionType>addcrn</actionType>
                <crn>ABDNK3D389D</crn>
                <responseCode>00</responseCode>
                <responseText>Successful</responseText>
                <successful>yes</successful>
                <DirectEntryInfo>
                    <bsbNumber/>
                    <accountNumber/>
                    <accountName/>
                    <creditFlag>no</creditFlag>
                </DirectEntryInfo>
                <CreditCardInfo>
                    <pan>444433...111</pan>
                    <expiryDate>01/15</expiryDate>
                    <recurringFlag>no</recurringFlag>
                </CreditCardInfo>
                <currency>AUD</currency>
                <periodicType>5</periodicType>
                <paymentInterval/>
                <numberOfPayments/>
            </PeriodicItem>
        </PeriodicList>
    </Periodic>
</NABTransactMessage>