<?php include 'securepay.php'; /*//Create a new SecurePay object $sp = new SecurePay('username','password'); //OR $sp = new SecurePay(); $sp->Login('username','password');*/ $sp = new SecurePay('username', 'password'); $sp->TestMode(); // Remove this line to actually preform a transaction $sp->TestConnection(); print_r($sp->ResponseXml); /*if ($sp->TestConnection()) { echo "Server is working\n"; } else { echo "Server is Down\n"; }*/ /* //Enable Test Mode (Optional) $sp->TestMode(); //OR $sp->TestMode(TRUE); */ /* //Check if all provided Data is valid (Quick Method) if ($sp->Valid()) { echo "Everything is valid\n";
/** * 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!"); } }