Skip to content
Snippets Groups Projects
Commit 3cd87fd0 authored by ayduns's avatar ayduns Committed by mattwire
Browse files

Add entity files for StripeCustomer

parent fa2839cd
No related branches found
No related tags found
1 merge request!2096.8
<?php
use CRM_Stripe_ExtensionUtil as E;
class CRM_Stripe_BAO_StripeCustomer extends CRM_Stripe_DAO_StripeCustomer {
/**
* Create a new StripeCustomer based on array-data
*
* @param array $params key-value pairs
* @return CRM_Stripe_DAO_StripeCustomer|NULL
*
public static function create($params) {
$className = 'CRM_Stripe_DAO_StripeCustomer';
$entityName = 'StripeCustomer';
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, $entityName, CRM_Utils_Array::value('id', $params), $params);
$instance = new $className();
$instance->copyValues($params);
$instance->save();
CRM_Utils_Hook::post($hook, $entityName, $instance->id, $instance);
return $instance;
} */
}
<?php
/**
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*
* Generated from com.drastikbydesign.stripe/xml/schema/CRM/Stripe/StripeCustomer.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:2ce3243ca4d4f01342a48d0ef1ac2d99)
*/
use CRM_Stripe_ExtensionUtil as E;
/**
* Database access object for the StripeCustomer entity.
*/
class CRM_Stripe_DAO_StripeCustomer extends CRM_Core_DAO {
const EXT = E::LONG_NAME;
const TABLE_ADDED = '';
/**
* Static instance to hold the table name.
*
* @var string
*/
public static $_tableName = 'civicrm_stripe_customers';
/**
* Primary key field(s).
*
* @var string[]
*/
public static $_primaryKey = [];
/**
* Should CiviCRM log any modifications to this table in the civicrm_log table.
*
* @var bool
*/
public static $_log = TRUE;
/**
* The Stripe Customer ID
*
* @var string|null
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $id;
/**
* FK to Contact
*
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $contact_id;
/**
* Foreign key to civicrm_payment_processor.id
*
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $processor_id;
/**
* Class constructor.
*/
public function __construct() {
$this->__table = 'civicrm_stripe_customers';
parent::__construct();
}
/**
* Returns localized title of this entity.
*
* @param bool $plural
* Whether to return the plural version of the title.
*/
public static function getEntityTitle($plural = FALSE) {
return $plural ? E::ts('Stripe Customers') : E::ts('Stripe Customer');
}
/**
* Returns foreign keys and entity references.
*
* @return array
* [CRM_Core_Reference_Interface]
*/
public static function getReferenceColumns() {
if (!isset(Civi::$statics[__CLASS__]['links'])) {
Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), 'contact_id', 'civicrm_contact', 'id');
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
}
return Civi::$statics[__CLASS__]['links'];
}
/**
* Returns all the column names of this table
*
* @return array
*/
public static function &fields() {
if (!isset(Civi::$statics[__CLASS__]['fields'])) {
Civi::$statics[__CLASS__]['fields'] = [
'id' => [
'name' => 'id',
'type' => CRM_Utils_Type::T_STRING,
'title' => E::ts('Stripe Customer ID'),
'description' => E::ts('The Stripe Customer ID'),
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_stripe_customers.id',
'table_name' => 'civicrm_stripe_customers',
'entity' => 'StripeCustomer',
'bao' => 'CRM_Stripe_DAO_StripeCustomer',
'localizable' => 0,
'add' => NULL,
],
'contact_id' => [
'name' => 'contact_id',
'type' => CRM_Utils_Type::T_INT,
'description' => E::ts('FK to Contact'),
'where' => 'civicrm_stripe_customers.contact_id',
'table_name' => 'civicrm_stripe_customers',
'entity' => 'StripeCustomer',
'bao' => 'CRM_Stripe_DAO_StripeCustomer',
'localizable' => 0,
'FKClassName' => 'CRM_Contact_DAO_Contact',
'add' => NULL,
],
'processor_id' => [
'name' => 'processor_id',
'type' => CRM_Utils_Type::T_INT,
'title' => E::ts('Payment Processor ID'),
'description' => E::ts('Foreign key to civicrm_payment_processor.id'),
'where' => 'civicrm_stripe_customers.processor_id',
'table_name' => 'civicrm_stripe_customers',
'entity' => 'StripeCustomer',
'bao' => 'CRM_Stripe_DAO_StripeCustomer',
'localizable' => 0,
'pseudoconstant' => [
'table' => 'civicrm_payment_processor',
'keyColumn' => 'id',
'labelColumn' => 'name',
],
'add' => NULL,
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
return Civi::$statics[__CLASS__]['fields'];
}
/**
* Return a mapping from field-name to the corresponding key (as used in fields()).
*
* @return array
* Array(string $name => string $uniqueName).
*/
public static function &fieldKeys() {
if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {
Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
}
return Civi::$statics[__CLASS__]['fieldKeys'];
}
/**
* Returns the names of this table
*
* @return string
*/
public static function getTableName() {
return self::$_tableName;
}
/**
* Returns if this table needs to be logged
*
* @return bool
*/
public function getLog() {
return self::$_log;
}
/**
* Returns the list of fields that can be imported
*
* @param bool $prefix
*
* @return array
*/
public static function &import($prefix = FALSE) {
$r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, 'stripe_customers', $prefix, []);
return $r;
}
/**
* Returns the list of fields that can be exported
*
* @param bool $prefix
*
* @return array
*/
public static function &export($prefix = FALSE) {
$r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, 'stripe_customers', $prefix, []);
return $r;
}
/**
* Returns the list of indices
*
* @param bool $localize
*
* @return array
*/
public static function indices($localize = TRUE) {
$indices = [
'id' => [
'name' => 'id',
'field' => [
0 => 'id',
],
'localizable' => FALSE,
'unique' => TRUE,
'sig' => 'civicrm_stripe_customers::1::id',
],
];
return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;
}
}
......@@ -6,7 +6,7 @@
*
* Generated from com.drastikbydesign.stripe/xml/schema/CRM/Stripe/StripePaymentintent.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:879fe95dcb092ea9b7a6e7df9ed17657)
* (GenCodeChecksum:50c4ef9341699c0242005eede56e04d8)
*/
use CRM_Stripe_ExtensionUtil as E;
......@@ -34,28 +34,36 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO {
/**
* Unique ID
*
* @var int
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $id;
/**
* The Stripe PaymentIntent/SetupIntent/PaymentMethod ID
*
* @var string
* @var string|null
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $stripe_intent_id;
/**
* FK ID from civicrm_contribution
*
* @var int
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $contribution_id;
/**
* Foreign key to civicrm_payment_processor.id
*
* @var int
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $payment_processor_id;
......@@ -63,6 +71,8 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO {
* Description of this paymentIntent
*
* @var string
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $description;
......@@ -70,6 +80,8 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO {
* The status of the paymentIntent
*
* @var string
* (SQL type: varchar(25))
* Note that values will be retrieved from the database as a string.
*/
public $status;
......@@ -77,20 +89,26 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO {
* An identifier that we can use in CiviCRM to find the paymentIntent if we do not have the ID (eg. session key)
*
* @var string
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $identifier;
/**
* FK to Contact
*
* @var int
* @var int|string|null
* (SQL type: int unsigned)
* Note that values will be retrieved from the database as a string.
*/
public $contact_id;
/**
* When was paymentIntent created
*
* @var timestamp
* @var string|null
* (SQL type: timestamp)
* Note that values will be retrieved from the database as a string.
*/
public $created_date;
......@@ -98,6 +116,8 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO {
* Flags associated with this PaymentIntent (NC=no contributionID when doPayment called)
*
* @var string
* (SQL type: varchar(100))
* Note that values will be retrieved from the database as a string.
*/
public $flags;
......@@ -105,6 +125,8 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO {
* HTTP referrer of this paymentIntent
*
* @var string
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $referrer;
......@@ -112,6 +134,8 @@ class CRM_Stripe_DAO_StripePaymentintent extends CRM_Core_DAO {
* Extra data collected to help with diagnostics (such as email, name)
*
* @var string
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
public $extra_data;
......
<?php
namespace Civi\Api4;
/**
* StripeCustomer entity.
*
* Provided by the Stripe Payment Processor extension.
*
* @package Civi\Api4
*/
class StripeCustomer extends Generic\DAOEntity {
}
......@@ -18,4 +18,4 @@ SET FOREIGN_KEY_CHECKS=0;
DROP TABLE IF EXISTS `civicrm_stripe_paymentintent`;
DROP TABLE IF EXISTS `civicrm_stripe_customers`;
SET FOREIGN_KEY_CHECKS=1;
SET FOREIGN_KEY_CHECKS=1;
\ No newline at end of file
CREATE TABLE IF NOT EXISTS `civicrm_stripe_customers` (
`id` varchar(255) DEFAULT NULL,
`contact_id` int(10) UNSIGNED DEFAULT NULL COMMENT 'FK ID from civicrm_contact',
`processor_id` int(10) DEFAULT NULL COMMENT 'ID from civicrm_payment_processor',
UNIQUE KEY `id` (`id`),
CONSTRAINT `FK_civicrm_stripe_customers_contact_id` FOREIGN KEY (`contact_id`)
REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB;
-- /*******************************************************
-- *
-- * Create new tables
-- *
-- *******************************************************/
-- /*******************************************************
-- *
-- * civicrm_stripe_customers
-- *
-- * Stripe Customers
-- *
-- *******************************************************/
CREATE TABLE `civicrm_stripe_customers` (
`id` varchar(255) COMMENT 'Stripe Customer ID',
`contact_id` int unsigned COMMENT 'FK to Contact',
`processor_id` int unsigned COMMENT 'ID from civicrm_payment_processor',
UNIQUE INDEX `id`(id),
CONSTRAINT FK_civicrm_stripe_customers_contact_id FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact`(`id`) ON DELETE CASCADE
)
ENGINE=InnoDB;
......@@ -295,6 +295,11 @@ function _stripe_civix_fixNavigationMenuItems(&$nodes, &$maxNavID, $parentID) {
*/
function _stripe_civix_civicrm_entityTypes(&$entityTypes) {
$entityTypes = array_merge($entityTypes, [
'CRM_Stripe_DAO_StripeCustomer' => [
'name' => 'StripeCustomer',
'class' => 'CRM_Stripe_DAO_StripeCustomer',
'table' => 'civicrm_stripe_customers',
],
'CRM_Stripe_DAO_StripePaymentintent' => [
'name' => 'StripePaymentintent',
'class' => 'CRM_Stripe_DAO_StripePaymentintent',
......
<?php
use Civi\Test\HeadlessInterface;
use Civi\Test\HookInterface;
use Civi\Test\TransactionalInterface;
/**
* StripeCustomer API Test Case
* @group headless
*/
class api_v3_StripeCustomerTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, HookInterface, TransactionalInterface {
use \Civi\Test\Api3TestTrait;
/**
* Set up for headless tests.
*
* Civi\Test has many helpers, like install(), uninstall(), sql(), and sqlFile().
*
* See: https://docs.civicrm.org/dev/en/latest/testing/phpunit/#civitest
*/
public function setUpHeadless() {
return \Civi\Test::headless()
->installMe(__DIR__)
->apply();
}
/**
* The setup() method is executed before the test is executed (optional).
*/
public function setUp() {
$table = CRM_Core_DAO_AllCoreTables::getTableForEntityName('StripeCustomer');
$this->assertTrue($table && CRM_Core_DAO::checkTableExists($table), 'There was a problem with extension installation. Table for ' . 'StripeCustomer' . ' not found.');
parent::setUp();
}
/**
* The tearDown() method is executed after the test was executed (optional)
* This can be used for cleanup.
*/
public function tearDown() {
parent::tearDown();
}
/**
* Simple example test case.
*
* Note how the function name begins with the word "test".
*/
public function testCreateGetDelete() {
// Boilerplate entity has one data field -- 'contact_id'.
// Put some data in, read it back out, and delete it.
$created = $this->callAPISuccess('StripeCustomer', 'create', [
'contact_id' => 1,
]);
$this->assertTrue(is_numeric($created['id']));
$get = $this->callAPISuccess('StripeCustomer', 'get', []);
$this->assertEquals(1, $get['count']);
$this->assertEquals(1, $get['values'][$created['id']]['contact_id']);
$this->callAPISuccess('StripeCustomer', 'delete', [
'id' => $created['id'],
]);
}
}
<?php
// This file declares a new entity type. For more details, see "hook_civicrm_entityTypes" at:
// https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
return [
[
'name' => 'StripeCustomer',
'class' => 'CRM_Stripe_DAO_StripeCustomer',
'table' => 'civicrm_stripe_customers',
],
];
<?xml version="1.0" encoding="iso-8859-1" ?>
<table>
<base>CRM/Stripe</base>
<class>StripeCustomer</class>
<name>civicrm_stripe_customers</name>
<comment>Stripe Customers</comment>
<log>true</log>
<field>
<name>id</name>
<title>Stripe Customer ID</title>
<type>varchar</type>
<length>255</length>
<comment>The Stripe Customer ID</comment>
</field>
<index>
<name>id</name>
<fieldName>id</fieldName>
<unique>true</unique>
</index>
<field>
<name>contact_id</name>
<type>int unsigned</type>
<comment>FK to Contact</comment>
</field>
<foreignKey>
<name>contact_id</name>
<table>civicrm_contact</table>
<key>id</key>
<onDelete>CASCADE</onDelete>
</foreignKey>
<field>
<name>processor_id</name>
<title>Payment Processor ID</title>
<type>int unsigned</type>
<comment>Foreign key to civicrm_payment_processor.id</comment>
<pseudoconstant>
<table>civicrm_payment_processor</table>
<keyColumn>id</keyColumn>
<labelColumn>name</labelColumn>
</pseudoconstant>
</field>
<!-- <foreignKey>
<name>processor_id</name>
<table>civicrm_payment_processor</table>
<key>id</key>
<onDelete>SET NULL</onDelete>
</foreignKey> -->
</table>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment