Source of file DPSRecurringPayment.php
Size: 4,766 Bytes - Last Modified: 2021-12-23T10:33:28+00:00
/var/www/docs.ssmods.com/process/src/code/DPSPayment/DPSRecurringPayment.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 | <?php class DPSRecurringPayment extends RecurringPayment { //Note: as a DPS Recurring Payment, its TxnType should be always Auth public static $db = array( 'TxnRef' => 'Text', 'AuthCode' => 'Varchar(22)', 'MerchantReference' => 'Varchar(64)', 'DPSHostedRedirectURL' => 'Text', 'DPSBillingID' => "Varchar(16)", 'AuthAmount' => 'Decimal', // We store the whole raw response xml in case that tracking back the payment is needed in a later stage for whatever the reason. 'ResponseXML' => "Text", ); private static $input_elements = array( 'Amount', 'CardHolderName', 'CardNumber', 'BillingId', 'Cvc2', 'DateExpiry', 'DpsBillingId', 'DpsTxnRef', 'EnableAddBillCard', 'InputCurrency', 'MerchantReference', 'PostUsername', 'PostPassword', 'TxnType', 'TxnData1', 'TxnData2', 'TxnData3', 'TxnId', 'EnableAvsData', 'AvsAction', 'AvsPostCode', 'AvsStreetAddress', 'DateStart', 'IssueNumber', 'Track2', ); private static $dpshosted_input_elements = array( 'PxPayUserId', 'PxPayKey', 'AmountInput', 'CurrencyInput', 'EmailAddress', 'EnableAddBillCard', 'MerchantReference', 'TxnData1', 'TxnData2', 'TxnData3', 'TxnType', 'TxnId', 'UrlFail', 'UrlSuccess', ); public static $default_sort = "ID DESC"; public function recurringAuth($data) { DB::getConn()->transactionStart(); try { $this->TxnType = "Auth"; $this->AuthAmount = 1.00; $this->write(); $adapter = new DPSAdapter(); $inputs = $this->prepareDPSHostedRecurringAuthRequest($data); $adapter->doDPSHostedPayment($inputs, $this); } catch (Exception $e) { DB::getConn()->transactionRollback(); $this->handleError($e); } } public function prepareDPSHostedRecurringAuthRequest($data) { //never put this loop after $inputs['AmountInput'] = $amount, since it will change it to an array. foreach ($data as $element => $value) { if (in_array($element, self::$dpshosted_input_elements)) { $inputs[$element] = $value; } } $inputs['TxnData1'] = $this->ID; $inputs['TxnType'] = 'Auth'; $inputs['EnableAddBillCard'] = 1; $inputs['AmountInput'] = $this->AuthAmount; $inputs['InputCurrency'] = $this->Amount->Currency; $inputs['MerchantReference'] = $this->MerchantReference; $postProcess_url = Director::absoluteBaseURL() ."DPSAdapter/processDPSHostedResponse"; $inputs['UrlFail'] = $postProcess_url; $inputs['UrlSuccess'] = $postProcess_url; return $inputs; } public function merchantRecurringAuth($data) { DB::getConn()->transactionStart(); try { $this->AuthAmount = 1.00; $this->write(); $adapter = new DPSAdapter(); $inputs = $this->prepareMerchantHostedRecurringAuthInputs($data); $adapter->doPayment($inputs, $this); DB::getConn()->transactionEnd(); } catch (Exception $e) { DB::getConn()->transactionRollback(); $this->handleError($e); } } public function prepareMerchantHostedRecurringAuthInputs($data) { //never put this loop after $inputs['AmountInput'] = $this->Amount->Amount;, since it will change it to an array. foreach ($data as $element => $value) { if (in_array($element, self::$input_elements)) { $inputs[$element] = $value; } } $inputs['TxnData1'] = $this->ID; $inputs['TxnType'] = 'Validate'; $inputs['EnableAddBillCard'] = 1; $inputs['Amount'] = $this->AuthAmount; $inputs['InputCurrency'] = $this->Amount->Currency; $inputs['MerchantReference'] = $this->MerchantReference; //special element $inputs['CardNumber'] = implode('', $data['CardNumber']); return $inputs; } public function getNextPayment() { $next = parent::getNextPayment(); $next->ClassName = 'DPSPayment'; $next->RecordClassName = 'DPSPayment'; $next->TxnType = 'Purchase'; $next->MerchantReference = $this->MerchantReference; $next->write(); return DataObject::get_by_id('DPSPayment', $next->ID); } } |