|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* The WPSC Gateway class |
|
5
|
|
|
*/ |
|
6
|
|
|
class wpsc_gateways { |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
var $wpsc_gateways; |
|
9
|
|
|
var $gateway; |
|
10
|
|
|
var $gateway_count = 0; |
|
11
|
|
|
var $current_gateway = -1; |
|
12
|
|
|
var $in_the_loop = false; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct() { |
|
15
|
|
|
global $nzshpcrt_gateways; |
|
16
|
|
|
|
|
17
|
|
|
$gateway_options = get_option( 'custom_gateway_options' ); |
|
18
|
|
|
foreach ( $nzshpcrt_gateways as $gateway ) { |
|
19
|
|
|
if ( array_search( $gateway['internalname'], (array)$gateway_options ) !== false ) { |
|
20
|
|
|
$this->wpsc_gateways[] = $gateway; |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
$this->wpsc_gateways = apply_filters( |
|
25
|
|
|
'wpsc_merchant_v2_gateway_loop_items', |
|
26
|
|
|
$this->wpsc_gateways, |
|
27
|
|
|
$this |
|
28
|
|
|
); |
|
29
|
|
|
$this->gateway_count = count( $this->wpsc_gateways ); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* checkout loop methods |
|
34
|
|
|
*/ |
|
35
|
|
|
public function next_gateway() { |
|
36
|
|
|
$this->current_gateway++; |
|
37
|
|
|
$this->gateway = $this->wpsc_gateways[$this->current_gateway]; |
|
38
|
|
|
return $this->gateway; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function the_gateway() { |
|
42
|
|
|
$this->in_the_loop = true; |
|
43
|
|
|
$this->gateway = $this->next_gateway(); |
|
44
|
|
|
if ( $this->current_gateway == 0 ) // loop has just started |
|
45
|
|
|
do_action( 'wpsc_checkout_loop_start' ); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function have_gateways() { |
|
49
|
|
|
if ( $this->current_gateway + 1 < $this->gateway_count ) { |
|
50
|
|
|
return true; |
|
51
|
|
|
} else if ( $this->current_gateway + 1 == $this->gateway_count && $this->gateway_count > 0 ) { |
|
52
|
|
|
do_action( 'wpsc_checkout_loop_end' ); |
|
53
|
|
|
// Do some cleaning up after the loop, |
|
54
|
|
|
$this->rewind_gateways(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$this->in_the_loop = false; |
|
58
|
|
|
return false; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function rewind_gateways() { |
|
62
|
|
|
$this->current_gateway = -1; |
|
63
|
|
|
if ( $this->gateway_count > 0 ) { |
|
64
|
|
|
$this->gateway = $this->wpsc_gateways[0]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
} |