Skip to content

Commit

Permalink
Added feature to stripe plugin to allow setting a field with custom v…
Browse files Browse the repository at this point in the history
…alue on the custoemrs table when payment goes thru
  • Loading branch information
cheesegrits committed Jan 13, 2017
1 parent b67c74d commit 195ddf7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
15 changes: 15 additions & 0 deletions plugins/fabrik_form/stripe/forms/fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,21 @@
table="params_stripe_customers_table"
type="element"/>

<field connection="params_stripe_customers_connection"
description="PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_FIELD_DESC"
label="PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_FIELD_LABEL"
name="stripe_customers_custom_field"
repeat="true"
table="params_stripe_customers_table"
type="element"/>

<field name="stripe_customers_custom_value"
type="text"
default=""
description="PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_VALUE_DESC"
label="PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_VALUE_LABEL"
repeat="true"/>

<field connection="params_stripe_customers_connection"
description="PLG_FORM_STRIPE_CUSTOMERS_BILLING_NAME_DESC"
label="PLG_FORM_STRIPE_CUSTOMERS_BILLING_NAME_LABEL"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ PLG_FORM_STRIPE_CUSTOMERS_STRIPEID_DESC="This is the field you use to store the
PLG_FORM_STRIPE_CUSTOMERS_STRIPEID_LABEL="Stripe ID Element"
PLG_FORM_STRIPE_CUSTOMERS_INSERT_DESC="If yes, the plugin will insert a row in this table with the user ID and stripe ID fields filled in. If no, the plugin will only update an existing row with the matching user ID"
PLG_FORM_STRIPE_CUSTOMERS_INSERT_LABEL="Insert Customer"
PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_FIELD_DESC="Optionally select an element to write a custom value into when a payment is made."
PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_FIELD_LABEL="Custom Field"
PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_VALUE_DESC="Optionally specify value to write into custom field when a payment is made. Can use placeholders."
PLG_FORM_STRIPE_CUSTOMERS_CUSTOM_VALUE_LABEL="Custom Value"
PLG_FORM_STRIPE_COLLECT_BILLING_ADDRESS_DESC="If yes, the Stripe payment process will ask for their billing address, which you can then store in your (optional) Customer data table"
PLG_FORM_STRIPE_COLLECT_BILLING_ADDRESS_LABEL="Collect Billing Address"
PLG_FORM_STRIPE_CUSTOMERS_BILLING_NAME_DESC="Element to store billing name"
Expand Down
28 changes: 28 additions & 0 deletions plugins/fabrik_form/stripe/stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ public function onBeforeStore()
$formModel->updateFormData($chargeEmailField, $tokenEmail, true, true);
}

$this->updateCustomerCustom($userId);

$opts = new stdClass;
$opts->listid = $listModel->getId();
$opts->formid = $formModel->getId();
Expand Down Expand Up @@ -670,6 +672,32 @@ private function getCustomerId($userId)
return $cDb->loadResult();
}

private function updateCustomerCustom($userId)
{
$params = $this->getParams();
$cDb = FabrikWorker::getDbo(false, $params->get('stripe_customers_connection'));
$cQuery = $cDb->getQuery(true);
$cUserIdField = FabrikString::shortColName($params->get('stripe_customers_userid'));
$customField = FabrikString::shortColName($params->get('stripe_customers_custom_field'));
$customValue = $params->get('stripe_customers_custom_value', '');

if (empty($cUserIdField) || empty($customField) || empty($customValue))
{
return;
}

$w = new FabrikWorker;
$customValue = $w->parseMessageForPlaceHolder($customValue, $this->data);

$cQuery
->clear()
->update($cDb->quoteName($this->getCustomerTableName()))
->set($cDb->quoteName($customField) . ' = ' . $cDb->quote($customValue))
->where($cDb->quoteName($cUserIdField) . ' = ' . $cDb->quote($userId));
$cDb->setQuery($cQuery);
$cDb->execute();
}

private function updateCustomerId($userId, $customerId, $opts)
{
$params = $this->getParams();
Expand Down

0 comments on commit 195ddf7

Please sign in to comment.