Completed
Push — master ( 1db5db...8743f5 )
by Michael
06:44
created

bookshop_paypal   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 89
rs 10
wmc 8
lcom 2
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getURL() 0 16 4
B getFormContent() 0 29 3
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 35 and the first side effect is on line 30.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
//  ------------------------------------------------------------------------ //
3
//                      BOOKSHOP - MODULE FOR XOOPS 2                        //
4
//                  Copyright (c) 2007, 2008 Instant Zero                    //
5
//                     <http://www.instant-zero.com/>                        //
6
// ------------------------------------------------------------------------- //
7
//  This program is free software; you can redistribute it and/or modify     //
8
//  it under the terms of the GNU General Public License as published by     //
9
//  the Free Software Foundation; either version 2 of the License, or        //
10
//  (at your option) any later version.                                      //
11
//                                                                           //
12
//  You may not change or alter any portion of this comment or credits       //
13
//  of supporting developers from this source code or any supporting         //
14
//  source code which is considered copyrighted (c) material of the          //
15
//  original comment or credit authors.                                      //
16
//                                                                           //
17
//  This program is distributed in the hope that it will be useful,          //
18
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
19
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
20
//  GNU General Public License for more details.                             //
21
//                                                                           //
22
//  You should have received a copy of the GNU General Public License        //
23
//  along with this program; if not, write to the Free Software              //
24
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
25
//  ------------------------------------------------------------------------ //
26
/**
27
 * Classe responsable de la gestion de tout ce qui est relatif à Paypal
28
 */
29
30
defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
31
32
/**
33
 * Class bookshop_paypal
34
 */
35
class bookshop_paypal
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
36
{
37
    public $testMode;
38
    public $email;
39
    public $moneyCode;
40
    public $useIpn;
41
    public $passwordCancel;
42
43
    /**
44
     * @param        $testMode
45
     * @param        $emailPaypal
46
     * @param        $moneyCode
47
     * @param bool   $ipn
48
     * @param string $passwordCancel
49
     */
50
    public function __construct($testMode, $emailPaypal, $moneyCode, $ipn = false, $passwordCancel = '')
51
    {
52
        $this->testMode       = $testMode;
53
        $this->email          = $emailPaypal;
54
        $this->moneyCode      = $moneyCode;
55
        $this->useIpn         = $ipn;
56
        $this->passwordCancel = $passwordCancel;
57
    }
58
59
    /**
60
	 * Renvoie l'url à utiliser en tenant compte du fait qu'on est en mode test ou pas
61
     *
62
     * @param bool $securized
63
     *
64
     * @return string
65
     */
66
    public function getURL($securized = false)
67
    {
68
        if (!$securized) {
69
            if ($this->testMode == 1) {
70
                return 'https://www.sandbox.paypal.com/cgi-bin/webscr';
71
            } else {
72
                return 'https://www.paypal.com/cgi-bin/webscr';
73
            }
74
        } else {
75
            if ($this->testMode == 1) {
76
                return 'www.sandbox.paypal.com';
77
            } else {
78
                return 'www.paypal.com';
79
            }
80
        }
81
    }
82
83
    /**
84
	 * Renvoie les éléments à ajouter au formulaire en tant que zones cachées
85
     *
86
     * @param       $commandId
87
	 * @param float $ttc TTC à facturer
88
     *
89
     * @param       $emailClient
90
     *
91
     * @internal param int $commmandId Num�ro de la commande
92
     * @return array
93
     */
94
    public function getFormContent($commandId, $ttc, $emailClient)
95
    {
96
        global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
97
        $ret                     = array();
98
        $ret['cmd']              = '_xclick';
99
        $ret['upload']           = '1';
100
        $ret['currency_code']    = $this->moneyCode;
101
        $ret['business']         = $this->email;
102
		$ret['return'] = BOOKSHOP_URL.'thankyou.php';			// Page (générique) de remerciement après paiement
103
        $ret['image_url']        = XOOPS_URL . '/images/logo.gif';
104
        $ret['cpp_header_image'] = XOOPS_URL . '/images/logo.gif';
105
        $ret['invoice']          = $commandId;
106
        $ret['item_name']        = _BOOKSHOP_COMMAND . $commandId . ' - ' . $xoopsConfig['sitename'];
107
        $ret['item_number']      = $commandId;
108
        $ret['tax']              = 0;    // ajout 25/03/2008
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
109
        $ret['amount']           = $ttc;
110
        $ret['custom']           = $commandId;
111
		//$ret['rm'] = 2;	// Renvoyer les données par POST (normalement)
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
112
        $ret['email'] = $emailClient;
113
        // paypal_pdt
114
		if(xoops_trim($this->passwordCancel) != '') {	// URL à laquelle le navigateur du client est ramené si le paiement est annulé
115
            $ret['cancel_return'] = BOOKSHOP_URL . 'cancel-payment.php?id=' . $this->passwordCancel;
116
        }
117
        if ($this->useIpn == 1) {
118
            $ret['notify_url'] = BOOKSHOP_URL . 'paypal-notify.php';
119
        }
120
121
        return $ret;
122
    }
123
}
124