Skip to content

Commit

Permalink
Add payment token api
Browse files Browse the repository at this point in the history
I put up a merge request to edit in somewhere to link to
https://lab.civicrm.org/documentation/docs/user-en/-/merge_requests/472 since I couldn't
see anywhere that payment tokens were discussed
  • Loading branch information
eileenmcnaughton committed Mar 30, 2021
1 parent 5b92de4 commit 57520df
Show file tree
Hide file tree
Showing 2 changed files with 62 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

0 comments on commit 57520df

Please sign in to comment.