Exemple #1
0
    // $opt2 = new eWAY\Option();
    // $opt2->Value = $_POST['txtOption2'];
    // $opt3 = new eWAY\Option();
    // $opt3->Value = $_POST['txtOption3'];
    // $request->Options->Option[0]= $opt1;
    // $request->Options->Option[1]= $opt2;
    // $request->Options->Option[2]= $opt3;
    $request->Method = $_POST['ddlMethod'];
    $request->TransactionType = $_POST['ddlTransactionType'];
    // Call RapidAPI
    $eway_params = array();
    if ($_POST['ddlSandbox']) {
        $eway_params['sandbox'] = true;
    }
    $service = new eWAY\RapidAPI($_POST['txtUsername'], $_POST['txtPassword'], $eway_params);
    $result = $service->DirectPayment($request);
    // Check if any error returns
    if (isset($result->Errors)) {
        // Get Error Messages from Error Code. Error Code Mappings are in the Config.ini file
        $ErrorArray = explode(",", $result->Errors);
        $lblError = "";
        foreach ($ErrorArray as $error) {
            $error = $service->getMessage($error);
            $lblError .= $error . "<br />\n";
        }
    } else {
        $in_page = 'view_result';
    }
}
?>
Exemple #2
0
 function submit()
 {
     require_once 'eWay/lib.php';
     //Send card data
     $this->credit_card_details = array('card_number' => $_POST['eway_card_number'], 'expiry_month' => $_POST['eway_expiry_month'], 'expiry_year' => $_POST['eway_expiry_year'], 'card_code' => $_POST['eway_card_code']);
     $request = new eWAY\CreateDirectPaymentRequest();
     //Send vars to eWay
     $request->Customer->FirstName = $this->cart_data['billing_address']['first_name'];
     $request->Customer->LastName = $this->cart_data['billing_address']['last_name'];
     $request->Customer->Reference = $this->cart_data['session_id'];
     $request->Customer->City = $this->cart_data['billing_address']['city'];
     $request->Customer->State = $this->cart_data['billing_address']['state'];
     $request->Customer->PostalCode = $this->cart_data['billing_address']['post_code'];
     $request->Customer->Email = $this->cart_data['email_address'];
     //Card info
     $request->Customer->CardDetails->Name = $request->Customer->FirstName . ' ' . $request->Customer->LastName;
     $request->Customer->CardDetails->Number = $this->credit_card_details['card_number'];
     $request->Customer->CardDetails->ExpiryMonth = $this->credit_card_details['expiry_month'];
     $request->Customer->CardDetails->ExpiryYear = $this->credit_card_details['expiry_year'];
     $request->Customer->CardDetails->CVN = $this->credit_card_details['card_code'];
     //Populate values for LineItems
     $i = 0;
     foreach ($this->cart_items as $cart_row) {
         $item[$i] = new eWAY\LineItem();
         $item[$i]->Description = $cart_row['name'];
         $item[$i]->Quantity = $cart_row['quantity'];
         $item[$i]->UnitCost = $cart_row['price'] * 100;
         $item[$i]->Total = $cart_row['price'] * 100 * $cart_row['quantity'];
         $request->Items->LineItem[$i] = $item[$i];
         $i++;
     }
     //Options
     $opt = new eWAY\Option();
     $opt->Value = $this->cart_data['session_id'];
     $request->Options->Option[0] = $opt;
     //Populate values for Payment Object
     $request->Payment->TotalAmount = number_format($this->cart_data['total_price'], 2, '.', '') * 100;
     $request->Payment->CurrencyCode = $this->cart_data['store_currency'];
     $request->Payment->InvoiceReference = $this->cart_data['session_id'];
     //Misc data
     $request->Method = 'ProcessPayment';
     $request->TransactionType = 'Purchase';
     $eway_params = array();
     if (get_option('eway_testmode') == 'test') {
         $eway_params['sandbox'] = true;
     }
     $service = new eWAY\RapidAPI(get_option('eway_apikey'), get_option('eway_apipassword'), $eway_params);
     $result = $service->DirectPayment($request);
     if (isset($result->Errors)) {
         // Get Error Messages from Error Code. Error Code Mappings are in the Config.ini file
         $ErrorArray = explode(",", $result->Errors);
         $lblError = "";
         foreach ($ErrorArray as $error) {
             $error = $service->getMessage($error);
             $lblError .= $error . "<br />\n";
         }
     }
     if (isset($lblError)) {
         $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages');
         if (!is_array($error_messages)) {
             $error_messages = array();
         }
         $error_messages[] = '<strong style="color:red">' . $lblError . ' </strong>';
         wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages);
         $this->return_to_checkout();
         exit;
     }
     if (isset($result->TransactionStatus) && $result->TransactionStatus && (is_bool($result->TransactionStatus) || $result->TransactionStatus != "false")) {
         $sessionid = $result->Payment->InvoiceReference;
         $purchase_log = new WPSC_Purchase_Log($sessionid, 'sessionid');
         $purchase_log->set(array('processed' => WPSC_Purchase_Log::ACCEPTED_PAYMENT, 'transactid' => $result->TransactionID, 'notes' => 'eWay Auth Code : "' . $result->AuthorisationCode . '"'));
         $purchase_log->save();
         $this->go_to_transaction_results($this->cart_data['session_id']);
         exit;
     } else {
         $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages');
         if (!is_array($error_messages)) {
             $error_messages = array();
         }
         $error_messages[] = '<strong style="color:red">' . parse_error_message_eway($result->ResponseMessage) . ' </strong>';
         wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages);
         $checkout_page_url = get_option('shopping_cart_url');
         if ($checkout_page_url) {
             header('Location: ' . $checkout_page_url);
             exit;
         }
     }
 }