/** * Contact anet and attempt to refund the payment * @see ApplyPaymentInterface::refundPayment() */ public function refundPayment(\Jazzee\Entity\Payment $payment, \Foundation\Form\Input $input) { $client = new \SoapClient(self::CASHNET_WSDL); $parameters = array('OperatorID' => $this->_paymentType->getVar('operatorId'), 'Password' => $this->_paymentType->getVar('operatorPassword'), 'VirtualDirectory' => $this->_controller->getConfig()->getStatus() == 'PRODUCTION' ? self::CASHNET_VIRTUALDIRECTORY : self::CASHNET_TEST_VIRTUALDIRECTORY, 'TransactionNo' => $input->get('transactionId')); $results = $client->CASHNetSOAPRequestInquiry(array('inquiryParams' => $parameters)); $xml = new \SimpleXMLElement($results->CASHNetSOAPRequestInquiryResult); if ($xml->result != 0) { return "Unable to get refund transaction details from cashnet for payment: {$payment->getId()}, transaction: {$input->get('transactionId')} for applicant {$payment->getAnswer()->getApplicant()->getId()}. Cashnet said: {$xml->respmessage}"; } if ($xml->transactions[0]->transaction->txno == $input->get('transactionId')) { $payment->refunded(); $payment->setVar('refundAmount', $xml->transactions[0]->transaction->totalamount); $payment->setVar('refundTransactionId', $xml->transactions[0]->transaction->txno); $payment->setVar('refundedReason', $input->get('refundedReason')); return true; } else { throw new \Jazzee\Exception("Transaction details differ between cashnet and payment: {$payment->getId()} for applicant {$payment->getAnswer()->getApplicant()->getId()}."); } return true; }
/** * Record the reason the payment was refunded * @see ApplyPaymentInterface::rejectPaymentForm() */ public function getRefundPaymentForm(\Jazzee\Entity\Payment $payment) { $transactionDetails = new \AuthorizeNetTD($this->_paymentType->getVar('gatewayId'), $this->_paymentType->getVar('gatewayKey')); $transactionDetails->setSandBox($this->_paymentType->getVar('testAccount')); //test accounts get sent to the sandbox // Get Transaction Details $transactionId = $payment->getVar('transactionId'); $response = $transactionDetails->getTransactionDetails($transactionId); if ($response->isError()) { throw new \Jazzee\Exception('Unable to get transaction details for payment #' . $payment->getId() . " transcation id {$transactionId}. Authorize.net said " . $response->getMessageText(), E_ERROR, 'There was a problem getting payment information.'); } $submitted = new \DateTime($response->xml->transaction->submitTimeLocal); if ($submitted->diff(new \DateTime())->days > 120) { throw new \Jazzee\Exception('Cannot refund payment, it is too old. Payment ID #' . $payment->getId() . " transcation id {$transactionId}.", E_ERROR, 'Payment is too old to refund.'); } $form = new \Foundation\Form(); $field = $form->newField(); $field->setLegend('Refund Payment'); $element = $field->newElement('Plaintext', 'details'); $element->setLabel('Details'); $element->setValue('Refund $' . $payment->getAmount() . ' to card ' . $response->xml->transaction->payment->creditCard->cardNumber); $element = $field->newElement('Textarea', 'refundedReason'); $element->setLabel('Reason displayed to Applicant'); $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element)); $form->newHiddenElement('cardNumber', substr($response->xml->transaction->payment->creditCard->cardNumber, strlen($response->xml->transaction->payment->creditCard->cardNumber) - 4, 4)); $form->newHiddenElement('zip', (string) $response->xml->transaction->billTo->zip); $form->newButton('submit', 'Save'); return $form; }