Payment_Process
[ class tree: Payment_Process ] [ index: Payment_Process ] [ all elements ]

Source for file Payment_Process-example.php

Documentation is available at Payment_Process-example.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at                              |
  11. // | http://www.php.net/license/3_0.txt.                                  |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Ian Eure <ieure@php.net>                                    |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Payment_Process-example.php,v 1.3 2004/03/22 20:37:13 ieure Exp $
  20.  
  21. require 'Payment/Process.php';
  22.  
  23. // Set options. These are processor-specific.
  24. $options = array(
  25.     'randomResult' => true
  26. );
  27.  
  28. // Get an instance of the processor
  29. $processor Payment_Process::factory('Dummy'$options);
  30.  
  31. // The data for our transaction.
  32. $data = array(
  33.     'login' => "foo",
  34.     'password' => "bar",
  35.     'action' => PAYMENT_PROCESS_ACTION_NORMAL,
  36.     'amount' => 15.00
  37. );
  38.  
  39. // The credit card information
  40. $cc &Payment_Process_Type::factory('CreditCard');
  41. $cc->cardNumber = "4111111111111111";
  42. $cc->expDate = "99/99";
  43. $cc->cvv = "123";
  44.  
  45. /* Alternately, you can use setFrom()
  46. $ccData = array(
  47.     'type' => PAYMENT_PROCESS_CC_VISA,
  48.     'cardNumber' => "4111111111111111",
  49.     'expDate' => "99/99",
  50.     'cvv' => 123
  51. );
  52. $cc->setFrom($ccData);
  53. */
  54.  
  55. // Process it
  56. $processor->setFrom($data);
  57. if (!$processor->setPayment(&$cc)) {
  58.     PEAR::raiseError("Payment data is invalid.");
  59.     die();
  60. }
  61. $result $processor->process();
  62.  
  63. if (PEAR::isError($result)) {
  64.     // process() returns a PEAR_Error if validation failed.
  65.     print "Validation failed: {$result->message}\n";
  66. else if ($result->isSuccess()) {
  67.     // Transaction approved
  68.     print "Success: ";
  69. else {
  70.     // Transaction declined
  71.     print "Failure: ";
  72. }
  73. print $result->getMessage()."\n";
  74.  
  75. ?>

Documentation generated on Mon, 11 Mar 2019 14:00:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.