@@ -12,145 +12,145 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Expires expired subscriptions. |
|
108 | - * |
|
109 | - */ |
|
110 | - public function maybe_expire_subscriptions() { |
|
111 | - |
|
112 | - // Fetch expired subscriptions (skips those that expire today). |
|
113 | - $args = array( |
|
114 | - 'number' => -1, |
|
115 | - 'count_total' => false, |
|
116 | - 'status' => 'trialling active failing cancelled', |
|
117 | - 'date_expires_query' => array( |
|
118 | - 'before' => 'today', |
|
119 | - 'inclusive' => false, |
|
120 | - ), |
|
121 | - ); |
|
122 | - |
|
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | - |
|
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
128 | - $subscription->save(); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Logs cron runs. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function log_cron_run() { |
|
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Updates GeoIP databases. |
|
144 | - * |
|
145 | - */ |
|
146 | - public function maybe_update_geoip_databases() { |
|
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | - |
|
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
152 | - } |
|
153 | - |
|
154 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | + 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | + 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Expires expired subscriptions. |
|
108 | + * |
|
109 | + */ |
|
110 | + public function maybe_expire_subscriptions() { |
|
111 | + |
|
112 | + // Fetch expired subscriptions (skips those that expire today). |
|
113 | + $args = array( |
|
114 | + 'number' => -1, |
|
115 | + 'count_total' => false, |
|
116 | + 'status' => 'trialling active failing cancelled', |
|
117 | + 'date_expires_query' => array( |
|
118 | + 'before' => 'today', |
|
119 | + 'inclusive' => false, |
|
120 | + ), |
|
121 | + ); |
|
122 | + |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | + |
|
125 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
127 | + $subscription->set_status( 'expired' ); |
|
128 | + $subscription->save(); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Logs cron runs. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function log_cron_run() { |
|
139 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Updates GeoIP databases. |
|
144 | + * |
|
145 | + */ |
|
146 | + public function maybe_update_geoip_databases() { |
|
147 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | + |
|
149 | + if ( false === $updated ) { |
|
150 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | + do_action( 'getpaid_update_geoip_databases' ); |
|
152 | + } |
|
153 | + |
|
154 | + } |
|
155 | 155 | |
156 | 156 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | + add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions')); |
|
31 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
32 | 32 | |
33 | 33 | } |
34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function maybe_create_scheduled_event() { |
40 | 40 | |
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
41 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
42 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
43 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function maybe_clear_deprecated_events() { |
53 | 53 | |
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
54 | + if (!get_option('wpinv_cleared_old_events')) { |
|
55 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
56 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
57 | + update_option('wpinv_cleared_old_events', 1); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | */ |
66 | 66 | public function backwards_compat() { |
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + do_action('wpinv_register_schedule_event_daily'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | public function check_renewing_subscriptions() { |
75 | 75 | |
76 | 76 | // Fetch subscriptions that expire today. |
77 | - $args = array( |
|
77 | + $args = array( |
|
78 | 78 | 'number' => -1, |
79 | 79 | 'count_total' => false, |
80 | 80 | 'status' => 'trialling active', |
81 | 81 | 'date_expires_query' => array( |
82 | 82 | array( |
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
83 | + 'year' => date('Y', current_time('timestamp')), |
|
84 | + 'month' => date('n', current_time('timestamp')), |
|
85 | + 'day' => date('j', current_time('timestamp')), |
|
86 | 86 | 'compare' => '=', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | ); |
90 | 90 | |
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
92 | 92 | |
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
93 | + foreach ($subscriptions->get_results() as $subscription) { |
|
94 | 94 | |
95 | 95 | /** @var WPInv_Subscription $subscription */ |
96 | - if ( $subscription->is_last_renewal() ) { |
|
96 | + if ($subscription->is_last_renewal()) { |
|
97 | 97 | $subscription->complete(); |
98 | 98 | } else { |
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
99 | + do_action('getpaid_should_renew_subscription', $subscription); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function maybe_expire_subscriptions() { |
111 | 111 | |
112 | 112 | // Fetch expired subscriptions (skips those that expire today). |
113 | - $args = array( |
|
113 | + $args = array( |
|
114 | 114 | 'number' => -1, |
115 | 115 | 'count_total' => false, |
116 | 116 | 'status' => 'trialling active failing cancelled', |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | ), |
121 | 121 | ); |
122 | 122 | |
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
124 | 124 | |
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
125 | + foreach ($subscriptions->get_results() as $subscription) { |
|
126 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) { |
|
127 | + $subscription->set_status('expired'); |
|
128 | 128 | $subscription->save(); |
129 | 129 | } |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * |
137 | 137 | */ |
138 | 138 | public function log_cron_run() { |
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | * |
145 | 145 | */ |
146 | 146 | public function maybe_update_geoip_databases() { |
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
148 | 148 | |
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
149 | + if (false === $updated) { |
|
150 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
151 | + do_action('getpaid_update_geoip_databases'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | } |
@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | - * Retrieves a customer profile. |
|
179 | - * |
|
180 | - * |
|
181 | - * @param string $profile_id profile id. |
|
182 | - * @return string|WP_Error Profile id. |
|
178 | + * Retrieves a customer profile. |
|
179 | + * |
|
180 | + * |
|
181 | + * @param string $profile_id profile id. |
|
182 | + * @return string|WP_Error Profile id. |
|
183 | 183 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
184 | - */ |
|
185 | - public function get_customer_profile( $profile_id ) { |
|
184 | + */ |
|
185 | + public function get_customer_profile( $profile_id ) { |
|
186 | 186 | |
187 | 187 | // Generate args. |
188 | 188 | $args = array( |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | /** |
200 | - * Creates a customer profile. |
|
201 | - * |
|
202 | - * |
|
200 | + * Creates a customer profile. |
|
201 | + * |
|
202 | + * |
|
203 | 203 | * @param string $profile_id profile id. |
204 | - * @param WPInv_Invoice $invoice Invoice. |
|
204 | + * @param WPInv_Invoice $invoice Invoice. |
|
205 | 205 | * @param array $submission_data Posted checkout fields. |
206 | 206 | * @param bool $save Whether or not to save the payment as a token. |
207 | 207 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
208 | - * @return string|WP_Error Profile id. |
|
209 | - */ |
|
210 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
208 | + * @return string|WP_Error Profile id. |
|
209 | + */ |
|
210 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
211 | 211 | |
212 | 212 | // Remove non-digits from the number |
213 | 213 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | - * Retrieves payment details from cache. |
|
286 | - * |
|
287 | - * |
|
285 | + * Retrieves payment details from cache. |
|
286 | + * |
|
287 | + * |
|
288 | 288 | * @param array $payment_details. |
289 | - * @return array|false Profile id. |
|
290 | - */ |
|
291 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
289 | + * @return array|false Profile id. |
|
290 | + */ |
|
291 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
292 | 292 | |
293 | 293 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
294 | 294 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -313,13 +313,13 @@ discard block |
||
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
316 | - * Securely adds payment details to cache. |
|
317 | - * |
|
318 | - * |
|
316 | + * Securely adds payment details to cache. |
|
317 | + * |
|
318 | + * |
|
319 | 319 | * @param array $payment_details. |
320 | 320 | * @param string $payment_profile_id. |
321 | - */ |
|
322 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
321 | + */ |
|
322 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
323 | 323 | |
324 | 324 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
325 | 325 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -331,15 +331,15 @@ discard block |
||
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
334 | - * Retrieves a customer payment profile. |
|
335 | - * |
|
336 | - * |
|
337 | - * @param string $customer_profile_id customer profile id. |
|
334 | + * Retrieves a customer payment profile. |
|
335 | + * |
|
336 | + * |
|
337 | + * @param string $customer_profile_id customer profile id. |
|
338 | 338 | * @param string $payment_profile_id payment profile id. |
339 | - * @return string|WP_Error Profile id. |
|
339 | + * @return string|WP_Error Profile id. |
|
340 | 340 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
341 | - */ |
|
342 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
341 | + */ |
|
342 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
343 | 343 | |
344 | 344 | // Generate args. |
345 | 345 | $args = array( |
@@ -355,15 +355,15 @@ discard block |
||
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Charges a customer payment profile. |
|
359 | - * |
|
358 | + * Charges a customer payment profile. |
|
359 | + * |
|
360 | 360 | * @param string $customer_profile_id customer profile id. |
361 | 361 | * @param string $payment_profile_id payment profile id. |
362 | - * @param WPInv_Invoice $invoice Invoice. |
|
362 | + * @param WPInv_Invoice $invoice Invoice. |
|
363 | 363 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
364 | - * @return WP_Error|object |
|
365 | - */ |
|
366 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
364 | + * @return WP_Error|object |
|
365 | + */ |
|
366 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
367 | 367 | |
368 | 368 | // Generate args. |
369 | 369 | $args = array( |
@@ -409,41 +409,41 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Processes a customer charge. |
|
413 | - * |
|
412 | + * Processes a customer charge. |
|
413 | + * |
|
414 | 414 | * @param stdClass $result Api response. |
415 | - * @param WPInv_Invoice $invoice Invoice. |
|
416 | - */ |
|
417 | - public function process_charge_response( $result, $invoice ) { |
|
415 | + * @param WPInv_Invoice $invoice Invoice. |
|
416 | + */ |
|
417 | + public function process_charge_response( $result, $invoice ) { |
|
418 | 418 | |
419 | 419 | wpinv_clear_errors(); |
420 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
420 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
421 | 421 | |
422 | - // Succeeded. |
|
423 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
422 | + // Succeeded. |
|
423 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
424 | 424 | |
425 | - // Maybe set a transaction id. |
|
426 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
427 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
428 | - } |
|
425 | + // Maybe set a transaction id. |
|
426 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
427 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
428 | + } |
|
429 | 429 | |
430 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
430 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
431 | 431 | |
432 | - if ( 1 == $response_code ) { |
|
433 | - return $invoice->mark_paid(); |
|
434 | - } |
|
432 | + if ( 1 == $response_code ) { |
|
433 | + return $invoice->mark_paid(); |
|
434 | + } |
|
435 | 435 | |
436 | - $invoice->set_status( 'wpi-onhold' ); |
|
437 | - $invoice->add_note( |
|
436 | + $invoice->set_status( 'wpi-onhold' ); |
|
437 | + $invoice->add_note( |
|
438 | 438 | sprintf( |
439 | 439 | __( 'Held for review: %s', 'invoicing' ), |
440 | 440 | $result->transactionResponse->messages->message[0]->description |
441 | 441 | ) |
442 | - ); |
|
442 | + ); |
|
443 | 443 | |
444 | - return $invoice->save(); |
|
444 | + return $invoice->save(); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | 448 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
449 | 449 | |
@@ -455,13 +455,13 @@ discard block |
||
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
458 | - * Returns payment information. |
|
459 | - * |
|
460 | - * |
|
461 | - * @param array $card Card details. |
|
462 | - * @return array |
|
463 | - */ |
|
464 | - public function get_payment_information( $card ) { |
|
458 | + * Returns payment information. |
|
459 | + * |
|
460 | + * |
|
461 | + * @param array $card Card details. |
|
462 | + * @return array |
|
463 | + */ |
|
464 | + public function get_payment_information( $card ) { |
|
465 | 465 | return array( |
466 | 466 | |
467 | 467 | 'creditCard' => array ( |
@@ -474,25 +474,25 @@ discard block |
||
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Returns the customer profile meta name. |
|
478 | - * |
|
479 | - * |
|
480 | - * @param WPInv_Invoice $invoice Invoice. |
|
481 | - * @return string |
|
482 | - */ |
|
483 | - public function get_customer_profile_meta_name( $invoice ) { |
|
477 | + * Returns the customer profile meta name. |
|
478 | + * |
|
479 | + * |
|
480 | + * @param WPInv_Invoice $invoice Invoice. |
|
481 | + * @return string |
|
482 | + */ |
|
483 | + public function get_customer_profile_meta_name( $invoice ) { |
|
484 | 484 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Validates the submitted data. |
|
489 | - * |
|
490 | - * |
|
491 | - * @param array $submission_data Posted checkout fields. |
|
488 | + * Validates the submitted data. |
|
489 | + * |
|
490 | + * |
|
491 | + * @param array $submission_data Posted checkout fields. |
|
492 | 492 | * @param WPInv_Invoice $invoice |
493 | - * @return WP_Error|string The payment profile id |
|
494 | - */ |
|
495 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
493 | + * @return WP_Error|string The payment profile id |
|
494 | + */ |
|
495 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
496 | 496 | |
497 | 497 | // Validate authentication details. |
498 | 498 | $auth = $this->get_auth_params(); |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
527 | - * Returns invoice line items. |
|
528 | - * |
|
529 | - * |
|
530 | - * @param WPInv_Invoice $invoice Invoice. |
|
531 | - * @return array |
|
532 | - */ |
|
533 | - public function get_line_items( $invoice ) { |
|
527 | + * Returns invoice line items. |
|
528 | + * |
|
529 | + * |
|
530 | + * @param WPInv_Invoice $invoice Invoice. |
|
531 | + * @return array |
|
532 | + */ |
|
533 | + public function get_line_items( $invoice ) { |
|
534 | 534 | $items = array(); |
535 | 535 | |
536 | 536 | foreach ( $invoice->get_items() as $item ) { |
@@ -568,15 +568,15 @@ discard block |
||
568 | 568 | } |
569 | 569 | |
570 | 570 | /** |
571 | - * Process Payment. |
|
572 | - * |
|
573 | - * |
|
574 | - * @param WPInv_Invoice $invoice Invoice. |
|
575 | - * @param array $submission_data Posted checkout fields. |
|
576 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
577 | - * @return array |
|
578 | - */ |
|
579 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
571 | + * Process Payment. |
|
572 | + * |
|
573 | + * |
|
574 | + * @param WPInv_Invoice $invoice Invoice. |
|
575 | + * @param array $submission_data Posted checkout fields. |
|
576 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
577 | + * @return array |
|
578 | + */ |
|
579 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
580 | 580 | |
581 | 581 | // Validate the submitted data. |
582 | 582 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -609,45 +609,45 @@ discard block |
||
609 | 609 | |
610 | 610 | exit; |
611 | 611 | |
612 | - } |
|
612 | + } |
|
613 | 613 | |
614 | - /** |
|
615 | - * Processes the initial payment. |
|
616 | - * |
|
614 | + /** |
|
615 | + * Processes the initial payment. |
|
616 | + * |
|
617 | 617 | * @param WPInv_Invoice $invoice Invoice. |
618 | - */ |
|
619 | - protected function process_initial_payment( $invoice ) { |
|
618 | + */ |
|
619 | + protected function process_initial_payment( $invoice ) { |
|
620 | 620 | |
621 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
621 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
622 | 622 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
623 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
623 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
624 | 624 | |
625 | - // Do we have an error? |
|
626 | - if ( is_wp_error( $result ) ) { |
|
627 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
628 | - wpinv_send_back_to_checkout( $invoice ); |
|
629 | - } |
|
625 | + // Do we have an error? |
|
626 | + if ( is_wp_error( $result ) ) { |
|
627 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
628 | + wpinv_send_back_to_checkout( $invoice ); |
|
629 | + } |
|
630 | 630 | |
631 | - // Process the response. |
|
632 | - $this->process_charge_response( $result, $invoice ); |
|
631 | + // Process the response. |
|
632 | + $this->process_charge_response( $result, $invoice ); |
|
633 | 633 | |
634 | - if ( wpinv_get_errors() ) { |
|
635 | - wpinv_send_back_to_checkout( $invoice ); |
|
636 | - } |
|
634 | + if ( wpinv_get_errors() ) { |
|
635 | + wpinv_send_back_to_checkout( $invoice ); |
|
636 | + } |
|
637 | 637 | |
638 | - } |
|
638 | + } |
|
639 | 639 | |
640 | 640 | /** |
641 | - * Processes recurring payments. |
|
642 | - * |
|
641 | + * Processes recurring payments. |
|
642 | + * |
|
643 | 643 | * @param WPInv_Invoice $invoice Invoice. |
644 | 644 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
645 | - */ |
|
646 | - public function process_subscription( $invoice, $subscriptions ) { |
|
645 | + */ |
|
646 | + public function process_subscription( $invoice, $subscriptions ) { |
|
647 | 647 | |
648 | 648 | // Check if there is an initial amount to charge. |
649 | 649 | if ( (float) $invoice->get_total() > 0 ) { |
650 | - $this->process_initial_payment( $invoice ); |
|
650 | + $this->process_initial_payment( $invoice ); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | // Activate the subscriptions. |
@@ -665,36 +665,36 @@ discard block |
||
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | - // Redirect to the success page. |
|
668 | + // Redirect to the success page. |
|
669 | 669 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
670 | 670 | |
671 | 671 | } |
672 | 672 | |
673 | - /** |
|
674 | - * (Maybe) renews an authorize.net subscription profile. |
|
675 | - * |
|
676 | - * |
|
673 | + /** |
|
674 | + * (Maybe) renews an authorize.net subscription profile. |
|
675 | + * |
|
676 | + * |
|
677 | 677 | * @param WPInv_Subscription $subscription |
678 | - */ |
|
679 | - public function maybe_renew_subscription( $subscription ) { |
|
678 | + */ |
|
679 | + public function maybe_renew_subscription( $subscription ) { |
|
680 | 680 | |
681 | 681 | // Ensure its our subscription && it's active. |
682 | 682 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
683 | 683 | $this->renew_subscription( $subscription ); |
684 | 684 | } |
685 | 685 | |
686 | - } |
|
686 | + } |
|
687 | 687 | |
688 | 688 | /** |
689 | - * Renews a subscription. |
|
690 | - * |
|
689 | + * Renews a subscription. |
|
690 | + * |
|
691 | 691 | * @param WPInv_Subscription $subscription |
692 | - */ |
|
693 | - public function renew_subscription( $subscription ) { |
|
692 | + */ |
|
693 | + public function renew_subscription( $subscription ) { |
|
694 | 694 | |
695 | - // Generate the renewal invoice. |
|
696 | - $new_invoice = $subscription->create_payment(); |
|
697 | - $old_invoice = $subscription->get_parent_payment(); |
|
695 | + // Generate the renewal invoice. |
|
696 | + $new_invoice = $subscription->create_payment(); |
|
697 | + $old_invoice = $subscription->get_parent_payment(); |
|
698 | 698 | |
699 | 699 | if ( empty( $new_invoice ) ) { |
700 | 700 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -703,37 +703,37 @@ discard block |
||
703 | 703 | } |
704 | 704 | |
705 | 705 | // Charge the payment method. |
706 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
707 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
708 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
709 | - |
|
710 | - // Do we have an error? |
|
711 | - if ( is_wp_error( $result ) ) { |
|
712 | - |
|
713 | - $old_invoice->add_note( |
|
714 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
715 | - true, |
|
716 | - false, |
|
717 | - true |
|
718 | - ); |
|
719 | - $subscription->failing(); |
|
720 | - return; |
|
721 | - |
|
722 | - } |
|
723 | - |
|
724 | - // Process the response. |
|
725 | - $this->process_charge_response( $result, $new_invoice ); |
|
726 | - |
|
727 | - if ( wpinv_get_errors() ) { |
|
728 | - |
|
729 | - $old_invoice->add_note( |
|
730 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
731 | - true, |
|
732 | - false, |
|
733 | - true |
|
734 | - ); |
|
735 | - $subscription->failing(); |
|
736 | - return; |
|
706 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
707 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
708 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
709 | + |
|
710 | + // Do we have an error? |
|
711 | + if ( is_wp_error( $result ) ) { |
|
712 | + |
|
713 | + $old_invoice->add_note( |
|
714 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
715 | + true, |
|
716 | + false, |
|
717 | + true |
|
718 | + ); |
|
719 | + $subscription->failing(); |
|
720 | + return; |
|
721 | + |
|
722 | + } |
|
723 | + |
|
724 | + // Process the response. |
|
725 | + $this->process_charge_response( $result, $new_invoice ); |
|
726 | + |
|
727 | + if ( wpinv_get_errors() ) { |
|
728 | + |
|
729 | + $old_invoice->add_note( |
|
730 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
731 | + true, |
|
732 | + false, |
|
733 | + true |
|
734 | + ); |
|
735 | + $subscription->failing(); |
|
736 | + return; |
|
737 | 737 | |
738 | 738 | } |
739 | 739 | |
@@ -742,13 +742,13 @@ discard block |
||
742 | 742 | } |
743 | 743 | |
744 | 744 | /** |
745 | - * Processes invoice addons. |
|
746 | - * |
|
747 | - * @param WPInv_Invoice $invoice |
|
748 | - * @param GetPaid_Form_Item[] $items |
|
749 | - * @return WPInv_Invoice |
|
750 | - */ |
|
751 | - public function process_addons( $invoice, $items ) { |
|
745 | + * Processes invoice addons. |
|
746 | + * |
|
747 | + * @param WPInv_Invoice $invoice |
|
748 | + * @param GetPaid_Form_Item[] $items |
|
749 | + * @return WPInv_Invoice |
|
750 | + */ |
|
751 | + public function process_addons( $invoice, $items ) { |
|
752 | 752 | |
753 | 753 | global $getpaid_authorize_addons; |
754 | 754 | |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | $invoice->recalculate_total(); |
769 | 769 | |
770 | 770 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
771 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
771 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
772 | 772 | |
773 | 773 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
774 | 774 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -783,11 +783,11 @@ discard block |
||
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
786 | - * Processes invoice addons. |
|
787 | - * |
|
786 | + * Processes invoice addons. |
|
787 | + * |
|
788 | 788 | * @param array $args |
789 | - * @return array |
|
790 | - */ |
|
789 | + * @return array |
|
790 | + */ |
|
791 | 791 | public function filter_addons_request( $args ) { |
792 | 792 | |
793 | 793 | global $getpaid_authorize_addons; |
@@ -821,11 +821,11 @@ discard block |
||
821 | 821 | } |
822 | 822 | |
823 | 823 | /** |
824 | - * Filters the gateway settings. |
|
825 | - * |
|
826 | - * @param array $admin_settings |
|
827 | - */ |
|
828 | - public function admin_settings( $admin_settings ) { |
|
824 | + * Filters the gateway settings. |
|
825 | + * |
|
826 | + * @param array $admin_settings |
|
827 | + */ |
|
828 | + public function admin_settings( $admin_settings ) { |
|
829 | 829 | |
830 | 830 | $currencies = sprintf( |
831 | 831 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | 'readonly' => true, |
866 | 866 | ); |
867 | 867 | |
868 | - return $admin_settings; |
|
869 | - } |
|
868 | + return $admin_settings; |
|
869 | + } |
|
870 | 870 | |
871 | 871 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
27 | + protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @var array |
54 | 54 | */ |
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct() { |
68 | 68 | |
69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
71 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
71 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
72 | 72 | |
73 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
73 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
75 | 75 | parent::__construct(); |
76 | 76 | } |
77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param int $invoice_id 0 or invoice id. |
82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
83 | 83 | */ |
84 | - public function payment_fields( $invoice_id, $form ) { |
|
84 | + public function payment_fields($invoice_id, $form) { |
|
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
87 | 87 | echo $this->saved_payment_methods(); |
88 | 88 | |
89 | 89 | // Show the credit card entry form. |
90 | - echo $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
90 | + echo $this->new_payment_method_entry($this->get_cc_form(true)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -100,72 +100,72 @@ discard block |
||
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | 101 | * @return string|WP_Error Payment profile id. |
102 | 102 | */ |
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
107 | 107 | |
108 | 108 | // Generate args. |
109 | 109 | $args = array( |
110 | 110 | 'createCustomerProfileRequest' => array( |
111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
112 | 112 | 'profile' => array( |
113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
116 | 116 | 'paymentProfiles' => array( |
117 | 117 | 'customerType' => 'individual', |
118 | 118 | |
119 | 119 | // Billing information. |
120 | 120 | 'billTo' => array( |
121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
128 | 128 | ), |
129 | 129 | |
130 | 130 | // Payment information. |
131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
132 | 132 | ) |
133 | 133 | ), |
134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
135 | 135 | ) |
136 | 136 | ); |
137 | 137 | |
138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
140 | + if (is_wp_error($response)) { |
|
141 | 141 | |
142 | 142 | // In case the customer profile already exists remotely. |
143 | - if ( 'E00039' == $response->get_error_code() ) { |
|
144 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
145 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
146 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
143 | + if ('E00039' == $response->get_error_code()) { |
|
144 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
145 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
146 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | return $response; |
150 | 150 | } |
151 | 151 | |
152 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
152 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
153 | 153 | |
154 | 154 | // Save the payment token. |
155 | - if ( $save ) { |
|
155 | + if ($save) { |
|
156 | 156 | $this->save_token( |
157 | 157 | array( |
158 | 158 | 'id' => $response->customerPaymentProfileIdList[0], |
159 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
159 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
160 | 160 | 'default' => true, |
161 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
161 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
162 | 162 | ) |
163 | 163 | ); |
164 | 164 | } |
165 | 165 | |
166 | 166 | // Add a note about the validation response. |
167 | 167 | $invoice->add_note( |
168 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
168 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
169 | 169 | false, |
170 | 170 | false, |
171 | 171 | true |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return string|WP_Error Profile id. |
183 | 183 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
184 | 184 | */ |
185 | - public function get_customer_profile( $profile_id ) { |
|
185 | + public function get_customer_profile($profile_id) { |
|
186 | 186 | |
187 | 187 | // Generate args. |
188 | 188 | $args = array( |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | ) |
193 | 193 | ); |
194 | 194 | |
195 | - return $this->post( $args, false ); |
|
195 | + return $this->post($args, false); |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
208 | 208 | * @return string|WP_Error Profile id. |
209 | 209 | */ |
210 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
210 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
211 | 211 | |
212 | 212 | // Remove non-digits from the number |
213 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
213 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
214 | 214 | |
215 | 215 | // Prepare card details. |
216 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
216 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
217 | 217 | |
218 | 218 | // Authorize.NET does not support saving the same card twice. |
219 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
219 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
220 | 220 | |
221 | - if ( $cached_information ) { |
|
221 | + if ($cached_information) { |
|
222 | 222 | return $cached_information; |
223 | 223 | } |
224 | 224 | |
@@ -231,52 +231,52 @@ discard block |
||
231 | 231 | |
232 | 232 | // Billing information. |
233 | 233 | 'billTo' => array( |
234 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
235 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
236 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
237 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
238 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
239 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
240 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
234 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
235 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
236 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
237 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
238 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
239 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
240 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
241 | 241 | ), |
242 | 242 | |
243 | 243 | // Payment information. |
244 | 244 | 'payment' => $payment_information |
245 | 245 | ), |
246 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
246 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
247 | 247 | ) |
248 | 248 | ); |
249 | 249 | |
250 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
250 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
251 | 251 | |
252 | - if ( is_wp_error( $response ) ) { |
|
252 | + if (is_wp_error($response)) { |
|
253 | 253 | return $response; |
254 | 254 | } |
255 | 255 | |
256 | 256 | // Save the payment token. |
257 | - if ( $save ) { |
|
257 | + if ($save) { |
|
258 | 258 | $this->save_token( |
259 | 259 | array( |
260 | 260 | 'id' => $response->customerPaymentProfileId, |
261 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
261 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
262 | 262 | 'default' => true, |
263 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
263 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
264 | 264 | ) |
265 | 265 | ); |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Cache payment profile id. |
269 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
269 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
270 | 270 | |
271 | 271 | // Add a note about the validation response. |
272 | 272 | $invoice->add_note( |
273 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
273 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
274 | 274 | false, |
275 | 275 | false, |
276 | 276 | true |
277 | 277 | ); |
278 | 278 | |
279 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
279 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
280 | 280 | |
281 | 281 | return $response->customerPaymentProfileId; |
282 | 282 | } |
@@ -288,12 +288,12 @@ discard block |
||
288 | 288 | * @param array $payment_details. |
289 | 289 | * @return array|false Profile id. |
290 | 290 | */ |
291 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
291 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
292 | 292 | |
293 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
294 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
293 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
294 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
295 | 295 | |
296 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
296 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
297 | 297 | return false; |
298 | 298 | } |
299 | 299 | |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | 'getCustomerPaymentProfileRequest' => array( |
303 | 303 | 'merchantAuthentication' => $this->get_auth_params(), |
304 | 304 | 'customerProfileId' => $customer_profile, |
305 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
305 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
306 | 306 | ) |
307 | 307 | ); |
308 | 308 | |
309 | - $response = $this->post( $args, $invoice ); |
|
309 | + $response = $this->post($args, $invoice); |
|
310 | 310 | |
311 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
311 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
312 | 312 | |
313 | 313 | } |
314 | 314 | |
@@ -319,14 +319,14 @@ discard block |
||
319 | 319 | * @param array $payment_details. |
320 | 320 | * @param string $payment_profile_id. |
321 | 321 | */ |
322 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
322 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
323 | 323 | |
324 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
325 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
326 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
324 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
325 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
326 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
327 | 327 | |
328 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
329 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
328 | + $cached_information[$payment_details] = $payment_profile_id; |
|
329 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
330 | 330 | |
331 | 331 | } |
332 | 332 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @return string|WP_Error Profile id. |
340 | 340 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
341 | 341 | */ |
342 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
342 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
343 | 343 | |
344 | 344 | // Generate args. |
345 | 345 | $args = array( |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | ) |
351 | 351 | ); |
352 | 352 | |
353 | - return $this->post( $args, false ); |
|
353 | + return $this->post($args, false); |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
364 | 364 | * @return WP_Error|object |
365 | 365 | */ |
366 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
366 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
367 | 367 | |
368 | 368 | // Generate args. |
369 | 369 | $args = array( |
@@ -383,28 +383,28 @@ discard block |
||
383 | 383 | ) |
384 | 384 | ), |
385 | 385 | 'order' => array( |
386 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
386 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
387 | 387 | ), |
388 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
388 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
389 | 389 | 'tax' => array( |
390 | 390 | 'amount' => $invoice->get_total_tax(), |
391 | - 'name' => __( 'TAX', 'invoicing' ), |
|
391 | + 'name' => __('TAX', 'invoicing'), |
|
392 | 392 | ), |
393 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
393 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
394 | 394 | 'customer' => array( |
395 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
396 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
395 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
396 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
397 | 397 | ), |
398 | 398 | 'customerIP' => $invoice->get_ip(), |
399 | 399 | ) |
400 | 400 | ) |
401 | 401 | ); |
402 | 402 | |
403 | - if ( 0 == $invoice->get_total_tax() ) { |
|
404 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
403 | + if (0 == $invoice->get_total_tax()) { |
|
404 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
405 | 405 | } |
406 | 406 | |
407 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
407 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
408 | 408 | |
409 | 409 | } |
410 | 410 | |
@@ -414,29 +414,29 @@ discard block |
||
414 | 414 | * @param stdClass $result Api response. |
415 | 415 | * @param WPInv_Invoice $invoice Invoice. |
416 | 416 | */ |
417 | - public function process_charge_response( $result, $invoice ) { |
|
417 | + public function process_charge_response($result, $invoice) { |
|
418 | 418 | |
419 | 419 | wpinv_clear_errors(); |
420 | 420 | $response_code = (int) $result->transactionResponse->responseCode; |
421 | 421 | |
422 | 422 | // Succeeded. |
423 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
423 | + if (1 == $response_code || 4 == $response_code) { |
|
424 | 424 | |
425 | 425 | // Maybe set a transaction id. |
426 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
427 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
426 | + if (!empty($result->transactionResponse->transId)) { |
|
427 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
428 | 428 | } |
429 | 429 | |
430 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
430 | + $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
431 | 431 | |
432 | - if ( 1 == $response_code ) { |
|
432 | + if (1 == $response_code) { |
|
433 | 433 | return $invoice->mark_paid(); |
434 | 434 | } |
435 | 435 | |
436 | - $invoice->set_status( 'wpi-onhold' ); |
|
436 | + $invoice->set_status('wpi-onhold'); |
|
437 | 437 | $invoice->add_note( |
438 | 438 | sprintf( |
439 | - __( 'Held for review: %s', 'invoicing' ), |
|
439 | + __('Held for review: %s', 'invoicing'), |
|
440 | 440 | $result->transactionResponse->messages->message[0]->description |
441 | 441 | ) |
442 | 442 | ); |
@@ -445,11 +445,11 @@ discard block |
||
445 | 445 | |
446 | 446 | } |
447 | 447 | |
448 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
448 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
449 | 449 | |
450 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
450 | + if (!empty($result->transactionResponse->errors)) { |
|
451 | 451 | $errors = (object) $result->transactionResponse->errors; |
452 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
452 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | } |
@@ -461,10 +461,10 @@ discard block |
||
461 | 461 | * @param array $card Card details. |
462 | 462 | * @return array |
463 | 463 | */ |
464 | - public function get_payment_information( $card ) { |
|
464 | + public function get_payment_information($card) { |
|
465 | 465 | return array( |
466 | 466 | |
467 | - 'creditCard' => array ( |
|
467 | + 'creditCard' => array( |
|
468 | 468 | 'cardNumber' => $card['cc_number'], |
469 | 469 | 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'], |
470 | 470 | 'cardCode' => $card['cc_cvv2'], |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * @param WPInv_Invoice $invoice Invoice. |
481 | 481 | * @return string |
482 | 482 | */ |
483 | - public function get_customer_profile_meta_name( $invoice ) { |
|
484 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
483 | + public function get_customer_profile_meta_name($invoice) { |
|
484 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -492,34 +492,34 @@ discard block |
||
492 | 492 | * @param WPInv_Invoice $invoice |
493 | 493 | * @return WP_Error|string The payment profile id |
494 | 494 | */ |
495 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
495 | + public function validate_submission_data($submission_data, $invoice) { |
|
496 | 496 | |
497 | 497 | // Validate authentication details. |
498 | 498 | $auth = $this->get_auth_params(); |
499 | 499 | |
500 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
501 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') ); |
|
500 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
501 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | // Validate the payment method. |
505 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
506 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') ); |
|
505 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
506 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | // Are we adding a new payment method? |
510 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
510 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
511 | 511 | return $submission_data['getpaid-authorizenet-payment-method']; |
512 | 512 | } |
513 | 513 | |
514 | 514 | // Retrieve the customer profile id. |
515 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
515 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
516 | 516 | |
517 | 517 | // Create payment method. |
518 | - if ( empty( $profile_id ) ) { |
|
519 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
518 | + if (empty($profile_id)) { |
|
519 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
520 | 520 | } |
521 | 521 | |
522 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
522 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
523 | 523 | |
524 | 524 | } |
525 | 525 | |
@@ -530,32 +530,32 @@ discard block |
||
530 | 530 | * @param WPInv_Invoice $invoice Invoice. |
531 | 531 | * @return array |
532 | 532 | */ |
533 | - public function get_line_items( $invoice ) { |
|
533 | + public function get_line_items($invoice) { |
|
534 | 534 | $items = array(); |
535 | 535 | |
536 | - foreach ( $invoice->get_items() as $item ) { |
|
536 | + foreach ($invoice->get_items() as $item) { |
|
537 | 537 | |
538 | 538 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
539 | 539 | $items[] = array( |
540 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
541 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
542 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
543 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
540 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
541 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
542 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
543 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
544 | 544 | 'unitPrice' => (float) $amount, |
545 | 545 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
546 | 546 | ); |
547 | 547 | |
548 | 548 | } |
549 | 549 | |
550 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
550 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
551 | 551 | |
552 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
552 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
553 | 553 | |
554 | - if ( $amount > 0 ) { |
|
554 | + if ($amount > 0) { |
|
555 | 555 | $items[] = array( |
556 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
557 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
558 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
556 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
557 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
558 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
559 | 559 | 'quantity' => '1', |
560 | 560 | 'unitPrice' => (float) $amount, |
561 | 561 | 'taxable' => false, |
@@ -576,36 +576,36 @@ discard block |
||
576 | 576 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
577 | 577 | * @return array |
578 | 578 | */ |
579 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
579 | + public function process_payment($invoice, $submission_data, $submission) { |
|
580 | 580 | |
581 | 581 | // Validate the submitted data. |
582 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
582 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
583 | 583 | |
584 | 584 | // Do we have an error? |
585 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
586 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
587 | - wpinv_send_back_to_checkout( $invoice ); |
|
585 | + if (is_wp_error($payment_profile_id)) { |
|
586 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
587 | + wpinv_send_back_to_checkout($invoice); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | // Save the payment method to the order. |
591 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
591 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
592 | 592 | |
593 | 593 | // Check if this is a subscription or not. |
594 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
595 | - if ( ! empty( $subscriptions ) ) { |
|
596 | - $this->process_subscription( $invoice, $subscriptions ); |
|
594 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
595 | + if (!empty($subscriptions)) { |
|
596 | + $this->process_subscription($invoice, $subscriptions); |
|
597 | 597 | } |
598 | 598 | |
599 | 599 | // If it is free, send to the success page. |
600 | - if ( ! $invoice->needs_payment() ) { |
|
600 | + if (!$invoice->needs_payment()) { |
|
601 | 601 | $invoice->mark_paid(); |
602 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
602 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | // Charge the payment profile. |
606 | - $this->process_initial_payment( $invoice ); |
|
606 | + $this->process_initial_payment($invoice); |
|
607 | 607 | |
608 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
608 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
609 | 609 | |
610 | 610 | exit; |
611 | 611 | |
@@ -616,23 +616,23 @@ discard block |
||
616 | 616 | * |
617 | 617 | * @param WPInv_Invoice $invoice Invoice. |
618 | 618 | */ |
619 | - protected function process_initial_payment( $invoice ) { |
|
619 | + protected function process_initial_payment($invoice) { |
|
620 | 620 | |
621 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
622 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
623 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
621 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
622 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
623 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
624 | 624 | |
625 | 625 | // Do we have an error? |
626 | - if ( is_wp_error( $result ) ) { |
|
627 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
628 | - wpinv_send_back_to_checkout( $invoice ); |
|
626 | + if (is_wp_error($result)) { |
|
627 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
628 | + wpinv_send_back_to_checkout($invoice); |
|
629 | 629 | } |
630 | 630 | |
631 | 631 | // Process the response. |
632 | - $this->process_charge_response( $result, $invoice ); |
|
632 | + $this->process_charge_response($result, $invoice); |
|
633 | 633 | |
634 | - if ( wpinv_get_errors() ) { |
|
635 | - wpinv_send_back_to_checkout( $invoice ); |
|
634 | + if (wpinv_get_errors()) { |
|
635 | + wpinv_send_back_to_checkout($invoice); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | } |
@@ -643,30 +643,30 @@ discard block |
||
643 | 643 | * @param WPInv_Invoice $invoice Invoice. |
644 | 644 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
645 | 645 | */ |
646 | - public function process_subscription( $invoice, $subscriptions ) { |
|
646 | + public function process_subscription($invoice, $subscriptions) { |
|
647 | 647 | |
648 | 648 | // Check if there is an initial amount to charge. |
649 | - if ( (float) $invoice->get_total() > 0 ) { |
|
650 | - $this->process_initial_payment( $invoice ); |
|
649 | + if ((float) $invoice->get_total() > 0) { |
|
650 | + $this->process_initial_payment($invoice); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | // Activate the subscriptions. |
654 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
654 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
655 | 655 | |
656 | - foreach ( $subscriptions as $subscription ) { |
|
657 | - if ( $subscription->exists() ) { |
|
658 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
659 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
656 | + foreach ($subscriptions as $subscription) { |
|
657 | + if ($subscription->exists()) { |
|
658 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
659 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
660 | 660 | |
661 | - $subscription->set_next_renewal_date( $expiry ); |
|
662 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
663 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
661 | + $subscription->set_next_renewal_date($expiry); |
|
662 | + $subscription->set_date_created(current_time('mysql')); |
|
663 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
664 | 664 | $subscription->activate(); |
665 | 665 | } |
666 | 666 | } |
667 | 667 | |
668 | 668 | // Redirect to the success page. |
669 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
669 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
670 | 670 | |
671 | 671 | } |
672 | 672 | |
@@ -676,11 +676,11 @@ discard block |
||
676 | 676 | * |
677 | 677 | * @param WPInv_Subscription $subscription |
678 | 678 | */ |
679 | - public function maybe_renew_subscription( $subscription ) { |
|
679 | + public function maybe_renew_subscription($subscription) { |
|
680 | 680 | |
681 | 681 | // Ensure its our subscription && it's active. |
682 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
683 | - $this->renew_subscription( $subscription ); |
|
682 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
683 | + $this->renew_subscription($subscription); |
|
684 | 684 | } |
685 | 685 | |
686 | 686 | } |
@@ -690,28 +690,28 @@ discard block |
||
690 | 690 | * |
691 | 691 | * @param WPInv_Subscription $subscription |
692 | 692 | */ |
693 | - public function renew_subscription( $subscription ) { |
|
693 | + public function renew_subscription($subscription) { |
|
694 | 694 | |
695 | 695 | // Generate the renewal invoice. |
696 | 696 | $new_invoice = $subscription->create_payment(); |
697 | 697 | $old_invoice = $subscription->get_parent_payment(); |
698 | 698 | |
699 | - if ( empty( $new_invoice ) ) { |
|
700 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
699 | + if (empty($new_invoice)) { |
|
700 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
701 | 701 | $subscription->failing(); |
702 | 702 | return; |
703 | 703 | } |
704 | 704 | |
705 | 705 | // Charge the payment method. |
706 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
707 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
708 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
706 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
707 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
708 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
709 | 709 | |
710 | 710 | // Do we have an error? |
711 | - if ( is_wp_error( $result ) ) { |
|
711 | + if (is_wp_error($result)) { |
|
712 | 712 | |
713 | 713 | $old_invoice->add_note( |
714 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
714 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
715 | 715 | true, |
716 | 716 | false, |
717 | 717 | true |
@@ -722,12 +722,12 @@ discard block |
||
722 | 722 | } |
723 | 723 | |
724 | 724 | // Process the response. |
725 | - $this->process_charge_response( $result, $new_invoice ); |
|
725 | + $this->process_charge_response($result, $new_invoice); |
|
726 | 726 | |
727 | - if ( wpinv_get_errors() ) { |
|
727 | + if (wpinv_get_errors()) { |
|
728 | 728 | |
729 | 729 | $old_invoice->add_note( |
730 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
730 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
731 | 731 | true, |
732 | 732 | false, |
733 | 733 | true |
@@ -737,7 +737,7 @@ discard block |
||
737 | 737 | |
738 | 738 | } |
739 | 739 | |
740 | - $subscription->add_payment( array(), $new_invoice ); |
|
740 | + $subscription->add_payment(array(), $new_invoice); |
|
741 | 741 | $subscription->renew(); |
742 | 742 | } |
743 | 743 | |
@@ -748,34 +748,34 @@ discard block |
||
748 | 748 | * @param GetPaid_Form_Item[] $items |
749 | 749 | * @return WPInv_Invoice |
750 | 750 | */ |
751 | - public function process_addons( $invoice, $items ) { |
|
751 | + public function process_addons($invoice, $items) { |
|
752 | 752 | |
753 | 753 | global $getpaid_authorize_addons; |
754 | 754 | |
755 | 755 | $getpaid_authorize_addons = array(); |
756 | - foreach ( $items as $item ) { |
|
756 | + foreach ($items as $item) { |
|
757 | 757 | |
758 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
758 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
759 | 759 | $getpaid_authorize_addons[] = $item; |
760 | 760 | } |
761 | 761 | |
762 | 762 | } |
763 | 763 | |
764 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
764 | + if (empty($getpaid_authorize_addons)) { |
|
765 | 765 | return; |
766 | 766 | } |
767 | 767 | |
768 | 768 | $invoice->recalculate_total(); |
769 | 769 | |
770 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
771 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
770 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
771 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
772 | 772 | |
773 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
774 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
775 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
773 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
774 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
775 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
776 | 776 | |
777 | - if ( is_wp_error( $result ) ) { |
|
778 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
777 | + if (is_wp_error($result)) { |
|
778 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
779 | 779 | return; |
780 | 780 | } |
781 | 781 | |
@@ -788,19 +788,19 @@ discard block |
||
788 | 788 | * @param array $args |
789 | 789 | * @return array |
790 | 790 | */ |
791 | - public function filter_addons_request( $args ) { |
|
791 | + public function filter_addons_request($args) { |
|
792 | 792 | |
793 | 793 | global $getpaid_authorize_addons; |
794 | 794 | $total = 0; |
795 | 795 | |
796 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
796 | + foreach ($getpaid_authorize_addons as $addon) { |
|
797 | 797 | $total += $addon->get_sub_total(); |
798 | 798 | } |
799 | 799 | |
800 | 800 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
801 | 801 | |
802 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
803 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
802 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
803 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | return $args; |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | public function sandbox_notice() { |
814 | 814 | |
815 | 815 | return sprintf( |
816 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
816 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
817 | 817 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
818 | 818 | '</a>' |
819 | 819 | ); |
@@ -825,42 +825,42 @@ discard block |
||
825 | 825 | * |
826 | 826 | * @param array $admin_settings |
827 | 827 | */ |
828 | - public function admin_settings( $admin_settings ) { |
|
828 | + public function admin_settings($admin_settings) { |
|
829 | 829 | |
830 | 830 | $currencies = sprintf( |
831 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
832 | - implode( ', ', $this->currencies ) |
|
831 | + __('Supported Currencies: %s', 'invoicing'), |
|
832 | + implode(', ', $this->currencies) |
|
833 | 833 | ); |
834 | 834 | |
835 | 835 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
836 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
836 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
837 | 837 | |
838 | 838 | $admin_settings['authorizenet_login_id'] = array( |
839 | 839 | 'type' => 'text', |
840 | 840 | 'id' => 'authorizenet_login_id', |
841 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
842 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
841 | + 'name' => __('API Login ID', 'invoicing'), |
|
842 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
843 | 843 | ); |
844 | 844 | |
845 | 845 | $admin_settings['authorizenet_transaction_key'] = array( |
846 | 846 | 'type' => 'text', |
847 | 847 | 'id' => 'authorizenet_transaction_key', |
848 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
848 | + 'name' => __('Transaction Key', 'invoicing'), |
|
849 | 849 | ); |
850 | 850 | |
851 | 851 | $admin_settings['authorizenet_signature_key'] = array( |
852 | 852 | 'type' => 'text', |
853 | 853 | 'id' => 'authorizenet_signature_key', |
854 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
855 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
854 | + 'name' => __('Signature Key', 'invoicing'), |
|
855 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
856 | 856 | ); |
857 | 857 | |
858 | 858 | $admin_settings['authorizenet_ipn_url'] = array( |
859 | 859 | 'type' => 'ipn_url', |
860 | 860 | 'id' => 'authorizenet_ipn_url', |
861 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
861 | + 'name' => __('Webhook URL', 'invoicing'), |
|
862 | 862 | 'std' => $this->notify_url, |
863 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
863 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
864 | 864 | 'custom' => 'authorizenet', |
865 | 865 | 'readonly' => true, |
866 | 866 | ); |