function samurai_refund($params) { $setup = Samurai::setup(array('sandbox' => $params['testMode'], 'merchantKey' => $params['merchantKey'], 'merchantPassword' => $params['merchantPass'], 'processorToken' => $params['procToken'])); $gatewayid = $params['gatewayid']; $transid = $params['transid']; $amount = $params['amount']; $trans = Samurai_Transaction::find($transid); if ($amount) { $trans->reverse($amount); } else { $trans->reverse(); } if ($trans->isSuccess()) { $refid = $trans->attributes['reference_id']; return array('status' => 'success', 'transid' => $refid); } else { $allerrors = "This transaction could not be processed:\n"; foreach ($trans->errors as $context => $errors) { foreach ($errors as $error) { $allerrors .= $error->description . "\n"; } } return array('status' => 'error', 'rawdata' => $allerrors); } }
private function handleResponse($error, $response) { $transaction = new Samurai_Transaction(); $transaction->handleResponse($error, $response); return $transaction; }