public function voidCreditCard() { fb('PayPal void'); Attempt::setAttemptStatus($this->attemptModel, Attempt::INPROGRESS_STATUS); $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id); $successAttemptCustomData = json_decode($successAttemptModel->custom_data, true); $options = array('username' => $this->gatewayModel->username, 'password' => $this->gatewayModel->routing_number, 'signature' => $this->gatewayModel->shared_secret); $transaction = new PayPal($options); if (self::$isTest) { $transaction->setIsProduction(false); } $transaction->set('TRANSACTIONID', $successAttemptCustomData['tracking_number']); $transaction->void(); try { $response = $transaction->execute(); fb($response); } catch (Exception $e) { $aErrors = array('Error processing your request'); $this->attemptError($aErrors); return false; } if (!is_array($response) || !isset($response['ACK'])) { // payment server errors $aErrors = array('Error processing your request'); $this->attemptError($aErrors); return false; } if (in_array($response['ACK'], array(Paypal::STATUS_SUCCESS, Paypal::STATUS_SUCCESS_WITH_WARNING))) { $this->attemptModel->status = Attempt::SUCCESS_STATUS; $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS; } else { $this->attemptModel->status = Attempt::DECLINED_STATUS; $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS; } //Save custom data $customData = array(); if (isset($response['TRANSACTIONID'])) { $customData['tracking_number'] = $response['REFUNDTRANSACTIONID']; } if (isset($response['CORRELATIONID'])) { $customData['correlation_id'] = $response['CORRELATIONID']; } if (isset($response['REFUNDSTATUS'])) { $customData['refund_status'] = $response['REFUNDSTATUS']; } if (isset($response['PENDINGREASON'])) { $customData['pending_reason'] = $response['PENDINGREASON']; } if ($customData) { $this->attemptModel->custom_data = json_encode($customData); } //Save status_note $errors = array(); if (isset($response['L_ERRORCODE0'])) { $errors[] = 'Code: ' . $response['L_ERRORCODE0']; } if (isset($response['L_LONGMESSAGE0'])) { $errors[] = 'Message: ' . $response['L_LONGMESSAGE0']; } if ($errors) { $this->attemptModel->status_note = implode('. ', $errors); } $this->attemptModel->save(); //Set success status to response $this->_paymetnResponse->attemptModel = $this->attemptModel; $this->_paymetnResponse->paymentModel = $this->paymentModel; OrderLog::createLog(0, $this->orderModel->order_id, 13, $this->attemptModel->amount . ' ' . $this->campaignModel->currency_id); return true; }
public function voidCreditCard() { $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id); $successAttemptCustomData = json_decode($successAttemptModel->custom_data, true); if (self::$isTest) { //Approved / Successful Action //$successAttemptCustomData['tracking_number'] = '44444444-1D500CFBC1CAEA888888-00000001'; //Declined / Forbidden Action //$successAttemptCustomData['tracking_number'] = '44444444-1D500CFBC1CAEA888888-00000002'; //Error (general error) //$successAttemptCustomData['tracking_number'] = '44444444-1D500CFBC1CAEA888888-00000003'; } $transaction = new AldraPay(array('merchantID' => $this->gatewayModel->username, 'passCode' => $this->gatewayModel->shared_secret)); $transaction->set('transactionID', $successAttemptCustomData['tracking_number']); $transaction->void(); try { $result = $transaction->execute(); fb($result); } catch (Exception $e) { $aErrors = array('Error processing your request'); $this->attemptError($aErrors); return false; } if (!$result) { // payment server errors $aErrors = array('Error processing your request'); $this->attemptError($aErrors); return false; } // if not approved if (!isset($result['responseCode']) || !in_array($result['responseCode'], array(1, 7))) { //decline error $error = isset($result['reasonCodeString']) ? $result['reasonCodeString'] : 'Error processing your request'; if (isset($result['transaction']['transactionID'])) { $this->attemptModel->custom_data = json_encode(array('tracking_number' => $result['transaction']['transactionID'])); } $this->attemptError(array($error)); return false; } switch ($result['responseCode']) { case '1': $this->attemptModel->status = Attempt::SUCCESS_STATUS; break; case '7': $this->attemptModel->status = Attempt::SUBMITED_STATUS; break; } if (isset($result['transaction']['transactionID'])) { //the field tracking_number DECIMAL(16,0) $this->attemptModel->custom_data = json_encode(array('tracking_number' => $result['transaction']['transactionID'])); } $this->attemptModel->status_note = ''; if ($result['responseCodeString']) { $this->attemptModel->status_note .= $result['responseCodeString']; } if ($result['reasonCodeString']) { $this->attemptModel->status_note .= ' (' . $result['reasonCodeString'] . ')'; } $this->attemptModel->save(); //Set success status to response $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS; $this->_paymetnResponse->attemptModel = $this->attemptModel; $this->_paymetnResponse->paymentModel = $this->paymentModel; OrderLog::createLog(0, $this->orderModel->order_id, 13, $this->attemptModel->amount . ' ' . $this->campaignModel->currency_id); return true; }
public function voidCreditCard() { $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id); if (!$successAttemptModel) { //it need to test Attempt::setAttemptStatus($this->attemptModel, Attempt::UNKNOWN_STATUS); $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS; return false; } try { $response = $this->send(array('invoiceId' => $successAttemptModel->tracking_number), 'orders/refund', null, false, true); } catch (Exception $e) { //Change Attempt Status to unknown Attempt::setAttemptStatus($this->attemptModel, Attempt::UNKNOWN_STATUS); $this->_paymetnResponse->addError('error_processing_request'); $this->_paymetnResponse->addAlert('error_processing_your_request'); $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS; return false; } if ($response['body']) { //Change Attempt Status to decline $this->attemptModel->status = Attempt::DECLINED_STATUS; $this->attemptModel->status_note = 'Code: ' . $response['xml']->message->code . '. Desc: ' . $response['xml']->message->description; $this->attemptModel->save(); $this->_paymetnResponse->addError('error', $response['body']); $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS; OrderLog::createLog(0, $this->orderModel->order_id, 21, $response['body']); return false; } // Fill and save attempt Model $this->attemptModel->status = Attempt::SUCCESS_STATUS; $this->attemptModel->amount = $successAttemptModel->amount; $this->attemptModel->save(); //Set success status to response $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS; return true; }
public function refundCreditCard() { fb('refundCreditCard'); $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id); $customData = json_decode($successAttemptModel->custom_data); $options = $this->gatewayModel->getAttributes(); $options['url'] = $this->_paymentOptions['refundUrl']; if (self::$isTest) { /* $options['url']='http://pinnaclecrm.com/lj3/scripts/core/pbsapitest.php'; $options ['username']= '******'; $options ['shared_secret']= 'ZFksGze8o7URmtfRqBl3'; $options ['routing_number']= '15132'; */ } $transaction = new PBS($options); $refundType = $successAttemptModel->amount > $this->attemptModel->amount ? 2 : 1; $transaction->set('tradeNo', $customData->tradeNo); $transaction->set('refundType', $refundType); $transaction->set('tradeAmount', number_format($successAttemptModel->amount, 2)); $transaction->set('refundAmount', number_format($this->attemptModel->amount, 2)); $transaction->set('currency', $this->campaignModel->currency_id); $transaction->set('refundReason', 'Refund'); $transaction->set('remark', ''); $transaction->refund(); fb($transaction); $response = $transaction->execute(); fb($response); $xml = new DOMDocument(); $xml->loadXML($response); //some if (!$xml->getElementsByTagName("batchNo")->item(0)->nodeValue) { $this->_paymetnResponse->addAlert('An error occurred'); $this->attemptError(array('error' => 'no batchNo')); return false; } // Fill and save attempt Model $this->attemptModel->status = Attempt::SUCCESS_STATUS; $this->attemptModel->custom_data = json_encode(array('batchNo' => $xml->getElementsByTagName("batchNo")->item(0)->nodeValue)); $this->attemptModel->tracking_number = substr($xml->getElementsByTagName("tradeNo")->item(0)->nodeValue, 15); $this->attemptModel->status_note = $xml->getElementsByTagName("description")->item(0)->nodeValu; $this->attemptModel->save(); //Set success status to response $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS; return true; }
public function voidCreditCard() { fb('Argus void'); $options = $this->gatewayModel->getAttributes(); $options['url'] = $this->_paymentOptions['curlUrl']; $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id); $successCustomData = json_decode($successAttemptModel->custom_data, true); if (self::$isTest) { $options['username'] = '******'; $options['shared_secret'] = 'ZFksGze8o7URmtfRqBl3'; $options['routing_number'] = '16724'; } $transaction = new Argus($options); if (isset($successCustomData['po_id'])) { $transaction->set('request_ref_po_id', $successCustomData['po_id']); } $transaction->void(); $response = $transaction->execute(); $aResponse = $response['response']; fb($transaction); fb($response); if (!isset($aResponse['TRANS_STATUS_NAME']) || $aResponse['TRANS_STATUS_NAME'] != self::STATUS_APPROVED) { $aErrors = array(); $rFields = array('SERVICE_RESPONSE', 'SERVICE_ADVICE', 'PROCESSOR_RESPONSE', 'PROCESSOR_ADVICE', 'INDUSTRY_RESPONSE', 'INDUSTRY_ADVICE'); foreach ($rFields as $itemField) { if (isset($aResponse[$itemField]) && $aResponse[$itemField]) { $aErrors[$itemField] = $aResponse[$itemField]; } } fb($aErrors); $this->attemptError($aErrors); return false; } // Fill and save attempt Model $this->attemptModel->status = Attempt::SUCCESS_STATUS; if (isset($aResponse['TRANS_ID']) && $aResponse['TRANS_ID']) { $this->attemptModel->tracking_number = $aResponse['TRANS_ID']; } if (isset($aResponse['PROC_NAME'])) { $this->attemptModel->status_note = 'Response: ' . $aResponse['PROC_NAME']; } $customDate = array(); $cFields = array('PO_ID', 'BATCH_ID', 'PMT_L4', 'PMT_ID', 'PO_LI_ID_1', 'PO_LI_PROD_ID_1'); foreach ($cFields as $itemcField) { if (isset($aResponse[$itemcField]) && $aResponse[$itemcField]) { $customDate[$itemcField] = $aResponse[$itemcField]; } } if ($customDate) { $this->attemptModel->custom_data = json_encode($customDate); } $this->attemptModel->save(); //Set success status to response $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS; $this->_paymetnResponse->attemptModel = $this->attemptModel; $this->_paymetnResponse->paymentModel = $this->paymentModel; OrderLog::createLog(0, $this->orderModel->order_id, 3, $this->attemptModel->amount . ' ' . $this->campaignModel->currency_id); return true; }
public function voidCreditCard() { $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id); if (!$successAttemptModel) { //it need to test Attempt::setAttemptStatus($this->attemptModel, Attempt::UNKNOWN_STATUS); $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS; return false; } $pacnetOptions = $this->gatewayModel->getAttributes(); //$pacnetOptions['currency_id']=$this->campaignModel->currency_id; $pacnetOptions['isTest'] = self::$isTest; // Create and populate a request object $pymtReq = new RavenRequest('void', $pacnetOptions); $pymtReq->set('RequestID', $this->attemptModel->getrequest_id('pn')); $pymtReq->set('TrackingNumber', $successAttemptModel->tracking_number); $pymtReq->set('PymtType', self::CC_DEBIT); Attempt::setAttemptStatus($this->attemptModel, Attempt::INPROGRESS_STATUS); // Submit the request try { //Send request $pymtResp = $pymtReq->send(); } catch (Exception $e) { //Change Attempt Status to unknown Attempt::setAttemptStatus($this->attemptModel, Attempt::UNKNOWN_STATUS); $this->_paymetnResponse->addError('error_processing_request'); $this->_paymetnResponse->addAlert('error_processing_your_request'); $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS; return false; } $errors = array(); if ($pymtResp->get('httpStatus') == 'timeout') { $respReq = new RavenRequest('response', $this->gatewayModel->getAttributes()); $respReq->set('RequestID', $pymtReq->get('RequestID')); $pymtResp = $respReq->send(); } if ($pymtResp->get('httpStatus') != 200) { $this->_paymetnResponse->addAlert('error_processing_your_request'); $errors['httpStatus'] = $pymtResp->get('httpStatus'); } if ($pymtResp->get('ErrorCode')) { $errorCode = strtolower($pymtResp->get('ErrorCode')); $this->_paymetnResponse->addAlert($pymtResp->get('Message')); if (!in_array($errorCode, $errors)) { $errors['ErrorCode'] = $errorCode; } } if ($errors) { //Change Attempt Status to decline Attempt::setAttemptStatus($this->attemptModel, Attempt::DECLINED_STATUS); foreach ($errors as $key => $error) { $this->_paymetnResponse->addError($key, $error); } $this->_paymetnResponse->status = PaymentAPIResponse::ERROR_STATUS; OrderLog::createLog(0, $this->orderModel->order_id, 21, implode(',', $errors)); return false; } // Fill and save attempt Model $this->attemptModel->status = Attempt::SUCCESS_STATUS; $this->attemptModel->tracking_number = $pymtResp->get('TrackingNumber'); $this->attemptModel->status_note = $pymtResp->get('Status') ? $pymtResp->get('Status') : ''; $this->attemptModel->amount = $pymtResp->get('FormattedAmount'); $this->attemptModel->save(); //Set success status to response $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS; return true; }
public function voidCreditCard() { $successAttemptModel = Attempt::getSuccessAttempt($this->orderModel->order_id); $transaction = new NmiDirectPost(array('nmi_user' => $this->gatewayModel->username, 'nmi_password' => $this->gatewayModel->shared_secret)); $transaction->void($successAttemptModel->tracking_number); $result = $transaction->execute(); fb($result); // if error if ($result['response'] != 1 || !isset($result['response_code']) || $result['response_code'] != 100) { $aErrors = array('Response: ' . $result['responsetext'], ' Code: ' . $result['response_code']); if (isset(Nmi::$responseCodes[$result['response_code']])) { array_push($aErrors, ' Text:' . Nmi::$responseCodes[$result['response_code']]); } $this->attemptError($aErrors); return false; } // Fill and save attempt Model $this->attemptModel->status = Attempt::SUCCESS_STATUS; if (isset($result['transactionid']) && $result['transactionid']) { $this->attemptModel->tracking_number = $result['transactionid']; } $this->attemptModel->status_note = 'Response: ' . $result['responsetext'] . ', Code: ' . $result['response_code']; if (isset(Nmi::$responseCodes[$result['response_code']])) { $this->attemptModel->status_note .= ' Text:' . Nmi::$responseCodes[$result['response_code']]; } if (isset($result['authcode']) && $result['authcode']) { $this->attemptModel->custom_data = json_encode(array('authcode' => $result['authcode'])); } $this->attemptModel->save(); //Set success status to response $this->_paymetnResponse->status = PaymentAPIResponse::SUCCESS_STATUS; $this->_paymetnResponse->attemptModel = $this->attemptModel; $this->_paymetnResponse->paymentModel = $this->paymentModel; OrderLog::createLog(0, $this->orderModel->order_id, 3, $this->attemptModel->amount . ' ' . $this->campaignModel->currency_id); return true; }