PHP Classes

File: cybersource_example.php

Recommend this page to a friend!
  Classes of David Passey   EPS_Cybersource   cybersource_example.php   Download  
File: cybersource_example.php
Role: Example script
Content type: text/plain
Description: Example scripts
Class: EPS_Cybersource
Process credit card payments via Cybersource
Author: By
Last change:
Date: 14 years ago
Size: 3,083 bytes
 

Contents

Class file image Download
<?php

/**
 * Test script to show how the EPS_CYBERSOURCE class can be used.
 * 06.15.2010
 */

   
require 'class.eps_cybersource.inc';
   
/**
 * These should go in a config file somewhere on the box.
 */
   
$trans_key = 'your SOAP transaction key';
   
$merchant_id = 'your merchant id';
   
$url = 'https://ics2wstest.ic3.com/commerce/1.x/transactionProcessor/CyberSourceTransaction_1.53.wsdl';
   
/**
 * These are sent from some GUI and assembled into the applicable arrays.
 */
   
$bill_array = array('firstName'=>'John','lastName'=>'Doe','street1'=>'1295 Charleston Road','city'=>'Mountain View','state'=>'CA','postalCode' => '94043','country'=>'US','email'=> 'null@cybersource.com','ipaddress'=>'10.7.111.111');
   
$card_array = array('accountNumber'=>'4111111111111111','expirationMonth'=>'12', 'expirationYear'=>'2020','cvNumber'=>'123');
   
$item_array = array(
        array(
'unitPrice'=>'.50','quantity'=>2,'productName'=>'product one'),
        array(
'unitPrice'=>'2.5','quantity'=>1,'productName'=>'product two'));
   
$custom_array = array('one','two','three','four');

/**
 * Authorize a transaction.
 */
   
try
    {
       
$soap = new EPS_CYBERSOURCE($url, $merchant_id,$trans_key);
       
$soap->setMerchantDefinedData($custom_array);
       
$soap->setReferenceCode(array('CSTEST','YYYY','J','-','RNDM'));
       
$soap->setCCRequest($bill_array,$card_array,$item_array);
       
$soap->ccAuthorize();
    }
    catch (
SoapFault $e)
    {
        exit(
$e->getMessage());
    }

   
print_r($soap->reply);

/**
 * Capture the successful authorization.
 * A single ccCapture() could have been done instead of a ccAuthorize() followed by a ccCapture().
 */
   
if ($soap->success) $soap->ccCapture();
   
/**
 * These return values would be stored locally.
 */
   
$tok = $soap->reply->requestToken;
   
$id = $soap->reply->requestID;
   
$rc = $soap->reply->merchantReferenceCode;
   
$amount = $soap->reply->amount;
   
$currency = $soap->reply->currency;

   
print_r($soap->reply);
   
   
$trans_array = array('requestToken'=>$tok,
       
'requestID'=>$id,
       
'referenceCode'=>$rc,
       
'amount'=>$amount,
       
'currency'=>$currency);
   
/**
 * Reverse the capture or authorization.
 */
   
if ($soap->success)
    {
        unset(
$soap);
        try
        {
           
$soap = new EPS_CYBERSOURCE($url, $merchant_id,$trans_key);
           
$soap->setCCReversalRequest($tok,$id,$rc,$amount);
           
$soap->ccReverse('c');
        }
        catch (
SoapFault $e)
        {
            exit(
$e->getMessage());
        }
    }
   
   
print_r($soap->reply);

/**
 * Credit the account.
 */
   
if ($soap->success)
    {
        unset(
$soap);
        try
        {
           
$soap = new EPS_CYBERSOURCE($url, $merchant_id,$trans_key);
           
$soap->setCCCreditRequest($bill_array,$card_array);
           
$soap->setReferenceCode(array('CR','YYYY','J','-',array('RNDM',5,5)));
           
$soap->ccCredit('2.53');
        }
        catch (
SoapFault $e)
        {
            exit(
$e->getMessage());
        }
    }
   
   
print_r($soap->reply);
   
/**
 * Get some help on the XML schema.
 */
   
print_r($soap->getHelp());
   
    echo
"current version: " . $soap->getHelpVersion() . "\n";
   
   
print_r($soap->getHelp('item'));
   
    unset(
$soap);
   

?>