/** * {@inheritdoc} */ public function orderSave(OrderInterface $order) { _uc_credit_save_cc_data_to_order($order->payment_details, $order->id()); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { // Get the data from the form and replace masked data from the order. $cc_data = $form_state->getValue('cc_data'); if (strpos($cc_data['cc_number'], (string) $this->t('(Last 4) ')) === 0) { $cc_data['cc_number'] = $this->order->payment_details['cc_number']; } if (isset($cc_data['cc_cvv']) && isset($this->order->payment_details['cc_cvv'])) { if ($cc_data['cc_cvv'] == str_repeat('-', strlen($cc_data['cc_cvv']))) { $cc_data['cc_cvv'] = $this->order->payment_details['cc_cvv']; } } // Cache the values for use during processing. uc_credit_cache('save', $cc_data, FALSE); // Build the data array passed on to the payment gateway. $data = array(); switch ($form_state->getValue('op')) { case $this->t('Charge amount'): $data['txn_type'] = UC_CREDIT_AUTH_CAPTURE; break; case $this->t('Authorize amount only'): $data['txn_type'] = UC_CREDIT_AUTH_ONLY; break; case $this->t('Set a reference only'): $data['txn_type'] = UC_CREDIT_REFERENCE_SET; break; case $this->t('Credit amount to this card'): $data['txn_type'] = UC_CREDIT_CREDIT; break; case $this->t('Capture amount to this authorization'): $data['txn_type'] = UC_CREDIT_PRIOR_AUTH_CAPTURE; $data['auth_id'] = $form_state->getValue('select_auth'); break; case $this->t('Void authorization'): $data['txn_type'] = UC_CREDIT_VOID; $data['auth_id'] = $form_state->getValue('select_auth'); break; case $this->t('Charge amount to this reference'): $data['txn_type'] = UC_CREDIT_REFERENCE_TXN; $data['ref_id'] = $form_state->getValue('select_ref'); break; case $this->t('Remove reference'): $data['txn_type'] = UC_CREDIT_REFERENCE_REMOVE; $data['ref_id'] = $form_state->getValue('select_ref'); break; case $this->t('Credit amount to this reference'): $data['txn_type'] = UC_CREDIT_REFERENCE_CREDIT; $data['ref_id'] = $form_state->getValue('select_ref'); } $result = uc_payment_process_payment('credit', $this->order->id(), $form_state->getValue('amount'), $data, TRUE, NULL, FALSE); _uc_credit_save_cc_data_to_order(uc_credit_cache('load'), $this->order->id()); if ($result) { drupal_set_message($this->t('The credit card was processed successfully. See the admin comments for more details.')); } else { drupal_set_message($this->t('There was an error processing the credit card. See the admin comments for details.'), 'error'); } $form_state->setRedirect('uc_order.admin_view', ['uc_order' => $this->order->id()]); }