From 37d9fe653e4dc095ce6e3c478eb948f3a15434ab Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 29 Mar 2021 13:54:16 +1300 Subject: [PATCH] Add payment token api 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 --- Civi/Api4/PaymentToken.php | 30 +++++++++++++++++ tests/phpunit/api/v3/PaymentTokenTest.php | 40 ++++++++++++++++++----- 2 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 Civi/Api4/PaymentToken.php diff --git a/Civi/Api4/PaymentToken.php b/Civi/Api4/PaymentToken.php new file mode 100644 index 000000000000..e7ba25bcd26e --- /dev/null +++ b/Civi/Api4/PaymentToken.php @@ -0,0 +1,30 @@ +_apiversion = 3; - $this->useTransaction(TRUE); + $this->useTransaction(); parent::setUp(); $contactID = $this->individualCreate(); $this->params = [ @@ -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); @@ -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']);