Skip to content

Commit

Permalink
Merge pull request #19933 from eileenmcnaughton/pt
Browse files Browse the repository at this point in the history
dev/core#2486 Add payment token api
  • Loading branch information
colemanw authored Mar 30, 2021
2 parents a89b74c + 1c01743 commit bbfe459
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
30 changes: 30 additions & 0 deletions Civi/Api4/PaymentToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

namespace Civi\Api4;

/**
* Payment Token entity.
*
* @see https://docs.civicrm.org/user/en/latest/contributions/payment-processors/#managing-recurring-contributions
*
* @package Civi\Api4
*/
class PaymentToken extends Generic\DAOEntity {
use Generic\Traits\OptionList;

}
40 changes: 32 additions & 8 deletions tests/phpunit/api/v3/PaymentTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
* @group headless
*/
class api_v3_PaymentTokenTest extends CiviUnitTestCase {
protected $_apiversion;
protected $params;
protected $id;

public $DBResetRequired = FALSE;

/**
* Setup for class.
*
* @throws \CiviCRM_API3_Exception
*/
public function setUp(): void {
$this->_apiversion = 3;
$this->useTransaction(TRUE);
$this->useTransaction();
parent::setUp();
$contactID = $this->individualCreate();
$this->params = [
Expand All @@ -33,7 +36,14 @@ public function setUp(): void {
];
}

public function testCreatePaymentToken() {
/**
* Test create token.
*
* @dataProvider versionThreeAndFour
*
* @throws \CRM_Core_Exception
*/
public function testCreatePaymentToken(): void {
$description = "Create a payment token - Note use of relative dates here:
@link http://www.php.net/manual/en/datetime.formats.relative.php.";
$result = $this->callAPIAndDocument('payment_token', 'create', $this->params, __FUNCTION__, __FILE__, $description);
Expand All @@ -42,18 +52,32 @@ public function testCreatePaymentToken() {
$this->getAndCheck(array_merge($this->params, [$this->params]), $result['id'], 'payment_token', TRUE);
}

public function testGetPaymentToken() {
$result = $this->callAPISuccess('payment_token', 'create', $this->params);
/**
* Get token test.
*
* @dataProvider versionThreeAndFour
*
* @throws \CRM_Core_Exception
*/
public function testGetPaymentToken(): void {
$this->callAPISuccess('payment_token', 'create', $this->params);
$result = $this->callAPIAndDocument('payment_token', 'get', $this->params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
}

public function testDeletePaymentToken() {
/**
* Delete token test.
*
* @dataProvider versionThreeAndFour
*
* @throws \CRM_Core_Exception
*/
public function testDeletePaymentToken(): void {
$this->callAPISuccess('payment_token', 'create', $this->params);
$entity = $this->callAPISuccess('payment_token', 'get', ($this->params));
$delete = ['id' => $entity['id']];
$result = $this->callAPIAndDocument('payment_token', 'delete', $delete, __FUNCTION__, __FILE__);
$this->callAPIAndDocument('payment_token', 'delete', $delete, __FUNCTION__, __FILE__);

$checkDeleted = $this->callAPISuccess('payment_token', 'get', []);
$this->assertEquals(0, $checkDeleted['count']);
Expand Down
5 changes: 5 additions & 0 deletions tests/phpunit/api/v4/DataSets/ConformanceTest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@
"create_date" : "now",
"status_id:name" : "Pending"
}
],
"PaymentProcessor" : [
{
"payment_processor_type_id:name": "Dummy"
}
]
}

0 comments on commit bbfe459

Please sign in to comment.