⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 verisign.php

📁 apache windows下的一款好
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php /* -*- C++ -*- */
/*
   +----------------------------------------------------------------------+
   | PHP version 4.0                                                      |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2001 The PHP Group                                |
   +----------------------------------------------------------------------+
   | This source file is subject to version 2.02 of the PHP license,      |
   | that is bundled with this package in the file LICENSE, and is        |
   | available at through the world-wide-web at                           |
   | http://www.php.net/license/2_02.txt.                                 |
   | If you did not receive a copy of the PHP license and are unable to   |
   | obtain it through the world-wide-web, please send a note to          |
   | license@php.net so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author: David Croft: <david@infotrek.co.uk>                          |
   +----------------------------------------------------------------------+
*/

/* $Id: Verisign.php,v 1.3 2001/01/10 01:01:58 ssb Exp $ */

/*                 ******** NOTICE ********
 *
 *   This code is completely untested. Do not use it!
 *   It is here for peer review. It will undergo revision, bugfixes
 *   and probably API changes. It must not be used yet!
 */

/* Verisign Payment Processing class.
 *
 * Some test cards:
 * Amex:       378282246310005
 * Discover:   6011111111111117
 * Mastercard: 5105105105105100 or 5555555555551111
 * Visa:       4242424242424242 or 4111111111111111
*/

require_once 'PEAR.php';


/* Symbolic names for decoded response codes */
/* We want as few of these as possible so calling code has fewer branches */

define("VERISIGN_SUCCESS",                 0);

/* 10+ - user errors */

define("VERISIGN_BAD_CARD",               10);
define("VERISIGN_INVALID_EXPIRY",         11);
define("VERSIGIN_BAD_CARD_TYPE",          12);

/* 20+ - our errors */

define("VERISIGN_CONFIG_ERROR",           20);
define("VERISIGN_UNRECOGNISED_RESPONSE",  21);

/* 30+ - temporary errors, try again later */

define("VERISIGN_TEMPORARY_ERROR",        30);
define("VERISIGN_REFERRAL",               31);


class Payment_Verisign
{
  /* These are all private variables. DO NOT ACCESS THEM DIRECTLY. */
  /* There are specific functions to set each of these */

  var $hostaddress = 'test.signio.com';
  var $hostport = 443;

  var $timeout = 30;

  var $proxyaddress;
  var $proxyport;
  var $proxylogon;
  var $proxypassword;

  var $username;
  var $password;

  var $cardnumber;
  var $expiredate;

  var $params = array();

  function Payment_Verisign()
  {
    /* can you return stuff from a constructor? */

    if (!extension_loaded('pfpro')) {
      return new VerisignException('Payflow Pro module is not compiled into PHP. Compile PHP using --with-pfpro.');
    }
  }

  function set_host($hostaddress, $hostport = 443)
  {
    if (!$hostaddress or !strlen($hostaddress)) {
      return new VerisignException('Invalid host address');
    }

    if (!$hostport or $hostport < 1) {
      return new VerisignException('Invalid host port');
    }

    $this->hostaddress = $hostaddress;
    $this->hostport = $hostport;
  }

  function set_timeout($timeout)
  {
    if ($timeout < 1 or $timeout > 3600) {
      return new VerisignException('Invalid timeout value');
    }

    $this->timeout = $timeout;
  }

  function set_logon($username, $password)
  {
    if (!$username or !strlen($username)) {
      return new VerisignException('Invalid user name');
    }

    if (!$password or !strlen($password)) {
      return new VerisignException('Invalid password');
    }

    $this->username = $username;
    $this->password = $password;
  }

  function set_proxy($proxyaddress, $proxyport = 443, $proxylogon = '', $proxypassword = '')
  {
    if (!$proxyaddress or !strlen($proxyaddress)) {
      return new VerisignException('Invalid proxy address');
    }

    if (!$proxyport or $proxyport < 1) {
      return new VerisignException('Invalid proxy port');
    }
    
    $this->proxyaddress = $proxyaddress;
    $this->proxyport = $proxyport;

    if ($proxylogon and strlen($proxylogon)) {
      $this->proxypassword = $proxylogon;
    }

    if ($proxylogon and strlen($proxypassword)) {
      $this->proxypassword = $proxypassword;
    }
  }

  function set_card($cardnumber, $expiremonth, $expireyear)
  {
    $this->cardnumber = $cardnumber;

    if ($expiremonth < 1 or $expiremonth > 12) {
      return new VerisignException('Invalid expiry month');
    }

    if (($expireyear > 99 and $expireyear < 2000) or $expireyear > 2100) {
      return new VerisignException('Invalid expiry year');
    }

    $this->expiredate = sprintf("%02d%02d", $expiremonth, ($expireyear > 100) ? ($expireyear % 100) : $expireyear);

  }

  function set_avs($street, $zip)
  {
    if (!$street or !is_string($street) or !strlen($street)) {
      return new VerisignException('AVS Street was not specified or was not a string');
    }
    if (!$zip or !is_string($zip) or !strlen($zip)) {
      return new VerisignException('AVS Zip was not specified or was not a string');
    }

    $this->params['STREET'] = $street;
    $this->params['ZIP'] = $zip;
  }

  function add_parameter($key, $value)
  {
    if (!$key or !is_string($key) or !strlen($key)) {
      return new VerisignException('Key must be a string');
    }

    $this->params[$key] = $value;
  }

  function add_parameters($newparams)
  {
    foreach ($newparams as $key => $value) {
      if (!$key or !is_string($key) or !strlen($key)) {
	return new VerisignException('Keys must be strings');
      }
    }

    $this->params = array_merge($this->params, $newparams);
  }

  function reset_parameters()
  {
    $this->params = array();
  }

  function set_comment1($comment)
  {
    $this->params['COMMENT1'] = $comment;
  }

  function set_comment2($comment)
  {
    $this->params['COMMENT2'] = $comment;
  }

  /* Functions to process transactions */

  /* sale: authorise and immediate capture */

  function sale($amount)
  {
    if (!$amount or $amount <= 0) {
      return new VerisignException('You cannot perform a sale on a negative or zero amount');
    }

    $this->params['AMT'] = number_format($amount, 2, '.', '');

    return $this->process('S');
  }

  /* authorise: authorise only for capture later with capture() */

  function authorize($amount)
  {
    /* for the yanks */
    return $this->authorise($amount);
  }

  function authorise($amount)
  {
    if (!$amount or $amount <= 0) {
      return new VerisignException('You cannot perform an authorisation on a negative or zero amount');
    }

    $this->params['AMT'] = number_format($amount, 2, '.', '');

    return $this->process('A');
  }

  /* capture: capture an authorised transaction */

  function capture($origid)
  {
    if (!$origid or !strlen($origid)) {
      return new VerisignException('You must provide the original PNREF id for a delayed capture');
    }

    $this->params['ORIGID'] = $origid;

    return $this->process('D');
  }

  /* refund: give money back (ouch) */

  function refund($amount)
  {
    if (!$amount or $amount <= 0) {
      return new VerisignException('You cannot perform an authorisation on a negative or zero amount');
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -