-
Notifications
You must be signed in to change notification settings - Fork 0
/
bcash.php
812 lines (715 loc) · 36 KB
/
bcash.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
<?php
if (!defined('_VALID_MOS') && !defined('_JEXEC'))
die('Direct Access to ' . basename(__FILE__) . ' is not allowed.');
/**
* @version $Id: bcash.php,v 1.4 2005/05/27 19:33:57 ei
*
* a special type of 'cash on delivey':
* @author Max Milbers, Valérie Isaksen, Luiz Weber
* @version $Id: bcash.php 5122 2012-02-07 12:00:00Z luizwbr $
* @package VirtueMart
* @subpackage payment
* @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
if (!class_exists('vmPSPlugin'))
require(JPATH_VM_PLUGINS . DS . 'vmpsplugin.php');
class plgVmPaymentBcash extends vmPSPlugin {
// instance of class
public static $_this = false;
function __construct(& $subject, $config) {
//if (self::$_this)
// return self::$_this;
parent::__construct($subject, $config);
$this->_loggable = true;
$this->tableFields = array_keys($this->getTableSQLFields());
$varsToPush = $this->getVarsToPush ();
$this->setConfigParameterable($this->_configTableFieldName, $varsToPush);
}
/**
* Create the table for this plugin if it does not yet exist.
* @author Valérie Isaksen
*/
protected function getVmPluginCreateTableSQL() {
return $this->createTableSQL('Payment Pagamentodigital Table');
}
/**
* Fields to create the payment table
* @return string SQL Fileds
*/
function getTableSQLFields() {
$SQLfields = array(
'id' => 'bigint(15) unsigned NOT NULL AUTO_INCREMENT',
'virtuemart_order_id' => 'int(11) UNSIGNED DEFAULT NULL',
'order_number' => 'char(32) DEFAULT NULL',
'virtuemart_paymentmethod_id' => 'mediumint(1) UNSIGNED DEFAULT NULL',
'payment_name' => 'char(255) NOT NULL DEFAULT \'\' ',
'payment_order_total' => 'decimal(15,5) NOT NULL DEFAULT \'0.00000\' ',
'payment_currency' => 'char(3) ',
'cost_per_transaction' => ' decimal(10,2) DEFAULT NULL ',
'cost_percent_total' => ' decimal(10,2) DEFAULT NULL ',
'tax_id' => 'smallint(11) DEFAULT NULL'
);
return $SQLfields;
}
function getPluginParams(){
$db = JFactory::getDbo();
$sql = "select virtuemart_paymentmethod_id from #__virtuemart_paymentmethods where payment_element = 'bcash'";
$db->setQuery($sql);
$id = (int)$db->loadResult();
return $this->getVmPluginMethod($id);
}
/**
* @param $name
* @param $id
* @param $data
* @return bool
*/
function plgVmDeclarePluginParamsPaymentVM3( &$data) {
return $this->declarePluginParams('payment', $data);
}
/**
*
*
* @author Valérie Isaksen
*/
function plgVmConfirmedOrder($cart, $order) {
if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) {
return null; // Another method was selected, do nothing
}
if (!$this->selectedThisElement($method->payment_element)) {
return false;
}
// $params = new JParameter($payment->payment_params);
if (!class_exists('VirtueMartModelOrders'))
require( JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php' );
$this->getPaymentCurrency($method);
// END printing out HTML Form code (Payment Extra Info)
$q = 'SELECT `currency_code_3` FROM `#__virtuemart_currencies` WHERE `virtuemart_currency_id`="' . $method->payment_currency . '" ';
$db = &JFactory::getDBO();
$db->setQuery($q);
$currency_code_3 = $db->loadResult();
$paymentCurrency = CurrencyDisplay::getInstance($method->payment_currency);
$totalInPaymentCurrency = round($paymentCurrency->convertCurrencyTo($method->payment_currency, $order['details']['BT']->order_total, false), 2);
$cd = CurrencyDisplay::getInstance($cart->pricesCurrency);
$this->_virtuemart_paymentmethod_id = $order['details']['BT']->virtuemart_paymentmethod_id;
$dbValues['payment_name'] = $this->renderPluginName($method);
$dbValues['order_number'] = $order['details']['BT']->order_number;
$dbValues['virtuemart_paymentmethod_id'] = $this->_virtuemart_paymentmethod_id;
$dbValues['cost_per_transaction'] = $method->cost_per_transaction;
$dbValues['cost_percent_total'] = $method->cost_percent_total;
$dbValues['payment_currency'] = $currency_code_3;
$dbValues['payment_order_total'] = $totalInPaymentCurrency;
$dbValues['tax_id'] = $method->tax_id;
$this->storePSPluginInternalData($dbValues);
JFactory::getApplication()->enqueueMessage(utf8_encode(JTExt::_('VMPAYMENT_B_MSG_REDIRECT')));
$html = $this->retornaHtmlPagamento( $order, $method, 1);
$novo_status = $method->status_aguardando;
return $this->processConfirmedOrderPaymentResponse(1, $cart, $order, $html, $dbValues['payment_name'], $novo_status);
}
function retornaHtmlPagamento( $order, $method, $redir ) {
$app =& JFactory::getApplication();
if($app->getName() != 'site') {
return true;
}
$lang = JFactory::getLanguage();
$filename = 'com_virtuemart';
$lang->load($filename, JPATH_ADMINISTRATOR);
$vendorId = 0;
$html = '<table>' . "\n";
$html .= $this->getHtmlRow('STANDARD_PAYMENT_INFO', $dbValues['payment_name']);
if (!empty($payment_info)) {
$lang = & JFactory::getLanguage();
if ($lang->hasKey($method->payment_info)) {
$payment_info = JTExt::_($method->payment_info);
} else {
$payment_info = $method->payment_info;
}
$html .= $this->getHtmlRow('STANDARD_PAYMENTINFO', $payment_info);
}
if (!class_exists('VirtueMartModelCurrency')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php');
}
if (!class_exists('CurrencyDisplay')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
}
if (isset($order["details"]["ST"]->zip)) {
$tipo_endereco = "ST";
} else {
$tipo_endereco = "BT";
}
$currency = CurrencyDisplay::getInstance('', $order['details']['BT']->virtuemart_vendor_id);
$html .= $this->getHtmlRow('STANDARD_ORDER_NUMBER', $order['details']['BT']->order_number);
$html .= $this->getHtmlRow('STANDARD_AMOUNT', $currency->priceDisplay($order['details']['BT']->order_total));
$html .= '</table>' . "\n";
$html .= '<form name="bcash" id="bcash" action="https://www.bcash.com.br/checkout/pay/" method="post"> ';
$html .= '<input type="hidden" name="email_loja" value="' . $method->email_cobranca . '" />';
$html .= '<input type="hidden" name="cod_loja" value="'.$method->cod_loja.'" />';
$html .= '<input type="hidden" name="chave" value="'.$method->chave.'" />';
$html .= '<input type="hidden" name="id_plataforma" value="'.$method->id_plataforma.'" />';
$html .= '<input name="tipo_integracao" type="hidden" value="PAD">';
$html .= '<input type="hidden" name="id_pedido" value="' . $order["details"]["BT"]->order_number . '" />';
$url_aviso = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification') ;
$html .= '<input type="hidden" name="url_aviso" value="' . $url_aviso . '" />';
$url_retorno = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&pm=' . $order['details']['BT']->virtuemart_paymentmethod_id);
$html .= '<input type="hidden" name="url_retorno" value="' . $url_retorno . '" />';
$html .= '<input type="hidden" name="redirect" value="true" />';
$html .= '<input type="hidden" name="redirect_time" value="' . $method->redirect_time . '" />';
// Cupom de Desconto
$desconto_pedido = $order["details"]['BT']->coupon_discount;
$html .= '<input type="hidden" name="desconto" value="'.$desconto_pedido.'" />';
/*
// Desconto do pedido
if ($db->f("order_tax") != 0.00) {
echo '<input type="hidden" name="acrescimo" value="'.$db->f("order_tax").'" />';
}
*/
$zip = $order["details"][$tipo_endereco]->zip;
$replacements = array(" ", ".", ",", "-", ";");
$zip = str_replace($replacements, "", $zip);
$campo_cpf = $method->campo_cpf;
$cpf_form = $order["details"][$tipo_endereco]->$campo_cpf;
$cpf = str_replace($replacements, "", $cpf_form);
// configuração dos campos
$campo_cnpj = $method->campo_cnpj;
$campo_razao_social = $method->campo_razao_social;
$campo_numero = $method->campo_numero;
$campo_bairro = $method->campo_bairro;
// campos do usuário
$html .= '<input type="hidden" name="nome" value="' . $order["details"][$tipo_endereco]->first_name . ' ' . $order["details"][$tipo_endereco]->last_name . '" />
<input type="hidden" name="cep" value="' . $zip . '" />
<input type="hidden" name="endereco" value="' . $order["details"][$tipo_endereco]->address_1 . (isset($order["details"][$tipo_endereco]->$campo_numero)?',' .$order["details"][$tipo_endereco]->$campo_numero:'') . '" />
<input type="hidden" name="complemento" value="' . (isset($order["details"][$tipo_endereco]->address_2)?$order["details"][$tipo_endereco]->address_2:'') . '" />
<input type="hidden" name="cidade" value="' . $order["details"][$tipo_endereco]->city . '" />
<input type="hidden" name="estado" value="' . ShopFunctions::getStateByID($order["details"][$tipo_endereco]->virtuemart_state_id, "state_2_code") . '" />
<input type="hidden" name="cliente_pais" value="BRA" />
<input type="hidden" name="cliente_tel" value="' . $order["details"][$tipo_endereco]->phone_1 . '" />
<input type="hidden" name="email" value="' . $order["details"][$tipo_endereco]->email . '" />';
$html .= '<input type="hidden" name="cpf" value="' . $cpf . '" />';
if (isset($order["details"][$tipo_endereco]->$campo_cnpj)) {
$html .= '<input type="hidden" name="cliente_cnpj" value="' . $order["details"][$tipo_endereco]->$campo_cnpj . '" />';
}
if (isset($order["details"][$tipo_endereco]->$campo_razao_social)) {
$html .= '<input type="hidden" name="cliente_razao_social" value="' . $order["details"][$tipo_endereco]->campo_razao_social . '" />';
}
$html .= '<input type="hidden" name="valor" value="'.number_format(floatval($order['details']['BT']->order_total), 2, ".", "").'" />';
$html .= '<input type="hidden" name="tipo_frete" value="'. strip_tags(str_replace('</span><span','</span> - <span',$cart->cartData['shipmentName'])) .'" />';
$html .= '<input type="hidden" name="frete" value="'.number_format($order["details"]["BT"]->order_shipment ,2,'.','').'" />';
if(!class_exists('VirtueMartModelCustomfields'))require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'customfields.php');
// peso do produto
foreach ($order['items'] as $p) {
$i++;
$product_attribute = strip_tags(VirtueMartModelCustomfields::CustomsFieldOrderDisplay($p,'FE'));
$html .='<input type="hidden" name="produto_codigo_' . $i . '" value="' . $p->order_item_sku . '">
<input type="hidden" name="produto_descricao_' . $i . '" value="' . $p->order_item_name . '">
<input type="hidden" name="produto_qtde_' . $i . '" value="' . $p->product_quantity . '">
<input type="hidden" name="produto_extra_' . $i . '" value="' . $product_attribute . '">
<input type="hidden" name="produto_valor_' . $i . '" value="' . number_format($p->product_final_price, 2, ".", "") .' ">';
}
// imagem da forma de pagamento
$url = JURI::root();
$url_lib = $url.DS.'plugins'.DS.'vmpayment'.DS.'bcash'.DS;
$url_imagem_pagamento = $url_lib . 'imagens'.DS.'bcash.png';
// segundos para redirecionar para o Bcash
if ($redir) {
$segundos = $method->segundos_redirecionar;
$html .= '<br/><br/>'.JText::_('VMPAYMENT_B_MSG_REDIRECT2').'<br />';
$html .= '<script>setTimeout(\'document.getElementById("bcash").submit();\','.$segundos.'000);</script>';
}
$html .= '<div align="center"><br /><input type="image" value="'.JText::_('VMPAYMENT_B_MSG_PAYMENT').'" class="button" src="'.$url_imagem_pagamento.'" /></div>';
$html .= '</form>';
return $html;
}
/**
* Display stored payment data for an order
*
*/
function plgVmOnShowOrderBEPayment($virtuemart_order_id, $virtuemart_payment_id) {
if (!$this->selectedThisByMethodId($virtuemart_payment_id)) {
return null; // Another method was selected, do nothing
}
$db = JFactory::getDBO();
$q = 'SELECT * FROM `' . $this->_tablename . '` '
. 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id;
$db->setQuery($q);
if (!($paymentTable = $db->loadObject())) {
vmWarn(500, $q . " " . $db->getErrorMsg());
return '';
}
$this->getPaymentCurrency($paymentTable);
$html = '<table class="adminlist">' . "\n";
$html .= $this->getHtmlHeaderBE();
$html .= $this->getHtmlRowBE('B_PAYMENT_NAME', $paymentTable->payment_name);
$html .= $this->getHtmlRowBE('B_TOTAL', $paymentTable->payment_order_total . ' ' . $paymentTable->payment_currency);
$html .= '</table>' . "\n";
return $html;
}
function getCosts(VirtueMartCart $cart, $method, $cart_prices) {
if (preg_match('/%$/', $method->cost_percent_total)) {
$cost_percent_total = substr($method->cost_percent_total, 0, -1);
} else {
$cost_percent_total = $method->cost_percent_total;
}
return ($method->cost_per_transaction + ($cart_prices['salesPrice'] * $cost_percent_total * 0.01));
}
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method, $progressive=true) {
if ($method->modo_calculo_desconto == '2') {
return parent::setCartPrices($cart, $cart_prices, $method, false);
} else {
return parent::setCartPrices($cart, $cart_prices, $method, true);
}
}
/**
* Check if the payment conditions are fulfilled for this payment method
* @author: Valerie Isaksen
*
* @param $cart_prices: cart prices
* @param $payment
* @return true: if the conditions are fulfilled, false otherwise
*
*/
protected function checkConditions($cart, $method, $cart_prices) {
$address = (($cart->ST == 0) ? $cart->BT : $cart->ST);
$amount = $cart_prices['salesPrice'];
$amount_cond = ($amount >= $method->min_amount AND $amount <= $method->max_amount
OR
($method->min_amount <= $amount AND ($method->max_amount == 0) ));
if (!$amount_cond) {
return false;
}
$countries = array();
if (!empty($method->countries)) {
if (!is_array($method->countries)) {
$countries[0] = $method->countries;
} else {
$countries = $method->countries;
}
}
// probably did not gave his BT:ST address
if (!is_array($address)) {
$address = array();
$address['virtuemart_country_id'] = 0;
}
if (!isset($address['virtuemart_country_id']))
$address['virtuemart_country_id'] = 0;
if (count($countries) == 0 || in_array($address['virtuemart_country_id'], $countries) || count($countries) == 0) {
return true;
}
return false;
}
/*
* We must reimplement this triggers for joomla 1.7
*/
/**
* Create the table for this plugin if it does not yet exist.
* This functions checks if the called plugin is active one.
* When yes it is calling the bcash method to create the tables
* @author Valérie Isaksen
*
*/
function plgVmOnStoreInstallPaymentPluginTable($jplugin_id) {
return $this->onStoreInstallPluginTable($jplugin_id);
}
/**
* This event is fired after the payment method has been selected. It can be used to store
* additional payment info in the cart.
*
* @author Max Milbers
* @author Valérie isaksen
*
* @param VirtueMartCart $cart: the actual cart
* @return null if the payment was not selected, true if the data is valid, error message if the data is not vlaid
*
*/
public function plgVmOnSelectCheckPayment(VirtueMartCart $cart) {
return $this->OnSelectCheck($cart);
}
/**
* plgVmDisplayListFEPayment
* This event is fired to display the pluginmethods in the cart (edit shipment/payment) for exampel
*
* @param object $cart Cart object
* @param integer $selected ID of the method selected
* @return boolean True on succes, false on failures, null when this plugin was not selected.
* On errors, JError::raiseWarning (or JError::raiseError) must be used to set a message.
*
* @author Valerie Isaksen
* @author Max Milbers
*/
public function plgVmDisplayListFEPayment(VirtueMartCart $cart, $selected = 0, &$htmlIn) {
return $this->displayListFE($cart, $selected, $htmlIn);
}
/*
* plgVmonSelectedCalculatePricePayment
* Calculate the price (value, tax_id) of the selected method
* It is called by the calculator
* This function does NOT to be reimplemented. If not reimplemented, then the default values from this function are taken.
* @author Valerie Isaksen
* @cart: VirtueMartCart the current cart
* @cart_prices: array the new cart prices
* @return null if the method was not selected, false if the shiiping rate is not valid any more, true otherwise
*
*
*/
public function plgVmonSelectedCalculatePricePayment(VirtueMartCart $cart, array &$cart_prices, &$cart_prices_name) {
return $this->onSelectedCalculatePrice($cart, $cart_prices, $cart_prices_name);
}
function plgVmgetPaymentCurrency($virtuemart_paymentmethod_id, &$paymentCurrencyId) {
if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
return null; // Another method was selected, do nothing
}
if (!$this->selectedThisElement($method->payment_element)) {
return false;
}
$this->getPaymentCurrency($method);
$paymentCurrencyId = $method->payment_currency;
}
/**
* plgVmOnCheckAutomaticSelectedPayment
* Checks how many plugins are available. If only one, the user will not have the choice. Enter edit_xxx page
* The plugin must check first if it is the correct type
* @author Valerie Isaksen
* @param VirtueMartCart cart: the cart object
* @return null if no plugin was found, 0 if more then one plugin was found, virtuemart_xxx_id if only one plugin is found
*
*/
function plgVmOnCheckAutomaticSelectedPayment(VirtueMartCart $cart, array $cart_prices = array()) {
return $this->onCheckAutomaticSelected($cart, $cart_prices);
}
/**
* This method is fired when showing the order details in the frontend.
* It displays the method-specific data.
*
* @param integer $order_id The order ID
* @return mixed Null for methods that aren't active, text (HTML) otherwise
* @author Max Milbers
* @author Valerie Isaksen
*/
public function plgVmOnShowOrderFEPayment($virtuemart_order_id, $virtuemart_paymentmethod_id, &$payment_name) {
$orderModel = VmModel::getModel('orders');
$orderDetails = $orderModel->getOrder($virtuemart_order_id);
if (!($method = $this->getVmPluginMethod($orderDetails['details']['BT']->virtuemart_paymentmethod_id))) {
return false;
}
if (!$this->selectedThisByMethodId ($virtuemart_paymentmethod_id)) {
return NULL;
} // Another method was selected, do nothing
$view = JRequest::getVar('view');
// somente retorna se estiver como transação pendente
if ($method->status_aguardando == $orderDetails['details']['BT']->order_status and $view == 'orders') {
JFactory::getApplication()->enqueueMessage(utf8_encode(JText::_('VMPAYMENT_B_MSG_REDIRECT_ORDER')));
$redir = 0;
$html = $this->retornaHtmlPagamento( $orderDetails, $method, $redir );
echo $html;
}
$this->onShowOrderFE($virtuemart_order_id, $virtuemart_paymentmethod_id, $payment_name);
}
/**
* This event is fired during the checkout process. It can be used to validate the
* method data as entered by the user.
*
* @return boolean True when the data was valid, false otherwise. If the plugin is not activated, it should return null.
* @author Max Milbers
public function plgVmOnCheckoutCheckDataPayment( VirtueMartCart $cart) {
return null;
}
*/
/**
* This method is fired when showing when priting an Order
* It displays the the payment method-specific data.
*
* @param integer $_virtuemart_order_id The order ID
* @param integer $method_id method used for this order
* @return mixed Null when for payment methods that were not selected, text (HTML) otherwise
* @author Valerie Isaksen
*/
function plgVmonShowOrderPrintPayment($order_number, $method_id) {
return $this->onShowOrderPrint($order_number, $method_id);
}
function plgVmDeclarePluginParamsPayment($name, $id, &$data) {
return $this->declarePluginParams('payment', $name, $id, $data);
}
function plgVmSetOnTablePluginParamsPayment($name, $id, &$table) {
return $this->setOnTablePluginParams($name, $id, $table);
}
//Notice: We only need to add the events, which should work for the specific plugin, when an event is doing nothing, it should not be added
/**
* Save updated order data to the method specific table
*
* @param array $_formData Form data
* @return mixed, True on success, false on failures (the rest of the save-process will be
* skipped!), or null when this method is not actived.
* @author Oscar van Eijk
*
public function plgVmOnUpdateOrderPayment( $_formData) {
return null;
}
/**
* Save updated orderline data to the method specific table
*
* @param array $_formData Form data
* @return mixed, True on success, false on failures (the rest of the save-process will be
* skipped!), or null when this method is not actived.
* @author Oscar van Eijk
*
public function plgVmOnUpdateOrderLine( $_formData) {
return null;
}
/**
* plgVmOnEditOrderLineBE
* This method is fired when editing the order line details in the backend.
* It can be used to add line specific package codes
*
* @param integer $_orderId The order ID
* @param integer $_lineId
* @return mixed Null for method that aren't active, text (HTML) otherwise
* @author Oscar van Eijk
*
public function plgVmOnEditOrderLineBEPayment( $_orderId, $_lineId) {
return null;
}
/**
* This method is fired when showing the order details in the frontend, for every orderline.
* It can be used to display line specific package codes, e.g. with a link to external tracking and
* tracing systems
*
* @param integer $_orderId The order ID
* @param integer $_lineId
* @return mixed Null for method that aren't active, text (HTML) otherwise
* @author Oscar van Eijk
*
public function plgVmOnShowOrderLineFE( $_orderId, $_lineId) {
return null;
}
/**
* This event is fired when the method notifies you when an event occurs that affects the order.
* Typically, the events represents for payment authorizations, Fraud Management Filter actions and other actions,
* such as refunds, disputes, and chargebacks.
*
* NOTE for Plugin developers:
* If the plugin is NOT actually executed (not the selected payment method), this method must return NULL
*
* @param $return_context: it was given and sent in the payment form. The notification should return it back.
* Used to know which cart should be emptied, in case it is still in the session.
* @param int $virtuemart_order_id : payment order id
* @param char $new_status : new_status for this order id.
* @return mixed Null when this method was not selected, otherwise the true or false
*
* @author Valerie Isaksen
*
*
public function plgVmOnPaymentNotification() {
return null;
}
*/
function plgVmOnPaymentNotification() {
header("Status: 200 OK");
if (!class_exists('VirtueMartModelOrders'))
require( JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php' );
$bcash_data = $_REQUEST;
if (!isset($bcash_data['transacao_id'])) {
return;
}
$order_number = $bcash_data['pedido'];
$virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number);
//$this->logInfo('plgVmOnPaymentNotification: Bcash - '.$bcash_data['transacao_id'].' - '.$bcash_data['pedido'].' - '.$bcash_data['status']);
if (!$virtuemart_order_id) {
return;
}
$vendorId = 0;
$payment = $this->getDataByOrderId($virtuemart_order_id);
if($payment->payment_name == '') {
return false;
}
$method = $this->getVmPluginMethod($payment->virtuemart_paymentmethod_id);
if (!$this->selectedThisElement($method->payment_element)) {
return false;
}
//$this->_debug = $method->debug;
if (!$payment) {
$this->logInfo('getDataByOrderId payment not found: exit ', 'ERROR');
return null;
}
$this->logInfo('bcash_data ' . implode(' ', $bcash_data), 'message');
// get all know columns of the table
$db = JFactory::getDBO();
/*
$query = 'SHOW COLUMNS FROM `' . $this->_tablename . '` ';
$db->setQuery($query);
$columns = $db->loadResultArray(0);
$post_msg = '';
foreach ($bcash_data as $key => $value) {
$post_msg .= $key . "=" . $value . "<br />";
$table_key = 'bcash_response_' . $key;
if (in_array($table_key, $columns)) {
$response_fields[$table_key] = $value;
}
}
$response_fields['payment_name'] = $payment->payment_name;
$response_fields['order_number'] = $order_number;
$response_fields['virtuemart_order_id'] = $virtuemart_order_id;
*/
// faz a validação dos dados
$email = $method->email_cobranca;
$token = $method->chave;
$urlPost = "https://www.bcash.com.br/transacao/consulta/";
$transacaoId = $bcash_data['transacao_id'];
$pedidoId = $bcash_data['pedido'];
$tipoRetorno = 2; // 1 => utf-8, 2 => ISO–8859–1
$codificacao = 1; // 1 => xml, 2 => json
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $urlPost); curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,array("id_transacao"=>$transacaoId,"id_pedido"=>$pedidoId,"tipo_retorno"=>$tipoRetorno,"codificacao"=>$codificacao));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Basic ".base64_encode($email. ":".$token)));
$resposta = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// faz a validação dos dados
if($httpCode == "200") {
$bcash_status = $bcash_data['status'];
if ($bcash_status == 'Aprovada' or $bcash_status == 'Concluída') {
$new_status = $method->status_aprovado;
} elseif ($bcash_status == 'Cancelada') {
$new_status = $method->status_cancelado;
} else {
$new_status = $method->status_aguardando;
}
// pega os dados da transação por completo
$transacao_dados = json_decode($resposta);
$meio_pagamento = $transacao_dados->transacao->meio_pagamento;
$parcelas = $transacao_dados->transacao->parcelas;
$this->logInfo('plgVmOnPaymentNotification return new_status:' . $new_status, 'message');
if ($virtuemart_order_id) {
// send the email only if payment has been accepted
if (!class_exists('VirtueMartModelOrders'))
require( JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php' );
$modelOrder = new VirtueMartModelOrders();
$orderitems = $modelOrder->getOrder($virtuemart_order_id);
$nb_history = count($orderitems['history']);
$order['order_status'] = $new_status;
$order['virtuemart_order_id'] = $virtuemart_order_id;
$order['comments'] = 'O status da transação foi atualizado para Transação <b>'.utf8_encode($bcash_data['status'].'</b>');
$order['comments'] .= '<br /> <b>Forma de Pagamento:</b> '.$meio_pagamento.' - '.$parcelas.' vez(es)';
if ($nb_history == 1) {
//$order['comments'] .= "<br />" . JText::sprintf('VMPAYMENT_PAYPAL_EMAIL_SENT');
$order['customer_notified'] = 0;
} else {
$order['customer_notified'] = 1;
}
$modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, true);
if ($nb_history == 1) {
if (!class_exists('shopFunctionsF'))
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
shopFunctionsF::sentOrderConfirmedEmail($orderitems);
$this->logInfo('Notification, sentOrderConfirmedEmail ' . $order_number. ' '. $new_status, 'message');
}
}
//// remove vmcart
$this->emptyCart($return_context);
}
}
/**
* plgVmOnPaymentResponseReceived
* This event is fired when the method returns to the shop after the transaction
*
* the method itself should send in the URL the parameters needed
* NOTE for Plugin developers:
* If the plugin is NOT actually executed (not the selected payment method), this method must return NULL
*
* @param int $virtuemart_order_id : should return the virtuemart_order_id
* @param text $html: the html to display
* @return mixed Null when this method was not selected, otherwise the true or false
*
* @author Valerie Isaksen
*
*
function plgVmOnPaymentResponseReceived(, &$virtuemart_order_id, &$html) {
return null;
}
*/
// retorno da transação para o pedido específico
function plgVmOnPaymentResponseReceived(&$html) {
// the payment itself should send the parameter needed.
$virtuemart_paymentmethod_id = JRequest::getInt('pm', 0);
$vendorId = 0;
if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) {
return null; // Another method was selected, do nothing
}
if (!$this->selectedThisElement($method->payment_element)) {
return false;
}
if (!class_exists('VirtueMartCart'))
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
$payment_data = JRequest::get('post');
$payment_name = $this->renderPluginName($method);
$html = $this->_getPaymentResponseHtml($payment_data, $payment_name);
if (!empty($payment_data)) {
vmdebug('plgVmOnPaymentResponseReceived', $payment_data);
$order_number = $payment_data['invoice'];
$return_context = $payment_data['custom'];
if (!class_exists('VirtueMartModelOrders'))
require( JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php' );
$virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number);
$payment_name = $this->renderPluginName($method);
$html = $this->_getPaymentResponseHtml($payment_data, $payment_name);
if ($virtuemart_order_id) {
// send the email ONLY if payment has been accepted
if (!class_exists('VirtueMartModelOrders'))
require( JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php' );
$modelOrder = new VirtueMartModelOrders();
$orderitems = $modelOrder->getOrder($virtuemart_order_id);
$nb_history = count($orderitems['history']);
//vmdebug('history', $orderitems);
if (!class_exists('shopFunctionsF'))
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
if ($nb_history == 1) {
if (!class_exists('shopFunctionsF'))
require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
shopFunctionsF::sentOrderConfirmedEmail($orderitems);
$this->logInfo('plgVmOnPaymentResponseReceived, sentOrderConfirmedEmail ' . $order_number, 'message');
$order['order_status'] = $orderitems['items'][$nb_history - 1]->order_status;
$order['virtuemart_order_id'] = $virtuemart_order_id;
$order['customer_notified'] = 0;
$order['comments'] = JText::sprintf('VMPAYMENT_PAYPAL_EMAIL_SENT');
$modelOrder->updateStatusForOneOrder($virtuemart_order_id, $order, true);
}
}
}
$cart = VirtueMartCart::getCart();
//We delete the old stuff
// get the correct cart / session
$cart = VirtueMartCart::getCart();
$cart->emptyCart();
return true;
}
/**
* @param $pagamentoDigitalTable
* @param $payment_name
* @return string
*/
public function _getPaymentResponseHtml ($pagamentoDigitalTable, $payment_name) {
$html = '<table>' . "\n";
$html .= $this->getHtmlRow ('B_PAYMENT_NAME', $payment_name);
if (!empty($pagamentoDigitalTable)) {
$html .= $this->getHtmlRow('B_ID_TRANSACAO', $pagamentoDigitalTable['id_transacao']);
$html .= $this->getHtmlRow('B_CODIGO_PEDIDO', $pagamentoDigitalTable['id_pedido']);
$html .= $this->getHtmlRow('B_DATA_TRANSACAO', $pagamentoDigitalTable['data_transacao']);
$html .= $this->getHtmlRow('B_TOTAL', 'R$ '. number_format($pagamentoDigitalTable['valor_total'],2,',','.'));
$html .= $this->getHtmlRow('B_TIPO_PAGAMENTO', utf8_encode($pagamentoDigitalTable['tipo_pagamento']));
$html .= $this->getHtmlRow('B_PARCELAS', $pagamentoDigitalTable['parcelas']);
}
$html .= '</table>' . "\n";
$link = '<br /><a href="'.JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=orders&layout=details&order_number='.$pagamentoDigitalTable['id_pedido']).'">'.JText::_('VMPAYMENT_B_MSG_ORDER_DETAILS').'</a>';
$html .= $link;
return $html;
}
}
// No closing tag