Ejemplo n.º 1
0
 /**
  * IPN->paypal()
  *
  * Validate PayPal payments
  *
  * @access	public
  * @return	none
  */
 public function paypal()
 {
     // Include the paypal library
     include_once APPPATH . 'libraries/payment/Paypal.php';
     $this->gateway = '1';
     // Create an instance of the paypal library
     $myPaypal = new Paypal();
     // Log the IPN results
     // $myPaypal->ipnLog = TRUE;
     // Enable test mode if needed
     if (defined('XUDEBUG') and XUDEBUG == true) {
         $myPaypal->enableTestMode();
     }
     // Check validity and write down it
     if ($myPaypal->validateIpn()) {
         if ($myPaypal->ipnData['payment_status'] == 'Completed') {
             $settings = unserialize(base64_decode($myPaypal->ipnData['custom']));
             if ($settings['type'] == 'reg') {
                 $this->_newUserPayment($settings['user_id'], $myPaypal->ipnData['amount']);
                 redirect('/user/pay_complete');
             }
             redirect('/user/pay_cancel');
         } else {
             $this->_logError($myPaypal->ipnData);
             redirect('/user/pay_cancel');
         }
     }
     redirect('/user/pay_cancel');
 }
Ejemplo n.º 2
0
function espresso_process_paypal($payment_data)
{
    do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
    $payment_data['txn_type'] = 'Paypal';
    $payment_data['txn_id'] = 0;
    $payment_data['payment_status'] = 'Incomplete';
    $payment_data['txn_details'] = serialize($_REQUEST);
    include_once 'Paypal.php';
    $myPaypal = new Paypal();
    echo '<!--Event Espresso PayPal Gateway Version ' . $myPaypal->gateway_version . '-->';
    $myPaypal->ipnLog = TRUE;
    $paypal_settings = get_option('event_espresso_paypal_settings');
    if ($paypal_settings['use_sandbox']) {
        $myPaypal->enableTestMode();
    }
    if ($myPaypal->validateIpn()) {
        $payment_data['txn_details'] = serialize($myPaypal->ipnData);
        $payment_data['txn_id'] = $myPaypal->ipnData['txn_id'];
        if ($myPaypal->ipnData['payment_status'] == 'Completed' || $myPaypal->ipnData['payment_status'] == 'Pending') {
            $payment_data['payment_status'] = 'Completed';
            if ($paypal_settings['use_sandbox']) {
                // For this, we'll just email ourselves ALL the data as plain text output.
                $subject = 'Instant Payment Notification - Gateway Variable Dump';
                $body = "An instant payment notification was successfully recieved\n";
                $body .= "from " . $myPaypal->ipnData['payer_email'] . " on " . date('m/d/Y');
                $body .= " at " . date('g:i A') . "\n\nDetails:\n";
                foreach ($myPaypal->ipnData as $key => $value) {
                    $body .= "\n{$key}: {$value}\n";
                }
                wp_mail($payment_data['contact'], $subject, $body);
            }
        } else {
            $subject = 'Instant Payment Notification - Gateway Variable Dump';
            $body = "An instant payment notification failed\n";
            $body .= "from " . $myPaypal->ipnData['payer_email'] . " on " . date('m/d/Y');
            $body .= " at " . date('g:i A') . "\n\nDetails:\n";
            foreach ($myPaypal->ipnData as $key => $value) {
                $body .= "\n{$key}: {$value}\n";
            }
            wp_mail($payment_data['contact'], $subject, $body);
        }
    }
    $payment_data = apply_filters('filter_hook_espresso_get_total_cost', $payment_data);
    $payment_data = apply_filters('filter_hook_espresso_update_attendee_payment_data_in_db', $payment_data);
    do_action('action_hook_espresso_email_after_payment', $payment_data);
    return $payment_data;
}
Ejemplo n.º 3
0
 public function verificationAction()
 {
     /*
      - check payment type use switch if necessary (paypal, twoco, manual )
      - use verification function from existing library of paypal/twoco
      - set order status if verified
      - redirect to proper page? or trigger mail?          
     */
     // Create an instance of the paypal library
     require_once 'PaymentGateway/Paypal.php';
     $myPaypal = new Paypal();
     // Log the IPN results
     $myPaypal->ipnLog = TRUE;
     // Enable test mode if needed
     if ($this->_testMode) {
         $myPaypal->enableTestMode();
     }
     // Check validity, status, amount and tax amount and write down it
     if ($myPaypal->validateIpn()) {
         //if ($myPaypal->ipnData['payment_status'] == 'Completed' && $myPaypal['']=='')
         if ($myPaypal->ipnData['payment_status'] == 'Completed') {
             $data = $myPaypal->ipnData;
             //$this->Mailer($data['custom'], 'admin-paypal', 'admin');
             //$this->Mailer($data['custom'], 'user-paypal', 'XXX');
             $this->paypalsave('SUCCESS', $data);
             $modDir = $this->getFrontController()->getModuleDirectory();
             require_once $modDir . '/models/Store/Mailer.php';
             $mod = new Holsite_Model_Store_Mailer();
             $mod->sendReceiptToUser($data['custom'], 'paypal', 'SUCCESS PAID');
         } else {
             $data = $myPaypal->ipnData;
             //$this->Mailer($data['custom'], 'admin-paypal', 'admin');
             //$this->Mailer($data['custom'], 'user-paypal', 'admin');
             $this->paypalsave('FAILED', $data);
             $modDir = $this->getFrontController()->getModuleDirectory();
             require_once $modDir . '/models/Store/Mailer.php';
             $mod = new Holsite_Model_Store_Mailer();
             $mod->sendReceiptToUser($data['custom'], 'paypal', 'FAILED');
         }
     } else {
         foreach ($this->_request->getParams() as $key => $val) {
             $data[$key] = $val;
         }
         //all data and key are same with ipnData
         //$this->Mailer($data['custom'], 'admin-paypal', 'admin');
         //send all post variables to admin email
         $writer = new Zend_Log_Writer_Stream(ROOT_PATH . '/app_log.txt');
         $logger = new Zend_Log($writer);
         $logger->info(var_dump($data));
     }
     die;
 }
Ejemplo n.º 4
0
 function indexAction()
 {
     //[TODO] must check if orderId has been paid before to avoid double charge, if somehow user can access directly to payment controller.
     $this->_helper->viewRenderer->setNoRender(TRUE);
     $this->_checkAuth();
     $orderId = $this->_request->getParam('orderId');
     $this->_orderIdNumber = $orderId;
     if (empty($orderId)) {
         echo "kosong";
         die;
     }
     $modelAppStore = new App_Model_Store();
     if (!$modelAppStore->isUserOwnOrder($this->_user->kopel, $orderId)) {
         //forward to error page
         $this->_helper->redirector->gotoSimple('error', 'store', 'hol-site', array('view' => 'notowner'));
         die;
     }
     if ($modelAppStore->isOrderPaid($orderId)) {
         //forward to error page
         $this->_helper->redirector->gotoSimple('error', 'store', 'hol-site', array('view' => 'orderalreadypaid'));
         die;
     }
     $items = App_Model_Show_Order::show()->getOrderDetail($orderId);
     $tmpMethod = $this->_request->getParam('method');
     if (!empty($tmpMethod)) {
         $items[0]['paymentMethod'] = $tmpMethod;
     }
     switch ($items[0]['paymentMethod']) {
         case 'nsiapay':
             require_once 'PaymentGateway/Nsiapay.php';
             // include the class file
             $paymentObject = new Nsiapay();
             // initiate an instance of the class
             if ($this->_testMode) {
                 $paymentObject->enableTestMode();
             }
             $paymentObject->addField('TYPE', "IMMEDIATE");
             $subTotal = 0;
             for ($iCart = 0; $iCart < count($items); $iCart++) {
                 $i = $iCart + 1;
                 $basket[] = $items[$iCart]['documentName'] . "," . $items[$iCart]['price'] . ".00" . "," . $items[$iCart]['qty'] . "," . $items[$iCart]['finalPrice'] . ".00";
                 $subTotal += $items[$iCart]['price'] * $items[$iCart]['qty'];
             }
             $ca = implode(";", $basket);
             $merchantId = "000100090000028";
             $paymentObject->addField("BASKET", $ca);
             $paymentObject->addField("MERCHANTID", $merchantId);
             $paymentObject->addField("CHAINNUM", "NA");
             $paymentObject->addField("TRANSIDMERCHANT", $items[0]['invoiceNumber']);
             $paymentObject->addField("AMOUNT", $subTotal);
             $paymentObject->addField("CURRENCY", "360");
             $paymentObject->addField("PurchaseCurrency", "360");
             $paymentObject->addField("acquirerBIN", "360");
             $paymentObject->addField("password", "123456");
             $paymentObject->addField("URL", ROOT_URL);
             $paymentObject->addField("MALLID", "199");
             $paymentObject->addField("SESSIONID", Zend_Session::getId());
             $sha1 = sha1($subTotal . ".00" . $merchantId . "08iIWbWvO16w" . $items[0]['invoiceNumber']);
             //                echo $subTotal.".00".$merchantId."08iIWbWvO16w".$items[0]['invoiceNumber']."<br>";
             //                echo $sha1;die;
             $paymentObject->addField("WORDS", $sha1);
             $ivnum = $this->updateInvoiceMethod($orderId, 'nsiapay', 1, 0, 'paid with nsiapay method');
             $data['orderId'] = $orderId;
             $data['starttime'] = date('YmdHis');
             $data['amount'] = $subTotal;
             $data['transidmerchant'] = $items[0]['invoiceNumber'];
             $tblNsiapay = new App_Model_Db_Table_Nsiapay();
             $tblNsiapay->insert($data);
             $nhis['orderId'] = $items[0]['invoiceNumber'];
             $nhis['paymentStatus'] = 'requested';
             $nhis['dateAdded'] = date('YmdHis');
             $tblNhis = new App_Model_Db_Table_NsiapayHistory();
             $tblNhis->insert($nhis);
             //$paymentObject->dumpFields();die();
             $this->_helper->layout->disableLayout();
             $paymentObject->submitPayment();
             break;
         case 'paypal':
             /*
              - Detect Multi Item and set accordingly
              - Logic for test mode 
             */
             require_once 'PaymentGateway/Paypal.php';
             // include the class file
             $paymentObject = new Paypal();
             // initiate an instance of the class
             if ($this->_testMode) {
                 $paymentObject->addField('business', $this->_paymentVars['paypalTestBusiness']);
                 $paymentObject->addField('return', $this->_paymentVars['paypalTestSuccessUrl']);
                 $paymentObject->addField('cancel_return', $this->_paymentVars['paypalTestCancelUrl']);
                 $paymentObject->addField('notify_url', $this->_paymentVars['paypalTestNotifyUrl']);
                 $paymentObject->enableTestMode();
             } else {
                 $paymentObject->addField('business', $this->_paymentVars['paypalBusiness']);
                 $paymentObject->addField('return', $this->_paymentVars['paypalSuccessUrl']);
                 $paymentObject->addField('cancel_return', $this->_paymentVars['paypalCancelUrl']);
                 $paymentObject->addField('notify_url', $this->_paymentVars['paypalNotifyUrl']);
             }
             for ($iCart = 0; $iCart < count($items); $iCart++) {
                 $i = $iCart + 1;
                 $paymentObject->addField("item_number_" . $i, $items[$iCart]['itemId']);
                 $paymentObject->addField("item_name_" . $i, $items[$iCart]['documentName']);
                 //nama barang [documentName]
                 $paymentObject->addField("amount_" . $i, $items[$iCart]['price']);
                 //harga satuan [price]
                 $paymentObject->addField("quantity_" . $i, $items[$iCart]['qty']);
                 //jumlah barang [qty]\
             }
             $paymentObject->addField('tax_cart', $items[0]['orderTax']);
             $paymentObject->addField('currency_code', $this->_defaultCurrency);
             //$paymentObject->addField('custom',$_SESSION['_orderIdNumber']);
             $paymentObject->addField('custom', $orderId);
             $ivnum = $this->updateInvoiceMethod($orderId, 'paypal', 1, 0, 'paid with paypal method');
             //$paymentObject->dumpFields();
             $this->_helper->layout->disableLayout();
             $paymentObject->submitPayment();
             //setting payment and status as pending (1), notify = 0, notes = 'paid with...'
             break;
         case 'manual':
         case 'bank':
             /*
              1. update order status
              2. redirect to instruction page 
             */
             //setting payment and status as pending (1), notify = 0, notes = 'paid with...'
             $this->updateInvoiceMethod($orderId, 'bank', 1, 0, 'paid with manual method');
             // HAP: i think we should send this notification when user were on page "Complete Order" and after confirmation made by user is approved;
             //$this->Mailer($orderId, 'admin-order', 'admin');
             //$this->Mailer($orderId, 'user-order', 'user');
             $this->_helper->redirector('instruction', 'store_payment', 'site', array('orderId' => $orderId));
             break;
         case 'postpaid':
             /*
              1. validate POSTPAID status of the client 
              2. validate CREDIT LIMIT (per user) with current Outstanding Bill + New Bill
              3. update order status
              4. redirect to success or failed 
             */
             /*
              * if userid isn't listed as postpaid user will be redirected
              */
             if (!$this->_userFinanceInfo->isPostPaid) {
                 echo 'Not Post Paid Customer';
                 //$paymentObject->submitPayment();
                 return $this->_helper->redirector('notpostpaid');
             }
             /*====================VALIDATE CREDIT LIMIT=====================*/
             /*
              * validate credit limit :
              * 1. count total transaction 
              * 2. counting total previous unpaid postpaid transaction
              * 3. validate
              */
             //$cart = $this->completeItem();
             /*-----count total amount of prevous unpaid transaction------*/
             //$tblOrder = new Pandamp_Modules_Payment_Order_Model_Order();
             //table kutuOrder
             //select previous transaction that are postpaid based on userid
             //echo ($tblOrder->outstandingUserAmout($this->_userInfo->userId));
             $outstandingAmount = App_Model_Show_Order::show()->outstandingUserAmout($this->_userFinanceInfo->userId);
             /*count total amount of prevous unpaid transaction------*/
             if ($this->_userFinanceInfo->creditLimit == 0) {
                 $limit = 'Unlimited';
                 $netLimit = 'Unlimited';
             } else {
                 $limit = number_format($this->_userFinanceInfo->creditLimit, 2);
                 $netLimit = $limit - $outstandingAmount;
                 $netLimit = number_format($netLimit, 2);
             }
             //$superTotal = $cart['grandTotal']+$outstandingAmount;
             $superTotal = $items[0]['orderTotal'] + $outstandingAmount;
             if ($this->_userFinanceInfo->creditLimit != 0 and $this->_userFinanceInfo->creditLimit < $superTotal) {
                 echo $superTotal . $limit;
                 $this->_helper->redirector('postpaidlimit');
                 echo 'Credit Limit Reached, Please Contact Our Billing';
                 /*====================VALIDATE CREDIT LIMIT=====================*/
             } else {
                 $this->view->type = "postpaid";
                 $this->view->limit = $limit;
                 $this->view->outstandingAmount = $outstandingAmount;
                 $this->view->grandTotal = $items[0]['orderTotal'];
                 $this->view->netLimit = $netLimit;
                 $this->view->taxInfo = $items[0];
                 $this->view->orderId = $orderId;
             }
             break;
     }
 }
Ejemplo n.º 5
0
<?php

// Include the paypal library
include_once 'Paypal.php';
// Create an instance of the paypal library
$myPaypal = new Paypal();
// Specify your paypal email
$myPaypal->addField('business', 'YOUR_PAYPAL_EMAIL');
// Specify the currency
$myPaypal->addField('currency_code', 'USD');
// Specify the url where paypal will send the user on success/failure
$myPaypal->addField('return', 'http://YOUR_HOST/payment/paypal_success.php');
$myPaypal->addField('cancel_return', 'http://YOUR_HOST/payment/paypal_failure.php');
// Specify the url where paypal will send the IPN
$myPaypal->addField('notify_url', 'http://YOUR_HOST/payment/paypal_ipn.php');
// Specify the product information
$myPaypal->addField('item_name', 'T-Shirt');
$myPaypal->addField('amount', '9.99');
$myPaypal->addField('item_number', '001');
// Specify any custom value
$myPaypal->addField('custom', 'muri-khao');
// Enable test mode if needed
$myPaypal->enableTestMode();
// Let's start the train!
$myPaypal->submitPayment();
Ejemplo n.º 6
0
 public function pay_new($id = '', $gate_id = '')
 {
     if (intval($id) == 0 or intval($gate_id) == 0) {
         show_404();
     }
     $user = $this->db->get_where('users', array('id' => $id))->row();
     if (!$user or $user->status != 0) {
         show_404();
     }
     $group = $this->db->get_where('groups', array('id' => $user->group))->row();
     if (!$group) {
         show_404();
     }
     $gate = $this->db->get_where('gateways', array('id' => $gate_id))->row();
     if (!$gate) {
         show_404();
     }
     // get payment gateway settings
     $gate_conf = unserialize($gate->settings);
     // load payment libs
     include_once APPPATH . 'libraries/payment/PaymentGateway.php';
     // which payment system to use?
     if ($gate->name == 'paypal') {
         // Include the paypal library
         include_once APPPATH . 'libraries/payment/Paypal.php';
         // Create an instance of the paypal library
         $myPaypal = new Paypal();
         // Specify your paypal email
         $myPaypal->addField('business', $gate_conf['email']);
         // Specify the currency
         $myPaypal->addField('currency_code', $gate_conf['currency']);
         // Specify the url where paypal will send the user on success/failure
         $myPaypal->addField('return', site_url('user/pay_complete'));
         $myPaypal->addField('cancel_return', site_url('user/pay_cancel'));
         // Specify the url where paypal will send the IPN
         $myPaypal->addField('notify_url', site_url('payment/ipn/paypal'));
         // Specify the product information
         $myPaypal->addField('item_name', $this->startup->site_config['sitename'] . ' ' . $this->lang->line('user_controller_14'));
         $myPaypal->addField('amount', $group->price);
         $myPaypal->addField('item_number', rand(1, 1000) . '-' . $user->id);
         // Specify any custom value
         $myPaypal->addField('custom', base64_encode(serialize(array('user_id' => $user->id, 'type' => 'reg'))));
         // Enable test mode if needed
         if (defined('XUDEBUG') and XUDEBUG == true) {
             $myPaypal->enableTestMode();
         }
         // Let's start the train!
         $data['form'] = $myPaypal->submitPayment($this->lang->line('user_controller_paypal_submitpayment'));
     } else {
         if ($gate->name == 'authorize') {
             // Include the paypal library
             include_once APPPATH . 'libraries/payment/Authorize.php';
             // Create an instance of the authorize.net library
             $myAuthorize = new Authorize();
             // Specify your authorize.net login and secret
             $myAuthorize->setUserInfo($gate_conf['login'], $gate_conf['secret']);
             // Specify the url where authorize.net will send the user on success/failure
             $myAuthorize->addField('x_Receipt_Link_URL', site_url('user/pay_complete'));
             // Specify the url where authorize.net will send the IPN
             $myAuthorize->addField('x_Relay_URL', site_url('payment/ipn/authorize'));
             // Specify the product information
             $myAuthorize->addField('x_Description', $this->startup->site_config['sitename'] . ' ' . $this->lang->line('user_controller_14'));
             $myAuthorize->addField('x_Amount', $group->price);
             $myAuthorize->addField('x_Invoice_num', rand(1, 1000) . '-' . $user->id);
             $myAuthorize->addField('x_Cust_ID', base64_encode(serialize(array('user_id' => $user->id, 'type' => 'reg'))));
             // Enable test mode if needed
             if (defined('XUDEBUG') and XUDEBUG == true) {
                 $myAuthorize->enableTestMode();
             }
             // Let's start the train!
             $data['form'] = $myAuthorize->submitPayment($this->lang->line('user_controller_paypal_submitpayment'));
         } else {
             if ($gate->name = '2co') {
                 // Include the paypal library
                 include_once APPPATH . 'libraries/payment/TwoCo.php';
                 // Create an instance of the authorize.net library
                 $my2CO = new TwoCo();
                 // Specify your 2CheckOut vendor id
                 $my2CO->addField('sid', $gate_conf['vendor_id']);
                 // Specify the order information
                 $my2CO->addField('cart_order_id', rand(1, 1000) . '-' . $user->id);
                 $my2CO->addField('total', $group->price);
                 // Specify the url where authorize.net will send the IPN
                 $my2CO->addField('x_Receipt_Link_URL', site_url('payment/ipn/two_checkout'));
                 $my2CO->addField('tco_currency', $gate_conf['currency']);
                 $my2CO->addField('custom', base64_encode(serialize(array('user_id' => $user->id, 'type' => 'reg'))));
                 // Enable test mode if needed
                 if (defined('XUDEBUG') and XUDEBUG == true) {
                     $my2CO->enableTestMode();
                 }
                 // Let's start the train!
                 $data['form'] = $my2CO->submitPayment($this->lang->line('user_controller_paypal_submitpayment'));
             }
         }
     }
     $this->load->view($this->startup->skin . '/header', array('headerTitle' => $this->lang->line('user_controller_15')));
     $this->load->view($this->startup->skin . '/user/register/pay_new', array('ammount' => $group, 'user' => $id, 'form' => $data['form']));
     $this->load->view($this->startup->skin . '/footer');
 }
 public function gateway_ipn($config)
 {
     $cancel = $this->EE->input->get('cancel', TRUE);
     $ipn_valid = FALSE;
     if ($cancel != '') {
         $this->EE->product_model->cart_update_status(session_id(), 0);
         $this->EE->functions->redirect($this->EE->functions->create_url($this->_config["store"][$this->site_id]["cart_url"]));
         exit;
     }
     // Create an instance of the paypal library
     $myPaypal = new Paypal();
     if ($config["sandbox"] == "TRUE") {
         $myPaypal->enableTestMode();
     }
     # Debug file_put_contents(APPPATH.'cache/brilliant_retail/paypal_'.time().'.txt', 'SUCCESS\n\n'.json_encode($_POST));
     // Check validity and write down it
     if ($myPaypal->validateIpn()) {
         $ipn_valid = TRUE;
     }
     // Update BR
     if ($myPaypal->ipnData['payment_status'] == 'Completed' || $myPaypal->ipnData['payment_status'] == 'Pending') {
         if ($ipn_valid == TRUE) {
             $status['Pending'] = 2;
             $status['Completed'] = 3;
             $new_status = $status[$myPaypal->ipnData['payment_status']];
         } else {
             $new_status = 1;
         }
         // The ipn_create_order funtion is a core
         // function that will 'create' the order
         // based on the merchant_id value stored in the br_order_table.
         // Function handles both creating and updating from pending to complete
         // just pass the merchant_id. For paypal standard it is in the custom field.
         $this->ipn_create_order($myPaypal->ipnData['custom'], $new_status);
     }
     @header("HTTP/1.0 200 OK");
     @header("HTTP/1.1 200 OK");
     exit('Success');
 }
Ejemplo n.º 8
0
 public function verificationAction()
 {
     /*
      - check payment type use switch if necessary (paypal, twoco, manual )
      - use verification function from existing library of paypal/twoco
      - set order status if verified
      - redirect to proper page? or trigger mail?          
     */
     // Create an instance of the paypal library
     require_once 'PaymentGateway/Paypal.php';
     $myPaypal = new Paypal();
     // Log the IPN results
     $myPaypal->ipnLog = TRUE;
     // Enable test mode if needed
     if ($this->_testMode) {
         $myPaypal->enableTestMode();
     }
     // Check validity, status, amount and tax amount and write down it
     if ($myPaypal->validateIpn()) {
         //if ($myPaypal->ipnData['payment_status'] == 'Completed' && $myPaypal['']=='')
         if ($myPaypal->ipnData['payment_status'] == 'Completed') {
             $data = $myPaypal->ipnData;
             $this->Mailer($data['custom'], 'admin-paypal', 'admin');
             $this->Mailer($data['custom'], 'user-paypal', 'admin');
             $this->paypalsave('SUCCESS', $data);
         } else {
             $data = $myPaypal->ipnData;
             $this->Mailer($data['custom'], 'admin-paypal', 'admin');
             $this->Mailer($data['custom'], 'user-paypal', 'admin');
             $this->paypalsave('FAILED', $data);
             /*$this->paypalsave('FAILED');
             	 $this->Mailer($data['orderId'], 'admin-paypal', 'admin');
             	 $this->Mailer($data['orderId'], 'user-paypal', 'admin');*/
         }
     } else {
         foreach ($this->_request->getParams() as $key => $val) {
             $data[$key] = $val;
         }
         //all data and key are same with ipnData
         $this->Mailer($data['custom'], 'admin-paypal', 'admin');
         //send all post variables to admin email
     }
     $_SESSION['jCart'] = '';
     die;
 }
Ejemplo n.º 9
0
function espresso_display_paypal($payment_data)
{
    extract($payment_data);
    global $wpdb;
    include_once 'Paypal.php';
    $myPaypal = new Paypal();
    echo '<!-- Event Espresso PayPal Gateway Version ' . $myPaypal->gateway_version . '-->';
    global $org_options;
    $paypal_settings = get_option('event_espresso_paypal_settings');
    $paypal_id = empty($paypal_settings['paypal_id']) ? '' : $paypal_settings['paypal_id'];
    $paypal_cur = empty($paypal_settings['currency_format']) ? '' : $paypal_settings['currency_format'];
    $no_shipping = isset($paypal_settings['no_shipping']) ? $paypal_settings['no_shipping'] : '0';
    $use_sandbox = $paypal_settings['use_sandbox'];
    if ($use_sandbox) {
        $myPaypal->enableTestMode();
    }
    $myPaypal->addField('business', $paypal_id);
    $myPaypal->addField('return', home_url() . '/?page_id=' . $org_options['return_url'] . '&id=' . $attendee_id);
    $myPaypal->addField('cancel_return', home_url() . '/?page_id=' . $org_options['cancel_return']);
    $myPaypal->addField('notify_url', home_url() . '/?page_id=' . $org_options['notify_url'] . '&id=' . $attendee_id . '&event_id=' . $event_id . '&attendee_action=post_payment&form_action=payment');
    $event_name = $wpdb->get_var('SELECT event_name FROM ' . EVENTS_DETAIL_TABLE . " WHERE id='" . $event_id . "'");
    $myPaypal->addField('cmd', '_cart');
    $myPaypal->addField('upload', '1');
    $i = 1;
    $sql = "SELECT attendee_session FROM " . EVENTS_ATTENDEE_TABLE . " WHERE id='" . $attendee_id . "'";
    $session_id = $wpdb->get_var($sql);
    $sql = "SELECT amount_pd FROM " . EVENTS_ATTENDEE_TABLE . " WHERE attendee_session='" . $session_id . "'";
    $amount_pds = $wpdb->get_col($sql);
    $cost = 0;
    foreach ($amount_pds as $amount_pd) {
        $cost += $amount_pd;
    }
    $myPaypal->addField('item_name_' . $i, $event_name);
    $myPaypal->addField('amount_' . $i, $cost);
    $myPaypal->addField('quantity_' . $i, '1');
    $myPaypal->addField('currency_code', $paypal_cur);
    $myPaypal->addField('image_url', empty($paypal_settings['image_url']) ? '' : $paypal_settings['image_url']);
    $myPaypal->addField('no_shipping ', $no_shipping);
    $myPaypal->addField('first_name', $fname);
    $myPaypal->addField('last_name', $lname);
    $myPaypal->addField('email', $attendee_email);
    $myPaypal->addField('address1', $address);
    $myPaypal->addField('city', $city);
    $myPaypal->addField('state', $state);
    $myPaypal->addField('zip', $zip);
    if (!empty($paypal_settings['bypass_payment_page']) && $paypal_settings['bypass_payment_page'] == 'Y') {
        $myPaypal->submitPayment();
    } else {
        if (empty($paypal_settings['button_url'])) {
            if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "/paypal/btn_stdCheckout2.gif")) {
                $button_url = EVENT_ESPRESSO_GATEWAY_DIR . "/paypal/btn_stdCheckout2.gif";
            } else {
                $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/paypal/btn_stdCheckout2.gif";
            }
        } elseif (file_exists($paypal_settings['button_url'])) {
            $button_url = $paypal_settings['button_url'];
        } else {
            $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/paypal/btn_stdCheckout2.gif";
        }
        $myPaypal->submitButton($button_url, 'paypal');
    }
    if ($use_sandbox) {
        echo '<h3 style="color:#ff0000;" title="Payments will not be processed">' . __('Paypal Debug Mode Is Turned On', 'event_espresso') . '</h3>';
        $myPaypal->dump_fields();
    }
}
Ejemplo n.º 10
0
 /**
  * Shows the paypal button after new post
  *
  * @param type $type
  * @param type $post_id
  * @param type $pack_id
  * @param type $display
  * @return type
  */
 public function paypal_form($type = 'post', $post_id = 0, $pack_id = 0, $display = false)
 {
     // Include the paypal library
     include_once dirname(__FILE__) . '/lib/payment/Paypal.php';
     //var_dump( $type, $post_id, $pack_id ); exit;
     $email = get_option('wpuf_sub_paypal_mail');
     $curreny = get_option('wpuf_sub_currency');
     $amount = 0;
     if ($type == 'post') {
         $post = get_post($post_id);
         $amount = get_option('wpuf_sub_amount');
         $item_name = $post->post_title;
         $item_number = get_post_meta($post_id, 'wpuf_order_id', true);
         $custom = 'post';
         $cbt = sprintf(__('Click here to complete the pack on %s', 'wpuf'), get_bloginfo('name'));
     }
     if ($type == 'pack') {
         $pack = $this->get_subscription($pack_id);
         if ($pack) {
             $amount = $pack->cost;
             $item_name = $pack->name;
             $item_number = $pack->id;
             $custom = 'pack';
             $cbt = sprintf(__('Click here to complete the pack on %s', 'wpuf'), get_bloginfo('name'));
         }
     }
     // Create an instance of the paypal library
     $myPaypal = new Paypal();
     // Specify your paypal email
     $myPaypal->addField('business', $email);
     // Specify the currency
     $myPaypal->addField('currency_code', $curreny);
     // Specify the url where paypal will send the user on success/failure
     $myPaypal->addField('return', get_bloginfo('home') . '/?action=wpuf_pay_success');
     $myPaypal->addField('cancel_return', get_bloginfo('home'));
     // Specify the url where paypal will send the IPN
     $myPaypal->addField('notify_url', get_bloginfo('home') . '/?action=wpuf_pay_success');
     // Specify the product information
     $myPaypal->addField('item_name', $item_name);
     $myPaypal->addField('amount', $amount);
     $myPaypal->addField('item_number', $item_number);
     // Specify any custom value
     $myPaypal->addField('custom', $custom);
     $myPaypal->addField('cbt', $cbt);
     // Enable test mode if needed
     if (get_option('wpuf_sub_paypal_sandbox') == 'yes') {
         $myPaypal->enableTestMode();
     }
     // Let's start the train!
     $form = $myPaypal->submitPayment();
     return $form;
 }
Ejemplo n.º 11
0
 public function actionIpn()
 {
     Yii::import('application.modules.shop.components.payment.Paypal');
     $paypal = new Paypal();
     Shop::log('Paypal payment attempt');
     // Log the IPN results
     $paypal->ipnLog = TRUE;
     if (Shop::module()->payPalTestMode) {
         $paypal->enableTestMode();
     }
     // Check validity and write down it
     if ($paypal->validateIpn()) {
         if ($paypal->ipnData['payment_status'] == 'Completed') {
             Shop::log('Paypal payment arrived :' . var_dump($paypal));
         } else {
             Shop::log('Paypal payment raised an error :' . var_dump($paypal));
         }
     }
 }
function submit_to_paypal()
{
    $eStore_default_currency = get_option('cart_payment_currency');
    $eStore_return_url = get_option('cart_return_from_paypal_url');
    $eStore_sandbox_enabled = get_option('eStore_cart_enable_sandbox');
    if (!empty($eStore_default_currency)) {
        $paypal_currency = $eStore_default_currency;
    } else {
        $paypal_currency = 'USD';
    }
    $email = get_option('cart_paypal_email');
    $myPaypal = new Paypal();
    $myPaypal->gatewayUrl = 'https://www.paypal.com/cgi-bin/webscr';
    //PAYPAL_LIVE_URL
    $myPaypal->addField('charset', "utf-8");
    $myPaypal->addField('business', $email);
    $paypal_currency = apply_filters('eStore_change_curr_code_before_payment_filter', $paypal_currency);
    $myPaypal->addField('currency_code', $paypal_currency);
    $cancel_url = get_option('cart_cancel_from_paypal_url');
    if (!empty($cancel_url)) {
        $myPaypal->addField('cancel_return', $cancel_url);
    }
    if (get_option('eStore_auto_product_delivery') != '') {
        if (WP_ESTORE_ENABLE_NEW_CHECKOUT_REDIRECTION === '1') {
            $notify = WP_ESTORE_SITE_HOME_URL . '/?estore_pp_ipn=process';
        } else {
            $notify = WP_ESTORE_URL . '/paypal.php';
        }
        $myPaypal->addField('notify_url', $notify);
    }
    // =======================
    global $wpdb;
    $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
    $weight = 0;
    $count = 1;
    $all_items_digital = true;
    foreach ($_SESSION['eStore_cart'] as $item) {
        $rounded_price = round($item['price'], 2);
        $rounded_price = apply_filters('eStore_change_price_before_payment_filter', $rounded_price);
        $myPaypal->addField("item_name_{$count}", htmlspecialchars($item['name']));
        $myPaypal->addField("amount_{$count}", $rounded_price);
        $myPaypal->addField("quantity_{$count}", $item['quantity']);
        $myPaypal->addField("item_number_{$count}", $item['item_number']);
        //Check to see if this is a tax free item and set the tax accordingly so that the profile based PayPal tax can work nicely
        if ($item['tax'] == "0") {
            $myPaypal->addField("tax_{$count}", $item['tax']);
        }
        $id = $item['item_number'];
        $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT);
        if (!empty($ret_product->weight)) {
            $weight += $ret_product->weight * $item['quantity'];
        }
        if (empty($item['digital_flag'])) {
            $all_items_digital = false;
        }
        $count++;
    }
    $total_items_in_cart = count($_SESSION['eStore_cart']);
    if ($total_items_in_cart == 1 && !empty($ret_product->return_url)) {
        $myPaypal->addField('return', $ret_product->return_url);
    } else {
        if (!empty($eStore_return_url)) {
            $myPaypal->addField('return', $eStore_return_url);
        }
    }
    if (!get_option('eStore_paypal_profile_shipping')) {
        //Not Using paypal's profile based shipping so include shipping otherwise ignore shipping here as it will be calculated on paypal's site
        $shipping = round($_SESSION['eStore_cart_postage_cost'], 2);
        if (!empty($shipping)) {
            $shipping = apply_filters('eStore_change_shipping_before_payment_filter', $shipping);
            //change tax amount before submitting if converting currency to another type
            $myPaypal->addField('no_shipping', '2');
            $myPaypal->addField('handling_cart', $shipping);
            //$myPaypal->addField('shipping_1', $shipping);
        } else {
            //If you do not want to collect address for checkout that has no shipping cost then uncomment the following line of code.
            //$myPaypal->addField('no_shipping', '1');
        }
    } else {
        //Include the weight for profile based shipping calc
        $myPaypal->addField('weight_cart', round($weight, 2));
        $myPaypal->addField('weight_unit', 'lbs');
        if ($all_items_digital) {
            //All the items in the cart are digital items so set the shipping flag to 0 so no shipping is charged
            $total_items = count($_SESSION['eStore_cart']);
            for ($i = 1; $i <= $total_items; $i++) {
                $myPaypal->addField('shipping_' . $i, '0');
            }
        } else {
            if (isset($_SESSION['eStore_cart_postage_cost']) && $_SESSION['eStore_cart_postage_cost'] == 0) {
                //Free shipping discount applied. send 0 shipping to override profile based shipping
                if (empty($weight)) {
                    //Add $0 shipping override
                    $myPaypal->addField('shipping_1', '0');
                }
            }
        }
    }
    if (!empty($_SESSION['eStore_cart_total_tax'])) {
        $cart_total_tax = round($_SESSION['eStore_cart_total_tax'], 2);
        $cart_total_tax = apply_filters('eStore_change_tax_before_payment_filter', $cart_total_tax);
        //change tax amount before submitting if converting currency to another type
        $myPaypal->addField('tax_cart', $cart_total_tax);
    }
    if (get_option('eStore_display_tx_result')) {
        $myPaypal->addField('rm', '1');
    }
    if (defined('WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE') && WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE !== '0') {
        //Set the country/region preference by force.
        $myPaypal->addField('lc', WP_ESTORE_FORCE_LANGUAGE_OF_PAYPAL_PAGE);
    }
    $myPaypal->addField('cmd', '_cart');
    $myPaypal->addField('upload', '1');
    $custom_field_val = eStore_get_custom_field_value();
    $myPaypal->addField('custom', $custom_field_val);
    $myPaypal->addField('mrb', '3FWGC6LFTMTUG');
    $page_style_name = get_option('eStore_paypal_co_page_style');
    if (!empty($page_style_name)) {
        $myPaypal->addField('page_style', $page_style_name);
    }
    $returnButtonText = get_option('eStore_paypal_return_button_text');
    if (!empty($returnButtonText)) {
        $myPaypal->addField('cbt', $returnButtonText);
    }
    // Enable sandbox mode if needed
    if ($eStore_sandbox_enabled) {
        $myPaypal->enableTestMode();
    }
    // Lets clear the cart if automatic redirection is not being used otherwise we will empty the cart after the redirection
    $PDT_auth_token = get_option('eStore_paypal_pdt_token');
    if (empty($PDT_auth_token)) {
        reset_eStore_cart();
    }
    // submit the payment!
    $myPaypal->submitPayment2(WP_ESTORE_CLICK_HERE);
}