class pay_method_direct in Pay 6
Same name and namespace in other branches
- 7 includes/handlers/pay_method_direct.inc \pay_method_direct
@file The base class for 'direct' payment activities, where payments are collected on third-party sites such as PayPal, and the responses are returned to Drupal on a URL callback.
Hierarchy
- class \pay
- class \pay_method
- class \pay_method_direct
- class \pay_method
Expanded class hierarchy of pay_method_direct
File
- includes/
handlers/ pay_method_direct.inc, line 9 - The base class for 'direct' payment activities, where payments are collected on third-party sites such as PayPal, and the responses are returned to Drupal on a URL callback.
View source
class pay_method_direct extends pay_method {
/**
* This method will be called when the user needs to be sent to the gateway
* provider for processing. Override it to include valid request values.
*/
function direct_request() {
}
/**
* This method will be called on a return response (e.g. PayPal IPN)
* including an unfiltered version of the $_REQUEST array. This method must
* be extended in order for your direct method to work!
*/
function direct_response($response = array()) {
}
/**
* Augment the available payment actions for transactions that include
* direct payment methods.
*
* The 'response' action will allow us to respond to updates from the gateway.
*/
function set_valid_actions($pay_form, &$actions) {
$actions['response'] = array(
'title' => 'Response',
'callback' => 'response_action',
'valid states' => array(
'pending',
),
);
}
/**
* Create a stub method to ensure that do_action('authorize') is executed.
* If your subclass wants to change, store, or fixup data before it's sent to
* the gateway, do it by overriding this method.
*
* The 'real' work will be done in the form_submit() function.
*/
function authorize_action($values = array()) {
$this
->set_direct_pending($values);
}
/**
* Create a stub method to ensure that do_action('complete') is executed.
* If your subclass wants to change, store, or fixup data before it's sent to
* the gateway, do it by overriding this method.
*
* The 'real' work will be done in the form_submit() function.
*/
function complete_action($values = array()) {
$this
->set_direct_pending($values);
// Look for an 'authorize' action in this activity's history.
foreach ($this->activity
->history() as $previous) {
// If there was a successful authorization, copy its details.
if ($previous->action == 'authorize' && $previous->result) {
$this->activity->identifier = $previous->identifier;
$this->activity->data = $previous->data;
$this->activity->total = $previous->total;
$this->payment_type = $previous->payment_type;
$this->activity->action = 'complete';
}
}
}
/**
* Implement a 'response' action, which interprets the response from a
* direct payment gateway.
*/
function response_action($values = array()) {
// Copy the submitted/stored values from the previous activity.
foreach ($this->activity
->history() as $previous) {
if (in_array($previous->action, array(
'pending',
'authorize',
)) && $previous->result) {
$this
->__construct($previous->data);
if ($previous->action == 'pending') {
$this->activity->action = $previous->data['action'];
}
}
}
// Get a boolean response from the response parser.
return $this
->direct_response($values) ? 'complete' : 'canceled';
}
/**
* Store values submitted by a form function, etc. This will allow us to
* construct a request to the gateway processor when necessary.
*/
function set_direct_pending($values = array()) {
$this->activity->data = $values;
$this->activity->result = TRUE;
// Store the current activity for response handling, but store 'pending'.
$this->activity->data['action'] = $this->activity->action;
$this->activity->action = 'pending';
// The direct handler may hardcode its payment_type.
if (isset($this->payment_type)) {
$this->activity->payment_type = $this->payment_type;
}
}
function form(&$form, &$form_state) {
global $user;
parent::form($form, $form_state);
if (isset($this->gateway_testmode) && $this->gateway_testmode) {
drupal_set_message(t('The @name payment method is in test mode. This transaction will not be fully processed.', array(
'@name' => $this
->title(),
)), 'warning');
}
$method_form = array();
$method_form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#required' => TRUE,
);
$method_form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#required' => TRUE,
);
if ($user->uid) {
$method_form['mail'] = array(
'#type' => 'value',
'#value' => $user->mail,
);
}
else {
$method_form['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#required' => TRUE,
);
}
$method_form['billto'] = array(
'#type' => 'postal',
'#postal_user' => $user,
'#title' => t('Billing address'),
'#required' => TRUE,
);
// Add this method_form to the expected place on the parent form.
$form[$this->pay_form
->handler()]['pay_method'][$this->pmid] = $method_form;
}
function form_submit(&$form, &$form_state) {
// Find our transaction object provided by pay_form::form_submit().
if (isset($form_state['pay_activity']) && $form_state['pay_activity']) {
foreach ($form_state['pay_activity'] as $key => $activity) {
if ($activity->pmid == $this->pmid) {
// Load the activity as the 'current' one.
$this->activity = pay_activity_load($activity->paid);
$this
->__construct($this->activity->data);
$this->activity->action = $this->pay_form_action;
// Effect a redirect to the direct payment gateway.
if ($this->activity->action && $this->activity->action != 'pending') {
unset($form_state['storage']);
$form_state['rebuild'] = FALSE;
$form_state['redirect'] = $this
->direct_request();
break;
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
pay:: |
property | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | Execute an named Drupal hook function, passing $this as the first parameter. | ||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | 1 | ||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | 1 | ||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | 1 | ||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | Do not allow this value to be automatically set. | ||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | Do not allow this value to be automatically set. | ||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | 2 | ||
pay:: |
function | 1 | ||
pay:: |
function | |||
pay:: |
function | |||
pay:: |
function | |||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property |
Overrides pay:: |
||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
property |
Overrides pay:: |
||
pay_method:: |
property | |||
pay_method:: |
property | |||
pay_method:: |
function | Your payment method should return an array of valid currencies, using 3-digit currency codes. Example: | ||
pay_method:: |
function | Cancel a transaction by marking it as 'canceled'. | 1 | |
pay_method:: |
function | 1 | ||
pay_method:: |
function |
Overrides pay:: |
2 | |
pay_method:: |
function | Set a default description if none is specified. | ||
pay_method:: |
function | Set a default max_amount if none is specified. | ||
pay_method:: |
function | Set a default min_amount if none is specified. | ||
pay_method:: |
function | Set a default title if none is specified. | ||
pay_method:: |
function | Determine whether an action is valid and appropraite for a transaction. | ||
pay_method_direct:: |
function | Create a stub method to ensure that do_action('authorize') is executed. If your subclass wants to change, store, or fixup data before it's sent to the gateway, do it by overriding this method. | ||
pay_method_direct:: |
function | Create a stub method to ensure that do_action('complete') is executed. If your subclass wants to change, store, or fixup data before it's sent to the gateway, do it by overriding this method. | ||
pay_method_direct:: |
function | This method will be called when the user needs to be sent to the gateway provider for processing. Override it to include valid request values. | ||
pay_method_direct:: |
function | This method will be called on a return response (e.g. PayPal IPN) including an unfiltered version of the $_REQUEST array. This method must be extended in order for your direct method to work! | ||
pay_method_direct:: |
function |
Overrides pay:: |
||
pay_method_direct:: |
function |
Overrides pay:: |
||
pay_method_direct:: |
function | Implement a 'response' action, which interprets the response from a direct payment gateway. | ||
pay_method_direct:: |
function | Store values submitted by a form function, etc. This will allow us to construct a request to the gateway processor when necessary. | ||
pay_method_direct:: |
function |
Augment the available payment actions for transactions that include
direct payment methods. Overrides pay_method:: |