FILTER BY TAG

Sample Code

The client contains sample scripts and sample PHP pages that you can use to test the client.

Basic PHP Page Example

The example below shows the primary code required to send a Simple Order API request for credit card authorization. The example uses name-value pairs. For a more complete example, see the sample program and sample PHP pages included in the package (see Sample Code). Using Name-Value Pairs shows you how to create the code.
// Load the configuration settings $config = cybs_load_config( 'cybs.ini' ); // set up the request by creating an array and adding fields to it $request = array(); // We want to do credit card authorization in this example $request['ccAuthService_run'] = "true"; // Add required fields $request['merchantID'] = 'infodev'; $request['merchantReferenceCode'] = 'MRC-14344'; $request['billTo_firstName'] = 'Jane'; $request['billTo_lastName'] = 'Smith'; $request['billTo_street1'] = '1295 Charleston Road'; $request['billTo_city'] = 'Mountain View'; $request['billTo_state'] = 'CA'; $request['billTo_postalCode'] = '94043'; $request['billTo_country'] = 'US'; $request['billTo_email'] = 'jsmith@example.com'; $request['card_accountNumber'] = '4111111111111111'; $request['card_expirationMonth'] = '12'; $request['card_expirationYear'] = '2010'; $request['purchaseTotals_currency'] = 'USD'; // This example has two items $request['item_0_unitPrice'] = '12.34'; $request['item_1_unitPrice'] = '56.78'; // Add optional fields here according to your business needs // Send request $reply = array(); $status = cybs_run_transaction( $config, $request, $reply ); // Handle the reply. See Handling the Return Status

Sample Scripts

The client contains two sample scripts, one for using name-value pairs and one for using XML. See Testing the Client, or see the README file for more information about using the
authCaptureSample.php
script to test the client.
  • Name-value pairs: See
    authCaptureSample.php
    in <installation directory>
    /samples/nvp
    .
  • XML: We suggest that you examine the name-value pair sample code listed above before implementing your code to process XML requests.
For the XML sample code, see
authSample.php
in <installation directory>
/samples/xml
. Also see the
auth.xml
XML document that the script uses.

Sample PHP Pages

The client download package also includes sample PHP pages in the
<installation directory>
/samples/store
directory.
Files in sampleStore Directory
File
Description
util.php
Used by the other PHP pages in the directory.
checkout.php
Displays the contents of the shopping basket and prompts for address and payment information.
checkout2.php
Authorizes the order and displays the result.
store_footer.php
Footer used in the checkout pages.
store_header.php
Header used in the checkout pages.

Use the Sample PHP Pages

If you have files in your web server’s root directory that have the same name as the files listed in Files in sampleStore Directory back up those files. You will be copying the sample store files into the root directory in the next step. For Apache, the root directory is the one specified by
DocumentRoot
in
httpd.conf
.
  1. Copy all of the files in the
    <installation directory>
    /samples/store
    directory into your web server’s root directory.
  2. Modify the
    cybs.ini
    file as appropriate. For more information, see Configuring Client Settings.

    ADDITIONAL INFORMATION

    Use absolute paths for the directories in the
    cybs.ini
    file that you use with the sample store, for example:
    keysDirectory
    =
    c:\keys
    .
    If you encounter problems getting the sample PHP pages to work, you might need to locate your
    cybs.ini
    file outside of the root directory.
  3. Open the
    checkout.php
    file in a text editor and locate the
    cybs_load_config()
    function.
  4. Make sure that the parameter for the
    cybs.ini
    file passed to the function includes the absolute path. For example, make sure the line reads:
    $config = cybs_load_config( 'c:\cybs.ini' );

    ADDITIONAL INFORMATION

    not this line:
    $config = cybs_load_config( 'cybs.ini' );
  5. Restart your web server.

    ADDITIONAL INFORMATION

    If you are using Microsoft Internet Information Services (IIS), you might need to restart your computer for IIS to pick up the new server path.
  6. Open a web browser and type the following URL: http://<your web server name or IP address>/<virtual directory if applicable>/checkout.php