Skip to content

Latest commit

 

History

History
93 lines (72 loc) · 2.51 KB

README.mdown

File metadata and controls

93 lines (72 loc) · 2.51 KB

SagePay

PHP class for interacting with SagePay Direct.

Usage example:

<?php

$sagepay = new SagePay('vendorid', 'live');

if (SagePay::is3dResponse()) {
  $sagepay = SagePay::recover3d();
  $sagepay->complete3d();
  // recover persistent data - see below
  $basket = $sagepay->basket;
}

elseif ($_POST) {

  /**
   * All the below fields are required for successful submission
   * to Sagepay.
   **/

  // VendorTxCode must be unique per successful transaction. Its purpose
  // is to link your record of the charge and the Sagepay transaction.
  $sagepay->VendorTxCode = '0001';

  $sagepay->Amount       = 10;
  $sagepay->Currency     = 'GBP';
  $sagepay->Description  = 'Basket Contents';

  // Get test card details here...
  // http://www.sagepay.co.uk/support/12/36/test-card-details-for-your-test-transactions
  $sagepay->CardHolder   = 'Mr John Doe';
  $sagepay->CardNumber   = '';
    $sagepay->ExpiryDate   = '';
    $sagepay->CV2          = '';
    $sagepay->CardType     = '';


    $sagepay->BillingSurname        = '';
    $sagepay->BillingFirstnames     = '';
    $sagepay->BillingAddress1       = '';
    $sagepay->BillingCity           = '';
    $sagepay->BillingPostCode       = '';
    $sagepay->BillingCountry        = '';
    $sagepay->DeliverySurname       = '';
    $sagepay->DeliveryFirstnames    = '';
    $sagepay->DeliveryAddress1      = '';
    $sagepay->DeliveryFirstnames    = '';
    $sagepay->DeliveryCity          = '';
    $sagepay->DeliveryPostCode      = '';
    $sagepay->DeliveryCountry       = '';



  foreach ($basket_contents as $line_item) {
    $sagepay->addLine($line_item['name'], $line_item['quantity'], $line_item['value'], $line_item['tax']);
  }

  $sagepay->register();

}

if ($sagepay->status() == 'OK') {
  // The order has been completed.
  echo "Payment complete. See details:\n";
  print_r($sagepay->result);
}

elseif ($sagepay->status() == '3DAUTH') {
  // Any data that needs to persist through 3DAUTH can be added to the object
  $sagepay->basket = $basket;

  // POST to ACSURL - usually by outputting a auto-submitting form
  ?>
  <form action="<?=$sagepay->result['ACSURL']?>" method="post">
    <input type="hidden" name="PaReq" value="<?=$sagepay->result['PAReq']?>" />
    <input type="hidden" name="MD" value="<?=$sagepay->result['MD']?>" />
    <input type="hidden" name="TermUrl" value="http://full.path.to/this/page" />
    <input type="submit" value="Continue to Card Verification" />
  </form>
  <?php
}

else {
  echo "Errors:\n";
  print_r($sagepay->result['Errors']);
}