示例#1
0
 /**
  * Starts a transaction and returns the payment url
  *
  * @return string
  */
 public function getPaymentLink($order)
 {
     $this->log('Request payment link for manual order');
     $this->checkSettings();
     $this->createSignature();
     $payment = $order->getPayment()->getMethodInstance();
     $pm_code = $payment->getCode();
     $storename = Mage::app()->getStore()->getName();
     $billing = $order->getBillingAddress();
     $shipping = $order->getShippingAddress();
     $items = "<ul>\n";
     foreach ($order->getAllVisibleItems() as $item) {
         $items .= "<li>" . $item->getQtyOrdered() * 1 . " x : " . $item->getName() . "</li>\n";
     }
     $items .= "</ul>\n";
     // build request
     $mapi = new MultiSafepay();
     $mapi->plugin_name = 'Magento';
     $mapi->version = Mage::getConfig()->getNode('modules/MultiSafepay_Msp/version');
     $mapi->use_shipping_notification = false;
     $mapi->merchant['account_id'] = $this->merchant['account_id'];
     $mapi->merchant['site_id'] = $this->merchant['site_id'];
     $mapi->merchant['site_code'] = $this->merchant['security_code'];
     $mapi->test = $this->test;
     $mapi->merchant['notification_url'] = Mage::getUrl("msp/standard/notification") . '&type=initial';
     $mapi->merchant['cancel_url'] = Mage::getUrl("msp/standard/cancel", array("_secure" => true));
     $mapi->merchant['redirect_url'] = Mage::getUrl("msp/standard/return", array("_secure" => true));
     $mapi->parseCustomerAddress($billing->getStreet(1));
     if ($mapi->customer['housenumber'] == '') {
         $mapi->customer['housenumber'] = $billing->getStreet(2);
         $mapi->customer['address1'] = $billing->getStreet(1);
     }
     $mapi->customer['locale'] = Mage::app()->getLocale()->getLocaleCode();
     //Mage::app()->getLocale()->getDefaultLocale();
     $mapi->customer['firstname'] = $billing->getFirstname();
     $mapi->customer['lastname'] = $billing->getLastname();
     $mapi->customer['zipcode'] = $billing->getPostcode();
     $mapi->customer['city'] = $billing->getCity();
     $mapi->customer['state'] = $billing->getState();
     $mapi->customer['country'] = $billing->getCountry();
     $mapi->customer['phone'] = $billing->getTelephone();
     $mapi->customer['email'] = $order->getCustomerEmail();
     $mapi->customer['ipaddress'] = $_SERVER['REMOTE_ADDR'];
     $mapi->transaction['id'] = $this->transaction['id'];
     $mapi->transaction['amount'] = $this->transaction['amount'];
     $mapi->transaction['currency'] = $this->transaction['currency'];
     $mapi->transaction['var3'] = Mage::app()->getStore()->getStoreId();
     $mapi->transaction['description'] = 'Order #' . $this->transaction['id'] . ' at ' . $storename;
     $mapi->transaction['gateway'] = $this->availablePaymentMethodCodes[$pm_code];
     $mapi->transaction['items'] = $items;
     $mapi->transaction['daysactive'] = $this->transaction['days_active'];
     $url = $mapi->startTransaction();
     if ($mapi->error) {
         return array('error' => true, 'code' => $mapi->error_code, 'description' => $mapi->error);
     }
     return array('error' => false, 'url' => $url);
 }
 public static function multisafepay_redirect($description, $amount, $user_id, $payment_id, $invoice_id, $currency_id)
 {
     $currency = module_config::get_currency($currency_id);
     if ($currency['code'] != 'EUR') {
         echo "Multisafepay only accepts currency in EUR";
     }
     include 'MultiSafepay.combined.php';
     $msp = new MultiSafepay();
     /*
      * Merchant Settings
      */
     $msp->test = self::is_sandbox();
     $msp->merchant['account_id'] = module_config::c('payment_method_multisafepay_account', '');
     $msp->merchant['site_id'] = module_config::c('payment_method_multisafepay_site_id', '');
     $msp->merchant['site_code'] = module_config::c('payment_method_multisafepay_side_code', '');
     $msp->merchant['notification_url'] = full_link(_EXTERNAL_TUNNEL . '?m=paymethod_multisafepay&h=ipn&method=multisafepay&type=initial');
     $msp->merchant['cancel_url'] = module_invoice::link_public($invoice_id);
     // optional automatic redirect back to the shop:
     $msp->merchant['redirect_url'] = module_invoice::link_public($invoice_id);
     /*
      * Customer Details
      */
     $invoice = $invoice_data = module_invoice::get_invoice($invoice_id);
     $customer = module_customer::get_customer($invoice_data['customer_id'], true);
     if (!$user_id) {
         $user_id = $customer['primary_user_id'];
     }
     $user = module_user::get_user($user_id, false);
     //$msp->customer['locale']           = 'nl';
     $msp->customer['firstname'] = $user['name'];
     $msp->customer['lastname'] = $user['last_name'];
     $address = module_address::get_address($invoice_data['customer_id'], 'customer', 'physical');
     $msp->customer['zipcode'] = isset($address['post_code']) ? $address['post_code'] : '';
     $msp->customer['city'] = isset($address['region']) ? $address['region'] : '';
     $msp->customer['country'] = isset($address['country']) ? $address['country'] : module_config::c('payment_method_multisafepay_country', '');
     $msp->customer['phone'] = $user['phone'];
     $msp->customer['email'] = $user['email'];
     $msp->parseCustomerAddress(isset($address['line_1']) ? $address['line_1'] : '');
     // or
     // $msp->customer['address1']         = 'Teststraat';
     // $msp->customer['housenumber']      = '21';
     /*
      * Transaction Details
      */
     $msp->transaction['id'] = self::multisafepay_custom($user_id, $payment_id, $invoice_id);
     $msp->transaction['currency'] = $currency['code'];
     $msp->transaction['amount'] = $amount * 100;
     // cents
     $msp->transaction['description'] = $description;
     $msp->transaction['items'] = '<br/><ul>';
     // copied from invoice_task_list.php
     foreach (module_invoice::get_invoice_items($invoice_id) as $invoice_item_id => $invoice_item_data) {
         // copy any changes here to template/invoice_task_list.php
         $task_hourly_rate = isset($invoice_item_data['hourly_rate']) && $invoice_item_data['hourly_rate'] != 0 ? $invoice_item_data['hourly_rate'] : $invoice_data['hourly_rate'];
         // if there are no hours logged against this task
         if (!$invoice_item_data['hours']) {
             //$task_hourly_rate=0;
         }
         // if we have a custom price for this task
         if ($invoice_item_data['amount'] != 0 && $invoice_item_data['amount'] != $invoice_item_data['hours'] * $task_hourly_rate) {
             $invoice_item_amount = $invoice_item_data['amount'];
             $task_hourly_rate = false;
         } else {
             if ($invoice_item_data['hours'] > 0) {
                 $invoice_item_amount = $invoice_item_data['hours'] * $task_hourly_rate;
             } else {
                 $invoice_item_amount = 0;
                 $task_hourly_rate = false;
             }
         }
         $msp->transaction['items'] .= '<li>';
         $msp->transaction['items'] .= $invoice_item_data['hours'] > 0 ? $invoice_item_data['hours'] . ' x ' : '';
         $msp->transaction['items'] .= $invoice_item_data['custom_description'] ? htmlspecialchars($invoice_item_data['custom_description']) : htmlspecialchars($invoice_item_data['description']);
         $msp->transaction['items'] .= ' = ' . dollar($invoice_item_amount, true, $invoice['currency_id']);
         $msp->transaction['items'] .= '</li>';
     }
     $msp->transaction['items'] .= '<li>Sub Total: ' . dollar($invoice_data['total_sub_amount'], true, $invoice_data['currency_id']) . '</li>';
     if ($invoice_data['total_tax_rate'] > 0) {
         $msp->transaction['items'] .= '<li>' . $invoice['total_tax_name'] . ' ' . $invoice['total_tax_rate'] . '% = ' . dollar($invoice['total_tax'], true, $invoice['currency_id']) . '</li>';
     }
     $msp->transaction['items'] .= '<li>Total: ' . dollar($invoice['total_amount'], true, $invoice['currency_id']) . '</li>';
     $msp->transaction['items'] .= '</ul>';
     // returns a payment url
     $url = $msp->startTransaction();
     if ($msp->error) {
         echo "Error " . $msp->error_code . ": " . $msp->error;
         exit;
     }
     // redirect
     redirect_browser($url);
     /*
             $url = 'https://www.'. (self::is_sandbox()? 'sandbox.' : '') . 'multisafepay.com/cgi-bin/webscr?';
     
             $fields = array(
                 'cmd' => '_xclick',
                 'business' => module_config::c('payment_method_multisafepay_email',_ERROR_EMAIL),
                 'currency_code' => $currency['code'],
                 'item_name' => $description,
                 'amount' => $amount,
                 'return' => module_invoice::link_open($invoice_id),
                 'notify_url' => full_link(_EXTERNAL_TUNNEL.'?m=paymethod_multisafepay&h=ipn&method=multisafepay'),
                 'custom' => self::multisafepay_custom($user_id,$payment_id,$invoice_id),
             );
     
             foreach($fields as $key=>$val){
                 $url .= $key.'='.urlencode($val).'&';
             }
     
             //echo '<a href="'.$url.'">'.$url.'</a>';exit;
     
             redirect_browser($url);
     */
 }