sage pay testing error

Posted by Phil Jackson on Stack Overflow See other posts from Stack Overflow or by Phil Jackson
Published on 2011-02-17T06:28:46Z Indexed on 2011/02/17 7:25 UTC
Read the original article Hit count: 437

Filed under:
|
|
|

Hi, im trying to test my sage pay integration but to no avail.

Here is my code:

private function init_sagepay(){
    extract( static::$post );
    $settings = global_data::get_settings();
    $strConnectTo = "TTEST";
    $strVirtualDir = "VSPForm-Kit";
    $strYourSiteFQDN = global_data::get_web_root();  
    $strVSPVendorName = $settings->sagepay_vendor;
    $strEncryptionPassword = "z5p************";
    $strCurrency = static::$currency;
    $strVendorEMail = $settings->sagepay_email;
    $strTransactionType = "PAYMENT";

    $strProtocol = "2.23";
    if ( $strConnectTo == "LIVE" ) 
        $strPurchaseURL = "https://live.sagepay.com/gateway/service/vspform-register.vsp"; 
    elseif ( $strConnectTo == "TEST" )
        $strPurchaseURL = "https://test.sagepay.com/gateway/service/vspform-register.vsp";
    elseif( $strConnectTo == 'TTEST' )
        $strPurchaseURL = 'https://test.sagepay.com/Simulator/VSPServerGateway.asp?Service=VendorRegisterTx';
    else
        $strPurchaseURL = "https://test.sagepay.com/Simulator/VSPDirectGateway.asp";

    $details = self::get_member_details();
    $thisOrderDeteails = 'order details...';
    $ThisVendorTxCode = 'fdsdgfd';
    $ThisAmount = $total;
    $ThisCurrency = static::$currency;
    $ThisDescription = "description...";
    $ThisCustomerEmail = $details->email;
    $ThisCustomerName = $details->first_name . " " . $details->last_name;
    $ThisVendorEmail = $strVendorEMail;
    $ThisApplyAVSCV2 = 1;
    $ThisApply3DSecure = 1;
    $ThisDeliveryAddress = $address_line_1 . ", " . $address_line_2 . ", " . $address_line_3 . ", " . $address_line_4 . ", " . $country;
    $ThisDeliveryPostCode = $postcode;
    $address_full = $ThisDeliveryAddress . ' ' . $ThisDeliveryPostCode;

    $ThisBillingAddress = $details->address_line_1 . ", " . $details->address_line_2 . ", " . $details->address_line_3 . ", " . $details->address_line_4 . ", " . $details->country;
    $ThisBillingPostCode = $details->postcode;

    // new 2.22 fields
    $ThisContactNumber = $details->home_number;
    $ThisContactFax = $details->fax_number;
    $ThisAllowGiftAid = '';
    //$ThisApplyAVSCV2 = $_REQUEST[ 'ApplyAVSCV2' ];
    //$ThisApply3DSecure = $_REQUEST[ 'Apply3DSecure' ];
    $ShoppingBasket = array();
    $x = 0;
    foreach( $items as $item ) {
        preg_match( "#^\[([^\]]+)\]\[([^\]]+)\]$#is", $item, $match );
        $item = $match[1];
        $price = $match[2];
        $ShoppingBasket[$x][0] = $item;
        $ShoppingBasket[$x][1] = $price;
        $x++;
    }

    if ( isset( $ShoppingBasket ) ) {
        $ThisShoppingBasket = $ShoppingBasket;
    }else{
        $ThisShoppingBasket = "OFF";  
    }

    //** Build the crypt string plaintext **
    $stuff = "VendorTxCode=" . $ThisVendorTxCode . "&";
    $stuff .= "Amount=" . $ThisAmount . "&";
    $stuff .= "Currency=" . $ThisCurrency . "&";
    $stuff .= "Description=" . $ThisDescription . "&";
    $stuff .= "SuccessURL=" . $strYourSiteFQDN . "completed.php&";
    $stuff .= "FailureURL=" . $strYourSiteFQDN . "notcompleted.php&";

    if ($ThisCustomerEmail) {
      $stuff .= "CustomerEmail=" . $ThisCustomerEmail . "&";
    }
    if ($ThisVendorEmail) {
      $stuff .= "VendorEmail=" . $ThisVendorEmail . "&";
    }
    if ($ThisCustomerName) {
      $stuff .= "CustomerName=" . $ThisCustomerName . "&";
    }
    if ($ThisDeliveryAddress) {
      $stuff .= "DeliveryAddress=" . $ThisDeliveryAddress . "&";
    }
    if ($ThisDeliveryPostCode) {
      $stuff .= "DeliveryPostCode=" . $ThisDeliveryPostCode . "&";
    }
    if ($ThisBillingAddress) {
      $stuff .= "BillingAddress=" . $ThisBillingAddress . "&";
    }
    if ($ThisBillingPostCode) {
      $stuff .= "BillingPostCode=" . $ThisBillingPostCode . "&";
    }
    // new 2.22 fields
    if ($ThisContactNumber) {
      $stuff .= "ContactNumber=" . $ThisContactNumber . "&";
    }
    if ($ThisContactFax) {
      $stuff .= "ContactFax=" . $ThisContactFax . "&";
    }
    if ($ThisAllowGiftAid) {
      $stuff .= "AllowGiftAid=" . $ThisAllowGiftAid . "&";
    }
    if ($ThisApplyAVSCV2) {
      $stuff .= "ApplyAVSCV2=" . $ThisApplyAVSCV2 . "&";
    }
    if ($ThisApply3DSecure) {
      $stuff .= "Apply3DSecure=" . $ThisApply3DSecure . "&";
    }
    //echo $stuff;
    if ($ThisShoppingBasket=="ON") {
      $stuff .= "Basket=3:Sony SV-234 DVD Player:1:£170.20:£29.79:£199.99:£199.99:The Fast and The Furious Region 2 DVD:2:£17.01:£2.98:£19.99:£39.98:Delivery:1:£4.99:----:£4.99:£4.99&";
    }

    $stuff .= "EMailMessage=For an update on the status of your order please email us at $ThisVendorEmail";

    $crypt = self::base64Encode( self::SimpleXor( $stuff,$strEncryptionPassword ) );

    $ThisDate = date('U');

    ob_start();
    ?>
    <form action="<?php echo $strPurchaseURL; ?>" method="post" id="sageForm" name="form1">
        <input TYPE="hidden" name="VPSProtocol" value="<?php echo $strProtocol; ?>">
        <input TYPE="hidden" name="TxType" value="<?php echo $strTransactionType; ?>">
        <input TYPE="hidden" name="Vendor" value="<?php echo $strVSPVendorName; ?>">
        <input TYPE="hidden" name="Crypt" value="<?php echo $crypt; ?>">    
        <input name="sbbutton" type="submit" value="Checkout" class="wpcf7-submit">                  
    </form>     
    <?php
    return ob_get_clean();
}

when using "TEST" im getting an error:

Status Detail:  5005 : The Vendor configuration is missing or invalid

when using "TTEST" im getting an error:

VPSProtocol=2.23
Status=INVALID
StatusDetail=The VendorTxCode you supplied is an invalid length.  VendorTxCodes should be between 1 to 40 characters long

I cannot seem to figure this out at all. If anyone has any ideas it would be greatfuly appreciated.

EDIT: $stuff echos out:

VendorTxCode=fdsdgfd&Amount=45.60&Currency=GBP&Description=description...&SuccessURL=http://localhost/ecom_framework/&FailureURL=http://localhost/ecom_framework/&[email protected]&[email protected]&CustomerName=Luke Snowden&DeliveryAddress=mansfield, nottinghamshire, mansfield, nottinghamshire, United Kingdom&DeliveryPostCode=ng19 8pw&BillingAddress=mansfield, nottinghamshire, mansfield, nottinghamshire, United Kingdom&BillingPostCode=ng19 8pw&ContactNumber=0165656567&ApplyAVSCV2=1&Apply3DSecure=1&Basket=3:Blue Hat - black :2:£2£:0.00:£4.00:Blue Hat - brown :3:£3£:0.00:£9.00:Blue Hat - grey :4:£4£:0.00:£16.00:Delivery:1:£4.99EMailMessage=For an update on the status of your order please email us at [email protected]

© Stack Overflow or respective owner

Related posts about php

Related posts about error