echo "All data is valid\n"; } */ /* //Process a payment // Charge the credit card '462834666666' '$123' US dollars. The card expires on '07/09', has the CVV code '32' and the local order ID is 'ORD34234'. $sp->Process(123, 'USD', '462834666666', '07/09', '321', 'ORD34234'); */ $sp->Cc = 462834666666; $sp->ExpiryDate = '07/09'; $sp->ChargeAmount = 123; $sp->ChargeCurrency = 'USD'; $sp->Cvv = 321; $sp->OrderId = 'ORD34234'; if ($sp->Valid()) { // Is the above data valid? $response = $sp->Process(); if ($response == SECUREPAY_STATUS_APPROVED) { echo "Transaction was a success\n"; } else { echo "Transaction failed with the error code: {$response}\n"; echo "XML Dump: " . print_r($sp->ResponseXml, 1) . "\n"; } } else { die("Your data is invalid\n"); } /* //Pre-authorize a payment // This is the same process as passing a regular payment but the last parameter indicates that it should be treated as a PreAuth transaction
/** * Proccess SecurePayment. Try to complete SecurePay transaction * * @throws SecurePayServerDownException * @throws SecurePayTransactionFailedException * @throws SecurePayCustomerDataInvalidException */ public function proccessPayment() { $sp = new \SecurePay($this->config['merchantId'], $this->config['password']); $sp->TestMode(TRUE); // Remove this line to actually preform a transaction if (!$sp->TestConnection()) { $this->savePayment('Failed', 'SecurePay server is down'); throw new SecurePayServerDownException('SecurePay server is down'); } $sp->PreAuth = 1; // Mark proccess as Pre Auth proccess ( With this one we must comunicate with SecurePay // server two times ) $sp->Cc = $this->postPaymentData['ccnumber']; $sp->ExpiryDate = $this->postPaymentData['expmonth'] . '/' . $this->postPaymentData['expyear']; $sp->Cvv = $this->postPaymentData['cvv']; $total_amount = $this->order->total_price + $this->order->shipping_price - $this->order->discount_amount; // NRB-Gem: total and shipping price are already inclusive of GST // $gst_amount = $total_amount * .10; // $sp->ChargeAmount = $total_amount + $gst_amount; $sp->ChargeAmount = $total_amount; $sp->ChargeCurrency = 'AUD'; $sp->OrderId = $this->order->id; if ($sp->Valid()) { // Is the above data valid? $response = $sp->Process(); // echo $sp->ResponseXml; // Uncomment to see response if ($response == SECUREPAY_STATUS_APPROVED) { $preauthid = $sp->PreAuthId; } else { $this->savePayment('Failed', 'Transaction failed'); // throw new SecurePayTransactionFailedException("Transaction authorisation failed with the error code: $response"); throw new SecurePayTransactionFailedException("It appears you have not entered your information correctly. Please try again."); } } else { $this->savePayment('Failed', 'Data invalid'); throw new SecurePayCustomerDataInvalidException("Your data is invalid!"); } $sp->PreAuth = 1; $sp->PreAuthID = $preauthid; // NRB-Gem: total and shipping price are already inclusive of GST // $sp->ChargeAmount = $total_amount + $gst_amount; $sp->ChargeAmount = $total_amount; $sp->ChargeCurrency = 'AUD'; $sp->OrderId = $this->order->id; if ($sp->Valid()) { // Is the above data valid? $response = $sp->Process(); if ($response == SECUREPAY_STATUS_APPROVED) { $txnData = array(); if (!empty($sp->ResponseTree->Payment->TxnList->Txn)) { // Get transaction data from server response $txnData = $sp->ResponseTree->Payment->TxnList->Txn; unset($txnData->CreditCardInfo); } $this->savePayment('Completed', 'Completed', $txnData); //$this->notify(); } else { // Save payment for this order as completed $this->savePayment('Failed', 'Transaction failed'); throw new SecurePayTransactionFailedException("Transaction failed with the error code: {$response}"); } } else { $this->savePayment('Failed', 'Data invalid'); throw new SecurePayCustomerDataInvalidException("Your data is invalid!"); } }