Integrating A Credit Card Payment Processor

To process the credit card details a function called _ccPayment($args) needs to be placed in a file in the "code/" directory for the site.
The function needs to create and return a wtTransaction node with "Successful" set to "Yes" for a successful transaction, or "No" for an unsuccessful transaction.

The _ccPayment($args) will be passed an associative array with the following keys:

Order ID
First Name
Last Name
Email Address
CustomerReference
CardExpiry
CardHolderName
CardNumber
Amount
CardSecurityNumber

Example: Integrating Eway



<?php

function _ccPayment($args) {
  require_once("EwayPayment.php");

  $useSandbox = WTConfig::get("Orders/Payment Options/eWay Options/Use Sandbox");
  if($useSandbox=="Yes")
  {
    $eway = new EwayPayment( '91673884', 'https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp' );
  } else {
    $customerID = WTConfig::get("Orders/Payment Options/eWay Options/Customer ID");
    $eway = new EwayPayment($customerID, 'https://www.eway.com.au/gateway_cvn/xmlpayment.asp' );
  }

  // set the details for the transaction, based on the $args array passed to the function
  $eway->setCustomerFirstname( $args["First Name"] );
  $eway->setCustomerLastname( $args["Last Name"] );
  $eway->setCustomerEmail( $args["Email Address"] );

  $eway->setCustomerInvoiceDescription( $args["CustomerReference"] );

  $expiryMonth = substr($args["CardExpiry"], 0, 2);
  $expiryYear = substr($args["CardExpiry"], 2);

  $eway->setCustomerInvoiceRef( $args["CustomerReference"] );
  $eway->setCardHoldersName( $args["CardHolderName"] );
  $eway->setCardNumber( $args["CardNumber"] );
  $eway->setCardExpiryMonth( $expiryMonth );
  $eway->setCardExpiryYear( $expiryYear );
  $eway->setTrxnNumber( $args["Order ID"] );
  $eway->setTotalAmount( $args["Amount"] * 100 );
  $eway->setCVN( $args["CardSecurityNumber"] );

  // transaction data is used to create the wtTransaction node to return from this function
  $transactionData = Array();
  $transactionData["Description"] = $args["CustomerReference"] . " " . $args["CardHolderName"];

  // try the payment
  if( $eway->doPayment() == EWAY_TRANSACTION_OK ) {
    // successful payment, need to set the "Successful ID" attribute to 1
    $transactionData["Successful ID"] = 1;
    $transactionData["Response"] = $eway->getTrxnError();
    $transactionData["Receipt"] = $eway->getTrxnNumber();
  } else {
    // unsuccessful payment, store the error in the Description attribute of the wtTransaction node
    $error = $eway->getErrorMessage();
    $transactionData["Successful ID"] = 0;
    $transactionData["Response"] = $eway->getTrxnError();
    $transactionData["Receipt"] = $eway->getTrxnNumber();
    $transactionData["Description"] =  $eway->getTrxnError();

  }

  // create the wtTransaction node and return it
  $transactions = $GLOBALS["WT"]->getNode("/Transactions");
  if(!$transactions ) {
    $root = $GLOBALS["WT"]->getNode("/");
    $transactions = $root->createChild("wtNode", Array("Node Name" => "Transactions"));
  }

  if($transactions) {
    return $transactions->createChild("wtTransaction", $transactionData);
  }
}