1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Les fonctions principales pour les paiements. |
4
|
|
|
* |
5
|
|
|
* @author Eoxia <[email protected]> |
6
|
|
|
* @copyright (c) 2011-2018 Eoxia <[email protected]>. |
7
|
|
|
* |
8
|
|
|
* @license AGPLv3 <https://spdx.org/licenses/AGPL-3.0-or-later.html> |
9
|
|
|
* |
10
|
|
|
* @package WPshop\Classes |
11
|
|
|
* |
12
|
|
|
* @since 2.0.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace wpshop; |
16
|
|
|
|
17
|
|
|
defined( 'ABSPATH' ) || exit; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Payement Class. |
21
|
|
|
*/ |
22
|
|
|
class Payment extends \eoxia\Singleton_Util { |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Les méthodes de paiement |
26
|
|
|
* |
27
|
|
|
* @since 2.0.0 |
28
|
|
|
* |
29
|
|
|
* @var array |
30
|
|
|
*/ |
31
|
|
|
public $default_options; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructeur. |
35
|
|
|
* |
36
|
|
|
* @since 2.0.0 |
37
|
|
|
*/ |
38
|
|
|
protected function construct() { |
39
|
|
|
$this->default_options = array( |
40
|
|
|
'cheque' => array( |
41
|
|
|
'active' => true, |
42
|
|
|
'title' => __( 'Cheque', 'wpshop' ), |
43
|
|
|
'description' => __( 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'wpshop' ), |
44
|
|
|
), |
45
|
|
|
'payment_in_shop' => array( |
46
|
|
|
'active' => true, |
47
|
|
|
'title' => __( 'Payment in shop', 'wpshop' ), |
48
|
|
|
'description' => __( 'Pay and pick up directly your products at the shop.', 'wpshop' ), |
49
|
|
|
), |
50
|
|
|
'paypal' => array( |
51
|
|
|
'active' => true, |
52
|
|
|
'title' => __( 'PayPal', 'wpshop' ), |
53
|
|
|
'description' => __( 'Accept payments via PayPal using account balance or credit card.', 'wpshop' ), |
54
|
|
|
'paypal_email' => '', |
55
|
|
|
'use_paypal_sandbox' => false, |
56
|
|
|
), |
57
|
|
|
'stripe' => array( |
58
|
|
|
'active' => true, |
59
|
|
|
'title' => __( 'Stripe', 'wpshop' ), |
60
|
|
|
'description' => __( 'Use your credit card to place your order', 'wpshop' ), |
61
|
|
|
'publish_key' => '', |
62
|
|
|
'secret_key' => '', |
63
|
|
|
'use_stripe_sandbox' => false, |
64
|
|
|
), |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->default_options = apply_filters( 'wps_payment_methods', $this->default_options ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Récupères les données d'un méthode de paiement selon $slug. |
72
|
|
|
* |
73
|
|
|
* @since 2.0.0 |
74
|
|
|
* |
75
|
|
|
* @param string $slug Le slug de la méthode de paiement. |
76
|
|
|
* |
77
|
|
|
* @return array Les données de la méthode de paiement. |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function get_payment_option( $slug = '' ) { |
|
|
|
|
80
|
|
|
$payment_methods_option = get_option( 'wps_payment_methods', $this->default_options ); |
81
|
|
|
|
82
|
|
|
if ( empty( $slug ) || ! isset( $payment_methods_option[ $slug ] ) ) { |
83
|
|
|
return $payment_methods_option; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
return $payment_methods_option[ $slug ]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Récupères les données d'un méthode de paiement selon $slug. |
91
|
|
|
* |
92
|
|
|
* @todo Voir ou c'est appelé |
93
|
|
|
* |
94
|
|
|
* @since 2.0.0 |
95
|
|
|
* |
96
|
|
|
* @param string $slug Le slug de la méthode de paiement. |
97
|
|
|
* |
98
|
|
|
* @return array Le titre de la méthode de paiement. |
99
|
|
|
*/ |
100
|
|
View Code Duplication |
public function get_payment_title( $slug ) { |
|
|
|
|
101
|
|
|
$payment_methods_option = get_option( 'wps_payment_methods', $this->default_options ); |
102
|
|
|
$payment_method = $payment_methods_option[ $slug ]; |
103
|
|
|
|
104
|
|
|
if ( empty( $payment_method ) ) { |
105
|
|
|
return null; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $payment_method['title']; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Convertis le status vers un message lisible. |
113
|
|
|
* |
114
|
|
|
* @todo: A voir, a traduire. |
115
|
|
|
* |
116
|
|
|
* @param array $object Un tableau contenant un type et la méta billed |
117
|
|
|
* ainsi que la méta payment_method. |
118
|
|
|
* |
119
|
|
|
* @return string Le message |
120
|
|
|
*/ |
121
|
|
|
public function convert_status( $object ) { |
122
|
|
|
$statut = ''; |
123
|
|
|
|
124
|
|
|
if ( 'wps-order' === $object['type'] ) { |
125
|
|
|
switch ( $object['payment_method'] ) { |
126
|
|
|
case 'cheque': |
127
|
|
|
if ( $object['billed'] ) { |
128
|
|
|
$statut = 'Payée'; |
129
|
|
|
} else { |
130
|
|
|
$statut = 'En attente du chèque'; |
131
|
|
|
} |
132
|
|
|
break; |
133
|
|
View Code Duplication |
case 'paypal': |
|
|
|
|
134
|
|
|
if ( $object['billed'] ) { |
135
|
|
|
$statut = 'Payée'; |
136
|
|
|
} elseif ( $object['payment_failed'] ) { |
137
|
|
|
$statut = 'Paiment échoué.'; |
138
|
|
|
} else { |
139
|
|
|
$statut = 'En attente du paiement'; |
140
|
|
|
} |
141
|
|
|
break; |
142
|
|
|
case 'payment_in_shop': |
143
|
|
|
if ( $object['billed'] ) { |
144
|
|
|
$statut = 'Payée'; |
145
|
|
|
} else { |
146
|
|
|
$statut = 'En attente du paiement.<br />Paiement a régler en boutique'; |
147
|
|
|
} |
148
|
|
|
break; |
149
|
|
View Code Duplication |
case 'stripe': |
|
|
|
|
150
|
|
|
if ( $object['billed'] ) { |
151
|
|
|
$statut = 'Payée'; |
152
|
|
|
} elseif ( $object['payment_failed'] ) { |
153
|
|
|
$statut = 'Paiment échoué.'; |
154
|
|
|
} else { |
155
|
|
|
$statut = 'En attente du paiement'; |
156
|
|
|
} |
157
|
|
|
break; |
158
|
|
|
default: |
159
|
|
|
break; |
160
|
|
|
} |
161
|
|
|
} elseif ( 'wps-doli-invoice' === $object['type'] ) { |
162
|
|
|
if ( $object['paye'] ) { |
163
|
|
|
$statut = 'Payée'; |
164
|
|
|
} else { |
165
|
|
|
$statut = 'Impayée'; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $statut; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
Payment::g(); |
174
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.