You are here

function _uc_recurring_cybersource_create_profile in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 includes/uc_recurring.uc_cybersource.inc \_uc_recurring_cybersource_create_profile()

Set up a CyberSource customer profile

Parameters

$order Order object:

1 call to _uc_recurring_cybersource_create_profile()
uc_recurring_cybersource_process in includes/uc_recurring.uc_cybersource.inc
Set up the recurring fee by creating a CIM profile for future payments

File

includes/uc_recurring.uc_cybersource.inc, line 386
Uc recurring implementation for the CyberSource module.

Code

function _uc_recurring_cybersource_create_profile($order) {
  module_load_include('inc', 'uc_cybersource', 'uc_cybersource.soap');
  try {
    $soapClient = new CyberSourceSoapClient(_uc_recurring_cybersource_soap_wsdl_url(), array());
    $login = _uc_cybersource_soap_login_data();

    // Create the request with some meta data.
    $request = new stdClass();
    $request->merchantID = $login['merchant_id'];
    $request->merchantReferenceCode = $order->order_id;
    $recurringSubscriptionInfo = new stdClass();
    $recurringSubscriptionInfo->amount = 0;
    $recurringSubscriptionInfo->frequency = 'on-demand';
    $request->recurringSubscriptionInfo = $recurringSubscriptionInfo;
    $paySubscriptionCreateService = new stdClass();
    $paySubscriptionCreateService->run = 'true';
    $request->paySubscriptionCreateService = $paySubscriptionCreateService;
    $purchaseTotals = new stdClass();
    $purchaseTotals->currency = variable_get('uc_cybersource_currency', 'usd');
    $request->purchaseTotals = $purchaseTotals;
    $request->billTo = _uc_recurring_cybersource_billto_obj($order);
    $request->card = _uc_recurring_cybersource_card_obj($order);
    $reply = $soapClient
      ->runTransaction($request);
  } catch (SoapFault $exception) {

    // Log and display errors if Ubercart is unable to connect via SOAP.
    watchdog('uc_cybersource', 'Unable to connect to CyberSource via SOAP.', array(), WATCHDOG_ERROR);
    drupal_set_message(t('We apologize for the delay, but we are unable to process your credit card at this time. Please <a href="!url">contact sales</a> to complete your order.', array(
      '!url' => url('contact'),
    )), 'error');
  }
  if (isset($reply->paySubscriptionCreateReply)) {

    // If the create request was successful...
    if ($reply->paySubscriptionCreateReply->reasonCode == '100') {
      $id = $reply->paySubscriptionCreateReply->subscriptionID;

      // Save the subscription ID to the order's data array.
      $order->data = uc_credit_log_reference($order->order_id, $id, $order->payment_details['cc_number']);
      uc_order_comment_save($order->order_id, 0, t('<b>CyberSource profile created.</b><br /><b>Subscription ID:</b> @id', array(
        '@id' => $id,
      )), 'admin');
      return TRUE;
    }
    else {
      uc_order_comment_save($order->order_id, 0, t('<b>Attempt to create CyberSource profile failed.</b><br /><b>Reason:</b> @code', array(
        '@code' => $reply->paySubscriptionCreateReply->reasonCode,
      )), 'admin');
    }
  }
  return FALSE;
}