hook_receipt_process_payment

Definition

hook_receipt_process_payment($receipt, $atype, $object)
ecommerce-5--4/docs/developer/hooks/ec_receipt.php, line 136

Description

Using the information past from the payment form the system will process the payment and update the receipt.

Parameters

$receipt A blank receipt is past to the system for the payment to be connected to. The identifier for the payment is against the receipt and not the transactions. At this stage the transaction may or may not have been created, and if there is a crash the receipt can be tracked to the customer.

$type The allocation type which corresponds to the $object which can be past to the e-Commerce Receipt allocation interface.

$object This is a data type which can pass the information to the allocation interface to reteive data from the object.

Return value

Pass back the $receipt->erid after ec_receipt_save($receipt);

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_receipt_process_payment($receipt, $atype, $object) {

  // Some receipt types, like C.O.D. may just set some values and return.
  // This example looks at a payment gateway.

  // Do some general preparation of xml, or whatever the gateway requires.
  // $ret == ...

  $ret = drupal_http_request(variable_get('my_gateway_url', $gateway_url), $headers, 'POST', $request_xml);
  $response = simplexml_load_string($ret->data);

  switch ($response->txnStatus) {
    case 'True':
      $receipt->status = RECEIPT_STATUS_COMPLETED;
      $receipt->approval_code = $response->authCode;
      break;

    case 'False':
      $receipt->status = RECEIPT_STATUS_FAILED;
      $receipt->response_text = $response->trxnError;
      form_set_error('', $receipt->response_text);
      break;
  }
  ec_receipt_save($receipt);

  return $receipt->erid;
}
?>