Add payment_processor api
authorColeman Watts <coleman@civicrm.org>
Sun, 7 Apr 2013 22:19:48 +0000 (15:19 -0700)
committerColeman Watts <coleman@civicrm.org>
Sun, 7 Apr 2013 22:27:48 +0000 (15:27 -0700)
api/v3/PaymentProcessor.php [new file with mode: 0644]
api/v3/examples/PaymentProcessorCreate.php [new file with mode: 0644]
api/v3/examples/PaymentProcessorDelete.php [new file with mode: 0644]
tests/phpunit/api/v3/PaymentProcessorTest.php [new file with mode: 0644]
tests/phpunit/api/v3/PaymentProcessorTypeTest.php
tests/phpunit/api/v3/RelationshipTypeTest.php

diff --git a/api/v3/PaymentProcessor.php b/api/v3/PaymentProcessor.php
new file mode 100644 (file)
index 0000000..b3423d1
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.2                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2012                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ * File for the CiviCRM APIv3 PaymentProcessor functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_PaymentProcessor
+ *
+ * @copyright CiviCRM LLC (c) 2004-2013
+ */
+
+/**
+ * Add/Update a PaymentProcessor
+ *
+ * Allowed @params array keys are:
+ * {@getfields payment_processor_create}
+ *
+ * @return array of newly created PaymentProcessor property values.
+ * @access public
+ */
+function civicrm_api3_payment_processor_create($params) {
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust Metadata for Create action
+ *
+ * The metadata is used for setting defaults, documentation & validation
+ * @param array $params array or parameters determined by getfields
+ */
+function _civicrm_api3_payment_processor_create_spec(&$params) {
+  $params['payment_processor_type_id']['api.required'] = 1;
+  $params['is_default']['api.default'] = 0;
+  $params['is_test']['api.default'] = 0;
+}
+
+/**
+ * Deletes an existing PaymentProcessor
+ *
+ * @param  array  $params
+ * {@getfields payment_processor_delete}
+ *
+ * @return array API result Array
+ * @access public
+ */
+function civicrm_api3_payment_processor_delete($params) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Retrieve one or more PaymentProcessor
+ *
+ * @param  mixed[]  (reference) input parameters
+ * {@getfields payment_processor_get}
+ * @param  array $params  an associative array of name/value pairs.
+ *
+ * @return  array details of found PaymentProcessor
+ * @access public
+ */
+function civicrm_api3_payment_processor_get($params) {
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
diff --git a/api/v3/examples/PaymentProcessorCreate.php b/api/v3/examples/PaymentProcessorCreate.php
new file mode 100644 (file)
index 0000000..38b7233
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+
+/*
+ */
+function payment_processor_create_example(){
+$params = array( 
+  'version' => 3,
+  'name' => 'API Test PP',
+  'payment_processor_type_id' => 1,
+  'class_name' => 'CRM_Core_Payment_APITest',
+  'is_recur' => 0,
+  'domain_id' => 1,
+);
+
+  $result = civicrm_api( 'payment_processor','create',$params );
+
+  return $result;
+}
+
+/*
+ * Function returns array of result expected from previous function
+ */
+function payment_processor_create_expectedresult(){
+
+  $expectedResult = array( 
+  'is_error' => 0,
+  'version' => 3,
+  'count' => 1,
+  'id' => 1,
+  'values' => array( 
+      '1' => array( 
+          'id' => '1',
+          'domain_id' => '1',
+          'name' => 'API Test PP',
+          'description' => '',
+          'payment_processor_type_id' => '1',
+          'is_active' => '',
+          'is_default' => 0,
+          'is_test' => 0,
+          'user_name' => '',
+          'password' => '',
+          'signature' => '',
+          'url_site' => '',
+          'url_api' => '',
+          'url_recur' => '',
+          'url_button' => '',
+          'subject' => '',
+          'class_name' => 'CRM_Core_Payment_APITest',
+          'billing_mode' => '1',
+          'is_recur' => 0,
+          'payment_type' => '1',
+        ),
+    ),
+);
+
+  return $expectedResult  ;
+}
+
+
+/*
+* This example has been generated from the API test suite. The test that created it is called
+*
+* testPaymentProcessorCreate and can be found in
+* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/PaymentProcessorTest.php
+*
+* You can see the outcome of the API tests at
+* http://tests.dev.civicrm.org/trunk/results-api_v3
+*
+* To Learn about the API read
+* http://book.civicrm.org/developer/current/techniques/api/
+*
+* and review the wiki at
+* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
+*
+* Read more about testing here
+* http://wiki.civicrm.org/confluence/display/CRM/Testing
+*
+* API Standards documentation:
+* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
+*/
\ No newline at end of file
diff --git a/api/v3/examples/PaymentProcessorDelete.php b/api/v3/examples/PaymentProcessorDelete.php
new file mode 100644 (file)
index 0000000..4156742
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ */
+function payment_processor_delete_example(){
+$params = array( 
+  'id' => 1,
+  'version' => 3,
+);
+
+  $result = civicrm_api( 'payment_processor','delete',$params );
+
+  return $result;
+}
+
+/*
+ * Function returns array of result expected from previous function
+ */
+function payment_processor_delete_expectedresult(){
+
+  $expectedResult = array( 
+  'is_error' => 0,
+  'version' => 3,
+  'count' => 1,
+  'values' => true,
+);
+
+  return $expectedResult  ;
+}
+
+
+/*
+* This example has been generated from the API test suite. The test that created it is called
+*
+* testPaymentProcessorDelete and can be found in
+* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/PaymentProcessorTest.php
+*
+* You can see the outcome of the API tests at
+* http://tests.dev.civicrm.org/trunk/results-api_v3
+*
+* To Learn about the API read
+* http://book.civicrm.org/developer/current/techniques/api/
+*
+* and review the wiki at
+* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
+*
+* Read more about testing here
+* http://wiki.civicrm.org/confluence/display/CRM/Testing
+*
+* API Standards documentation:
+* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
+*/
\ No newline at end of file
diff --git a/tests/phpunit/api/v3/PaymentProcessorTest.php b/tests/phpunit/api/v3/PaymentProcessorTest.php
new file mode 100644 (file)
index 0000000..7813b24
--- /dev/null
@@ -0,0 +1,162 @@
+<?php
+// $Id$
+
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.3                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+require_once 'CiviTest/CiviUnitTestCase.php';
+
+/**
+ * Class contains api test cases for "civicrm_payment_processor"
+ *
+ */
+class api_v3_PaymentProcessorTest extends CiviUnitTestCase {
+  protected $_paymentProcessorType;
+  protected $_apiversion;
+  protected $_params;
+  public $_eNoticeCompliant = TRUE;
+  function get_info() {
+    return array(
+      'name' => 'PaymentProcessor Create',
+      'description' => 'Test all PaymentProcessor Create API methods.',
+      'group' => 'CiviCRM API Tests',
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+    $this->_apiversion = 3;
+    // Create dummy processor
+    $params = array(
+      'version' => $this->_apiversion,
+      'name' => 'API_Test_PP_Type',
+      'title' => 'API Test Payment Processor Type',
+      'class_name' => 'CRM_Core_Payment_APITest',
+      'billing_mode' => 'form',
+      'is_recur' => 0,
+    );
+    $result = civicrm_api('payment_processor_type', 'create', $params);
+    $this->_paymentProcessorType = $result['id'];
+    $this->_params = array(
+      'version' => $this->_apiversion,
+      'name' => 'API Test PP',
+      'payment_processor_type_id' => $this->_paymentProcessorType,
+      'class_name' => 'CRM_Core_Payment_APITest',
+      'is_recur' => 0,
+      'domain_id' => 1,
+    );
+  }
+
+  function tearDown() {
+
+    $tablesToTruncate = array(
+      'civicrm_payment_processor',
+      'civicrm_payment_processor_type',
+    );
+    $this->quickCleanup($tablesToTruncate);
+  }
+
+  ///////////////// civicrm_payment_processor_add methods
+
+  /**
+   * check with no name
+   */
+  function testPaymentProcessorCreateWithoutName() {
+    $payProcParams = array(
+      'is_active' => 1,
+      'version' => $this->_apiversion,
+    );
+    $result = civicrm_api('payment_processor', 'create', $payProcParams);
+
+    $this->assertEquals($result['is_error'], 1);
+  }
+
+  /**
+   * create payment processor
+   */
+  function testPaymentProcessorCreate() {
+    $params = $this->_params;
+    $result = civicrm_api('payment_processor', 'create', $params);
+    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $this->assertNotNull($result['id'], 'in line ' . __LINE__);
+
+    // mutate $params to match expected return value
+    unset($params['version']);
+    //assertDBState compares expected values in $result to actual values in the DB
+    $this->assertDBState('CRM_Financial_DAO_PaymentProcessor', $result['id'], $params);
+    return $result['id'];
+  }
+
+  /**
+   * Test  using example code
+   */
+  function testPaymentProcessorCreateExample() {
+    require_once 'api/v3/examples/PaymentProcessorCreate.php';
+    $result = payment_processor_create_example();
+    $expectedResult = payment_processor_create_expectedresult();
+    $this->assertEquals($result['is_error'], 0);
+  }
+
+  ///////////////// civicrm_payment_processor_delete methods
+
+  /**
+   * check payment processor type delete
+   */
+  function testPaymentProcessorDelete() {
+    $id = $this->testPaymentProcessorCreate();
+    // create sample payment processor type.
+    $params = array(
+      'id' => $id,
+      'version' => $this->_apiversion,
+    );
+
+    $result = civicrm_api('payment_processor', 'delete', $params);
+    $this->documentMe($params, $result, __FUNCTION__, __FILE__);
+    $this->assertEquals($result['is_error'], 0);
+  }
+
+  ///////////////// civicrm_payment_processors_get methods
+
+  /**
+   * check with valid params array.
+   */
+  function testPaymentProcessorsGet() {
+    $params = $this->_params;
+    $params['user_name'] = 'test@test.com';
+    civicrm_api('payment_processor', 'create', $params);
+
+    $params = array(
+      'user_name' => 'test@test.com',
+      'version' => $this->_apiversion,
+    );
+    $results = civicrm_api('payment_processor', 'get', $params);
+
+    $this->assertEquals(0, $results['is_error'], ' in line ' . __LINE__);
+    $this->assertEquals(1, $results['count'], ' in line ' . __LINE__);
+    $this->assertEquals('test@test.com', $results['values'][$results['id']]['user_name'], ' in line ' . __LINE__);
+  }
+}
+
index 7cef998e477568d96f5d2df5eacadf0a282bb1d3..ec5b480b3d4372bba806e185df142bf305f2fec9 100644 (file)
@@ -34,8 +34,6 @@ require_once 'CiviTest/CiviUnitTestCase.php';
  *
  */
 class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
-  protected $_cId_a;
-  protected $_cId_b;
   protected $_ppTypeID;
   protected $_apiversion;
   public $_eNoticeCompliant = TRUE;
@@ -51,14 +49,11 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
 
     parent::setUp();
     $this->_apiversion = 3;
-    $this->_cId_a      = $this->individualCreate(NULL);
-    $this->_cId_b      = $this->organizationCreate(NULL);
   }
 
   function tearDown() {
 
     $tablesToTruncate = array(
-      'civicrm_contact',
       'civicrm_payment_processor_type',
     );
     $this->quickCleanup($tablesToTruncate);
@@ -225,7 +220,7 @@ class api_v3_PaymentProcessorTypeTest extends CiviUnitTestCase {
       'version' => $this->_apiversion,
     );
 
-    $result = &civicrm_api('payment_processor_type', 'create', $params);
+    $result = civicrm_api('payment_processor_type', 'create', $params);
     $this->assertNotNull($result['id']);
     unset($params['version']);
     // assertDBState compares expected values in $result to actual values in the DB
index b33b8d8224e9b06f82243710035bc77f2470fb24..eb95ad6c2102447f6930f5b10db6e88be00509f4 100644 (file)
@@ -275,7 +275,7 @@ class api_v3_RelationshipTypeTest extends CiviUnitTestCase {
       'version' => $this->_apiversion,
     );
 
-    $result = &civicrm_api('relationship_type', 'create', $params);
+    $result = civicrm_api('relationship_type', 'create', $params);
     $this->assertNotNull($result['id']);
     unset($params['version']);
     // assertDBState compares expected values in $result to actual values in the DB