This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
/
pay.php
162 lines (119 loc) · 4.77 KB
/
pay.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
<?php
/**
* Payment page shortcode
*
* DISCLAIMER
*
* Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
* versions in the future. If you wish to customise Jigoshop core for your needs,
* please use our GitHub repository to publish essential changes for consideration.
*
* @package Jigoshop
* @category Checkout
* @author Jigowatt
* @copyright Copyright © 2011-2012 Jigowatt Ltd.
* @license http://jigoshop.com/license/commercial-edition
*/
function get_jigoshop_pay( $atts ) {
return jigoshop_shortcode_wrapper('jigoshop_pay', $atts);
}
/**
* Outputs the pay page - payment gateways can hook in here to show payment forms etc
**/
function jigoshop_pay() {
if ( isset($_GET['pay_for_order']) && isset($_GET['order']) && isset($_GET['order_id']) ) :
// Pay for existing order
$order_key = urldecode( $_GET['order'] );
$order_id = (int) $_GET['order_id'];
$order = new jigoshop_order( $order_id );
if ($order->id == $order_id && $order->order_key == $order_key && $order->status=='pending') :
// Set customer location to order location
if ($order->billing_country) jigoshop_customer::set_country( $order->billing_country );
if ($order->billing_state) jigoshop_customer::set_state( $order->billing_state );
if ($order->billing_postcode) jigoshop_customer::set_postcode( $order->billing_postcode );
// Pay form was posted - process payment
if (isset($_POST['pay']) && jigoshop::verify_nonce('pay')) :
// Update payment method
if ($order->order_total > 0 ) :
$payment_method = jigowatt_clean($_POST['payment_method']);
$data = (array) maybe_unserialize( get_post_meta( $order_id, 'order_data', true ) );
$data['payment_method'] = $payment_method;
update_post_meta( $order_id, 'order_data', $data );
$available_gateways = jigoshop_payment_gateways::get_available_payment_gateways();
$result = $available_gateways[$payment_method]->process_payment( $order_id );
// Redirect to success/confirmation/payment page
if ($result['result']=='success') :
wp_safe_redirect( $result['redirect'] );
exit;
endif;
else :
// No payment was required for order
$order->payment_complete();
// filter redirect page
$checkout_redirect = apply_filters( 'jigoshop_get_checkout_redirect_page_id', jigoshop_get_page_id('thanks') );
wp_safe_redirect( get_permalink( $checkout_redirect ) );
exit;
endif;
endif;
// Show messages
jigoshop::show_messages();
// Show form
jigoshop_pay_for_existing_order( $order );
elseif ($order->status!='pending') :
jigoshop::add_error( __('Your order has already been paid for. Please contact us if you need assistance.', 'jigoshop') );
jigoshop::show_messages();
else :
jigoshop::add_error( __('Invalid order.', 'jigoshop') );
jigoshop::show_messages();
endif;
else :
// Pay for order after checkout step
if (isset($_GET['order'])) $order_id = $_GET['order']; else $order_id = 0;
if (isset($_GET['key'])) $order_key = $_GET['key']; else $order_key = '';
if ($order_id > 0) :
$order = new jigoshop_order( $order_id );
if ($order->order_key == $order_key && $order->status=='pending') :
?>
<ul class="order_details">
<li class="order">
<?php _e('Order:', 'jigoshop'); ?>
<strong># <?php echo $order->id; ?></strong>
</li>
<li class="date">
<?php _e('Date:', 'jigoshop'); ?>
<strong><?php echo date_i18n(get_option('date_format').' '.get_option('time_format'), strtotime($order->order_date)); ?></strong>
</li>
<li class="total">
<?php _e('Total:', 'jigoshop'); ?>
<strong><?php echo jigoshop_price($order->order_total); ?></strong>
</li>
<li class="method">
<?php _e('Payment method:', 'jigoshop'); ?>
<strong><?php
$gateways = jigoshop_payment_gateways::payment_gateways();
if (isset($gateways[$order->payment_method])) echo $gateways[$order->payment_method]->title;
else echo $order->payment_method;
?></strong>
</li>
</ul>
<?php do_action( 'receipt_' . $order->payment_method, $order_id ); ?>
<div class="clear"></div>
<?php
else :
wp_safe_redirect( apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))) );
exit;
endif;
else :
wp_safe_redirect( apply_filters('jigoshop_get_myaccount_page_id', get_permalink(jigoshop_get_page_id('myaccount'))) );
exit;
endif;
endif;
}
/**
* Outputs the payment page when a user comes to pay from a link (for an existing/past created order)
**/
function jigoshop_pay_for_existing_order( $pay_for_order ) {
global $order;
$order = $pay_for_order;
jigoshop_get_template('checkout/pay_for_order.php');
}