Esempio n. 1
0
function jg_front_end_sagepay($atts)
{
    if (session_id() == '' || !isset($_SESSION)) {
        // session isn't started
        session_start();
    }
    ob_start();
    global $current_user;
    global $wp_roles;
    global $wpdb;
    global $error;
    global $js_shortcode_on_front;
    extract(shortcode_atts(array('redirectPaid' => 0, 'display' => true, 'template' => ''), $atts));
    /*
       if ( trim($_SESSION['userEnc']) == '' ){
           $redirectLink = trim(home_url());
           if (intval($redirectLink) != 0)
               $redirectLink = get_permalink($redirectLink);
           else{
               if (!jg_check_missing_http($redirectLink)) $redirectLink = 'http://'. $redirectLink;
           }
           wp_redirect( $redirectLink ); exit;
       }
    */
    $wpjg_generalSettings = get_option('jg_general_settings');
    $result = $wpdb->get_row("SELECT * FROM {$wpdb->prefix}jgusers WHERE `userEnc`='" . trim($_SESSION['userEnc']) . "';", ARRAY_A);
    if (isset($result['paidaccess']) && $wpjg_generalSettings['paidaccess'] == 1 && $result['paidaccess'] == 1) {
        $redirectLink = trim($redirectPaid);
        if (intval($redirectLink) != 0) {
            $redirectLink = get_permalink($redirectLink);
        } else {
            if (!jg_check_missing_http($redirectLink)) {
                $redirectLink = 'http://' . $redirectLink;
            }
        }
        wp_redirect($redirectLink);
        exit;
    }
    if (trim($template) == '') {
        $template = 'sagepay.html';
    }
    $crypt = '';
    if (isset($_REQUEST["action"])) {
        require_once JG_PLUGIN_DIR . "/sagepay/sagepay.php";
        $p = new SagePay();
        // paypal class
        $action = $_REQUEST["action"];
        switch ($action) {
            case "process":
                // case process insert the form data in DB and process to the paypal
                $wpdb->update($wpdb->prefix . "jgusers", array('paytoken' => $_POST["invoice"]), array('userEnc' => trim($_SESSION['userEnc'])));
                $this_script = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                $p->setSuccessURL($this_script . '?action=success');
                // return URL after the transaction got over
                $p->setFailureURL($this_script . '?action=cancel');
                // cancel URL if the trasaction was cancelled during half of the transaction
                $p->setCurrency($_POST["currency_code"]);
                $p->setDescription($_POST["product_name"]);
                $p->setAmount($wpjg_generalSettings['payamount']);
                $p->setBillingFirstnames($_POST["payer_fname"]);
                $p->setBillingSurname($_POST["payer_lname"]);
                $p->setBillingAddress1($_POST["payer_address"]);
                $p->setBillingCity($_POST["payer_city"]);
                $p->setBillingState($_POST["payer_state"]);
                $p->setBillingCountry($_POST["payer_country"]);
                $p->setBillingPostCode($_POST["payer_zip"]);
                $p->setVendorTxCode($_POST["invoice"]);
                $p->setDeliverySameAsBilling();
                $xml = new DOMDocument();
                $basketNode = $xml->createElement("basket");
                $itemNode = $xml->createElement("item");
                $descriptionNode = $xml->createElement('description');
                $descriptionNode->nodeValue = 'Entry fee';
                $itemNode->appendChild($descriptionNode);
                $quantityNode = $xml->createElement('quantity');
                $quantityNode->nodeValue = $_POST["product_quantity"];
                $itemNode->appendChild($quantityNode);
                $unitNetAmountNode = $xml->createElement('unitNetAmount');
                $unitNetAmountNode->nodeValue = $wpjg_generalSettings['payamount'];
                $itemNode->appendChild($unitNetAmountNode);
                $unitTaxAmountNode = $xml->createElement('unitTaxAmount');
                $unitTaxAmountNode->nodeValue = '0';
                $itemNode->appendChild($unitTaxAmountNode);
                $unitGrossAmountNode = $xml->createElement('unitGrossAmount');
                $unitGrossAmountNode->nodeValue = $wpjg_generalSettings['payamount'];
                $itemNode->appendChild($unitGrossAmountNode);
                $totalGrossAmountNode = $xml->createElement('totalGrossAmount');
                $totalGrossAmountNode->nodeValue = $wpjg_generalSettings['payamount'];
                $itemNode->appendChild($totalGrossAmountNode);
                $basketNode->appendChild($itemNode);
                $xml->appendChild($basketNode);
                $p->setBasketXML($xml->saveHTML());
                $crypt = $sagePay->getCrypt();
                break;
            case "success":
                if ($_REQUEST['crypt']) {
                    $responseArray = $sagePay->decode($_REQUEST['crypt']);
                    //Check status of response
                    if ($responseArray["Status"] === "OK") {
                        $wpdb->update($wpdb->prefix . "jgusers", array('paidaccess' => 1, 'txn_id' => $responseArray["VPSTxId"]), array('paytoken' => trim($_POST["VendorTxCode"])));
                    } elseif ($responseArray["Status"] === "ABORT") {
                        // Payment Cancelled
                    } else {
                        // Payment Failed
                        throw new \Exception($responseArray["StatusDetail"]);
                    }
                    print '<pre>';
                    print_r($responseArray);
                    print '</pre>';
                    exit;
                }
                break;
        }
    }
    require_once JG_PLUGIN_DIR . '/lib/Smarty.class.php';
    $smarty = new Smarty();
    $smarty->template_dir = JG_PLUGIN_DIR . '/smarty/templates/';
    $smarty->compile_dir = JG_PLUGIN_DIR . '/smarty/templates_c/';
    $smarty->config_dir = JG_PLUGIN_DIR . '/smarty/configs/';
    $smarty->cache_dir = JG_PLUGIN_DIR . '/smarty/cache/';
    $smarty->assign('formurl', jg_curpageurl());
    $smarty->assign('Errors', $errors);
    $smarty->assign('Settings', $wpjg_generalSettings);
    $invoice = array('productid' => rand(1111, 99999), 'invoiceid' => date("His") . rand(1234, 9632));
    $smarty->assign('Get', $_GET);
    $smarty->assign('Post', $_POST);
    $smarty->assign('User', $_SESSION);
    $smarty->assign('Invoice', $invoice);
    $smarty->assign('crypt', $crypt);
    $smarty->assign('vendor', $wpjg_generalSettings['paypal_femail']);
    $smarty->display($template);
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
Esempio n. 2
0
<?php

require_once 'SagePay.php';
$sagePay = new SagePay();
$sagePay->setCurrency('EUR');
$sagePay->setAmount('100');
$sagePay->setDescription('Lorem ipsum');
$sagePay->setBillingSurname('Mustermann');
$sagePay->setBillingFirstnames('Max');
$sagePay->setBillingCity('Cologne');
$sagePay->setBillingPostCode('50650');
$sagePay->setBillingAddress1('Bahnhofstr. 1');
$sagePay->setBillingCountry('de');
$sagePay->setDeliverySameAsBilling();
/* Example of using BasketXML */
$xml = new DOMDocument();
$basketNode = $xml->createElement("basket");
$itemNode = $xml->createElement("item");
$descriptionNode = $xml->createElement('description');
$descriptionNode->nodeValue = 'First Item Description';
$itemNode->appendChild($descriptionNode);
$quantityNode = $xml->createElement('quantity');
$quantityNode->nodeValue = '1';
$itemNode->appendChild($quantityNode);
$unitNetAmountNode = $xml->createElement('unitNetAmount');
$unitNetAmountNode->nodeValue = '90.00';
$itemNode->appendChild($unitNetAmountNode);
$unitTaxAmountNode = $xml->createElement('unitTaxAmount');
$unitTaxAmountNode->nodeValue = '10.00';
$itemNode->appendChild($unitTaxAmountNode);
$unitGrossAmountNode = $xml->createElement('unitGrossAmount');
 public function process_sagepay()
 {
     // pass the card and billing data to a static method in the
     // sagepay class to be formatted and returned.
     $data = SagePay::formatRawData($_POST);
     $validator = new Validator($data);
     $validator->filledIn("BillingFirstnames");
     $validator->filledIn("BillingSurname");
     $validator->filledIn("BillingAddress1");
     $validator->filledIn("BillingCity");
     $validator->filledIn("BillingCountry");
     $validator->filledIn("CardType");
     $validator->filledIn("CardNumber");
     $validator->filledIn("CV2");
     $validator->filledIn("ExpiryDateMonth");
     $validator->filledIn("ExpiryDateYear");
     $validator->filledIn("Amount");
     $errors = $validator->getErrors();
     $id = $validator->getId();
     $error_message = array('BillingFirstnames' => 'First name can not be left blank', 'BillingSurname' => 'Last name can not be left blank', 'BillingAddress1' => 'Address can not be left blank', 'BillingCity' => 'City can not be left blank', 'BillingCountry' => 'Country can not be left blank', 'Amount' => 'Amount can not be left blank', 'CardNumber' => 'Card number can not be left blank', 'ExpiryDateMonth' => 'Expiry month can not be left blank', 'ExpiryDateYear' => 'Expiry year can not be left blank', 'CardType' => 'Card type can not be left blank', 'CV2' => 'CV2 can not be left blank');
     if (!empty($errors)) {
         echo "Error:<br>";
         foreach ($errors as $key => $value) {
             echo $error_message[$key] . "<br>";
         }
         exit;
     }
     $description = isset($_SESSION['SAGEPAY_DATA']['description']) ? $_SESSION['SAGEPAY_DATA']['description'] : '';
     if (!empty($description)) {
         $data['description'] = $description;
     }
     // instantiate the SagePay object, passing it this formatted data.
     $payment = new SagePay($data);
     // execute the payment request
     $payment->execute();
     if ($payment->status == '3dAuth') {
         // SagePay has returned a request for 3DSecure authentication
         // returned by SagePay on request for 3DSecure authentication
         $_SESSION['payment']['acsurl'] = $payment->acsurl;
         // returned by SagePay on request for 3DSecure authentication
         $_SESSION['payment']['pareq'] = $payment->pareq;
         // Store the transaction code that you set for passing to 3DSecure
         $_SESSION['payment']['vendorTxCode'] = $payment->vendorTxCode;
         // returned by SagePay on request for 3DSecure authentication
         $_SESSION['payment']['md'] = $payment->md;
         // set a flag so your code knows to load the 3D Secure page.
         $secure_auth = true;
         echo "3dAuth";
         exit;
     } else {
         if ($payment->status == 'success') {
             // Transaction successful. Redirect to your complete page
             echo "success";
             exit;
         } else {
             echo $_SESSION['error'] = $payment->error;
         }
     }
 }
Esempio n. 4
0
 /**
  * Success page
  */
 public function post_donation()
 {
     if (!isset($_GET['crypt'])) {
         return;
     }
     // 0 | Set up
     require_once 'lib/SagePay.php';
     $sagePay = new SagePay();
     // 1 | Decode crypt from SagePay
     $crypt = $_GET['crypt'];
     $decoded = $sagePay->decode($crypt);
     // 2 | Update record with donation amount, success/fail & `VPSTxId`
     self::update_donation_detail($decoded['VendorTxCode'], $decoded);
     // 3 | Look up donation details
     $donation = self::select_donation_detail($decoded['VendorTxCode']);
     $show_allocation_field = get_option('sd_show_allocate');
     // 4 | Send notification email to admin
     $headers = array('Content-Type: text/html; charset=UTF-8');
     if ($notification_address = get_option('sd_notify_email')) {
         include sprintf("%s/templates/tpl_admin_notification_email.php", dirname(__FILE__));
         $mail = wp_mail($notification_address, 'Online donation', $email_content, $headers);
     }
     // 5 | Send a thank you email if the donation goes through
     if (get_option('sd_confirmation') && ($message = get_option('sd_confirmation_body'))) {
         if (strpos($donation->status, 'Successful')) {
             $headers = array();
             $reply_to = get_option('sd_reply_to_email');
             if ($reply_to != "") {
                 $headers['Reply-To'] = $reply_to;
                 add_filter('wp_mail_from', function ($email) {
                     return $reply_to;
                 });
                 add_filter('wp_mail_from_name', function ($name) {
                     return get_bloginfo('name');
                 });
             }
             add_filter('wp_mail_content_type', array(&$this, 'set_html_content_type'));
             $mail = wp_mail($donation->email, 'Thank you', apply_filters('the_content', $message), $headers);
             remove_filter('wp_mail_content_type', array(&$this, 'set_html_content_type'));
         }
     }
 }