/** * React to DSP response triggered by {@link processPayment()}. */ public function processResponse() { if (preg_match('/^PXHOST/i', $_SERVER['HTTP_USER_AGENT'])) { $dpsDirectlyConnecting = 1; } //$pxaccess = new PxAccess($PxAccess_Url, $PxAccess_Userid, $PxAccess_Key, $Mac_Key); $pxpay = new PxPay(DPSHostedPayment::$pxPay_Url, DPSHostedPayment::get_px_pay_userid(), DPSHostedPayment::get_px_pay_key()); $enc_hex = $_REQUEST["result"]; $rsp = $pxpay->getResponse($enc_hex); if (isset($dpsDirectlyConnecting) && $dpsDirectlyConnecting) { // DPS Service connecting directly $success = $rsp->getSuccess(); # =1 when request succeeds echo $success == '1' ? "success" : "failure"; } else { // Human visitor $paymentID = $rsp->getTxnId(); $SQL_paymentID = (int) $paymentID; $payment = DataObject::get_one('DPSHostedPayment', "`TxnID` = '{$SQL_paymentID}'"); if (!$payment) { // @todo more specific error messages return array('RedirectLink' => AccountPage::find_link()); } $success = $rsp->getSuccess(); if ($success == '1') { // @todo Use AmountSettlement for amount setting? $payment->TxnRef = $rsp->getDpsTxnRef(); $payment->Status = "Success"; $payment->AuthorizationCode = $rsp->getAuthCode(); } else { $payment->Message = $rsp->getResponseText(); $payment->Status = "Failure"; } $payment->write(); //TODO: this needs to be generalised in Payment?? $redirectURL = $payment->PaidObject() && $payment->PaidObject()->Link() ? $payment->PaidObject()->Link() : 'home'; Director::redirect($redirectURL); return null; } }
/** * React to DSP response triggered by {@link processPayment()}. */ public function processResponse() { if (preg_match('/^PXHOST/i', $_SERVER['HTTP_USER_AGENT'])) { $dpsDirectlyConnecting = 1; } // @todo more solid page detection (check if published) $page = DataObject::get_one('DPSHostedPaymentPage'); //$pxaccess = new PxAccess($PxAccess_Url, $PxAccess_Userid, $PxAccess_Key, $Mac_Key); $pxpay = new PxPay(DPSHostedPayment::$pxPay_Url, DPSHostedPayment::get_px_pay_userid(), DPSHostedPayment::get_px_pay_key()); $enc_hex = $_REQUEST["result"]; $rsp = $pxpay->getResponse($enc_hex); if (isset($dpsDirectlyConnecting) && $dpsDirectlyConnecting) { // DPS Service connecting directly $success = $rsp->getSuccess(); # =1 when request succeeds echo $success == '1' ? "success" : "failure"; } else { // Human visitor $paymentID = $rsp->getTxnId(); $SQL_paymentID = (int) $paymentID; $payment = DataObject::get_one('DPSHostedPayment', "`TxnID` = '{$SQL_paymentID}'"); if (!$payment) { // @todo more specific error messages $redirectURL = $page->Link() . '/error'; $this->redirect($redirectURL); } $success = $rsp->getSuccess(); if ($success == '1') { // @todo Use AmountSettlement for amount setting? $payment->TxnRef = $rsp->getDpsTxnRef(); $payment->Status = "Success"; $payment->AuthorizationCode = $rsp->getAuthCode(); $redirectURL = $page->Link() . '/success'; } else { $payment->Message = $rsp->getResponseText(); $payment->Status = "Failure"; $redirectURL = $page->Link() . '/error'; } $payment->write(); $this->redirect($redirectURL); } }
/** * Action called by DPS right after a payment operation, being a success or a failure * Will update the status of the payment accordingly, and redirect to the success/failure url * where more domain specific operations can be performed * @see {http://www.paymentexpress.com/technical_resources/ecommerce_hosted/pxaccess.html#ResultNotification} */ public function processDPSHostedResponse() { $pxpay = new PxPay(self::$pxPay_Url, self::$pxPay_Userid, self::$pxPay_Key); $enc_hex = $_REQUEST["result"]; $rsp = $pxpay->getResponse($enc_hex); $paymentID = $rsp->getTxnData1(); $SQL_paymentID = (int) $paymentID; if ($dpsBillingID = $rsp->getDpsBillingId()) { $payment = DataObject::get_by_id('DPSRecurringPayment', $SQL_paymentID); $payment->DPSBillingID = $dpsBillingID; } else { $payment = DataObject::get_by_id("DPSPayment", $SQL_paymentID); } if ($payment) { if (self::$using_transaction) { DB::getConn()->transactionStart(); } try { $payment->ResponseXML = $rsp->toXml(); $success = $rsp->getSuccess(); if ($success == '1') { // @todo Use AmountSettlement for amount setting? $payment->Status = "Success"; } else { $payment->Status = "Failure"; } $payment->TxnRef = $rsp->getDpsTxnRef(); $payment->AuthCode = $rsp->getAuthCode(); $payment->DateExpiry = $rsp->getDateExpiry(); $payment->CardNumberTruncated = $rsp->getCardNumber(); $payment->CardHolderName = $rsp->getCardHolderName(); $payment->Message = $rsp->getResponseText(); $payment->write(); if (self::$using_transaction) { DB::getConn()->transactionEnd(); } } catch (Exception $e) { if (self::$using_transaction) { DB::getConn()->transactionRollback(); } $payment->handleError($e); } Director::redirect($payment->DPSHostedRedirectURL); } else { Director::redirect(Director::baseURL()); } }
function processDPSHostedResponse() { if (preg_match('/^PXHOST/i', $_SERVER['HTTP_USER_AGENT'])) { $dpsDirectlyConnecting = 1; } $pxpay = new PxPay(self::$pxPay_Url, self::$pxPay_Userid, self::$pxPay_Key); $enc_hex = $_REQUEST["result"]; $rsp = $pxpay->getResponse($enc_hex); if (isset($dpsDirectlyConnecting) && $dpsDirectlyConnecting) { // DPS Service connecting directly $success = $rsp->getSuccess(); # =1 when request succeeds echo $success == '1' ? "success" : "failure"; } else { // Human visitor $paymentID = $rsp->getTxnData1(); $SQL_paymentID = (int) $paymentID; if ($dpsBillingID = $rsp->getDpsBillingId()) { $payment = DataObject::get_by_id('DPSRecurringPayment', $SQL_paymentID); $payment->DPSBillingID = $dpsBillingID; } else { $payment = DataObject::get_by_id("DPSPayment", $SQL_paymentID); } if ($payment) { DB::getConn()->transactionStart(); try { $payment->ResponseXML = $rsp->toXml(); $success = $rsp->getSuccess(); if ($success == '1') { // @todo Use AmountSettlement for amount setting? $payment->TxnRef = $rsp->getDpsTxnRef(); $payment->AuthCode = $rsp->getAuthCode(); $payment->Status = "Success"; } else { $payment->Status = "Failure"; } $payment->Message = $rsp->getResponseText(); $payment->write(); DB::getConn()->transactionEnd(); } catch (Exception $e) { DB::getConn()->transactionRollback(); $payment->handleError($e); } Director::redirect($payment->DPSHostedRedirectURL); } } }
/** * React to DSP response triggered by {@link processPayment()}. */ public function processResponse() { if (preg_match('/^PXHOST/i', $_SERVER['HTTP_USER_AGENT'])) { $dpsDirectlyConnecting = 1; } $pxpay = new PxPay(DPSHostedPayment::$pxPay_Url, DPSHostedPayment::get_px_pay_userid(), DPSHostedPayment::get_px_pay_key()); $enc_hex = $_REQUEST["result"]; $rsp = $pxpay->getResponse($enc_hex); if (isset($dpsDirectlyConnecting) && $dpsDirectlyConnecting) { // DPS Service connecting directly $paymentID = $rsp->getTxnId(); $SQL_paymentID = (int) $paymentID; $payment = DataObject::get_one('DPSHostedPayment', "`TxnID` = '{$SQL_paymentID}'"); if (!$payment) { echo "failure"; return; } $success = $rsp->getSuccess(); # =1 when request succeeds if ($success == '1') { $payment->TxnRef = $rsp->getDpsTxnRef(); $payment->Status = "Success"; $payment->AuthorizationCode = $rsp->getAuthCode(); echo "success"; } else { $payment->Message = $rsp->getResponseText(); $payment->Status = "Failure"; echo "failure"; } $payment->write(); $payment->redirectToOrder(); } else { // Human visitor $paymentID = $rsp->getTxnId(); $SQL_paymentID = (int) $paymentID; $payment = DataObject::get_one('DPSHostedPayment', "`TxnID` = '{$SQL_paymentID}'"); if (!$payment) { $payment->redirectToOrder(); return; } $success = $rsp->getSuccess(); if ($success == '1') { // @todo Use AmountSettlement for amount setting? $payment->TxnRef = $rsp->getDpsTxnRef(); $payment->Status = "Success"; $payment->AuthorizationCode = $rsp->getAuthCode(); } else { $payment->Message = $rsp->getResponseText(); $payment->Status = "Failure"; } $payment->write(); $payment->redirectToOrder(); } }