You are here

function _uc_authorizenet_cim_profile_charge in Ubercart 8.4

Same name and namespace in other branches
  1. 5 payment/uc_authorizenet/uc_authorizenet.module \_uc_authorizenet_cim_profile_charge()
  2. 6.2 payment/uc_authorizenet/uc_authorizenet.module \_uc_authorizenet_cim_profile_charge()
  3. 7.3 payment/uc_authorizenet/uc_authorizenet.module \_uc_authorizenet_cim_profile_charge()

Uses a reference to charge to a CIM profile.

1 call to _uc_authorizenet_cim_profile_charge()
AuthorizeNet::chargeCard in payment/uc_authorizenet/src/Plugin/Ubercart/PaymentMethod/AuthorizeNet.php
Called when a credit card should be processed.

File

payment/uc_authorizenet/uc_authorizenet.module, line 89
Processes payments using Authorize.net. Supports AIM and ARB.

Code

function _uc_authorizenet_cim_profile_charge(OrderInterface $order, $amount, $data) {
  global $user;
  $server = variable_get('uc_authnet_cim_mode', 'disabled');

  // Help build the request.
  $request = _uc_authorizenet_cim_profile_charge_request($order, $amount, $data);

  // Check error state.
  if (array_key_exists('errorCode', $request)) {
    $comment[] = $request['text'];
    $result = [
      'success' => FALSE,
    ];
  }
  else {

    // Request a profile from auth.net.
    $xml = _uc_authorizenet_xml_api_wrapper('createCustomerProfileTransactionRequest', _uc_authorizenet_array_to_xml($request));

    // Parse the response.
    $response = _uc_authorizenet_cim_parse_response(uc_authorizenet_xml_api($server, $xml));

    // Error state.
    if ($response['resultCode'] == 'Error') {
      $result = [
        'success' => FALSE,
      ];
      $comment[] = '(' . $response['resultCode'] . ': ' . $response['text'] . ')';
    }
    else {
      $result = [
        'success' => TRUE,
      ];

      // Build info message.
      $types = uc_credit_transaction_types();
      $comment[] = t('<b>@type:</b> @amount', [
        '@type' => $types[$data['txn_type']],
        '@amount' => uc_currency_format($amount),
      ]);
    }

    // Save a comment to the order.
    uc_order_comment_save($order
      ->id(), $user
      ->id(), implode('<br />', $comment), 'admin');
  }

  // Build the response to the payment gateway API.
  return $result + [
    'comment' => implode(', ', $comment),
    'message' => implode('<br />', $comment),
    'uid' => $user
      ->id(),
  ];
}