function pay_method_gateway::complete_action in Pay 7
Same name and namespace in other branches
- 6 includes/handlers/pay_method_gateway.inc \pay_method_gateway::complete_action()
Complete a transaction. For new transactions, this means creating an AUTH_CAPTURE request. For existing ones, capture a preauthorization.
Return value
string the recommended transaction state after this action. Possible states are listed in $pay_transaction->states().
File
- includes/
handlers/ pay_method_gateway.inc, line 48 - The base class for credit card payment activities.
Class
- pay_method_gateway
- @file The base class for credit card payment activities.
Code
function complete_action() {
// 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;
}
}
// TODO this should be deprecated: 'activity' has been renamed to 'action'.
$this->activity->activity = $this->activity->action;
// TODO passing in $this->activity should also be deprecated.
$result = $this
->execute($this->activity);
// If successful, increase the 'captured' balance.
if ($result) {
$this->activity
->set_transaction_total($this->activity->total);
}
// If the transaction's state is 'pending', this is an auth_capture
// action. We don't have enough to complete it, so return a failed state.
if ($this->activity
->pay_transaction()
->state() == 'pending') {
return $result ? 'complete' : 'canceled';
}
elseif ($this->activity
->pay_transaction()
->state() == 'active') {
return $result ? 'complete' : 'active';
}
}