I deliberately excluded card_type because I think we need to review the appropriateness of
the field first. My issue is that the wrangling wound up really wierd & it was apparent the issue
is that card_type is 'Visa' whereas card_type_id is 1 - we should either rename the field
or store the word.
// records finanical trxn and entity financial trxn
// also make it available as return value
self::recordAlwaysAccountsReceivable($trxnParams, $params);
+ $trxnParams['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $params);
$return = $financialTxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams);
$params['entity_id'] = $financialTxn->id;
if (empty($params['partial_payment_total']) && empty($params['partial_amount_pay'])) {
$params['partial_payment_total'] = $contributionDAO->total_amount;
$params['partial_amount_pay'] = $trxnsData['total_amount'];
$trxnsData['net_amount'] = !empty($trxnsData['net_amount']) ? $trxnsData['net_amount'] : $trxnsData['total_amount'];
+ $params['pan_truncation'] = CRM_Utils_Array::value('pan_truncation', $trxnsData);
// record the entry
$financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData);
}
if (empty($defaults['payment_instrument_id'])) {
- $defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
+ $defaults['payment_instrument_id'] = $this->getDefaultPaymentInstrumentId();
}
if (!empty($defaults['is_test'])) {
$paneNames[ts('Premium Information')] = 'Premium';
}
- if ($this->_mode) {
- if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE) == TRUE) {
- if (!empty($this->_recurPaymentProcessors)) {
- $buildRecurBlock = TRUE;
- if ($this->_ppID) {
- // ppID denotes a pledge payment.
- foreach ($this->_paymentProcessors as $processor) {
- if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) {
- $buildRecurBlock = TRUE;
- break;
- }
- $buildRecurBlock = FALSE;
+ if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE, $this->getDefaultPaymentInstrumentId()) == TRUE) {
+ if (!empty($this->_recurPaymentProcessors)) {
+ $buildRecurBlock = TRUE;
+ if ($this->_ppID) {
+ // ppID denotes a pledge payment.
+ foreach ($this->_paymentProcessors as $processor) {
+ if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) {
+ $buildRecurBlock = TRUE;
+ break;
}
+ $buildRecurBlock = FALSE;
}
- if ($buildRecurBlock) {
- CRM_Contribute_Form_Contribution_Main::buildRecur($this);
- $this->setDefaults(array('is_recur' => 0));
- $this->assign('buildRecurBlock', TRUE);
- $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
- }
+ }
+ if ($buildRecurBlock) {
+ CRM_Contribute_Form_Contribution_Main::buildRecur($this);
+ $this->setDefaults(array('is_recur' => 0));
+ $this->assign('buildRecurBlock', TRUE);
+ $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
}
}
}
return 0;
}
+ /**
+ * Get the default payment instrument id.
+ *
+ * @return int
+ */
+ protected function getDefaultPaymentInstrumentId() {
+ $paymentInstrumentID = CRM_Utils_Request::retrieve('payment_instrument_id', 'Integer');
+ if ($paymentInstrumentID) {
+ return $paymentInstrumentID;
+ }
+ return key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
+ }
+
}
'is_required' => TRUE,
),
+ 'check_number' => array(
+ 'htmlType' => 'text',
+ 'name' => 'check_number',
+ 'title' => ts('Check Number'),
+ 'is_required' => FALSE,
+ 'cc_field' => TRUE,
+ 'attributes' => NULL,
+ ),
+ 'pan_truncation' => array(
+ 'htmlType' => 'text',
+ 'name' => 'pan_truncation',
+ 'title' => ts('Last 4 digits of the card'),
+ 'is_required' => FALSE,
+ 'cc_field' => TRUE,
+ 'attributes' => array(
+ 'size' => 4,
+ 'maxlength' => 4,
+ 'autocomplete' => 'off',
+ ),
+ ),
);
}
* @return array
*/
public function getPaymentFormFields() {
+ if (!$this->isBackOffice()) {
+ return array();
+ }
+
+ $paymentInstrument = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', $this->getPaymentInstrumentID());
+ if ($paymentInstrument === 'Credit Card') {
+ // @todo - return credit_card_type field once the underlying code works to extract this field.
+ // Note the problem is this should be stored in civicrm_financial_trxn.credit_card_type.
+ // However there is an ambiguity as that field is an integer & should hence be called
+ // credit_card_type_id, or it should store 'visa' It probably makes sense to fix that before going much
+ // further as the code I've seen makes it clear that it will require work arounds.
+ return array('pan_truncation');
+ }
+ elseif ($paymentInstrument === 'Check') {
+ // Really we should render check_number here, but we need to review how we edit
+ // check_numebr since we expose it as editable on the contribution form,
+ // even though it should only be editable from a transation specific form.
+ return array();
+ }
return array();
}
+
/**
* Process payment.
*
* @return string
*/
public function getPaymentTypeLabel() {
- return '';
+ return 'Payment';
}
/**
</td>
</tr>
</table>
+
<div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="paymentDetails_Information">
+ {if !$contributionMode}
<div class="crm-accordion-header">
{if $paymentType EQ 'refund'}{ts}Refund Details{/ts}{else}{ts}Payment Details{/ts}{/if}
</div>
<span class="description">{ts}Net value of the payment (Total Amount minus Fee).{/ts}</span></td></tr>
</table>
</div>
+ {/if}
{include file='CRM/Core/BillingBlockWrapper.tpl'}
</div>
</table>
{if !$contributionMode}
- <div class="crm-accordion-wrapper crm-accordion_title-accordion crm-accordion-processed" id="paymentDetails_Information">
- <div class="crm-accordion-header">
- {ts}Payment Details{/ts}
- </div>
- <div class="crm-accordion-body">
<table class="form-layout-compressed" >
<tr class="crm-contribution-form-block-receive_date">
<td class="label">{$form.receive_date.label}</td>
<td>{$form.from_email_address.html}</td>
</tr>
</table>
- </div>
- </div>
{/if}
{include file='CRM/Core/BillingBlockWrapper.tpl'}
buildPaymentBlock($(this).val());
});
+ $('#payment_instrument_id').on('change.paymentBlock', function() {
+ buildPaymentBlock(0);
+ });
+
$('#billing-payment-block').on('crmLoad', function() {
$('.crm-submit-buttons input').prop('disabled', false);
})