Skip to content
Snippets Groups Projects
Commit 88b90577 authored by mattwire's avatar mattwire
Browse files

Partial support for backend payments (disabled)

parent 93321013
Branches
Tags
No related merge requests found
......@@ -123,7 +123,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
* @return bool
*/
public function supportsBackOffice() {
return TRUE;
// @fixme Make this work again with stripe elements / 6.0
return FALSE;
// return TRUE;
}
/**
......@@ -134,6 +136,11 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
return FALSE;
}
public function supportsRecurring() {
// @fixme: Test and make this work for stripe elements / 6.0
return FALSE;
}
/**
* We can configure a start date for a smartdebit mandate
* @return bool
......@@ -316,7 +323,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
// Add help and javascript
CRM_Core_Region::instance('billing-block')->add(
['template' => 'CRM/Core/Payment/Stripe/Card.tpl', 'weight' => -1]);
CRM_Core_Resources::singleton()->addStyleFile(E::LONG_NAME, 'css/elements.css', 0, 'html-header');
CRM_Core_Resources::singleton()
->addStyleFile(E::LONG_NAME, 'css/elements.css', 0, 'page-header')
->addScriptFile('com.drastikbydesign.stripe', 'js/civicrm_stripe.js');
}
/**
......
......@@ -81,43 +81,40 @@ function stripe_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
}
/**
* Implementation of hook_civicrm_validateForm().
*
* Prevent server validation of cc fields
*
* @param $formName - the name of the form
* @param $fields - Array of name value pairs for all 'POST'ed form values
* @param $files - Array of file properties as sent by PHP POST protocol
* @param $form - reference to the form object
* @param $errors - Reference to the errors array.
*
*/
* Implementation of hook_civicrm_validateForm().
*
* Prevent server validation of cc fields
*
* @param $formName - the name of the form
* @param $fields - Array of name value pairs for all 'POST'ed form values
* @param $files - Array of file properties as sent by PHP POST protocol
* @param $form - reference to the form object
* @param $errors - Reference to the errors array.
*
*/
function stripe_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
if (empty($form->_paymentProcessor['payment_processor_type'])) {
return;
}
// If Stripe is active here.
if ($form->_paymentProcessor['class_name'] == 'Payment_Stripe') {
if (isset($form->_elementIndex['stripe_token'])) {
if ($form->elementExists('credit_card_number')) {
$cc_field = $form->getElement('credit_card_number');
$form->removeElement('credit_card_number', true);
$form->addElement($cc_field);
}
if ($form->elementExists('cvv2')) {
$cvv2_field = $form->getElement('cvv2');
$form->removeElement('cvv2', true);
$form->addElement($cvv2_field);
}
function stripe_civicrm_validateForm($formName, &$fields, &$files, &$form, &$errors) {
if (empty($form->_paymentProcessor['payment_processor_type'])) {
return;
}
// If Stripe is active here.
if ($form->_paymentProcessor['class_name'] == 'Payment_Stripe') {
if (isset($form->_elementIndex['stripe_token'])) {
if ($form->elementExists('credit_card_number')) {
$cc_field = $form->getElement('credit_card_number');
$form->removeElement('credit_card_number', true);
$form->addElement($cc_field);
}
if ($form->elementExists('cvv2')) {
$cvv2_field = $form->getElement('cvv2');
$form->removeElement('cvv2', true);
$form->addElement($cvv2_field);
}
} else {
return;
}
} else {
return;
}
// Flag so we don't add the stripe scripts more than once.
static $_stripe_scripts_added;
}
/**
* Implementation of hook_civicrm_alterContent
......@@ -128,7 +125,6 @@ static $_stripe_scripts_added;
* @return void
*/
function stripe_civicrm_alterContent( &$content, $context, $tplName, &$object ) {
global $_stripe_scripts_added;
/* Adding stripe js:
* - Webforms don't get scripts added by hook_civicrm_buildForm so we have to user alterContent
* - (Webforms still call buildForm and it looks like they are added but they are not,
......@@ -139,12 +135,12 @@ function stripe_civicrm_alterContent( &$content, $context, $tplName, &$object )
*
*/
if (($context == 'form' && !empty($object->_paymentProcessor['class_name']))
|| (($context == 'page') && !empty($object->_isPaymentProcessor))) {
if (!$_stripe_scripts_added || $object instanceof CRM_Financial_Form_Payment) {
|| (($context == 'page') && !empty($object->_isPaymentProcessor))) {
if (!isset(\Civi::$statics[E::LONG_NAME]['stripeJSLoaded']) || $object instanceof CRM_Financial_Form_Payment) {
$stripeJSURL = CRM_Core_Resources::singleton()
->getUrl('com.drastikbydesign.stripe', 'js/civicrm_stripe.js');
$content .= "<script src='{$stripeJSURL}'></script>";
$_stripe_scripts_added = TRUE;
\Civi::$statics[E::LONG_NAME]['stripeJSLoaded'] = TRUE;
}
}
}
......@@ -157,17 +153,15 @@ function stripe_civicrm_alterContent( &$content, $context, $tplName, &$object )
* @param CRM_Core_Form $form
*/
function stripe_civicrm_buildForm($formName, &$form) {
global $_stripe_scripts_added;
if (!isset($form->_paymentProcessor)) {
// Don't load stripe js on ajax forms
if (CRM_Utils_Request::retrieveValue('snippet', 'String') === 'json') {
return;
}
$paymentProcessor = $form->_paymentProcessor;
if (!empty($paymentProcessor['class_name'])) {
if (!$_stripe_scripts_added) {
CRM_Core_Resources::singleton()
->addScriptFile('com.drastikbydesign.stripe', 'js/civicrm_stripe.js');
}
$_stripe_scripts_added = TRUE;
// Load stripe.js on all civi forms per stripe requirements
if (!isset(\Civi::$statics[E::LONG_NAME]['stripeJSLoaded'])) {
CRM_Core_Resources::singleton()->addScriptUrl('https://js.stripe.com/v3');
\Civi::$statics[E::LONG_NAME]['stripeJSLoaded'] = TRUE;
}
}
......
{* https://civicrm.org/licensing *}
<script src="https://js.stripe.com/v3/"></script>
<label for="card-element">
<legend>Credit or debit card</legend>
</label>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment