ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilShopShoppingCartGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
5 
6 include_once './Services/Payment/classes/class.ilShopBaseGUI.php';
7 include_once './Services/Payment/classes/class.ilPaypalSettings.php';
8 //include_once './Services/Payment/classes/class.ilEPaySettings.php';
9 include_once './Services/Payment/classes/class.ilPaymentCoupons.php';
10 include_once './Services/Payment/classes/class.ilShopVatsList.php';
11 include_once './Services/Payment/classes/class.ilPaymentShoppingCart.php';
12 include_once './Services/Payment/classes/class.ilPayMethods.php';
13 
14 include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
15 include_once './Services/Payment/classes/class.ilShopBoughtObjectsGUI.php';
16 
27 {
28  private $user_obj;
29  private $psc_obj = null;
30  private $paypal_obj = null;
31 
32  private $totalAmount = array();
33  private $totalVat = 0;
34  private $epSet;
35 
36  #private $default_currency = 1;
37  private $session_id;
38 
39  public function __construct($user_obj)
40  {
42 
43  $this->user_obj = $user_obj;
44  $this->session_id = session_id();
45 
46  $this->coupon_obj = new ilPaymentCoupons($this->user_obj);
47 
49  $this->paypalConfig = $ppSet->getAll();
50 
51 // $this->epSet = ilEPaySettings::getInstance();
52 // $this->epayConfig = $this->epSet->getAll();
53 
55 
56  #$this->default_currency = ilPaymentCurrency::_getDefaultCurrency();
57  }
58 
62  public function executeCommand()
63  {
64  $cmd = $this->ctrl->getCmd();
65  $next_class = $this->ctrl->getNextClass($this);
66 
67  switch ($next_class)
68  {
69  default:
70  $this->prepareOutput();
71  if (!$cmd = $this->ctrl->getCmd())
72  {
73  $cmd = 'showItems';
74  }
75  $this->$cmd();
76  break;
77  }
78 
79  return true;
80  }
81 
82  protected function prepareOutput()
83  {
84  global $ilTabs;
85 
87 
88  $ilTabs->setTabActive('paya_shopping_cart');
89  }
91  {
92  include_once './Services/Payment/classes/class.ilPurchaseBaseGUI.php';
93  $purchase = new ilPurchaseBaseGUI($this->user_obj, ilPayMethods::_getIdByTitle('paypal'));
94  $purchase->__addBookings();
95 
96  $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
97 
98  return true;
99  }
100 
102  {
103  $this->addBookings(PAY_METHOD_BMF, 'bmf');
104 
105  $_SESSION['coupons']['bmf'] = '';
106  $_SESSION['bmf']['payment_type'] = '';
107  $_SESSION['bmf']['debit_entry'] = array();
108  $_SESSION['bmf']['credit_card'] = array();
109 
110  ilUtil::sendInfo($this->lng->txt('pay_bmf_thanks'), true);
111 
112  $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
113 
114  return true;
115  }
116 
118  {
119  include_once './Services/Payment/classes/class.ilPurchaseBaseGUI.php';
120  $purchase = new ilPurchaseBaseGUI($this->user_obj, ilPayMethods::_getIdByTitle('paypal'));
121  $purchase->__addBookings();
122 
123  ilUtil::sendSuccess($this->lng->txt('pay_paypal_success'), true);
124  $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
125 
126  return true;
127  }
128 
129  private function addBookings($pay_method, $coupon_session)
130  {
131  global $ilUser, $ilObjDataCache;
132 
133  include_once './Services/Payment/classes/class.ilPaymentBookings.php';
134  include_once './Services/Payment/classes/class.ilPaymentObject.php';
135  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
136 
137  $booking_obj = new ilPaymentBookings();
138  $sc_obj = new ilPaymentShoppingCart($this->user_obj);
139  $items = $sc_obj->getEntries($pay_method);
140  $sc_obj->clearCouponItemsSession();
141 
142  foreach($items as $entry)
143  {
144  $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
145  $price = ilPaymentPrices::_getPrice($entry['price_id']);
146 
147  if (!empty($_SESSION['coupons'][$coupon_session]))
148  {
149  $entry['math_price'] = $entry['price']; // (float) ilPaymentPrices::_getPriceFromArray($price);
150  foreach ($_SESSION['coupons'][$coupon_session] as $key => $coupon)
151  {
152  $this->coupon_obj->setId($coupon['pc_pk']);
153  $this->coupon_obj->setCurrentCoupon($coupon);
154 
155  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
156  {
157  $_SESSION['coupons'][$coupon_session][$key]['total_objects_coupon_price'] += $entry['price']; //(float) ilPaymentPrices::_getPriceFromArray($price);
158  $_SESSION['coupons'][$coupon_session][$key]['items'][] = $entry;
159  }
160  }
161  }
162  unset($pobject);
163  }
164 
165  $coupon_discount_items = $sc_obj->calcDiscountPrices($_SESSION['coupons'][$coupon_session]);
166 
167  foreach($items as $entry)
168  {
169  $pobject = new ilPaymentObject($this->user_obj, $entry['pobject_id']);
170 
171  $price = ilPaymentPrices::_getPrice($entry['price_id']);
172 
173  if (array_key_exists($entry['pobject_id'], $coupon_discount_items))
174  {
175  $bonus = $coupon_discount_items[$entry['pobject_id']]['math_price'] - $coupon_discount_items[$entry['pobject_id']]['discount_price'];
176  }
177 
178  $booking_obj->setPobjectId($entry['pobject_id']);
179 
180  $booking_obj->setCustomerId($this->user_obj->getId());
181  $booking_obj->setVendorId($pobject->getVendorId());
182  $booking_obj->setPayMethod($pobject->getPayMethod());
183  $booking_obj->setOrderDate(time());
184  $booking_obj->setDuration($price['duration']);
185  $booking_obj->setPrice(ilPaymentPrices::_getPriceString($entry['price_id']));
186  $booking_obj->setDiscount($bonus > 0 ? ((-1) * $bonus) : 0);
187  $booking_obj->setPayed(1);
188  $booking_obj->setAccess(1);
189 
190  switch($price['price_type'])
191  {
193  $booking_obj->setDuration(0);
194  break;
196  $booking_obj->setDuration($price['duration']);
197  break;
199  $booking_obj->setAccessStartdate($price['duration_from']);
200  $booking_obj->setAccessEnddate($price['duration_until']);
201  break;
202  }
203 
204  $booking_obj->setAccessExtension($price['extension']);
205 
206  $obj_id = $ilObjDataCache->lookupObjId($pobject->getRefId());
207  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
208 
209  $oVAT = new ilShopVats((int)$pobject->getVatId());
210  $obj_vat_rate = $oVAT->getRate();
211 
212  if($bonus > 0)
213  {
214  $tmp_price = $booking_obj->getPrice()-$bonus;
215  $obj_vat_unit = $pobject->getVat($tmp_price);
216  }else
217  $obj_vat_unit = $pobject->getVat($booking_obj->getPrice());
218 
219  $booking_obj->setObjectTitle($obj_title);
220  $booking_obj->setVatRate($obj_vat_rate);
221  $booking_obj->setVatUnit($obj_vat_unit);
222 
223  if(ilPaymethods::_EnabledSaveUserAddress($booking_obj->getPayMethod()))
224  {
225  $booking_obj->setStreet($ilUser->getStreet(), $ilUser->getHouseNumber);
226  $booking_obj->setZipcode($ilUser->getZipcode());
227  $booking_obj->setCity($ilUser->getCity());
228  $booking_obj->setCountry($ilUser->getCountry());
229  }
230 
231  $current_booking_id = $booking_obj->add();
232 
233  if ($current_booking_id)
234  {
235  $sc_obj->delete($entry['psc_id']);
236 
237  if (!empty($_SESSION['coupons'][$coupon_session]))
238  {
239  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
240  {
241  $this->coupon_obj->setId($coupon['pc_pk']);
242  $this->coupon_obj->setCurrentCoupon($coupon);
243 
244  if ($this->coupon_obj->isObjectAssignedToCoupon($pobject->getRefId()))
245  {
246  $this->coupon_obj->addCouponForBookingId($current_booking_id);
247  }
248  }
249  }
250  }
251 
252  unset($current_booking_id);
253  unset($pobject);
254  }
255 
256  if (!empty($_SESSION['coupons'][$coupon_session]))
257  {
258  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
259  {
260  $this->coupon_obj->setId($coupon['pc_pk']);
261  $this->coupon_obj->setCurrentCoupon($coupon);
262  $this->coupon_obj->addTracking();
263  }
264  }
265  }
266 
267  public function checkCouponsOfShoppingCart()
268  {
269  $objPM = new ilPayMethods();
270  $get_paymethods = $objPM->readAll();
271 
272  foreach($get_paymethods as $pm)
273  {
274  $pay_methods[$pm['pm_id']]['pm_title'] = $pm['pm_title'];
275  $pay_methods[$pm['pm_id']]['pm_id'] = $pm['pm_id'];
276  }
277 
278  if (is_array($pay_methods))
279  {
280  foreach($pay_methods as $pay_method)
281  {
282  $coupon_session_id = $pay_method['pm_title'];
283 
284  if (!is_array($_SESSION['coupons'][$coupon_session_id]))
285  {
286  $_SESSION['coupons'][$coupon_session_id] = array();
287  }
288  else // check if coupons are valid anymore
289  {
290  foreach ($_SESSION['coupons'][$coupon_session_id] as $coupon_id => $session_coupon)
291  {
292  $coupon = $this->coupon_obj->getCouponByCode($session_coupon['pcc_code']);
293 
294  if ($this->coupon_obj->checkCouponValidity() == 0)
295  {
296  $assignedItems = 0;
297  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
298 
299  if (count($items = $this->psc_obj->getEntries($pay_method['pm_id'])))
300  {
301  foreach($items as $item)
302  {
303  $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
304 
305  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
306  {
307  ++$assignedItems;
308  }
309  }
310  }
311  if (!$assignedItems)
312  {
313  unset($_SESSION['coupons'][$coupon_session_id][$coupon_id]);
314  }
315  }
316  else
317  {
318  unset($_SESSION['coupons'][$coupon_session_id][$coupon_id]);
319  }
320  }
321  }
322  }
323  }
324  }
325 
331  public function finishEPay()
332  {
333 // global $ilUser;
334 // require_once './Services/Payment/classes/class.ilPurchase.php';
335 //
336 // try
337 // {
338 // $pm_id = ilPayMethods::_getIdByTitle('epay');
339 // $buy = new ilPurchase( $ilUser->getId(), $pm_id );
340 // $buy->purchase($_REQUEST['tid'] );
341 // }
342 // catch (ilERPException $e)
343 // {
344 // $msg = $e->getMessage();
345 // if (DEVMODE) $msg .= " " . print_r($_REQUEST, true);
346 // ilUtil::sendFailure($msg);
347 // }
348 // ilUtil::sendSuccess($this->lng->txt('pay_epay_success'));
349 // $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
350  }
351 
352  public function finishPaypal()
353  {
354  global $ilUser;
355  $this->initPaypalObject();
356 
357  if (!($fp = $this->paypal_obj->openSocket()))
358  {
359  ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_unreachable').'<br />'.$this->lng->txt('pay_paypal_error_info'));
360  $this->showItems();
361  }
362  else
363  {
364 
365  $res = $this->paypal_obj->checkData($fp);
366 
367 
368  if ($res == SUCCESS)
369  {
370  ilUtil::sendSuccess($this->lng->txt('pay_paypal_success'), true);
371  if($ilUser->getId() == ANONYMOUS_USER_ID || $_SESSION['is_crs_object'] || $_SESSION['is_lm_object'] || $_SESSION['is_file_object'])
372  {
373 
374  $this->ctrl->redirectByClass('ilShopShoppingCartGUI', '');
375  }
376  else
377  {
378  # $this->ctrl->redirectByClass('ilShopBoughtObjectsGUI', '');
379  $this->ctrl->redirectByClass('ilShopShoppingCartGUI', '');
380  }
381  }
382  else
383  {
384  switch ($res)
385  {
386  case ERROR_WRONG_CUSTOMER : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_wrong_customer').'<br />'.$this->lng->txt('pay_paypal_error_info'));
387  break;
388  case ERROR_NOT_COMPLETED : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_not_completed').'<br />'.$this->lng->txt('pay_paypal_error_info'));
389  break;
390  case ERROR_PREV_TRANS_ID : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_prev_trans_id').'<br />'.$this->lng->txt('pay_paypal_error_info'));
391  break;
392  case ERROR_WRONG_VENDOR : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_wrong_vendor').'<br />'.$this->lng->txt('pay_paypal_error_info'));
393  break;
394  case ERROR_WRONG_ITEMS : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_wrong_items').'<br />'.$this->lng->txt('pay_paypal_error_info'));
395  break;
396  case ERROR_FAIL : ilUtil::sendFailure($this->lng->txt('pay_paypal_failed').'<br />'.$this->lng->txt('pay_paypal_error_fails').'<br />'.$this->lng->txt('pay_paypal_error_info'));
397  break;
398  }
399  $this->showItems();
400  }
401  fclose($fp);
402  }
403  }
404 
405 
406  public function cancelEPay()
407  {
408 // ilUtil::sendInfo($this->lng->txt('pay_epay_canceled'));
409 // $this->showItems();
410  }
411 
412  public function cancelPaypal()
413  {
414  ilUtil::sendInfo($this->lng->txt('pay_paypal_canceled'));
415  $this->showItems();
416  }
417 
418  private function _getPayMethods( $limitToEnabled = false )
419  {
420  $objPM = new ilPayMethods();
421  $get_paymethods = $objPM->readAll();
422 
423  if(!$limitToEnabled)
424  {
425  foreach($get_paymethods as $pm)
426  {
427  $pay_methods[$pm['pm_id']]['pm_title'] = $pm['pm_title'];
428  $pay_methods[$pm['pm_id']]['pm_id'] = $pm['pm_id'];
429  $pay_methods[$pm['pm_id']]['pm_enabled'] = $pm['pm_enabled'];
430  $pay_methods[$pm['pm_id']]['save_usr_adr'] = $pm['save_usr_adr'];
431  }
432  }
433  else
434  {
435  foreach($get_paymethods as $pm)
436  {
437  if($pm['pm_enabled'] == 1)
438  {
439  $pay_methods[$pm['pm_id']]['pm_title'] = $pm['pm_title'];
440  $pay_methods[$pm['pm_id']]['pm_id'] = $pm['pm_id'];
441  $pay_methods[$pm['pm_id']]['pm_enabled'] = $pm['pm_enabled'];
442  $pay_methods[$pm['pm_id']]['save_usr_adr'] = $pm['save_usr_adr'];
443  }
444  }
445  }
446  return $pay_methods;
447  }
448 
449  /*
450  *
451  */
452  private function _getTemplateFilename( $a_pm_title )
453  {
454  // use payment_paymethods -> pm_title
455  $base = "./Services/Payment/templates/default/tpl.pay_shopping_cart_";
456  $suffix = ".html";
457 
458  return $base . $a_pm_title . $suffix;
459  }
460 
461  public function showItems()
462  {
463  global $ilObjDataCache, $ilUser, $ilToolbar;
464 
465  include_once './Services/Payment/classes/class.ilPaymentPrices.php';
466  include_once './Services/Payment/classes/class.ilPaymentCurrency.php';
467 
468  $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.pay_shopping_cart.html','Services/Payment');
469 
470  if($_SESSION['forceShoppingCartRedirect'] == '1' && $ilUser->getId() != ANONYMOUS_USER_ID)
471  {
472  $_SESSION['forceShoppingCartRedirect'] = 0;
473  $this->tpl->touchBlock("close_js");
474  return true;
475  }
476 
477  $this->initShoppingCartObject();
478 
479  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
481  $pay_methods = $this->_getPayMethods( true );
482  $num_items = 0;
483  $desc = array();
484 
485  //course_objects
486  $is_crs_object = false;
487  $crs_obj_ids = array();
488 
489  //file_objects,exercise_objects
490  $is_file_object = false;
491 
492  // learning_modules,
493  $is_lm_object = false;
494  $lm_obj_ids = array();
495 
496  if($genSet->get('show_sr_shoppingcart') == 1)
497  {
498  require_once 'Services/RTE/classes/class.ilRTE.php';
499  $regulations = ilRTE::_replaceMediaObjectImageSrc($genSet->get('statutory_regulations'),1);
500  $this->tpl->setVariable('REGULATIONS_TITLE', $this->lng->txt('statutory_regulations'));
501  $this->tpl->setVariable('REGULATIONS', $regulations);
502  }
503 
504  $ilToolbar->addButton($this->lng->txt('payment_back_to_shop'),'ilias.php?baseClass=ilShopController');
505 
506  foreach($pay_methods as $pay_method)
507  {
508  $this->totalVat = 0;
509  $tpl = new ilTemplate( $this->_getTemplateFilename( $pay_method['pm_title'] ), true,'Services/Payment');
510  $coupon_session_id = $pay_method['pm_title'];
511 
512  if (count($items = $this->psc_obj->getEntries( $pay_method['pm_id'])))
513  {
514  $counter = 0;
515  $paypal_counter = 0;
516  $total_price = 0;
517 
518  foreach ($items as $item)
519  {
520  $tmp_pobject = new ilPaymentObject($this->user_obj,$item['pobject_id']);
521 
522  $obj_id = $ilObjDataCache->lookupObjId($tmp_pobject->getRefId());
523  $obj_type = $ilObjDataCache->lookupType($obj_id);
524  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
525  $desc[] = "[" . $obj_type . "] " . $obj_title;
526  $price_arr = ilPaymentPrices::_getPrice($item['price_id']);
527 
528  # checks object_type: needed for purchasing file or crs objects without login
529  switch ($obj_type)
530  {
531  case 'crs':
532  // if is_crs there an user-account will be autogenerated
533  $is_crs_object = true;
534  $_SESSION['is_crs_object'] = true;
535  $crs_obj_ids[] = $obj_id;
536  $_SESSION['crs_obj_ids'] = $crs_obj_ids;
537  break;
538  case 'lm':
539  case 'sahs':
540  case 'htlm':
541  case 'tst':
542  $is_lm_object = true;
543  $_SESSION['is_lm_object'] = true;
544  $lm_obj_ids[] = $obj_id;
545  $_SESSION['lm_obj_ids'] = $lm_obj_ids;
546  break;
547 
548  case 'exc':
549  case 'file':
550  $is_file_object = true;
551  break;
552  default:
553 
554  break;
555  }
556 
557  $direct_paypal_info_output = true;
558 
559  $assigned_coupons = '';
560  if (!empty($_SESSION['coupons'][$coupon_session_id]))
561  {
562  $price = $price_arr['price'];
563  $item['math_price'] = (float) $price;
564 
565  foreach ($_SESSION['coupons'][$coupon_session_id] as $key => $coupon)
566  {
567  $this->coupon_obj->setId($coupon['pc_pk']);
568  $this->coupon_obj->setCurrentCoupon($coupon);
569 
570  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
571  {
572  $assigned_coupons .= $this->lng->txt('paya_coupons_coupon') . ': ' . $coupon['pcc_code'];
573 
574  $_SESSION['coupons'][$coupon_session_id][$key]['total_objects_coupon_price'] += (float) $price;
575  $_SESSION['coupons'][$coupon_session_id][$key]['items'][] = $item;
576  $direct_paypal_info_output = false;
577  }
578  }
579  }
580 
581  $f_result[$counter]['item'] = ilUtil::formCheckBox(0,'item[]',$item['psc_id']);
582  $subtype = '';
583  if($obj_type == 'exc')
584  {
585  $subtype = ' ('.$this->lng->txt($tmp_pobject->getSubtype()).')';
586  $f_result[$counter]['title'] = "<a href=\"goto.php?target=".$obj_type."_".$tmp_pobject->getRefId() . "\">".$obj_title."</a>".$subtype ;
587  }
588  else
589  $f_result[$counter]['title'] = "<a href=\"ilias.php?baseClass=ilRepositoryGUI&amp;ref_id=".$tmp_pobject->getRefId() . "\">".$obj_title."</a>".$subtype ;
590 
591  if ($assigned_coupons != '')
592  {
593  // !!! $f_result[$counter][count($f_result[$counter]) - 1] .= $assigned_coupons;
594  $f_result[$counter]['assigned_coupons'] .= $assigned_coupons;
595  }
596 
597  switch($price_arr['price_type'])
598  {
600  $f_result[$counter]['duration'] = $price_arr['duration'].' '.$this->lng->txt('paya_months');
601  break;
603  $f_result[$counter]['duration'] =
604  ilDatePresentation::formatDate(new ilDate($price_arr['duration_from'], IL_CAL_DATE))
605  .' - '.ilDatePresentation::formatDate(new ilDate($price_arr['duration_until'], IL_CAL_DATE));
606  break;
608  $f_result[$counter]['duration'] = $this->lng->txt('unlimited_duration');
609  break;
610  }
611 
612  $float_price = $price_arr['price'];
613  $total_price += $float_price;
614 
615  $oVAT = new ilShopVats((int)$tmp_pobject->getVatId());
616  $f_result[$counter]['vat_rate'] = ilShopUtils::_formatVAT($oVAT->getRate());
617 
618  $this->totalVat = $this->totalVat + $tmp_pobject->getVat($float_price);
619 
620  $f_result[$counter]['price'] = ilPaymentPrices::_getPriceString($item['price_id']).' '.$genSet->get('currency_unit');
621  $f_result[$counter]['vat_unit'] = ilPaymentPrices::_getGUIPrice($tmp_pobject->getVat($float_price, 'CALCULATION'))
622  .' '.$genSet->get('currency_unit');
623 
624  if ($pay_method['pm_title'] == 'paypal')
625  {
626  if ($direct_paypal_info_output == true) // Paypal information in hidden fields
627  {
628  $tpl->setCurrentBlock('loop_items');
629  $tpl->setVariable('LOOP_ITEMS_NO', (++$paypal_counter));
630  $tpl->setVariable('LOOP_ITEMS_NAME', "[".$obj_id."]: ".$obj_title);
631  $tpl->setVariable('LOOP_ITEMS_AMOUNT', $float_price);
632  $tpl->parseCurrentBlock('loop_items');
633  }
634  }
635 
636  ++$counter;
637  unset($tmp_pobject);
638  } // foreach
639 
640  $this->showItemsTable($tpl, $f_result, $pay_method);
641 
642  if (!(bool)$genSet->get('hide_coupons'))
643  {
644  $tpl->setVariable('COUPON_TABLE', $this->showCouponInput($pay_method['pm_title']));
645  }
646  $tpl->setCurrentBlock('buy_link');
647  # $tpl->setCurrentBlock('terms_checkbox');
648 
649  $link_target = $this->ctrl->getLinkTargetByClass('iltermsconditionsgui','');
650  $terms_link = '<a href="'.$link_target.'">'.$this->lng->txt('terms_conditions').'</a>';
651  $tpl->setVariable('TERMS_CONDITIONS', sprintf($this->lng->txt('accept_terms_conditions'), $terms_link));
652 
653  switch($pay_method['pm_title'])
654  {
655  case 'bill':
656  if ($this->totalAmount[$pay_method['pm_id']] <= 0 && ANONYMOUS_USER_ID == $ilUser->getId())
657  {
658  $tpl->setVariable('TXT_UNLOCK', $this->lng->txt('pay_click_to_buy'));
659  $tpl->setVariable('LINK_UNLOCK', $this->ctrl->getLinkTarget($this, 'unlockBillObjectsInShoppingCart'));
660  }
661  else
662  {
663  # Anonymous user has to login
664  if(ANONYMOUS_USER_ID == $ilUser->getId())
665  {
666  ilUtil::sendInfo($this->lng->txt('click_to_continue_info'));
667  $tpl->touchBlock('attach_submit_event_bill');
668  $tpl->setVariable('TXT_BUY', $this->lng->txt('continue'));
669  $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
670  }
671  else
672  {
673  ilUtil::sendInfo($this->lng->txt('click_to_buy_info'));
674  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
675  $tpl->setVariable('SCRIPT_LINK', $this->ctrl->getLinkTargetByClass('ilPurchaseBillGUI', ''));
676  $tpl->parseCurrentBlock('terms_checkbox');
677  }
678  }
679  break;
680 
681  case 'bmf':
682  #$tpl->setVariable("SCRIPT_LINK", './payment.php?view=start_bmf');
683  if ($this->totalAmount[$pay_method['pm_id']] <= 0 && ANONYMOUS_USER_ID != $ilUser->getId())
684  {
685  $tpl->setVariable('TXT_UNLOCK', $this->lng->txt('pay_click_to_buy'));
686  $tpl->setVariable('LINK_UNLOCK', $this->ctrl->getLinkTarget($this, 'unlockBMFObjectsInShoppingCart'));
687  }
688  else
689  {
690  # Anonymous user has to login
691  if(ANONYMOUS_USER_ID == $ilUser->getId())
692  {
693  ilUtil::sendInfo($this->lng->txt('click_to_continue_info'));
694  $tpl->setVariable('TXT_BUY', $this->lng->txt('continue'));
695  $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
696  }
697  else
698  {
699  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
700  $tpl->setVariable('SCRIPT_LINK', $this->ctrl->getLinkTargetByClass('ilPurchaseBMFGUI', ''));
701  }
702  }
703  break;
704 
705  case 'epay':
706  # Anonymous user has to login
707 // if(ANONYMOUS_USER_ID == $ilUser->getId())
708 // {
709 // $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
710 // $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
711 // }
712 // else
713 // {
714 // /// http://uk.epay.dk/support/docs.asp?solution=2#pfinput
715 // $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
716 // $tpl->setVariable('SCRIPT_LINK', 'https://'.$this->epayConfig['server_host'].$this->epayConfig['server_path']);
717 // $tpl->setVariable('MERCHANT_NUMBER', $this->epayConfig['merchant_number']);
718 // $tpl->setVariable('AMOUNT', $total_price * 100);
719 // $tpl->setVariable('CURRENCY', "208");
720 // $tpl->setVariable('ORDERID', $ilUser->getId()."_".uniqid());
721 // $tpl->setVariable('ACCEPT_URL', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'finishEPay'));
722 // $tpl->setVariable('DECLINE_URL', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'cancelEPay'));
723 // $tpl->setVariable('INSTANT_CAPTURE', $this->epayConfig['instant_capture'] ? "1" : "0");
724 // $tpl->setVariable('ADDFEE', 1);
725 // $tpl->setVariable('LANGUAGE', 1);
726 // $tpl->setVariable('GROUP', "");
727 // $tpl->setVariable('CARDTYPE', "");
728 // $tpl->setVariable("CALLBACK_URL", ILIAS_HTTP_PATH . "/Services/Payment/classes/class.ilCallback.php?ilUser=" .$ilUser->getId() . "&pay_method=". PAY_METHOD_EPAY);
729 //
730 // $tpl->setVariable('DESCRIPTION', $ilUser->getFullName() . " (" . $ilUser->getEmail() . ") #" . $ilUser->getId() . " " . implode(",", $desc));
731 // $tpl->setVariable('AUTH_MAIL', $this->epayConfig['auth_email']);
732 // $tpl->setVariable('MD5KEY', $this->epSet->generateKeyForEpay(208, $total_price*100, $ilUser->getId()."_".uniqid()));
733 // }
734  break;
735 
736  case 'paypal':
737  if ($this->totalAmount[$pay_method['pm_id']] <= 0 && ANONYMOUS_USER_ID != $ilUser->getId())
738  {
739  $tpl->touchBlock('attach_submit_event');
740  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
741  $tpl->setVariable('SCRIPT_LINK', $this->ctrl->getLinkTarget($this, 'unlockPAYPALObjectsInShoppingCart'));
742  }
743  else
744  {
745  if(ANONYMOUS_USER_ID == $ilUser->getId())# && $force_user_login == true)
746  {
747  ilUtil::sendInfo($this->lng->txt('click_to_continue_info'));
748  $tpl->touchBlock('attach_submit_event');
749  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
750  $tpl->setVariable('SCRIPT_LINK','login.php?cmd=force_login&login_to_purchase_object=1&forceShoppingCartRedirect=1');
751  }
752  else
753  {
754  $tpl->setCurrentBlock('terms_checkbox');
755  ilUtil::sendInfo($this->lng->txt('click_to_buy_info'));
756  $tpl->setVariable('TXT_BUY', $this->lng->txt('pay_click_to_buy'));
757  $tpl->setVariable('SCRIPT_LINK', 'https://'.$this->paypalConfig['server_host'].$this->paypalConfig['server_path']);
758  $tpl->parseCurrentBlock('terms_checkbox');
759  }
760  }
761 
762  $tpl->setVariable('POPUP_BLOCKER', $this->lng->txt('popup_blocker'));
763  $tpl->setVariable('VENDOR', $this->paypalConfig['vendor']);
764  $tpl->setVariable('RETURN', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'finishPaypal'));
765  $tpl->setVariable('CANCEL_RETURN', ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTarget($this, 'cancelPaypal'));
766  $tpl->setVariable('CUSTOM', $ilUser->getId());
767  $tpl->setVariable('CURRENCY', $genSet->get('currency_unit'));
768  $tpl->setVariable('PAGE_STYLE', $this->paypalConfig['page_style']);
769 
770  if (!empty($_SESSION['coupons'][$coupon_session_id]))
771  {
772  $coupon_discount_items = $this->psc_obj->calcDiscountPrices($_SESSION['coupons'][$coupon_session_id]);
773 
774  if (is_array($coupon_discount_items) && !empty($coupon_discount_items))
775  {
776  foreach ($coupon_discount_items as $item)
777  {
778  $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
779 
780  $obj_id = $ilObjDataCache->lookupObjId($tmp_pobject->getRefId());
781  $obj_title = $ilObjDataCache->lookupTitle($obj_id);
782 
783  $tmp_amount = round($item['discount_price'], 2);
784  $loop_items_amount = str_replace(',','.',$tmp_amount);
785 
786  $tpl->setCurrentBlock('loop_items');
787  $tpl->setVariable('LOOP_ITEMS_NO', (++$paypal_counter));
788  $tpl->setVariable('LOOP_ITEMS_NAME', "[".$obj_id."]: ".$obj_title);
789  $tpl->setVariable('LOOP_ITEMS_AMOUNT',$loop_items_amount );
790 
791  $tpl->parseCurrentBlock('loop_items');
792 
793  unset($tmp_pobject);
794  }
795  }
796  }
797  break;
798  }
799 
800  if ($pay_method['pm_title'] == 'paypal')
801  {
802  $tpl->setVariable('PAYPAL_HINT', $this->lng->txt('pay_hint_paypal'));
803  $tpl->setVariable('PAYPAL_INFO', $this->lng->txt('pay_info_paypal'));
804  }
805  else if ($pay_method['pm_title'] == 'epay')
806  {
807  $tpl->setVariable('EPAY_HINT', $this->lng->txt('pay_hint_epay'));
808  $tpl->setVariable('EPAY_INFO', $this->lng->txt('pay_info_epay'));
809  }
810 
811  $tpl->parseCurrentBlock('buy_link');
812 
813  $tpl->setCurrentBlock('loop');
814  unset($f_result);
815 
816  $tpl->parseCurrentBlock('loop');
817 
818  $this->tpl->setVariable(''.strtoupper($pay_method['pm_title']).'', $tpl->get());
819 
820  $num_items += $counter;
821  }
822  }
823 
824  if ($num_items == 0)
825  {
826  # ilUtil::sendInfo($this->lng->txt('pay_shopping_cart_empty'));
827  return false;
828  }
829  return true;
830  }
831 
832  public function removeCoupon()
833  {
834  if (is_array($_SESSION['coupons']))
835  {
836  foreach ($_SESSION['coupons'] as $key => $val)
837  {
838  unset($_SESSION['coupons'][$key][$_GET['coupon_id']]);
839  }
840  }
841 
842  $this->showItems();
843  return true;
844  }
845 
846  public function setCoupon()
847  {
848  if ($_POST['coupon_code'] != '')
849  {
850  $coupon = $this->coupon_obj->getCouponByCode($_POST['coupon_code']);
851  switch ($this->coupon_obj->checkCouponValidity())
852  {
853  case 1:
854  case 2:
855  ilUtil::sendInfo($this->lng->txt('paya_coupons_not_valid'));
856  $this->showItems();
857  return true;
858  case 3:
859  ilUtil::sendInfo($this->lng->txt('paya_coupons_coupon_not_found'));
860  $this->showItems();
861  return true;
862  }
863  $assignedItems = 0;
864  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
865  if (count($items = $this->psc_obj->getEntries(isset($_POST['payment_type']) ? $_POST['payment_type'] : 'bmf')))
866  {
867  foreach($items as $item)
868  {
869  $tmp_pobject = new ilPaymentObject($this->user_obj,$item['pobject_id']);
870  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
871  {
872  ++$assignedItems;
873  }
874  }
875  }
876  if (!$assignedItems)
877  {
878  ilUtil::sendInfo($this->lng->txt('paya_coupons_no_object_assigned'));
879  $this->showItems();
880  return true;
881  }
882  $coupon_session_id = $_POST['payment_type'];
883  if (!array_key_exists($coupon['pc_pk'], $_SESSION['coupons'][$coupon_session_id]))
884  {
885  if (is_array($_SESSION['coupons']))
886  {
887  foreach ($_SESSION['coupons'] as $key => $val)
888  {
889  unset($_SESSION['coupons'][$key][$coupon['pc_pk']]);
890  }
891  }
892  ilUtil::sendInfo($this->lng->txt('paya_coupons_coupon_added'));
893  $_SESSION['coupons'][$coupon_session_id][$coupon['pc_pk']] = $coupon;
894  }
895  else
896  {
897  ilUtil::sendInfo($this->lng->txt('paya_coupons_already_in_use'));
898  }
899  $this->showItems();
900  return true;
901  }
902  $this->showItems();
903  return true;
904  }
905 /*
906  *
907  * @param string $payment_type pm_title
908  *
909  */
910  private function showCouponInput($payment_type = '')
911  {
912  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
914 
915  $tpl = new ilTemplate('tpl.pay_shopping_cart_coupons.html', true, true, 'Services/Payment');
916 
917  $tpl->setVariable('COUPON_FORMACTION', $this->ctrl->getFormAction($this));
918  $tpl->setVariable('TITLE', $this->lng->txt('paya_coupons_coupons'));
919  $tpl->setVariable('TYPE_IMG', ilUtil::getImagePath('icon_pays_b.png'));
920  $tpl->setVariable('ALT_IMG', $this->lng->txt('obj_usr'));
921 
922  $tpl->setVariable('TXT_CODE', $this->lng->txt('paya_coupons_code'));
923  $tpl->setVariable('CMD_VALUE', $this->lng->txt('send'));
924  $tpl->setVariable('CMD', 'setCoupon');
925 
926  $tpl->setVariable('PAYMENT_TYPE', $payment_type);
927 
928  $coupon_session = $payment_type;
929 
930  if (!empty($_SESSION['coupons'][$coupon_session]))
931  {
932  $i = 0;
933  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
934  {
935  $tpl->setCurrentBlock('loop');
936  $tpl->setVariable('LOOP_ROW', ilUtil::switchColor($i++, '1', '2'));
937  $tpl->setVariable('LOOP_TXT_COUPON', $this->lng->txt('paya_coupons_coupon'));
938  $tpl->setVariable('LOOP_CODE', $coupon['pcc_code']);
939  $this->ctrl->setParameter($this, 'coupon_id', $coupon['pc_pk']);
940  $this->ctrl->setParameter($this, 'payment_type', $_SESSION['bmf']['payment_type']);
941  $tpl->setVariable('LOOP_TITLE', $coupon['pc_title']);
942  if ($coupon['pc_description'] != '') $tpl->setVariable('LOOP_DESCRIPTION', nl2br($coupon['pc_description']));
943  $tpl->setVariable("LOOP_TYPE",
944  sprintf($this->lng->txt('paya_coupons_'.($coupon['pc_type'] == "fix" ? 'fix' : 'percentaged').'_'.(count($coupon['objects']) == 0 ? 'all' : 'selected').'_objects'),
945  (((float)$coupon['pc_value'] / round($coupon['pc_value'], 2) == 1 && $coupon['pc_type'] == "percent")
946  ? round($coupon['pc_value'], 2)
947  : number_format($coupon['pc_value'], 2, ',', '.')),
948  ($coupon['pc_type'] == "percent" ? "%" :$genSet->get('currency_unit'))));
949  $tpl->setVariable("LOOP_REMOVE", "<div class=\"il_ContainerItemCommands\" style=\"float: right;\"><a class=\"il_ContainerItemCommand\" href=\"".$this->ctrl->getLinkTarget($this, 'removeCoupon')."\">".$this->lng->txt('remove')."</a></div>");
950 
951  $tpl->parseCurrentBlock();
952  }
953  }
954 
955  return $tpl->get();
956  }
957 /*
958  *
959  * @param array $a_pay_method
960  *
961  */
962  private function showItemsTable(&$a_tpl, $a_result_set, $a_pay_method = 0)
963  {
964  include_once './Services/Payment/classes/class.ilPaymentSettings.php';
966 
967  include_once './Services/Payment/classes/class.ilShoppingCartTableGUI.php';
968 
969  $tbl = new ilShoppingCartTableGUI($this);
970  $tbl->setId('tbl_id_'.$a_pay_method);
971  $tbl->setTitle($this->lng->txt('paya_shopping_cart').
972  " (".$this->lng->txt('payment_system').": ".
973  ilPayMethods::getStringByPaymethod($a_pay_method['pm_title']) .")");
974 
975  $coupon_session = $a_pay_method['pm_title'];
976 
977  $tbl->setRowTemplate("tpl.shop_shoppingcart_row.html", "Services/Payment");
978  $tbl->addColumn('', 'item', '1%', true);
979  $tbl->addColumn($this->lng->txt('title'), "table". $a_pay_method['pm_title']."_title", '30%');
980  $tbl->addColumn($this->lng->txt('duration'), "table". $a_pay_method['pm_title']."_duration", '30%');
981  $tbl->addColumn($this->lng->txt('vat_rate'), "table". $a_pay_method['pm_title']."_vat_rate", '15%');
982  $tbl->addColumn($this->lng->txt('vat_unit'), "table". $a_pay_method['pm_title']."_vat_unit", '15%');
983  $tbl->addColumn($this->lng->txt('price_a'), "table". $a_pay_method['pm_title']."_price", '10%');
984 
985  $tbl->setPrefix("table". $a_pay_method['pm_title']."_");
986  $tbl->addMultiCommand('deleteItem', $this->lng->txt('delete'));
987 
988  // show total amount of costs
989  $sc_obj = new ilPaymentShoppingCart($this->user_obj);
990  $totalAmount = $sc_obj->getTotalAmount();
991 
992  if (!empty($_SESSION['coupons'][$coupon_session]))
993  {
994  if (count($items = $sc_obj->getEntries($a_pay_method['pm_id'])))
995  {
996  $tbl->setTotalData('TXT_SUB_TOTAL', $this->lng->txt('pay_bmf_subtotal_amount') . ": ");
997  $tbl->setTotalData('VAL_SUB_TOTAL', number_format($totalAmount[$a_pay_method['pm_id']], 2, ',', '.') . " " . $genSet->get('currency_unit'));
998 
999  foreach ($_SESSION['coupons'][$coupon_session] as $coupon)
1000  {
1001  $this->coupon_obj->setId($coupon['pc_pk']);
1002  $this->coupon_obj->setCurrentCoupon($coupon);
1003 
1004  $total_object_price = 0.0;
1005  $current_coupon_bonus = 0.0;
1006 
1007  foreach ($items as $item)
1008  {
1009  $tmp_pobject = new ilPaymentObject($this->user_obj, $item['pobject_id']);
1010 
1011  if ($this->coupon_obj->isObjectAssignedToCoupon($tmp_pobject->getRefId()))
1012  {
1013  $price_data = ilPaymentPrices::_getPrice($item['price_id']);
1014  $price = (float) $price_data['price'];
1015 
1016  $total_object_price += $price;
1017  }
1018  unset($tmp_pobject);
1019  }
1020 
1021  $current_coupon_bonus = $this->coupon_obj->getCouponBonus($total_object_price);
1022  $totalAmount[$current_coupon_bonus] += $current_coupon_bonus * (-1);
1023  }
1024  $tbl->setTotalData('TXT_COUPON_BONUS', $this->lng->txt('paya_coupons_coupon') . ": ");# . $coupon['pcc_code'] . ": ");
1025  #$tbl->setTotalData('VAL_COUPON_BONUS', number_format($current_coupon_bonus * (-1), 2, ',', '.') . " " . $genSet->get('currency_unit'));
1026  $tbl->setTotalData('VAL_COUPON_BONUS', number_format($totalAmount[$current_coupon_bonus], 2, ',', '.') . " " . $genSet->get('currency_unit'));
1027 
1028  if ($totalAmount[$a_pay_method['pm_id']] < 0)
1029  {
1030  $totalAmount[$a_pay_method['pm_id']] = 0;
1031  $this->totalVat = 0;
1032  }
1033  }
1034  }
1035 
1036  $this->totalAmount[$a_pay_method['pm_id']] = $totalAmount[$a_pay_method['pm_id']]-($totalAmount[$current_coupon_bonus] * (-1));
1037  $tbl->setTotalData('TXT_TOTAL_AMOUNT', $this->lng->txt('pay_bmf_total_amount').": ");
1038  $tbl->setTotalData('VAL_TOTAL_AMOUNT', number_format($this->totalAmount[$a_pay_method['pm_id']] , 2, ',', '.') . " " . $genSet->get('currency_unit')); #.$item['currency']);
1039 
1040  if ($this->totalVat > 0)
1041  {
1042  $tbl->setTotalData('TXT_TOTAL_VAT', $this->lng->txt('pay_bmf_vat_included') . ": ");
1043  $tbl->setTotalData('VAL_TOTAL_VAT', number_format($this->totalVat , 2, ',', '.') . " " . $genSet->get('currency_unit'));
1044  }
1045 
1046  $tbl->setData($a_result_set);
1047  $a_tpl->setVariable('ITEMS_TABLE',$tbl->getCartHTML());
1048 
1049  return true;
1050  }
1051 
1052  public function deleteItem()
1053  {
1054  if(!count($_POST['item']))
1055  {
1056  ilUtil::sendInfo($this->lng->txt('pay_select_one_item'));
1057 
1058  $this->showItems();
1059  return true;
1060  }
1061  $this->initShoppingCartObject();
1062 
1063  foreach($_POST['item'] as $id)
1064  {
1065  $this->psc_obj->delete($id);
1066  $this->checkCouponsOfShoppingCart();
1067  }
1068  ilUtil::sendInfo($this->lng->txt('pay_deleted_items'));
1069  $this->showItems();
1070 
1071  return true;
1072  }
1073 
1074  private function initShoppingCartObject()
1075  {
1076  $this->psc_obj = new ilPaymentShoppingCart($this->user_obj);
1077  $this->psc_obj->clearCouponItemsSession();
1078  }
1079 
1080  private function initPaypalObject()
1081  {
1082  include_once './Services/Payment/classes/class.ilPurchasePaypal.php';
1083  $this->paypal_obj = new ilPurchasePaypal($this->user_obj);
1084  }
1085 
1092  private function encryptButton($buttonParams)
1093  {
1094  $merchant_cert = $this->paypalConfig["vendor_cert"];
1095  $merchant_key = $this->paypalConfig["vendor_key"];
1096  $end_cert = $this->paypalConfig["enc_cert"];
1097 
1098  $tmpin_file = tempnam('/tmp', 'paypal_');
1099  $tmpout_file = tempnam('/tmp', 'paypal_');
1100  $tmpfinal_file = tempnam('/tmp', 'paypal_');
1101 
1102  $rawdata = array();
1103  $buttonParams['cert_id'] = $this->paypalConfig["cert_id"];
1104  foreach ($buttonParams as $name => $value) {
1105  $rawdata[] = "$name=$value";
1106  }
1107  $rawdata = implode("\n", $rawdata);
1108 
1109  $fp = fopen($tmpin_file, 'w');
1110  if (!$fp) {
1111  echo "Could not open temporary file '$tmpin_file')";
1112  return false;
1113 # return PayPal::raiseError("Could not open temporary file '$tmpin_file')");
1114  }
1115  fwrite($fp, $rawdata);
1116  fclose($fp);
1117 
1118  if (!@openssl_pkcs7_sign($tmpin_file, $tmpout_file, $merchant_cert,
1119  array($merchant_key, $this->paypalConfig["private_key_password"]),
1120  array(), PKCS7_BINARY)) {
1121  echo "Could not sign encrypted data: " . openssl_error_string();
1122  return false;
1123 # return PayPal::raiseError("Could not sign encrypted data: " . openssl_error_string());
1124  }
1125 
1126  $data = file_get_contents($tmpout_file);
1127  $data = explode("\n\n", $data);
1128  $data = $data[1];
1129  $data = base64_decode($data);
1130  $fp = fopen($tmpout_file, 'w');
1131  if (!$fp) {
1132  echo "Could not open temporary file '$tmpin_file')";
1133  return false;
1134 # return PayPal::raiseError("Could not open temporary file '$tmpin_file')");
1135  }
1136  fwrite($fp, $data);
1137  fclose($fp);
1138 
1139  if (!@openssl_pkcs7_encrypt($tmpout_file, $tmpfinal_file, $end_cert, array(), PKCS7_BINARY)) {
1140  echo "Could not encrypt data:" . openssl_error_string();
1141  return false;
1142 # return PayPal::raiseError("Could not encrypt data:" . openssl_error_string());
1143  }
1144 
1145  $encdata = @file_get_contents($tmpfinal_file, false);
1146  if (!$encdata) {
1147  echo "Encryption and signature of data failed.";
1148  return false;
1149 # return PayPal::raiseError("Encryption and signature of data failed.");
1150  }
1151 
1152  $encdata = explode("\n\n", $encdata);
1153  $encdata = trim(str_replace("\n", '', $encdata[1]));
1154  $encdata = "-----BEGIN PKCS7-----$encdata-----END PKCS7-----";
1155 
1156  @unlink($tmpfinal_file);
1157  @unlink($tmpin_file);
1158  @unlink($tmpout_file);
1159 
1160  return $encdata;
1161  }
1162 }
1163 ?>