@@ -46,64 +46,64 @@ discard block |
||
46 | 46 | <td style="width: 65%"> |
47 | 47 | <?php |
48 | 48 | |
49 | - switch ( $key ) { |
|
49 | + switch ( $key ) { |
|
50 | 50 | |
51 | - case 'status': |
|
52 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
53 | - break; |
|
51 | + case 'status': |
|
52 | + echo sanitize_text_field( $subscription->get_status_label() ); |
|
53 | + break; |
|
54 | 54 | |
55 | - case 'start_date': |
|
56 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
57 | - break; |
|
55 | + case 'start_date': |
|
56 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
57 | + break; |
|
58 | 58 | |
59 | - case 'expiry_date': |
|
60 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
61 | - break; |
|
59 | + case 'expiry_date': |
|
60 | + echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
61 | + break; |
|
62 | 62 | |
63 | - case 'initial_amount': |
|
64 | - echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
63 | + case 'initial_amount': |
|
64 | + echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
65 | 65 | |
66 | - if ( $subscription->has_trial_period() ) { |
|
66 | + if ( $subscription->has_trial_period() ) { |
|
67 | 67 | |
68 | - echo "<small class='text-muted'> "; |
|
69 | - printf( |
|
70 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
71 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
72 | - ); |
|
73 | - echo '</small>'; |
|
68 | + echo "<small class='text-muted'> "; |
|
69 | + printf( |
|
70 | + _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
71 | + sanitize_text_field( $subscription->get_trial_period() ) |
|
72 | + ); |
|
73 | + echo '</small>'; |
|
74 | 74 | |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | - break; |
|
77 | + break; |
|
78 | 78 | |
79 | - case 'recurring_amount': |
|
80 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
81 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
82 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ); |
|
83 | - break; |
|
79 | + case 'recurring_amount': |
|
80 | + $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
81 | + $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
82 | + echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ); |
|
83 | + break; |
|
84 | 84 | |
85 | - case 'item': |
|
85 | + case 'item': |
|
86 | 86 | |
87 | - if ( empty( $subscription_group ) ) { |
|
88 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
89 | - } else { |
|
90 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
91 | - echo implode( ' | ', $markup ); |
|
92 | - } |
|
87 | + if ( empty( $subscription_group ) ) { |
|
88 | + echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
89 | + } else { |
|
90 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
91 | + echo implode( ' | ', $markup ); |
|
92 | + } |
|
93 | 93 | |
94 | - break; |
|
94 | + break; |
|
95 | 95 | |
96 | - case 'payments': |
|
96 | + case 'payments': |
|
97 | 97 | |
98 | - $max_activations = (int) $subscription->get_bill_times(); |
|
99 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
98 | + $max_activations = (int) $subscription->get_bill_times(); |
|
99 | + echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
100 | 100 | |
101 | - break; |
|
101 | + break; |
|
102 | 102 | |
103 | - } |
|
104 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
103 | + } |
|
104 | + do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
105 | 105 | |
106 | - ?> |
|
106 | + ?> |
|
107 | 107 | </td> |
108 | 108 | |
109 | 109 | </tr> |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | <span class="form-text"> |
131 | 131 | |
132 | 132 | <?php |
133 | - if ( $subscription->can_cancel() ) { |
|
134 | - printf( |
|
135 | - '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
136 | - esc_url( $subscription->get_cancel_url() ), |
|
137 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
138 | - __( 'Cancel Subscription', 'invoicing' ) |
|
139 | - ); |
|
140 | - } |
|
141 | - |
|
142 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
143 | - ?> |
|
133 | + if ( $subscription->can_cancel() ) { |
|
134 | + printf( |
|
135 | + '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
|
136 | + esc_url( $subscription->get_cancel_url() ), |
|
137 | + esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
138 | + __( 'Cancel Subscription', 'invoicing' ) |
|
139 | + ); |
|
140 | + } |
|
141 | + |
|
142 | + do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
143 | + ?> |
|
144 | 144 | |
145 | 145 | <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
146 | 146 | </span> |
@@ -9,17 +9,17 @@ discard block |
||
9 | 9 | * @var WPInv_Subscriptions_Widget $widget |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | -do_action( 'getpaid_single_subscription_before_notices', $subscription ); |
|
14 | +do_action('getpaid_single_subscription_before_notices', $subscription); |
|
15 | 15 | |
16 | 16 | // Display errors and notices. |
17 | 17 | wpinv_print_errors(); |
18 | 18 | |
19 | -$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_invoice_id() ); |
|
20 | -$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
19 | +$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_invoice_id()); |
|
20 | +$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
21 | 21 | |
22 | -do_action( 'getpaid_before_single_subscription', $subscription, $subscription_groups ); |
|
22 | +do_action('getpaid_before_single_subscription', $subscription, $subscription_groups); |
|
23 | 23 | |
24 | 24 | ?> |
25 | 25 | |
@@ -31,44 +31,44 @@ discard block |
||
31 | 31 | |
32 | 32 | </style> |
33 | 33 | |
34 | -<h2 class="mb-1 h4"><?php _e( 'Subscription Details', 'invoicing' ); ?></h2> |
|
34 | +<h2 class="mb-1 h4"><?php _e('Subscription Details', 'invoicing'); ?></h2> |
|
35 | 35 | <table class="table table-bordered"> |
36 | 36 | <tbody> |
37 | 37 | |
38 | - <?php foreach ( $widget->get_single_subscription_columns( $subscription ) as $key => $label ) : ?> |
|
38 | + <?php foreach ($widget->get_single_subscription_columns($subscription) as $key => $label) : ?> |
|
39 | 39 | |
40 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
40 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
41 | 41 | |
42 | 42 | <th class="font-weight-bold" style="width: 35%"> |
43 | - <?php echo sanitize_text_field( $label ); ?> |
|
43 | + <?php echo sanitize_text_field($label); ?> |
|
44 | 44 | </th> |
45 | 45 | |
46 | 46 | <td style="width: 65%"> |
47 | 47 | <?php |
48 | 48 | |
49 | - switch ( $key ) { |
|
49 | + switch ($key) { |
|
50 | 50 | |
51 | 51 | case 'status': |
52 | - echo sanitize_text_field( $subscription->get_status_label() ); |
|
52 | + echo sanitize_text_field($subscription->get_status_label()); |
|
53 | 53 | break; |
54 | 54 | |
55 | 55 | case 'start_date': |
56 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_date_created() ) ); |
|
56 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_date_created())); |
|
57 | 57 | break; |
58 | 58 | |
59 | 59 | case 'expiry_date': |
60 | - echo sanitize_text_field( getpaid_format_date_value( $subscription->get_next_renewal_date() ) ); |
|
60 | + echo sanitize_text_field(getpaid_format_date_value($subscription->get_next_renewal_date())); |
|
61 | 61 | break; |
62 | 62 | |
63 | 63 | case 'initial_amount': |
64 | - echo wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
64 | + echo wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
65 | 65 | |
66 | - if ( $subscription->has_trial_period() ) { |
|
66 | + if ($subscription->has_trial_period()) { |
|
67 | 67 | |
68 | 68 | echo "<small class='text-muted'> "; |
69 | 69 | printf( |
70 | - _x( '( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing' ), |
|
71 | - sanitize_text_field( $subscription->get_trial_period() ) |
|
70 | + _x('( %1$s trial )', 'Subscription trial period. (e.g.: 1 month trial)', 'invoicing'), |
|
71 | + sanitize_text_field($subscription->get_trial_period()) |
|
72 | 72 | ); |
73 | 73 | echo '</small>'; |
74 | 74 | |
@@ -77,18 +77,18 @@ discard block |
||
77 | 77 | break; |
78 | 78 | |
79 | 79 | case 'recurring_amount': |
80 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
81 | - $amount = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
82 | - echo strtolower( "<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>" ); |
|
80 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
81 | + $amount = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
82 | + echo strtolower("<strong style='font-weight: 500;'>$amount</strong> / <span class='getpaid-item-recurring-period'>$frequency</span>"); |
|
83 | 83 | break; |
84 | 84 | |
85 | 85 | case 'item': |
86 | 86 | |
87 | - if ( empty( $subscription_group ) ) { |
|
88 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
87 | + if (empty($subscription_group)) { |
|
88 | + echo WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id()); |
|
89 | 89 | } else { |
90 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
91 | - echo implode( ' | ', $markup ); |
|
90 | + $markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
91 | + echo implode(' | ', $markup); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | break; |
@@ -96,12 +96,12 @@ discard block |
||
96 | 96 | case 'payments': |
97 | 97 | |
98 | 98 | $max_activations = (int) $subscription->get_bill_times(); |
99 | - echo (int) $subscription->get_times_billed() . ' / ' . ( empty( $max_activations ) ? "∞" : $max_activations ); |
|
99 | + echo (int) $subscription->get_times_billed() . ' / ' . (empty($max_activations) ? "∞" : $max_activations); |
|
100 | 100 | |
101 | 101 | break; |
102 | 102 | |
103 | 103 | } |
104 | - do_action( "getpaid_render_single_subscription_column_$key", $subscription ); |
|
104 | + do_action("getpaid_render_single_subscription_column_$key", $subscription); |
|
105 | 105 | |
106 | 106 | ?> |
107 | 107 | </td> |
@@ -113,34 +113,34 @@ discard block |
||
113 | 113 | </tbody> |
114 | 114 | </table> |
115 | 115 | |
116 | -<?php if ( ! empty( $subscription_group ) ) : ?> |
|
117 | - <h2 class='mt-5 mb-1 h4'><?php _e( 'Subscription Items', 'invoicing' ); ?></h2> |
|
118 | - <?php getpaid_admin_subscription_item_details_metabox( $subscription ); ?> |
|
116 | +<?php if (!empty($subscription_group)) : ?> |
|
117 | + <h2 class='mt-5 mb-1 h4'><?php _e('Subscription Items', 'invoicing'); ?></h2> |
|
118 | + <?php getpaid_admin_subscription_item_details_metabox($subscription); ?> |
|
119 | 119 | <?php endif; ?> |
120 | 120 | |
121 | -<h2 class='mt-5 mb-1 h4'><?php _e( 'Related Invoices', 'invoicing' ); ?></h2> |
|
121 | +<h2 class='mt-5 mb-1 h4'><?php _e('Related Invoices', 'invoicing'); ?></h2> |
|
122 | 122 | |
123 | -<?php echo getpaid_admin_subscription_invoice_details_metabox( $subscription ); ?> |
|
123 | +<?php echo getpaid_admin_subscription_invoice_details_metabox($subscription); ?> |
|
124 | 124 | |
125 | -<?php if ( 1 < count( $subscription_groups ) ) : ?> |
|
126 | - <h2 class='mt-5 mb-1 h4'><?php _e( 'Related Subscriptions', 'invoicing' ); ?></h2> |
|
127 | - <?php getpaid_admin_subscription_related_subscriptions_metabox( $subscription ); ?> |
|
125 | +<?php if (1 < count($subscription_groups)) : ?> |
|
126 | + <h2 class='mt-5 mb-1 h4'><?php _e('Related Subscriptions', 'invoicing'); ?></h2> |
|
127 | + <?php getpaid_admin_subscription_related_subscriptions_metabox($subscription); ?> |
|
128 | 128 | <?php endif; ?> |
129 | 129 | |
130 | 130 | <span class="form-text"> |
131 | 131 | |
132 | 132 | <?php |
133 | - if ( $subscription->can_cancel() ) { |
|
133 | + if ($subscription->can_cancel()) { |
|
134 | 134 | printf( |
135 | 135 | '<a href="%s" class="btn btn-danger btn-sm" onclick="return confirm(\'%s\')">%s</a> ', |
136 | - esc_url( $subscription->get_cancel_url() ), |
|
137 | - esc_attr__( 'Are you sure you want to cancel this subscription?', 'invoicing' ), |
|
138 | - __( 'Cancel Subscription', 'invoicing' ) |
|
136 | + esc_url($subscription->get_cancel_url()), |
|
137 | + esc_attr__('Are you sure you want to cancel this subscription?', 'invoicing'), |
|
138 | + __('Cancel Subscription', 'invoicing') |
|
139 | 139 | ); |
140 | 140 | } |
141 | 141 | |
142 | - do_action( 'getpaid-single-subscription-page-actions', $subscription ); |
|
142 | + do_action('getpaid-single-subscription-page-actions', $subscription); |
|
143 | 143 | ?> |
144 | 144 | |
145 | - <a href="<?php echo esc_url( getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); ?>" class="btn btn-secondary btn-sm"><?php _e( 'Go Back', 'invoicing' ); ?></a> |
|
145 | + <a href="<?php echo esc_url(getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')))); ?>" class="btn btn-secondary btn-sm"><?php _e('Go Back', 'invoicing'); ?></a> |
|
146 | 146 | </span> |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,206 +10,206 @@ discard block |
||
10 | 10 | class GetPaid_Payment_Form_Submission { |
11 | 11 | |
12 | 12 | /** |
13 | - * Submission ID |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * The raw submission data. |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $data = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * Submission totals |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $totals = array( |
|
32 | - |
|
33 | - 'subtotal' => array( |
|
34 | - 'initial' => 0, |
|
35 | - 'recurring' => 0, |
|
36 | - ), |
|
37 | - |
|
38 | - 'discount' => array( |
|
39 | - 'initial' => 0, |
|
40 | - 'recurring' => 0, |
|
41 | - ), |
|
42 | - |
|
43 | - 'fees' => array( |
|
44 | - 'initial' => 0, |
|
45 | - 'recurring' => 0, |
|
46 | - ), |
|
47 | - |
|
48 | - 'taxes' => array( |
|
49 | - 'initial' => 0, |
|
50 | - 'recurring' => 0, |
|
51 | - ), |
|
52 | - |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * Sets the associated payment form. |
|
57 | - * |
|
58 | - * @var GetPaid_Payment_Form |
|
59 | - */ |
|
13 | + * Submission ID |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * The raw submission data. |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $data = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * Submission totals |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $totals = array( |
|
32 | + |
|
33 | + 'subtotal' => array( |
|
34 | + 'initial' => 0, |
|
35 | + 'recurring' => 0, |
|
36 | + ), |
|
37 | + |
|
38 | + 'discount' => array( |
|
39 | + 'initial' => 0, |
|
40 | + 'recurring' => 0, |
|
41 | + ), |
|
42 | + |
|
43 | + 'fees' => array( |
|
44 | + 'initial' => 0, |
|
45 | + 'recurring' => 0, |
|
46 | + ), |
|
47 | + |
|
48 | + 'taxes' => array( |
|
49 | + 'initial' => 0, |
|
50 | + 'recurring' => 0, |
|
51 | + ), |
|
52 | + |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * Sets the associated payment form. |
|
57 | + * |
|
58 | + * @var GetPaid_Payment_Form |
|
59 | + */ |
|
60 | 60 | protected $payment_form = null; |
61 | 61 | |
62 | 62 | /** |
63 | - * The country for the submission. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $country = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The state for the submission. |
|
71 | - * |
|
72 | - * @since 1.0.19 |
|
73 | - * @var string |
|
74 | - */ |
|
75 | - public $state = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * The invoice associated with the submission. |
|
79 | - * |
|
80 | - * @var WPInv_Invoice |
|
81 | - */ |
|
82 | - protected $invoice = null; |
|
83 | - |
|
84 | - /** |
|
85 | - * The recurring item for the submission. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - public $has_recurring = 0; |
|
90 | - |
|
91 | - /** |
|
92 | - * The subscription groups. If more than 2, ensure the gateway |
|
93 | - * supports multiple subscriptions. |
|
94 | - * |
|
95 | - * @var array |
|
96 | - */ |
|
97 | - public $subscription_groups = array(); |
|
98 | - |
|
99 | - /** |
|
100 | - * An array of fees for the submission. |
|
101 | - * |
|
102 | - * @var array |
|
103 | - */ |
|
104 | - protected $fees = array(); |
|
105 | - |
|
106 | - /** |
|
107 | - * An array of discounts for the submission. |
|
108 | - * |
|
109 | - * @var array |
|
110 | - */ |
|
111 | - protected $discounts = array(); |
|
112 | - |
|
113 | - /** |
|
114 | - * An array of taxes for the submission. |
|
115 | - * |
|
116 | - * @var array |
|
117 | - */ |
|
118 | - protected $taxes = array(); |
|
119 | - |
|
120 | - /** |
|
121 | - * An array of items for the submission. |
|
122 | - * |
|
123 | - * @var GetPaid_Form_Item[] |
|
124 | - */ |
|
125 | - protected $items = array(); |
|
126 | - |
|
127 | - /** |
|
128 | - * The last error. |
|
129 | - * |
|
130 | - * @var string |
|
131 | - */ |
|
132 | - public $last_error = null; |
|
133 | - |
|
134 | - /** |
|
135 | - * The last error code. |
|
136 | - * |
|
137 | - * @var string |
|
138 | - */ |
|
139 | - public $last_error_code = null; |
|
140 | - |
|
141 | - /** |
|
142 | - * Class constructor. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function __construct() { |
|
146 | - |
|
147 | - // Set the state and country to the default state and country. |
|
148 | - $this->country = wpinv_default_billing_country(); |
|
149 | - $this->state = wpinv_get_default_state(); |
|
150 | - |
|
151 | - // Do we have an actual submission? |
|
152 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
153 | - $this->load_data( $_POST ); |
|
154 | - } |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Loads submission data. |
|
160 | - * |
|
161 | - * @param array $data |
|
162 | - */ |
|
163 | - public function load_data( $data ) { |
|
164 | - |
|
165 | - // Remove slashes from the submitted data... |
|
166 | - $data = wp_unslash( $data ); |
|
167 | - |
|
168 | - // Allow plugins to filter the data. |
|
169 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
170 | - |
|
171 | - // Cache it... |
|
172 | - $this->data = $data; |
|
173 | - |
|
174 | - // Then generate a unique id from the data. |
|
175 | - $this->id = md5( wp_json_encode( $data ) ); |
|
176 | - |
|
177 | - // Finally, process the submission. |
|
178 | - try { |
|
179 | - |
|
180 | - // Each process is passed an instance of the class (with reference) |
|
181 | - // and should throw an Exception whenever it encounters one. |
|
182 | - $processors = apply_filters( |
|
183 | - 'getpaid_payment_form_submission_processors', |
|
184 | - array( |
|
185 | - array( $this, 'process_payment_form' ), |
|
186 | - array( $this, 'process_invoice' ), |
|
187 | - array( $this, 'process_fees' ), |
|
188 | - array( $this, 'process_items' ), |
|
189 | - array( $this, 'process_discount' ), |
|
190 | - array( $this, 'process_taxes' ), |
|
191 | - ), |
|
192 | - $this |
|
193 | - ); |
|
194 | - |
|
195 | - foreach ( $processors as $processor ) { |
|
196 | - call_user_func_array( $processor, array( &$this ) ); |
|
197 | - } |
|
198 | - |
|
199 | - } catch( GetPaid_Payment_Exception $e ) { |
|
200 | - $this->last_error = $e->getMessage(); |
|
201 | - $this->last_error_code = $e->getErrorCode(); |
|
202 | - } catch ( Exception $e ) { |
|
203 | - $this->last_error = $e->getMessage(); |
|
204 | - $this->last_error_code = $e->getCode(); |
|
205 | - } |
|
206 | - |
|
207 | - // Fired when we are done processing a submission. |
|
208 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - /* |
|
63 | + * The country for the submission. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $country = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The state for the submission. |
|
71 | + * |
|
72 | + * @since 1.0.19 |
|
73 | + * @var string |
|
74 | + */ |
|
75 | + public $state = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * The invoice associated with the submission. |
|
79 | + * |
|
80 | + * @var WPInv_Invoice |
|
81 | + */ |
|
82 | + protected $invoice = null; |
|
83 | + |
|
84 | + /** |
|
85 | + * The recurring item for the submission. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + public $has_recurring = 0; |
|
90 | + |
|
91 | + /** |
|
92 | + * The subscription groups. If more than 2, ensure the gateway |
|
93 | + * supports multiple subscriptions. |
|
94 | + * |
|
95 | + * @var array |
|
96 | + */ |
|
97 | + public $subscription_groups = array(); |
|
98 | + |
|
99 | + /** |
|
100 | + * An array of fees for the submission. |
|
101 | + * |
|
102 | + * @var array |
|
103 | + */ |
|
104 | + protected $fees = array(); |
|
105 | + |
|
106 | + /** |
|
107 | + * An array of discounts for the submission. |
|
108 | + * |
|
109 | + * @var array |
|
110 | + */ |
|
111 | + protected $discounts = array(); |
|
112 | + |
|
113 | + /** |
|
114 | + * An array of taxes for the submission. |
|
115 | + * |
|
116 | + * @var array |
|
117 | + */ |
|
118 | + protected $taxes = array(); |
|
119 | + |
|
120 | + /** |
|
121 | + * An array of items for the submission. |
|
122 | + * |
|
123 | + * @var GetPaid_Form_Item[] |
|
124 | + */ |
|
125 | + protected $items = array(); |
|
126 | + |
|
127 | + /** |
|
128 | + * The last error. |
|
129 | + * |
|
130 | + * @var string |
|
131 | + */ |
|
132 | + public $last_error = null; |
|
133 | + |
|
134 | + /** |
|
135 | + * The last error code. |
|
136 | + * |
|
137 | + * @var string |
|
138 | + */ |
|
139 | + public $last_error_code = null; |
|
140 | + |
|
141 | + /** |
|
142 | + * Class constructor. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function __construct() { |
|
146 | + |
|
147 | + // Set the state and country to the default state and country. |
|
148 | + $this->country = wpinv_default_billing_country(); |
|
149 | + $this->state = wpinv_get_default_state(); |
|
150 | + |
|
151 | + // Do we have an actual submission? |
|
152 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
153 | + $this->load_data( $_POST ); |
|
154 | + } |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Loads submission data. |
|
160 | + * |
|
161 | + * @param array $data |
|
162 | + */ |
|
163 | + public function load_data( $data ) { |
|
164 | + |
|
165 | + // Remove slashes from the submitted data... |
|
166 | + $data = wp_unslash( $data ); |
|
167 | + |
|
168 | + // Allow plugins to filter the data. |
|
169 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
170 | + |
|
171 | + // Cache it... |
|
172 | + $this->data = $data; |
|
173 | + |
|
174 | + // Then generate a unique id from the data. |
|
175 | + $this->id = md5( wp_json_encode( $data ) ); |
|
176 | + |
|
177 | + // Finally, process the submission. |
|
178 | + try { |
|
179 | + |
|
180 | + // Each process is passed an instance of the class (with reference) |
|
181 | + // and should throw an Exception whenever it encounters one. |
|
182 | + $processors = apply_filters( |
|
183 | + 'getpaid_payment_form_submission_processors', |
|
184 | + array( |
|
185 | + array( $this, 'process_payment_form' ), |
|
186 | + array( $this, 'process_invoice' ), |
|
187 | + array( $this, 'process_fees' ), |
|
188 | + array( $this, 'process_items' ), |
|
189 | + array( $this, 'process_discount' ), |
|
190 | + array( $this, 'process_taxes' ), |
|
191 | + ), |
|
192 | + $this |
|
193 | + ); |
|
194 | + |
|
195 | + foreach ( $processors as $processor ) { |
|
196 | + call_user_func_array( $processor, array( &$this ) ); |
|
197 | + } |
|
198 | + |
|
199 | + } catch( GetPaid_Payment_Exception $e ) { |
|
200 | + $this->last_error = $e->getMessage(); |
|
201 | + $this->last_error_code = $e->getErrorCode(); |
|
202 | + } catch ( Exception $e ) { |
|
203 | + $this->last_error = $e->getMessage(); |
|
204 | + $this->last_error_code = $e->getCode(); |
|
205 | + } |
|
206 | + |
|
207 | + // Fired when we are done processing a submission. |
|
208 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + /* |
|
213 | 213 | |-------------------------------------------------------------------------- |
214 | 214 | | Payment Forms. |
215 | 215 | |-------------------------------------------------------------------------- |
@@ -218,39 +218,39 @@ discard block |
||
218 | 218 | | submission has an active payment form etc. |
219 | 219 | */ |
220 | 220 | |
221 | - /** |
|
222 | - * Prepares the submission's payment form. |
|
223 | - * |
|
224 | - * @since 1.0.19 |
|
225 | - */ |
|
226 | - public function process_payment_form() { |
|
221 | + /** |
|
222 | + * Prepares the submission's payment form. |
|
223 | + * |
|
224 | + * @since 1.0.19 |
|
225 | + */ |
|
226 | + public function process_payment_form() { |
|
227 | 227 | |
228 | - // Every submission needs an active payment form. |
|
229 | - if ( empty( $this->data['form_id'] ) ) { |
|
230 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
231 | - } |
|
228 | + // Every submission needs an active payment form. |
|
229 | + if ( empty( $this->data['form_id'] ) ) { |
|
230 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
231 | + } |
|
232 | 232 | |
233 | - // Fetch the payment form. |
|
234 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
233 | + // Fetch the payment form. |
|
234 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
235 | 235 | |
236 | - if ( ! $this->payment_form->is_active() ) { |
|
237 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
238 | - } |
|
236 | + if ( ! $this->payment_form->is_active() ) { |
|
237 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
238 | + } |
|
239 | 239 | |
240 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
241 | - } |
|
240 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
241 | + } |
|
242 | 242 | |
243 | 243 | /** |
244 | - * Returns the payment form. |
|
245 | - * |
|
246 | - * @since 1.0.19 |
|
247 | - * @return GetPaid_Payment_Form |
|
248 | - */ |
|
249 | - public function get_payment_form() { |
|
250 | - return $this->payment_form; |
|
251 | - } |
|
244 | + * Returns the payment form. |
|
245 | + * |
|
246 | + * @since 1.0.19 |
|
247 | + * @return GetPaid_Payment_Form |
|
248 | + */ |
|
249 | + public function get_payment_form() { |
|
250 | + return $this->payment_form; |
|
251 | + } |
|
252 | 252 | |
253 | - /* |
|
253 | + /* |
|
254 | 254 | |-------------------------------------------------------------------------- |
255 | 255 | | Invoices. |
256 | 256 | |-------------------------------------------------------------------------- |
@@ -259,84 +259,84 @@ discard block |
||
259 | 259 | | might be for an existing invoice. |
260 | 260 | */ |
261 | 261 | |
262 | - /** |
|
263 | - * Prepares the submission's invoice. |
|
264 | - * |
|
265 | - * @since 1.0.19 |
|
266 | - */ |
|
267 | - public function process_invoice() { |
|
262 | + /** |
|
263 | + * Prepares the submission's invoice. |
|
264 | + * |
|
265 | + * @since 1.0.19 |
|
266 | + */ |
|
267 | + public function process_invoice() { |
|
268 | 268 | |
269 | - // Abort if there is no invoice. |
|
270 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
271 | - return; |
|
272 | - } |
|
269 | + // Abort if there is no invoice. |
|
270 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
271 | + return; |
|
272 | + } |
|
273 | 273 | |
274 | - // If the submission is for an existing invoice, ensure that it exists |
|
275 | - // and that it is not paid for. |
|
276 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
274 | + // If the submission is for an existing invoice, ensure that it exists |
|
275 | + // and that it is not paid for. |
|
276 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
277 | 277 | |
278 | 278 | if ( empty( $invoice ) ) { |
279 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
280 | - } |
|
279 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
280 | + } |
|
281 | 281 | |
282 | - if ( $invoice->is_paid() ) { |
|
283 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
284 | - } |
|
282 | + if ( $invoice->is_paid() ) { |
|
283 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
284 | + } |
|
285 | 285 | |
286 | - $this->payment_form->invoice = $invoice; |
|
287 | - if ( ! $this->payment_form->is_default() ) { |
|
286 | + $this->payment_form->invoice = $invoice; |
|
287 | + if ( ! $this->payment_form->is_default() ) { |
|
288 | 288 | |
289 | - $items = array(); |
|
290 | - $item_ids = array(); |
|
289 | + $items = array(); |
|
290 | + $item_ids = array(); |
|
291 | 291 | |
292 | - foreach ( $invoice->get_items() as $item ) { |
|
293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
294 | - $item_ids[] = $item->get_id(); |
|
295 | - $items[] = $item; |
|
296 | - } |
|
297 | - } |
|
292 | + foreach ( $invoice->get_items() as $item ) { |
|
293 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
294 | + $item_ids[] = $item->get_id(); |
|
295 | + $items[] = $item; |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
300 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
301 | - $item_ids[] = $item->get_id(); |
|
302 | - $items[] = $item; |
|
303 | - } |
|
304 | - } |
|
299 | + foreach ( $this->payment_form->get_items() as $item ) { |
|
300 | + if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
301 | + $item_ids[] = $item->get_id(); |
|
302 | + $items[] = $item; |
|
303 | + } |
|
304 | + } |
|
305 | 305 | |
306 | - $this->payment_form->set_items( $items ); |
|
306 | + $this->payment_form->set_items( $items ); |
|
307 | 307 | |
308 | - } else { |
|
309 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
310 | - } |
|
311 | - |
|
312 | - $this->country = $invoice->get_country(); |
|
313 | - $this->state = $invoice->get_state(); |
|
314 | - $this->invoice = $invoice; |
|
315 | - |
|
316 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Returns the associated invoice. |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @return WPInv_Invoice |
|
324 | - */ |
|
325 | - public function get_invoice() { |
|
326 | - return $this->invoice; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Checks whether there is an invoice associated with this submission. |
|
331 | - * |
|
332 | - * @since 1.0.19 |
|
333 | - * @return bool |
|
334 | - */ |
|
335 | - public function has_invoice() { |
|
336 | - return ! empty( $this->invoice ); |
|
337 | - } |
|
338 | - |
|
339 | - /* |
|
308 | + } else { |
|
309 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
310 | + } |
|
311 | + |
|
312 | + $this->country = $invoice->get_country(); |
|
313 | + $this->state = $invoice->get_state(); |
|
314 | + $this->invoice = $invoice; |
|
315 | + |
|
316 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Returns the associated invoice. |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @return WPInv_Invoice |
|
324 | + */ |
|
325 | + public function get_invoice() { |
|
326 | + return $this->invoice; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Checks whether there is an invoice associated with this submission. |
|
331 | + * |
|
332 | + * @since 1.0.19 |
|
333 | + * @return bool |
|
334 | + */ |
|
335 | + public function has_invoice() { |
|
336 | + return ! empty( $this->invoice ); |
|
337 | + } |
|
338 | + |
|
339 | + /* |
|
340 | 340 | |-------------------------------------------------------------------------- |
341 | 341 | | Items. |
342 | 342 | |-------------------------------------------------------------------------- |
@@ -345,110 +345,110 @@ discard block |
||
345 | 345 | | recurring item. But can have an unlimited number of non-recurring items. |
346 | 346 | */ |
347 | 347 | |
348 | - /** |
|
349 | - * Prepares the submission's items. |
|
350 | - * |
|
351 | - * @since 1.0.19 |
|
352 | - */ |
|
353 | - public function process_items() { |
|
354 | - |
|
355 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
356 | - |
|
357 | - foreach ( $processor->items as $item ) { |
|
358 | - $this->add_item( $item ); |
|
359 | - } |
|
360 | - |
|
361 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Adds an item to the submission. |
|
366 | - * |
|
367 | - * @since 1.0.19 |
|
368 | - * @param GetPaid_Form_Item $item |
|
369 | - */ |
|
370 | - public function add_item( $item ) { |
|
371 | - |
|
372 | - // Make sure that it is available for purchase. |
|
373 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
374 | - return; |
|
375 | - } |
|
376 | - |
|
377 | - // Each submission can only contain one recurring item. |
|
378 | - if ( $item->is_recurring() ) { |
|
379 | - $this->has_recurring = $item->get_id(); |
|
380 | - } |
|
381 | - |
|
382 | - // Update the items and totals. |
|
383 | - $this->items[ $item->get_id() ] = $item; |
|
384 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
385 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
386 | - |
|
387 | - $this->subscription_groups = getpaid_calculate_subscription_totals( $this ); |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Removes a specific item. |
|
392 | - * |
|
393 | - * You should not call this method after the discounts and taxes |
|
394 | - * have been calculated. |
|
395 | - * |
|
396 | - * @since 1.0.19 |
|
397 | - */ |
|
398 | - public function remove_item( $item_id ) { |
|
399 | - |
|
400 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
401 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
402 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
403 | - |
|
404 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
405 | - $this->has_recurring = 0; |
|
406 | - } |
|
407 | - |
|
408 | - unset( $this->items[ $item_id ] ); |
|
409 | - } |
|
410 | - |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Returns the subtotal. |
|
415 | - * |
|
416 | - * @since 1.0.19 |
|
417 | - */ |
|
418 | - public function get_subtotal() { |
|
419 | - |
|
420 | - if ( wpinv_prices_include_tax() ) { |
|
421 | - return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
422 | - } |
|
423 | - |
|
424 | - return $this->totals['subtotal']['initial']; |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Returns the recurring subtotal. |
|
429 | - * |
|
430 | - * @since 1.0.19 |
|
431 | - */ |
|
432 | - public function get_recurring_subtotal() { |
|
433 | - |
|
434 | - if ( wpinv_prices_include_tax() ) { |
|
435 | - return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
436 | - } |
|
437 | - |
|
438 | - return $this->totals['subtotal']['recurring']; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Returns all items. |
|
443 | - * |
|
444 | - * @since 1.0.19 |
|
445 | - * @return GetPaid_Form_Item[] |
|
446 | - */ |
|
447 | - public function get_items() { |
|
448 | - return $this->items; |
|
449 | - } |
|
450 | - |
|
451 | - /* |
|
348 | + /** |
|
349 | + * Prepares the submission's items. |
|
350 | + * |
|
351 | + * @since 1.0.19 |
|
352 | + */ |
|
353 | + public function process_items() { |
|
354 | + |
|
355 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
356 | + |
|
357 | + foreach ( $processor->items as $item ) { |
|
358 | + $this->add_item( $item ); |
|
359 | + } |
|
360 | + |
|
361 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Adds an item to the submission. |
|
366 | + * |
|
367 | + * @since 1.0.19 |
|
368 | + * @param GetPaid_Form_Item $item |
|
369 | + */ |
|
370 | + public function add_item( $item ) { |
|
371 | + |
|
372 | + // Make sure that it is available for purchase. |
|
373 | + if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
374 | + return; |
|
375 | + } |
|
376 | + |
|
377 | + // Each submission can only contain one recurring item. |
|
378 | + if ( $item->is_recurring() ) { |
|
379 | + $this->has_recurring = $item->get_id(); |
|
380 | + } |
|
381 | + |
|
382 | + // Update the items and totals. |
|
383 | + $this->items[ $item->get_id() ] = $item; |
|
384 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
385 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
386 | + |
|
387 | + $this->subscription_groups = getpaid_calculate_subscription_totals( $this ); |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Removes a specific item. |
|
392 | + * |
|
393 | + * You should not call this method after the discounts and taxes |
|
394 | + * have been calculated. |
|
395 | + * |
|
396 | + * @since 1.0.19 |
|
397 | + */ |
|
398 | + public function remove_item( $item_id ) { |
|
399 | + |
|
400 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
401 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
402 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
403 | + |
|
404 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
405 | + $this->has_recurring = 0; |
|
406 | + } |
|
407 | + |
|
408 | + unset( $this->items[ $item_id ] ); |
|
409 | + } |
|
410 | + |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Returns the subtotal. |
|
415 | + * |
|
416 | + * @since 1.0.19 |
|
417 | + */ |
|
418 | + public function get_subtotal() { |
|
419 | + |
|
420 | + if ( wpinv_prices_include_tax() ) { |
|
421 | + return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
|
422 | + } |
|
423 | + |
|
424 | + return $this->totals['subtotal']['initial']; |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Returns the recurring subtotal. |
|
429 | + * |
|
430 | + * @since 1.0.19 |
|
431 | + */ |
|
432 | + public function get_recurring_subtotal() { |
|
433 | + |
|
434 | + if ( wpinv_prices_include_tax() ) { |
|
435 | + return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
|
436 | + } |
|
437 | + |
|
438 | + return $this->totals['subtotal']['recurring']; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Returns all items. |
|
443 | + * |
|
444 | + * @since 1.0.19 |
|
445 | + * @return GetPaid_Form_Item[] |
|
446 | + */ |
|
447 | + public function get_items() { |
|
448 | + return $this->items; |
|
449 | + } |
|
450 | + |
|
451 | + /* |
|
452 | 452 | |-------------------------------------------------------------------------- |
453 | 453 | | Taxes |
454 | 454 | |-------------------------------------------------------------------------- |
@@ -457,128 +457,128 @@ discard block |
||
457 | 457 | | or only one-time. |
458 | 458 | */ |
459 | 459 | |
460 | - /** |
|
461 | - * Prepares the submission's taxes. |
|
462 | - * |
|
463 | - * @since 1.0.19 |
|
464 | - */ |
|
465 | - public function process_taxes() { |
|
466 | - |
|
467 | - // Abort if we're not using taxes. |
|
468 | - if ( ! $this->use_taxes() ) { |
|
469 | - return; |
|
470 | - } |
|
471 | - |
|
472 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
473 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
474 | - if ( ! empty( $country ) ) { |
|
475 | - $this->country = $country; |
|
476 | - } |
|
477 | - |
|
478 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
479 | - if ( ! empty( $state ) ) { |
|
480 | - $this->state = $state; |
|
481 | - } |
|
482 | - |
|
483 | - // Confirm if the provided country and the ip country are similar. |
|
484 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
485 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
486 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
487 | - } |
|
488 | - |
|
489 | - // Abort if the country is not taxable. |
|
490 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
491 | - return; |
|
492 | - } |
|
493 | - |
|
494 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
495 | - |
|
496 | - foreach ( $processor->taxes as $tax ) { |
|
497 | - $this->add_tax( $tax ); |
|
498 | - } |
|
499 | - |
|
500 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Adds a tax to the submission. |
|
505 | - * |
|
506 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
507 | - * @since 1.0.19 |
|
508 | - */ |
|
509 | - public function add_tax( $tax ) { |
|
510 | - |
|
511 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
512 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
513 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
514 | - } |
|
515 | - |
|
516 | - $this->taxes[ $tax['name'] ] = $tax; |
|
517 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
518 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Removes a specific tax. |
|
524 | - * |
|
525 | - * @since 1.0.19 |
|
526 | - */ |
|
527 | - public function remove_tax( $tax_name ) { |
|
528 | - |
|
529 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
530 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
531 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
532 | - unset( $this->taxes[ $tax_name ] ); |
|
533 | - } |
|
534 | - |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Whether or not we'll use taxes for the submission. |
|
539 | - * |
|
540 | - * @since 1.0.19 |
|
541 | - */ |
|
542 | - public function use_taxes() { |
|
543 | - |
|
544 | - $use_taxes = wpinv_use_taxes(); |
|
545 | - |
|
546 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
547 | - $use_taxes = false; |
|
548 | - } |
|
549 | - |
|
550 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
551 | - |
|
552 | - } |
|
553 | - |
|
554 | - /** |
|
555 | - * Returns the tax. |
|
556 | - * |
|
557 | - * @since 1.0.19 |
|
558 | - */ |
|
559 | - public function get_tax() { |
|
560 | - return $this->totals['taxes']['initial']; |
|
561 | - } |
|
562 | - |
|
563 | - /** |
|
564 | - * Returns the recurring tax. |
|
565 | - * |
|
566 | - * @since 1.0.19 |
|
567 | - */ |
|
568 | - public function get_recurring_tax() { |
|
569 | - return $this->totals['taxes']['recurring']; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Returns all taxes. |
|
574 | - * |
|
575 | - * @since 1.0.19 |
|
576 | - */ |
|
577 | - public function get_taxes() { |
|
578 | - return $this->taxes; |
|
579 | - } |
|
580 | - |
|
581 | - /* |
|
460 | + /** |
|
461 | + * Prepares the submission's taxes. |
|
462 | + * |
|
463 | + * @since 1.0.19 |
|
464 | + */ |
|
465 | + public function process_taxes() { |
|
466 | + |
|
467 | + // Abort if we're not using taxes. |
|
468 | + if ( ! $this->use_taxes() ) { |
|
469 | + return; |
|
470 | + } |
|
471 | + |
|
472 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
473 | + $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
474 | + if ( ! empty( $country ) ) { |
|
475 | + $this->country = $country; |
|
476 | + } |
|
477 | + |
|
478 | + $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
479 | + if ( ! empty( $state ) ) { |
|
480 | + $this->state = $state; |
|
481 | + } |
|
482 | + |
|
483 | + // Confirm if the provided country and the ip country are similar. |
|
484 | + $address_confirmed = $this->get_field( 'confirm-address' ); |
|
485 | + if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
486 | + throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
487 | + } |
|
488 | + |
|
489 | + // Abort if the country is not taxable. |
|
490 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
491 | + return; |
|
492 | + } |
|
493 | + |
|
494 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
495 | + |
|
496 | + foreach ( $processor->taxes as $tax ) { |
|
497 | + $this->add_tax( $tax ); |
|
498 | + } |
|
499 | + |
|
500 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Adds a tax to the submission. |
|
505 | + * |
|
506 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
507 | + * @since 1.0.19 |
|
508 | + */ |
|
509 | + public function add_tax( $tax ) { |
|
510 | + |
|
511 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
512 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
513 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
514 | + } |
|
515 | + |
|
516 | + $this->taxes[ $tax['name'] ] = $tax; |
|
517 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
518 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Removes a specific tax. |
|
524 | + * |
|
525 | + * @since 1.0.19 |
|
526 | + */ |
|
527 | + public function remove_tax( $tax_name ) { |
|
528 | + |
|
529 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
530 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
531 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
532 | + unset( $this->taxes[ $tax_name ] ); |
|
533 | + } |
|
534 | + |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Whether or not we'll use taxes for the submission. |
|
539 | + * |
|
540 | + * @since 1.0.19 |
|
541 | + */ |
|
542 | + public function use_taxes() { |
|
543 | + |
|
544 | + $use_taxes = wpinv_use_taxes(); |
|
545 | + |
|
546 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
547 | + $use_taxes = false; |
|
548 | + } |
|
549 | + |
|
550 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
551 | + |
|
552 | + } |
|
553 | + |
|
554 | + /** |
|
555 | + * Returns the tax. |
|
556 | + * |
|
557 | + * @since 1.0.19 |
|
558 | + */ |
|
559 | + public function get_tax() { |
|
560 | + return $this->totals['taxes']['initial']; |
|
561 | + } |
|
562 | + |
|
563 | + /** |
|
564 | + * Returns the recurring tax. |
|
565 | + * |
|
566 | + * @since 1.0.19 |
|
567 | + */ |
|
568 | + public function get_recurring_tax() { |
|
569 | + return $this->totals['taxes']['recurring']; |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Returns all taxes. |
|
574 | + * |
|
575 | + * @since 1.0.19 |
|
576 | + */ |
|
577 | + public function get_taxes() { |
|
578 | + return $this->taxes; |
|
579 | + } |
|
580 | + |
|
581 | + /* |
|
582 | 582 | |-------------------------------------------------------------------------- |
583 | 583 | | Discounts |
584 | 584 | |-------------------------------------------------------------------------- |
@@ -587,99 +587,99 @@ discard block |
||
587 | 587 | | or only one-time. They also do not have to come from a discount code. |
588 | 588 | */ |
589 | 589 | |
590 | - /** |
|
591 | - * Prepares the submission's discount. |
|
592 | - * |
|
593 | - * @since 1.0.19 |
|
594 | - */ |
|
595 | - public function process_discount() { |
|
596 | - |
|
597 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
598 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
599 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
600 | - |
|
601 | - foreach ( $processor->discounts as $discount ) { |
|
602 | - $this->add_discount( $discount ); |
|
603 | - } |
|
604 | - |
|
605 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Adds a discount to the submission. |
|
610 | - * |
|
611 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
612 | - * @since 1.0.19 |
|
613 | - */ |
|
614 | - public function add_discount( $discount ) { |
|
615 | - $this->discounts[ $discount['name'] ] = $discount; |
|
616 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
617 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Removes a discount from the submission. |
|
622 | - * |
|
623 | - * @since 1.0.19 |
|
624 | - */ |
|
625 | - public function remove_discount( $name ) { |
|
626 | - |
|
627 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
628 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
629 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
630 | - unset( $this->discounts[ $name ] ); |
|
631 | - } |
|
632 | - |
|
633 | - } |
|
634 | - |
|
635 | - /** |
|
636 | - * Checks whether there is a discount code associated with this submission. |
|
637 | - * |
|
638 | - * @since 1.0.19 |
|
639 | - * @return bool |
|
640 | - */ |
|
641 | - public function has_discount_code() { |
|
642 | - return ! empty( $this->discounts['discount_code'] ); |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Returns the discount code. |
|
647 | - * |
|
648 | - * @since 1.0.19 |
|
649 | - * @return string |
|
650 | - */ |
|
651 | - public function get_discount_code() { |
|
652 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Returns the discount. |
|
657 | - * |
|
658 | - * @since 1.0.19 |
|
659 | - */ |
|
660 | - public function get_discount() { |
|
661 | - return $this->totals['discount']['initial']; |
|
662 | - } |
|
663 | - |
|
664 | - /** |
|
665 | - * Returns the recurring discount. |
|
666 | - * |
|
667 | - * @since 1.0.19 |
|
668 | - */ |
|
669 | - public function get_recurring_discount() { |
|
670 | - return $this->totals['discount']['recurring']; |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Returns all discounts. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - */ |
|
678 | - public function get_discounts() { |
|
679 | - return $this->discounts; |
|
680 | - } |
|
681 | - |
|
682 | - /* |
|
590 | + /** |
|
591 | + * Prepares the submission's discount. |
|
592 | + * |
|
593 | + * @since 1.0.19 |
|
594 | + */ |
|
595 | + public function process_discount() { |
|
596 | + |
|
597 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
598 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
599 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
600 | + |
|
601 | + foreach ( $processor->discounts as $discount ) { |
|
602 | + $this->add_discount( $discount ); |
|
603 | + } |
|
604 | + |
|
605 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Adds a discount to the submission. |
|
610 | + * |
|
611 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
612 | + * @since 1.0.19 |
|
613 | + */ |
|
614 | + public function add_discount( $discount ) { |
|
615 | + $this->discounts[ $discount['name'] ] = $discount; |
|
616 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
617 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * Removes a discount from the submission. |
|
622 | + * |
|
623 | + * @since 1.0.19 |
|
624 | + */ |
|
625 | + public function remove_discount( $name ) { |
|
626 | + |
|
627 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
628 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
629 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
630 | + unset( $this->discounts[ $name ] ); |
|
631 | + } |
|
632 | + |
|
633 | + } |
|
634 | + |
|
635 | + /** |
|
636 | + * Checks whether there is a discount code associated with this submission. |
|
637 | + * |
|
638 | + * @since 1.0.19 |
|
639 | + * @return bool |
|
640 | + */ |
|
641 | + public function has_discount_code() { |
|
642 | + return ! empty( $this->discounts['discount_code'] ); |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Returns the discount code. |
|
647 | + * |
|
648 | + * @since 1.0.19 |
|
649 | + * @return string |
|
650 | + */ |
|
651 | + public function get_discount_code() { |
|
652 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * Returns the discount. |
|
657 | + * |
|
658 | + * @since 1.0.19 |
|
659 | + */ |
|
660 | + public function get_discount() { |
|
661 | + return $this->totals['discount']['initial']; |
|
662 | + } |
|
663 | + |
|
664 | + /** |
|
665 | + * Returns the recurring discount. |
|
666 | + * |
|
667 | + * @since 1.0.19 |
|
668 | + */ |
|
669 | + public function get_recurring_discount() { |
|
670 | + return $this->totals['discount']['recurring']; |
|
671 | + } |
|
672 | + |
|
673 | + /** |
|
674 | + * Returns all discounts. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + */ |
|
678 | + public function get_discounts() { |
|
679 | + return $this->discounts; |
|
680 | + } |
|
681 | + |
|
682 | + /* |
|
683 | 683 | |-------------------------------------------------------------------------- |
684 | 684 | | Fees |
685 | 685 | |-------------------------------------------------------------------------- |
@@ -689,89 +689,89 @@ discard block |
||
689 | 689 | | fees. |
690 | 690 | */ |
691 | 691 | |
692 | - /** |
|
693 | - * Prepares the submission's fees. |
|
694 | - * |
|
695 | - * @since 1.0.19 |
|
696 | - */ |
|
697 | - public function process_fees() { |
|
698 | - |
|
699 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
700 | - |
|
701 | - foreach ( $fees_processor->fees as $fee ) { |
|
702 | - $this->add_fee( $fee ); |
|
703 | - } |
|
704 | - |
|
705 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Adds a fee to the submission. |
|
710 | - * |
|
711 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
712 | - * @since 1.0.19 |
|
713 | - */ |
|
714 | - public function add_fee( $fee ) { |
|
715 | - |
|
716 | - $this->fees[ $fee['name'] ] = $fee; |
|
717 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
718 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
719 | - |
|
720 | - } |
|
721 | - |
|
722 | - /** |
|
723 | - * Removes a fee from the submission. |
|
724 | - * |
|
725 | - * @since 1.0.19 |
|
726 | - */ |
|
727 | - public function remove_fee( $name ) { |
|
728 | - |
|
729 | - if ( isset( $this->fees[ $name ] ) ) { |
|
730 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
731 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
732 | - unset( $this->fees[ $name ] ); |
|
733 | - } |
|
734 | - |
|
735 | - } |
|
736 | - |
|
737 | - /** |
|
738 | - * Returns the fees. |
|
739 | - * |
|
740 | - * @since 1.0.19 |
|
741 | - */ |
|
742 | - public function get_fee() { |
|
743 | - return $this->totals['fees']['initial']; |
|
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * Returns the recurring fees. |
|
748 | - * |
|
749 | - * @since 1.0.19 |
|
750 | - */ |
|
751 | - public function get_recurring_fee() { |
|
752 | - return $this->totals['fees']['recurring']; |
|
753 | - } |
|
754 | - |
|
755 | - /** |
|
756 | - * Returns all fees. |
|
757 | - * |
|
758 | - * @since 1.0.19 |
|
759 | - */ |
|
760 | - public function get_fees() { |
|
761 | - return $this->fees; |
|
762 | - } |
|
763 | - |
|
764 | - /** |
|
765 | - * Checks if there are any fees for the form. |
|
766 | - * |
|
767 | - * @return bool |
|
768 | - * @since 1.0.19 |
|
769 | - */ |
|
770 | - public function has_fees() { |
|
771 | - return count( $this->fees ) !== 0; |
|
772 | - } |
|
773 | - |
|
774 | - /* |
|
692 | + /** |
|
693 | + * Prepares the submission's fees. |
|
694 | + * |
|
695 | + * @since 1.0.19 |
|
696 | + */ |
|
697 | + public function process_fees() { |
|
698 | + |
|
699 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
700 | + |
|
701 | + foreach ( $fees_processor->fees as $fee ) { |
|
702 | + $this->add_fee( $fee ); |
|
703 | + } |
|
704 | + |
|
705 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Adds a fee to the submission. |
|
710 | + * |
|
711 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
712 | + * @since 1.0.19 |
|
713 | + */ |
|
714 | + public function add_fee( $fee ) { |
|
715 | + |
|
716 | + $this->fees[ $fee['name'] ] = $fee; |
|
717 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
718 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
719 | + |
|
720 | + } |
|
721 | + |
|
722 | + /** |
|
723 | + * Removes a fee from the submission. |
|
724 | + * |
|
725 | + * @since 1.0.19 |
|
726 | + */ |
|
727 | + public function remove_fee( $name ) { |
|
728 | + |
|
729 | + if ( isset( $this->fees[ $name ] ) ) { |
|
730 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
731 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
732 | + unset( $this->fees[ $name ] ); |
|
733 | + } |
|
734 | + |
|
735 | + } |
|
736 | + |
|
737 | + /** |
|
738 | + * Returns the fees. |
|
739 | + * |
|
740 | + * @since 1.0.19 |
|
741 | + */ |
|
742 | + public function get_fee() { |
|
743 | + return $this->totals['fees']['initial']; |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * Returns the recurring fees. |
|
748 | + * |
|
749 | + * @since 1.0.19 |
|
750 | + */ |
|
751 | + public function get_recurring_fee() { |
|
752 | + return $this->totals['fees']['recurring']; |
|
753 | + } |
|
754 | + |
|
755 | + /** |
|
756 | + * Returns all fees. |
|
757 | + * |
|
758 | + * @since 1.0.19 |
|
759 | + */ |
|
760 | + public function get_fees() { |
|
761 | + return $this->fees; |
|
762 | + } |
|
763 | + |
|
764 | + /** |
|
765 | + * Checks if there are any fees for the form. |
|
766 | + * |
|
767 | + * @return bool |
|
768 | + * @since 1.0.19 |
|
769 | + */ |
|
770 | + public function has_fees() { |
|
771 | + return count( $this->fees ) !== 0; |
|
772 | + } |
|
773 | + |
|
774 | + /* |
|
775 | 775 | |-------------------------------------------------------------------------- |
776 | 776 | | MISC |
777 | 777 | |-------------------------------------------------------------------------- |
@@ -779,119 +779,119 @@ discard block |
||
779 | 779 | | Extra submission functions. |
780 | 780 | */ |
781 | 781 | |
782 | - /** |
|
783 | - * Checks if this is the initial fetch. |
|
784 | - * |
|
785 | - * @return bool |
|
786 | - * @since 1.0.19 |
|
787 | - */ |
|
788 | - public function is_initial_fetch() { |
|
789 | - return empty( $this->data['initial_state'] ); |
|
790 | - } |
|
791 | - |
|
792 | - /** |
|
793 | - * Returns the total amount to collect for this submission. |
|
794 | - * |
|
795 | - * @since 1.0.19 |
|
796 | - */ |
|
797 | - public function get_total() { |
|
798 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
799 | - return max( $total, 0 ); |
|
800 | - } |
|
801 | - |
|
802 | - /** |
|
803 | - * Returns the recurring total amount to collect for this submission. |
|
804 | - * |
|
805 | - * @since 1.0.19 |
|
806 | - */ |
|
807 | - public function get_recurring_total() { |
|
808 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
809 | - return max( $total, 0 ); |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * Whether payment details should be collected for this submission. |
|
814 | - * |
|
815 | - * @since 1.0.19 |
|
816 | - */ |
|
817 | - public function should_collect_payment_details() { |
|
818 | - $initial = $this->get_total(); |
|
819 | - $recurring = $this->get_recurring_total(); |
|
820 | - |
|
821 | - if ( $this->has_recurring == 0 ) { |
|
822 | - $recurring = 0; |
|
823 | - } |
|
824 | - |
|
825 | - $collect = $initial > 0 || $recurring > 0; |
|
826 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
827 | - } |
|
828 | - |
|
829 | - /** |
|
830 | - * Returns the billing email of the user. |
|
831 | - * |
|
832 | - * @since 1.0.19 |
|
833 | - */ |
|
834 | - public function get_billing_email() { |
|
835 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
836 | - } |
|
837 | - |
|
838 | - /** |
|
839 | - * Checks if the submitter has a billing email. |
|
840 | - * |
|
841 | - * @since 1.0.19 |
|
842 | - */ |
|
843 | - public function has_billing_email() { |
|
844 | - $billing_email = $this->get_billing_email(); |
|
845 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
846 | - } |
|
847 | - |
|
848 | - /** |
|
849 | - * Returns the appropriate currency for the submission. |
|
850 | - * |
|
851 | - * @since 1.0.19 |
|
852 | - * @return string |
|
853 | - */ |
|
854 | - public function get_currency() { |
|
855 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Returns the raw submission data. |
|
860 | - * |
|
861 | - * @since 1.0.19 |
|
862 | - * @return array |
|
863 | - */ |
|
864 | - public function get_data() { |
|
865 | - return $this->data; |
|
866 | - } |
|
867 | - |
|
868 | - /** |
|
869 | - * Returns a field from the submission data |
|
870 | - * |
|
871 | - * @param string $field |
|
872 | - * @since 1.0.19 |
|
873 | - * @return mixed|null |
|
874 | - */ |
|
875 | - public function get_field( $field, $sub_array_key = null ) { |
|
876 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
877 | - } |
|
878 | - |
|
879 | - /** |
|
880 | - * Checks if a required field is set. |
|
881 | - * |
|
882 | - * @since 1.0.19 |
|
883 | - */ |
|
884 | - public function is_required_field_set( $field ) { |
|
885 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
886 | - } |
|
887 | - |
|
888 | - /** |
|
889 | - * Formats an amount |
|
890 | - * |
|
891 | - * @since 1.0.19 |
|
892 | - */ |
|
893 | - public function format_amount( $amount ) { |
|
894 | - return wpinv_price( $amount, $this->get_currency() ); |
|
895 | - } |
|
782 | + /** |
|
783 | + * Checks if this is the initial fetch. |
|
784 | + * |
|
785 | + * @return bool |
|
786 | + * @since 1.0.19 |
|
787 | + */ |
|
788 | + public function is_initial_fetch() { |
|
789 | + return empty( $this->data['initial_state'] ); |
|
790 | + } |
|
791 | + |
|
792 | + /** |
|
793 | + * Returns the total amount to collect for this submission. |
|
794 | + * |
|
795 | + * @since 1.0.19 |
|
796 | + */ |
|
797 | + public function get_total() { |
|
798 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
799 | + return max( $total, 0 ); |
|
800 | + } |
|
801 | + |
|
802 | + /** |
|
803 | + * Returns the recurring total amount to collect for this submission. |
|
804 | + * |
|
805 | + * @since 1.0.19 |
|
806 | + */ |
|
807 | + public function get_recurring_total() { |
|
808 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
809 | + return max( $total, 0 ); |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * Whether payment details should be collected for this submission. |
|
814 | + * |
|
815 | + * @since 1.0.19 |
|
816 | + */ |
|
817 | + public function should_collect_payment_details() { |
|
818 | + $initial = $this->get_total(); |
|
819 | + $recurring = $this->get_recurring_total(); |
|
820 | + |
|
821 | + if ( $this->has_recurring == 0 ) { |
|
822 | + $recurring = 0; |
|
823 | + } |
|
824 | + |
|
825 | + $collect = $initial > 0 || $recurring > 0; |
|
826 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
827 | + } |
|
828 | + |
|
829 | + /** |
|
830 | + * Returns the billing email of the user. |
|
831 | + * |
|
832 | + * @since 1.0.19 |
|
833 | + */ |
|
834 | + public function get_billing_email() { |
|
835 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
836 | + } |
|
837 | + |
|
838 | + /** |
|
839 | + * Checks if the submitter has a billing email. |
|
840 | + * |
|
841 | + * @since 1.0.19 |
|
842 | + */ |
|
843 | + public function has_billing_email() { |
|
844 | + $billing_email = $this->get_billing_email(); |
|
845 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
846 | + } |
|
847 | + |
|
848 | + /** |
|
849 | + * Returns the appropriate currency for the submission. |
|
850 | + * |
|
851 | + * @since 1.0.19 |
|
852 | + * @return string |
|
853 | + */ |
|
854 | + public function get_currency() { |
|
855 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Returns the raw submission data. |
|
860 | + * |
|
861 | + * @since 1.0.19 |
|
862 | + * @return array |
|
863 | + */ |
|
864 | + public function get_data() { |
|
865 | + return $this->data; |
|
866 | + } |
|
867 | + |
|
868 | + /** |
|
869 | + * Returns a field from the submission data |
|
870 | + * |
|
871 | + * @param string $field |
|
872 | + * @since 1.0.19 |
|
873 | + * @return mixed|null |
|
874 | + */ |
|
875 | + public function get_field( $field, $sub_array_key = null ) { |
|
876 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
877 | + } |
|
878 | + |
|
879 | + /** |
|
880 | + * Checks if a required field is set. |
|
881 | + * |
|
882 | + * @since 1.0.19 |
|
883 | + */ |
|
884 | + public function is_required_field_set( $field ) { |
|
885 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
886 | + } |
|
887 | + |
|
888 | + /** |
|
889 | + * Formats an amount |
|
890 | + * |
|
891 | + * @since 1.0.19 |
|
892 | + */ |
|
893 | + public function format_amount( $amount ) { |
|
894 | + return wpinv_price( $amount, $this->get_currency() ); |
|
895 | + } |
|
896 | 896 | |
897 | 897 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | $this->state = wpinv_get_default_state(); |
150 | 150 | |
151 | 151 | // Do we have an actual submission? |
152 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
153 | - $this->load_data( $_POST ); |
|
152 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
153 | + $this->load_data($_POST); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | } |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param array $data |
162 | 162 | */ |
163 | - public function load_data( $data ) { |
|
163 | + public function load_data($data) { |
|
164 | 164 | |
165 | 165 | // Remove slashes from the submitted data... |
166 | - $data = wp_unslash( $data ); |
|
166 | + $data = wp_unslash($data); |
|
167 | 167 | |
168 | 168 | // Allow plugins to filter the data. |
169 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
169 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
170 | 170 | |
171 | 171 | // Cache it... |
172 | 172 | $this->data = $data; |
173 | 173 | |
174 | 174 | // Then generate a unique id from the data. |
175 | - $this->id = md5( wp_json_encode( $data ) ); |
|
175 | + $this->id = md5(wp_json_encode($data)); |
|
176 | 176 | |
177 | 177 | // Finally, process the submission. |
178 | 178 | try { |
@@ -182,30 +182,30 @@ discard block |
||
182 | 182 | $processors = apply_filters( |
183 | 183 | 'getpaid_payment_form_submission_processors', |
184 | 184 | array( |
185 | - array( $this, 'process_payment_form' ), |
|
186 | - array( $this, 'process_invoice' ), |
|
187 | - array( $this, 'process_fees' ), |
|
188 | - array( $this, 'process_items' ), |
|
189 | - array( $this, 'process_discount' ), |
|
190 | - array( $this, 'process_taxes' ), |
|
185 | + array($this, 'process_payment_form'), |
|
186 | + array($this, 'process_invoice'), |
|
187 | + array($this, 'process_fees'), |
|
188 | + array($this, 'process_items'), |
|
189 | + array($this, 'process_discount'), |
|
190 | + array($this, 'process_taxes'), |
|
191 | 191 | ), |
192 | 192 | $this |
193 | 193 | ); |
194 | 194 | |
195 | - foreach ( $processors as $processor ) { |
|
196 | - call_user_func_array( $processor, array( &$this ) ); |
|
195 | + foreach ($processors as $processor) { |
|
196 | + call_user_func_array($processor, array(&$this)); |
|
197 | 197 | } |
198 | 198 | |
199 | - } catch( GetPaid_Payment_Exception $e ) { |
|
199 | + } catch (GetPaid_Payment_Exception $e) { |
|
200 | 200 | $this->last_error = $e->getMessage(); |
201 | 201 | $this->last_error_code = $e->getErrorCode(); |
202 | - } catch ( Exception $e ) { |
|
202 | + } catch (Exception $e) { |
|
203 | 203 | $this->last_error = $e->getMessage(); |
204 | 204 | $this->last_error_code = $e->getCode(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | // Fired when we are done processing a submission. |
208 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
208 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
209 | 209 | |
210 | 210 | } |
211 | 211 | |
@@ -226,18 +226,18 @@ discard block |
||
226 | 226 | public function process_payment_form() { |
227 | 227 | |
228 | 228 | // Every submission needs an active payment form. |
229 | - if ( empty( $this->data['form_id'] ) ) { |
|
230 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
229 | + if (empty($this->data['form_id'])) { |
|
230 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Fetch the payment form. |
234 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
234 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
235 | 235 | |
236 | - if ( ! $this->payment_form->is_active() ) { |
|
237 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
236 | + if (!$this->payment_form->is_active()) { |
|
237 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
238 | 238 | } |
239 | 239 | |
240 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
240 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -267,53 +267,53 @@ discard block |
||
267 | 267 | public function process_invoice() { |
268 | 268 | |
269 | 269 | // Abort if there is no invoice. |
270 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
270 | + if (empty($this->data['invoice_id'])) { |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // If the submission is for an existing invoice, ensure that it exists |
275 | 275 | // and that it is not paid for. |
276 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
276 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
277 | 277 | |
278 | - if ( empty( $invoice ) ) { |
|
279 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
278 | + if (empty($invoice)) { |
|
279 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
280 | 280 | } |
281 | 281 | |
282 | - if ( $invoice->is_paid() ) { |
|
283 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
282 | + if ($invoice->is_paid()) { |
|
283 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | $this->payment_form->invoice = $invoice; |
287 | - if ( ! $this->payment_form->is_default() ) { |
|
287 | + if (!$this->payment_form->is_default()) { |
|
288 | 288 | |
289 | 289 | $items = array(); |
290 | 290 | $item_ids = array(); |
291 | 291 | |
292 | - foreach ( $invoice->get_items() as $item ) { |
|
293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
292 | + foreach ($invoice->get_items() as $item) { |
|
293 | + if (!in_array($item->get_id(), $item_ids)) { |
|
294 | 294 | $item_ids[] = $item->get_id(); |
295 | 295 | $items[] = $item; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
300 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
299 | + foreach ($this->payment_form->get_items() as $item) { |
|
300 | + if (!in_array($item->get_id(), $item_ids)) { |
|
301 | 301 | $item_ids[] = $item->get_id(); |
302 | 302 | $items[] = $item; |
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - $this->payment_form->set_items( $items ); |
|
306 | + $this->payment_form->set_items($items); |
|
307 | 307 | |
308 | 308 | } else { |
309 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
309 | + $this->payment_form->set_items($invoice->get_items()); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $this->country = $invoice->get_country(); |
313 | 313 | $this->state = $invoice->get_state(); |
314 | 314 | $this->invoice = $invoice; |
315 | 315 | |
316 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
316 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return bool |
334 | 334 | */ |
335 | 335 | public function has_invoice() { |
336 | - return ! empty( $this->invoice ); |
|
336 | + return !empty($this->invoice); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /* |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | */ |
353 | 353 | public function process_items() { |
354 | 354 | |
355 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
355 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
356 | 356 | |
357 | - foreach ( $processor->items as $item ) { |
|
358 | - $this->add_item( $item ); |
|
357 | + foreach ($processor->items as $item) { |
|
358 | + $this->add_item($item); |
|
359 | 359 | } |
360 | 360 | |
361 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
361 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -367,24 +367,24 @@ discard block |
||
367 | 367 | * @since 1.0.19 |
368 | 368 | * @param GetPaid_Form_Item $item |
369 | 369 | */ |
370 | - public function add_item( $item ) { |
|
370 | + public function add_item($item) { |
|
371 | 371 | |
372 | 372 | // Make sure that it is available for purchase. |
373 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
373 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Each submission can only contain one recurring item. |
378 | - if ( $item->is_recurring() ) { |
|
378 | + if ($item->is_recurring()) { |
|
379 | 379 | $this->has_recurring = $item->get_id(); |
380 | 380 | } |
381 | 381 | |
382 | 382 | // Update the items and totals. |
383 | - $this->items[ $item->get_id() ] = $item; |
|
383 | + $this->items[$item->get_id()] = $item; |
|
384 | 384 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
385 | 385 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
386 | 386 | |
387 | - $this->subscription_groups = getpaid_calculate_subscription_totals( $this ); |
|
387 | + $this->subscription_groups = getpaid_calculate_subscription_totals($this); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
@@ -395,17 +395,17 @@ discard block |
||
395 | 395 | * |
396 | 396 | * @since 1.0.19 |
397 | 397 | */ |
398 | - public function remove_item( $item_id ) { |
|
398 | + public function remove_item($item_id) { |
|
399 | 399 | |
400 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
401 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
402 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
400 | + if (isset($this->items[$item_id])) { |
|
401 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
402 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
403 | 403 | |
404 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
404 | + if ($this->items[$item_id]->is_recurring()) { |
|
405 | 405 | $this->has_recurring = 0; |
406 | 406 | } |
407 | 407 | |
408 | - unset( $this->items[ $item_id ] ); |
|
408 | + unset($this->items[$item_id]); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | */ |
418 | 418 | public function get_subtotal() { |
419 | 419 | |
420 | - if ( wpinv_prices_include_tax() ) { |
|
420 | + if (wpinv_prices_include_tax()) { |
|
421 | 421 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
422 | 422 | } |
423 | 423 | |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | */ |
432 | 432 | public function get_recurring_subtotal() { |
433 | 433 | |
434 | - if ( wpinv_prices_include_tax() ) { |
|
434 | + if (wpinv_prices_include_tax()) { |
|
435 | 435 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
436 | 436 | } |
437 | 437 | |
@@ -465,39 +465,39 @@ discard block |
||
465 | 465 | public function process_taxes() { |
466 | 466 | |
467 | 467 | // Abort if we're not using taxes. |
468 | - if ( ! $this->use_taxes() ) { |
|
468 | + if (!$this->use_taxes()) { |
|
469 | 469 | return; |
470 | 470 | } |
471 | 471 | |
472 | 472 | // If a custom country && state has been passed in, use it to calculate taxes. |
473 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
474 | - if ( ! empty( $country ) ) { |
|
473 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
474 | + if (!empty($country)) { |
|
475 | 475 | $this->country = $country; |
476 | 476 | } |
477 | 477 | |
478 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
479 | - if ( ! empty( $state ) ) { |
|
478 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
479 | + if (!empty($state)) { |
|
480 | 480 | $this->state = $state; |
481 | 481 | } |
482 | 482 | |
483 | 483 | // Confirm if the provided country and the ip country are similar. |
484 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
485 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
486 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
484 | + $address_confirmed = $this->get_field('confirm-address'); |
|
485 | + if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
486 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | // Abort if the country is not taxable. |
490 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
490 | + if (!wpinv_is_country_taxable($this->country)) { |
|
491 | 491 | return; |
492 | 492 | } |
493 | 493 | |
494 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
494 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
495 | 495 | |
496 | - foreach ( $processor->taxes as $tax ) { |
|
497 | - $this->add_tax( $tax ); |
|
496 | + foreach ($processor->taxes as $tax) { |
|
497 | + $this->add_tax($tax); |
|
498 | 498 | } |
499 | 499 | |
500 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
500 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -506,16 +506,16 @@ discard block |
||
506 | 506 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
507 | 507 | * @since 1.0.19 |
508 | 508 | */ |
509 | - public function add_tax( $tax ) { |
|
509 | + public function add_tax($tax) { |
|
510 | 510 | |
511 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
512 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
513 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
511 | + if (wpinv_round_tax_per_tax_rate()) { |
|
512 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
513 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
514 | 514 | } |
515 | 515 | |
516 | - $this->taxes[ $tax['name'] ] = $tax; |
|
517 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
518 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
516 | + $this->taxes[$tax['name']] = $tax; |
|
517 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
518 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
519 | 519 | |
520 | 520 | } |
521 | 521 | |
@@ -524,12 +524,12 @@ discard block |
||
524 | 524 | * |
525 | 525 | * @since 1.0.19 |
526 | 526 | */ |
527 | - public function remove_tax( $tax_name ) { |
|
527 | + public function remove_tax($tax_name) { |
|
528 | 528 | |
529 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
530 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
531 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
532 | - unset( $this->taxes[ $tax_name ] ); |
|
529 | + if (isset($this->taxes[$tax_name])) { |
|
530 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
531 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
532 | + unset($this->taxes[$tax_name]); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | } |
@@ -543,11 +543,11 @@ discard block |
||
543 | 543 | |
544 | 544 | $use_taxes = wpinv_use_taxes(); |
545 | 545 | |
546 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
546 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
547 | 547 | $use_taxes = false; |
548 | 548 | } |
549 | 549 | |
550 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
550 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
551 | 551 | |
552 | 552 | } |
553 | 553 | |
@@ -596,13 +596,13 @@ discard block |
||
596 | 596 | |
597 | 597 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
598 | 598 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
599 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
599 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
600 | 600 | |
601 | - foreach ( $processor->discounts as $discount ) { |
|
602 | - $this->add_discount( $discount ); |
|
601 | + foreach ($processor->discounts as $discount) { |
|
602 | + $this->add_discount($discount); |
|
603 | 603 | } |
604 | 604 | |
605 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
605 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | /** |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
612 | 612 | * @since 1.0.19 |
613 | 613 | */ |
614 | - public function add_discount( $discount ) { |
|
615 | - $this->discounts[ $discount['name'] ] = $discount; |
|
616 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
617 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
614 | + public function add_discount($discount) { |
|
615 | + $this->discounts[$discount['name']] = $discount; |
|
616 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
617 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | /** |
@@ -622,12 +622,12 @@ discard block |
||
622 | 622 | * |
623 | 623 | * @since 1.0.19 |
624 | 624 | */ |
625 | - public function remove_discount( $name ) { |
|
625 | + public function remove_discount($name) { |
|
626 | 626 | |
627 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
628 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
629 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
630 | - unset( $this->discounts[ $name ] ); |
|
627 | + if (isset($this->discounts[$name])) { |
|
628 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
629 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
630 | + unset($this->discounts[$name]); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | } |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | * @return bool |
640 | 640 | */ |
641 | 641 | public function has_discount_code() { |
642 | - return ! empty( $this->discounts['discount_code'] ); |
|
642 | + return !empty($this->discounts['discount_code']); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
@@ -696,13 +696,13 @@ discard block |
||
696 | 696 | */ |
697 | 697 | public function process_fees() { |
698 | 698 | |
699 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
699 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
700 | 700 | |
701 | - foreach ( $fees_processor->fees as $fee ) { |
|
702 | - $this->add_fee( $fee ); |
|
701 | + foreach ($fees_processor->fees as $fee) { |
|
702 | + $this->add_fee($fee); |
|
703 | 703 | } |
704 | 704 | |
705 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
705 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -711,11 +711,11 @@ discard block |
||
711 | 711 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
712 | 712 | * @since 1.0.19 |
713 | 713 | */ |
714 | - public function add_fee( $fee ) { |
|
714 | + public function add_fee($fee) { |
|
715 | 715 | |
716 | - $this->fees[ $fee['name'] ] = $fee; |
|
717 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
718 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
716 | + $this->fees[$fee['name']] = $fee; |
|
717 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
718 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
719 | 719 | |
720 | 720 | } |
721 | 721 | |
@@ -724,12 +724,12 @@ discard block |
||
724 | 724 | * |
725 | 725 | * @since 1.0.19 |
726 | 726 | */ |
727 | - public function remove_fee( $name ) { |
|
727 | + public function remove_fee($name) { |
|
728 | 728 | |
729 | - if ( isset( $this->fees[ $name ] ) ) { |
|
730 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
731 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
732 | - unset( $this->fees[ $name ] ); |
|
729 | + if (isset($this->fees[$name])) { |
|
730 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
731 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
732 | + unset($this->fees[$name]); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | } |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | * @since 1.0.19 |
769 | 769 | */ |
770 | 770 | public function has_fees() { |
771 | - return count( $this->fees ) !== 0; |
|
771 | + return count($this->fees) !== 0; |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | /* |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | * @since 1.0.19 |
787 | 787 | */ |
788 | 788 | public function is_initial_fetch() { |
789 | - return empty( $this->data['initial_state'] ); |
|
789 | + return empty($this->data['initial_state']); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | */ |
797 | 797 | public function get_total() { |
798 | 798 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
799 | - return max( $total, 0 ); |
|
799 | + return max($total, 0); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | /** |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | */ |
807 | 807 | public function get_recurring_total() { |
808 | 808 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
809 | - return max( $total, 0 ); |
|
809 | + return max($total, 0); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
@@ -818,12 +818,12 @@ discard block |
||
818 | 818 | $initial = $this->get_total(); |
819 | 819 | $recurring = $this->get_recurring_total(); |
820 | 820 | |
821 | - if ( $this->has_recurring == 0 ) { |
|
821 | + if ($this->has_recurring == 0) { |
|
822 | 822 | $recurring = 0; |
823 | 823 | } |
824 | 824 | |
825 | 825 | $collect = $initial > 0 || $recurring > 0; |
826 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
826 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
827 | 827 | } |
828 | 828 | |
829 | 829 | /** |
@@ -832,7 +832,7 @@ discard block |
||
832 | 832 | * @since 1.0.19 |
833 | 833 | */ |
834 | 834 | public function get_billing_email() { |
835 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
835 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
836 | 836 | } |
837 | 837 | |
838 | 838 | /** |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | */ |
843 | 843 | public function has_billing_email() { |
844 | 844 | $billing_email = $this->get_billing_email(); |
845 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
845 | + return !empty($billing_email) && is_email($billing_email); |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | /** |
@@ -872,8 +872,8 @@ discard block |
||
872 | 872 | * @since 1.0.19 |
873 | 873 | * @return mixed|null |
874 | 874 | */ |
875 | - public function get_field( $field, $sub_array_key = null ) { |
|
876 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
875 | + public function get_field($field, $sub_array_key = null) { |
|
876 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | /** |
@@ -881,8 +881,8 @@ discard block |
||
881 | 881 | * |
882 | 882 | * @since 1.0.19 |
883 | 883 | */ |
884 | - public function is_required_field_set( $field ) { |
|
885 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
884 | + public function is_required_field_set($field) { |
|
885 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
@@ -890,8 +890,8 @@ discard block |
||
890 | 890 | * |
891 | 891 | * @since 1.0.19 |
892 | 892 | */ |
893 | - public function format_amount( $amount ) { |
|
894 | - return wpinv_price( $amount, $this->get_currency() ); |
|
893 | + public function format_amount($amount) { |
|
894 | + return wpinv_price($amount, $this->get_currency()); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | } |
@@ -12,280 +12,280 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
14 | 14 | |
15 | - /** |
|
16 | - * Contains the response for refreshing prices. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $response = array(); |
|
15 | + /** |
|
16 | + * Contains the response for refreshing prices. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $response = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $this->response = array( |
|
29 | - 'submission_id' => $submission->id, |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $this->response = array( |
|
29 | + 'submission_id' => $submission->id, |
|
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | 31 | 'is_free' => ! $submission->should_collect_payment_details(), |
32 | - ); |
|
33 | - |
|
34 | - $this->add_totals( $submission ); |
|
35 | - $this->add_texts( $submission ); |
|
36 | - $this->add_items( $submission ); |
|
37 | - $this->add_fees( $submission ); |
|
38 | - $this->add_discounts( $submission ); |
|
39 | - $this->add_taxes( $submission ); |
|
40 | - $this->add_gateways( $submission ); |
|
41 | - $this->add_data( $submission ); |
|
42 | - |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Adds totals to a response for submission refresh prices. |
|
47 | - * |
|
48 | - * @param GetPaid_Payment_Form_Submission $submission |
|
49 | - */ |
|
50 | - public function add_totals( $submission ) { |
|
51 | - |
|
52 | - $this->response = array_merge( |
|
53 | - $this->response, |
|
54 | - array( |
|
55 | - |
|
56 | - 'totals' => array( |
|
57 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
58 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
59 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
60 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
61 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
62 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
63 | - ), |
|
64 | - |
|
65 | - 'recurring' => array( |
|
66 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
67 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
68 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
69 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
70 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
71 | - ), |
|
72 | - |
|
73 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
74 | - 'currency' => $submission->get_currency(), |
|
75 | - |
|
76 | - ) |
|
77 | - ); |
|
78 | - |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Adds texts to a response for submission refresh prices. |
|
83 | - * |
|
84 | - * @param GetPaid_Payment_Form_Submission $submission |
|
85 | - */ |
|
86 | - public function add_texts( $submission ) { |
|
87 | - |
|
88 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
89 | - |
|
90 | - if ( $submission->has_recurring != 0 && ! getpaid_should_group_subscriptions( $submission ) ) { |
|
91 | - |
|
92 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
93 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
94 | - |
|
95 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
96 | - $payable = "$payable / $period"; |
|
97 | - } else { |
|
98 | - $payable = sprintf( |
|
99 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
100 | - $submission->format_amount( $submission->get_total() ), |
|
101 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
102 | - $period |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - } |
|
107 | - |
|
108 | - $texts = array( |
|
109 | - '.getpaid-checkout-total-payable' => $payable, |
|
110 | - ); |
|
111 | - |
|
112 | - foreach ( $submission->get_items() as $item ) { |
|
113 | - $item_id = $item->get_id(); |
|
114 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
115 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
116 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
117 | - } |
|
118 | - |
|
119 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
120 | - |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Adds items to a response for submission refresh prices. |
|
125 | - * |
|
126 | - * @param GetPaid_Payment_Form_Submission $submission |
|
127 | - */ |
|
128 | - public function add_items( $submission ) { |
|
129 | - |
|
130 | - // Add items. |
|
131 | - $items = array(); |
|
32 | + ); |
|
33 | + |
|
34 | + $this->add_totals( $submission ); |
|
35 | + $this->add_texts( $submission ); |
|
36 | + $this->add_items( $submission ); |
|
37 | + $this->add_fees( $submission ); |
|
38 | + $this->add_discounts( $submission ); |
|
39 | + $this->add_taxes( $submission ); |
|
40 | + $this->add_gateways( $submission ); |
|
41 | + $this->add_data( $submission ); |
|
42 | + |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Adds totals to a response for submission refresh prices. |
|
47 | + * |
|
48 | + * @param GetPaid_Payment_Form_Submission $submission |
|
49 | + */ |
|
50 | + public function add_totals( $submission ) { |
|
51 | + |
|
52 | + $this->response = array_merge( |
|
53 | + $this->response, |
|
54 | + array( |
|
55 | + |
|
56 | + 'totals' => array( |
|
57 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
58 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
59 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
60 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
61 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
62 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
63 | + ), |
|
64 | + |
|
65 | + 'recurring' => array( |
|
66 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
67 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
68 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
69 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
70 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
71 | + ), |
|
72 | + |
|
73 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
74 | + 'currency' => $submission->get_currency(), |
|
75 | + |
|
76 | + ) |
|
77 | + ); |
|
78 | + |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Adds texts to a response for submission refresh prices. |
|
83 | + * |
|
84 | + * @param GetPaid_Payment_Form_Submission $submission |
|
85 | + */ |
|
86 | + public function add_texts( $submission ) { |
|
87 | + |
|
88 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
89 | + |
|
90 | + if ( $submission->has_recurring != 0 && ! getpaid_should_group_subscriptions( $submission ) ) { |
|
91 | + |
|
92 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
93 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
94 | + |
|
95 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
96 | + $payable = "$payable / $period"; |
|
97 | + } else { |
|
98 | + $payable = sprintf( |
|
99 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
100 | + $submission->format_amount( $submission->get_total() ), |
|
101 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
102 | + $period |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + } |
|
107 | + |
|
108 | + $texts = array( |
|
109 | + '.getpaid-checkout-total-payable' => $payable, |
|
110 | + ); |
|
132 | 111 | |
133 | 112 | foreach ( $submission->get_items() as $item ) { |
134 | - $item_id = $item->get_id(); |
|
135 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
136 | - } |
|
113 | + $item_id = $item->get_id(); |
|
114 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
115 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
116 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
117 | + } |
|
137 | 118 | |
138 | - $this->response = array_merge( |
|
139 | - $this->response, |
|
140 | - array( 'items' => $items ) |
|
141 | - ); |
|
119 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
142 | 120 | |
143 | - } |
|
121 | + } |
|
144 | 122 | |
145 | - /** |
|
146 | - * Adds fees to a response for submission refresh prices. |
|
147 | - * |
|
148 | - * @param GetPaid_Payment_Form_Submission $submission |
|
149 | - */ |
|
150 | - public function add_fees( $submission ) { |
|
123 | + /** |
|
124 | + * Adds items to a response for submission refresh prices. |
|
125 | + * |
|
126 | + * @param GetPaid_Payment_Form_Submission $submission |
|
127 | + */ |
|
128 | + public function add_items( $submission ) { |
|
151 | 129 | |
152 | - $fees = array(); |
|
130 | + // Add items. |
|
131 | + $items = array(); |
|
153 | 132 | |
154 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
155 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
156 | - } |
|
133 | + foreach ( $submission->get_items() as $item ) { |
|
134 | + $item_id = $item->get_id(); |
|
135 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
136 | + } |
|
157 | 137 | |
158 | - $this->response = array_merge( |
|
159 | - $this->response, |
|
160 | - array( 'fees' => $fees ) |
|
161 | - ); |
|
138 | + $this->response = array_merge( |
|
139 | + $this->response, |
|
140 | + array( 'items' => $items ) |
|
141 | + ); |
|
162 | 142 | |
163 | - } |
|
143 | + } |
|
164 | 144 | |
165 | - /** |
|
166 | - * Adds discounts to a response for submission refresh prices. |
|
167 | - * |
|
168 | - * @param GetPaid_Payment_Form_Submission $submission |
|
169 | - */ |
|
170 | - public function add_discounts( $submission ) { |
|
145 | + /** |
|
146 | + * Adds fees to a response for submission refresh prices. |
|
147 | + * |
|
148 | + * @param GetPaid_Payment_Form_Submission $submission |
|
149 | + */ |
|
150 | + public function add_fees( $submission ) { |
|
171 | 151 | |
172 | - $discounts = array(); |
|
152 | + $fees = array(); |
|
173 | 153 | |
174 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
175 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
176 | - } |
|
154 | + foreach ( $submission->get_fees() as $name => $data ) { |
|
155 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
156 | + } |
|
177 | 157 | |
178 | - $this->response = array_merge( |
|
179 | - $this->response, |
|
180 | - array( 'discounts' => $discounts ) |
|
181 | - ); |
|
158 | + $this->response = array_merge( |
|
159 | + $this->response, |
|
160 | + array( 'fees' => $fees ) |
|
161 | + ); |
|
182 | 162 | |
183 | - } |
|
163 | + } |
|
184 | 164 | |
185 | - /** |
|
186 | - * Adds taxes to a response for submission refresh prices. |
|
187 | - * |
|
188 | - * @param GetPaid_Payment_Form_Submission $submission |
|
189 | - */ |
|
190 | - public function add_taxes( $submission ) { |
|
165 | + /** |
|
166 | + * Adds discounts to a response for submission refresh prices. |
|
167 | + * |
|
168 | + * @param GetPaid_Payment_Form_Submission $submission |
|
169 | + */ |
|
170 | + public function add_discounts( $submission ) { |
|
191 | 171 | |
192 | - $taxes = array(); |
|
193 | - $markup = ''; |
|
194 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
195 | - $name = sanitize_text_field( $name ); |
|
196 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
197 | - $taxes[$name] = $amount; |
|
198 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
199 | - } |
|
172 | + $discounts = array(); |
|
173 | + |
|
174 | + foreach ( $submission->get_discounts() as $name => $data ) { |
|
175 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
176 | + } |
|
200 | 177 | |
201 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
202 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
203 | - } |
|
178 | + $this->response = array_merge( |
|
179 | + $this->response, |
|
180 | + array( 'discounts' => $discounts ) |
|
181 | + ); |
|
204 | 182 | |
205 | - $this->response = array_merge( |
|
206 | - $this->response, |
|
207 | - array( 'taxes' => $taxes ) |
|
208 | - ); |
|
183 | + } |
|
209 | 184 | |
210 | - } |
|
185 | + /** |
|
186 | + * Adds taxes to a response for submission refresh prices. |
|
187 | + * |
|
188 | + * @param GetPaid_Payment_Form_Submission $submission |
|
189 | + */ |
|
190 | + public function add_taxes( $submission ) { |
|
191 | + |
|
192 | + $taxes = array(); |
|
193 | + $markup = ''; |
|
194 | + foreach ( $submission->get_taxes() as $name => $data ) { |
|
195 | + $name = sanitize_text_field( $name ); |
|
196 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
197 | + $taxes[$name] = $amount; |
|
198 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
199 | + } |
|
211 | 200 | |
212 | - /** |
|
213 | - * Adds gateways to a response for submission refresh prices. |
|
214 | - * |
|
215 | - * @param GetPaid_Payment_Form_Submission $submission |
|
216 | - */ |
|
217 | - public function add_gateways( $submission ) { |
|
201 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
202 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
203 | + } |
|
218 | 204 | |
219 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
205 | + $this->response = array_merge( |
|
206 | + $this->response, |
|
207 | + array( 'taxes' => $taxes ) |
|
208 | + ); |
|
220 | 209 | |
221 | - if ( $this->response['has_recurring'] ) { |
|
210 | + } |
|
222 | 211 | |
223 | - foreach ( $gateways as $i => $gateway ) { |
|
212 | + /** |
|
213 | + * Adds gateways to a response for submission refresh prices. |
|
214 | + * |
|
215 | + * @param GetPaid_Payment_Form_Submission $submission |
|
216 | + */ |
|
217 | + public function add_gateways( $submission ) { |
|
224 | 218 | |
225 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
226 | - unset( $gateways[ $i ] ); |
|
227 | - } |
|
219 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
228 | 220 | |
229 | - } |
|
221 | + if ( $this->response['has_recurring'] ) { |
|
230 | 222 | |
231 | - } |
|
223 | + foreach ( $gateways as $i => $gateway ) { |
|
232 | 224 | |
225 | + if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
226 | + unset( $gateways[ $i ] ); |
|
227 | + } |
|
233 | 228 | |
234 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
235 | - $this->response = array_merge( |
|
236 | - $this->response, |
|
237 | - array( 'gateways' => $gateways ) |
|
238 | - ); |
|
229 | + } |
|
239 | 230 | |
240 | - } |
|
231 | + } |
|
241 | 232 | |
242 | - /** |
|
243 | - * Standardizes prices. |
|
244 | - * |
|
245 | - * @param int $item_id |
|
246 | - * @param float $item_total |
|
247 | - * @param string $discount_code |
|
248 | - * @param bool $recurring |
|
249 | - */ |
|
250 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
251 | 233 | |
252 | - $standardadized_price = $item_total; |
|
234 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
235 | + $this->response = array_merge( |
|
236 | + $this->response, |
|
237 | + array( 'gateways' => $gateways ) |
|
238 | + ); |
|
253 | 239 | |
254 | - // Do we have a $discount_code? |
|
255 | - if ( ! empty( $discount_code ) ) { |
|
240 | + } |
|
256 | 241 | |
257 | - $discount = new WPInv_Discount( $discount_code ); |
|
242 | + /** |
|
243 | + * Standardizes prices. |
|
244 | + * |
|
245 | + * @param int $item_id |
|
246 | + * @param float $item_total |
|
247 | + * @param string $discount_code |
|
248 | + * @param bool $recurring |
|
249 | + */ |
|
250 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
251 | + |
|
252 | + $standardadized_price = $item_total; |
|
258 | 253 | |
259 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
260 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
261 | - } |
|
254 | + // Do we have a $discount_code? |
|
255 | + if ( ! empty( $discount_code ) ) { |
|
262 | 256 | |
263 | - } |
|
257 | + $discount = new WPInv_Discount( $discount_code ); |
|
264 | 258 | |
265 | - return max( 0, $standardadized_price ); |
|
259 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
260 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
261 | + } |
|
266 | 262 | |
267 | - } |
|
263 | + } |
|
268 | 264 | |
269 | - /** |
|
270 | - * Adds data to a response for submission refresh prices. |
|
271 | - * |
|
272 | - * @param GetPaid_Payment_Form_Submission $submission |
|
273 | - */ |
|
274 | - public function add_data( $submission ) { |
|
265 | + return max( 0, $standardadized_price ); |
|
275 | 266 | |
276 | - $this->response = array_merge( |
|
277 | - $this->response, |
|
278 | - array( |
|
279 | - 'js_data' => apply_filters( |
|
280 | - 'getpaid_submission_js_data', |
|
281 | - array( |
|
282 | - 'is_recurring' => $this->response['has_recurring'], |
|
283 | - ), |
|
284 | - $submission |
|
285 | - ) |
|
286 | - ) |
|
287 | - ); |
|
267 | + } |
|
288 | 268 | |
289 | - } |
|
269 | + /** |
|
270 | + * Adds data to a response for submission refresh prices. |
|
271 | + * |
|
272 | + * @param GetPaid_Payment_Form_Submission $submission |
|
273 | + */ |
|
274 | + public function add_data( $submission ) { |
|
275 | + |
|
276 | + $this->response = array_merge( |
|
277 | + $this->response, |
|
278 | + array( |
|
279 | + 'js_data' => apply_filters( |
|
280 | + 'getpaid_submission_js_data', |
|
281 | + array( |
|
282 | + 'is_recurring' => $this->response['has_recurring'], |
|
283 | + ), |
|
284 | + $submission |
|
285 | + ) |
|
286 | + ) |
|
287 | + ); |
|
288 | + |
|
289 | + } |
|
290 | 290 | |
291 | 291 | } |
@@ -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 | * Payment form submission refresh prices class |
@@ -23,22 +23,22 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param GetPaid_Payment_Form_Submission $submission |
25 | 25 | */ |
26 | - public function __construct( $submission ) { |
|
26 | + public function __construct($submission) { |
|
27 | 27 | |
28 | 28 | $this->response = array( |
29 | 29 | 'submission_id' => $submission->id, |
30 | 30 | 'has_recurring' => $submission->has_recurring, |
31 | - 'is_free' => ! $submission->should_collect_payment_details(), |
|
31 | + 'is_free' => !$submission->should_collect_payment_details(), |
|
32 | 32 | ); |
33 | 33 | |
34 | - $this->add_totals( $submission ); |
|
35 | - $this->add_texts( $submission ); |
|
36 | - $this->add_items( $submission ); |
|
37 | - $this->add_fees( $submission ); |
|
38 | - $this->add_discounts( $submission ); |
|
39 | - $this->add_taxes( $submission ); |
|
40 | - $this->add_gateways( $submission ); |
|
41 | - $this->add_data( $submission ); |
|
34 | + $this->add_totals($submission); |
|
35 | + $this->add_texts($submission); |
|
36 | + $this->add_items($submission); |
|
37 | + $this->add_fees($submission); |
|
38 | + $this->add_discounts($submission); |
|
39 | + $this->add_taxes($submission); |
|
40 | + $this->add_gateways($submission); |
|
41 | + $this->add_data($submission); |
|
42 | 42 | |
43 | 43 | } |
44 | 44 | |
@@ -47,30 +47,30 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param GetPaid_Payment_Form_Submission $submission |
49 | 49 | */ |
50 | - public function add_totals( $submission ) { |
|
50 | + public function add_totals($submission) { |
|
51 | 51 | |
52 | 52 | $this->response = array_merge( |
53 | 53 | $this->response, |
54 | 54 | array( |
55 | 55 | |
56 | 56 | 'totals' => array( |
57 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
58 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
59 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
60 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
61 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
62 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
57 | + 'subtotal' => $submission->format_amount($submission->get_subtotal()), |
|
58 | + 'discount' => $submission->format_amount($submission->get_discount()), |
|
59 | + 'fees' => $submission->format_amount($submission->get_fee()), |
|
60 | + 'tax' => $submission->format_amount($submission->get_tax()), |
|
61 | + 'total' => $submission->format_amount($submission->get_total()), |
|
62 | + 'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES), |
|
63 | 63 | ), |
64 | 64 | |
65 | 65 | 'recurring' => array( |
66 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
67 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
68 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
69 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
70 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
66 | + 'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()), |
|
67 | + 'discount' => $submission->format_amount($submission->get_recurring_discount()), |
|
68 | + 'fees' => $submission->format_amount($submission->get_recurring_fee()), |
|
69 | + 'tax' => $submission->format_amount($submission->get_recurring_tax()), |
|
70 | + 'total' => $submission->format_amount($submission->get_recurring_total()), |
|
71 | 71 | ), |
72 | 72 | |
73 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
73 | + 'initial_amt' => wpinv_round_amount($submission->get_total(), null, true), |
|
74 | 74 | 'currency' => $submission->get_currency(), |
75 | 75 | |
76 | 76 | ) |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @param GetPaid_Payment_Form_Submission $submission |
85 | 85 | */ |
86 | - public function add_texts( $submission ) { |
|
86 | + public function add_texts($submission) { |
|
87 | 87 | |
88 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
88 | + $payable = $submission->format_amount($submission->get_total()); |
|
89 | 89 | |
90 | - if ( $submission->has_recurring != 0 && ! getpaid_should_group_subscriptions( $submission ) ) { |
|
90 | + if ($submission->has_recurring != 0 && !getpaid_should_group_subscriptions($submission)) { |
|
91 | 91 | |
92 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
93 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
92 | + $recurring = new WPInv_Item($submission->has_recurring); |
|
93 | + $period = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), ''); |
|
94 | 94 | |
95 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
95 | + if ($submission->get_total() == $submission->get_recurring_total()) { |
|
96 | 96 | $payable = "$payable / $period"; |
97 | 97 | } else { |
98 | 98 | $payable = sprintf( |
99 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
100 | - $submission->format_amount( $submission->get_total() ), |
|
101 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
99 | + __('%1$s (renews at %2$s / %3$s)', 'invoicing'), |
|
100 | + $submission->format_amount($submission->get_total()), |
|
101 | + $submission->format_amount($submission->get_recurring_total()), |
|
102 | 102 | $period |
103 | 103 | ); |
104 | 104 | } |
@@ -109,14 +109,14 @@ discard block |
||
109 | 109 | '.getpaid-checkout-total-payable' => $payable, |
110 | 110 | ); |
111 | 111 | |
112 | - foreach ( $submission->get_items() as $item ) { |
|
112 | + foreach ($submission->get_items() as $item) { |
|
113 | 113 | $item_id = $item->get_id(); |
114 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
115 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
116 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
114 | + $initial_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false)); |
|
115 | + $recurring_price = $submission->format_amount($this->standardize_price($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true)); |
|
116 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price); |
|
117 | 117 | } |
118 | 118 | |
119 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
119 | + $this->response = array_merge($this->response, array('texts' => $texts)); |
|
120 | 120 | |
121 | 121 | } |
122 | 122 | |
@@ -125,19 +125,19 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param GetPaid_Payment_Form_Submission $submission |
127 | 127 | */ |
128 | - public function add_items( $submission ) { |
|
128 | + public function add_items($submission) { |
|
129 | 129 | |
130 | 130 | // Add items. |
131 | 131 | $items = array(); |
132 | 132 | |
133 | - foreach ( $submission->get_items() as $item ) { |
|
133 | + foreach ($submission->get_items() as $item) { |
|
134 | 134 | $item_id = $item->get_id(); |
135 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
135 | + $items["$item_id"] = $submission->format_amount($item->get_sub_total()); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | $this->response = array_merge( |
139 | 139 | $this->response, |
140 | - array( 'items' => $items ) |
|
140 | + array('items' => $items) |
|
141 | 141 | ); |
142 | 142 | |
143 | 143 | } |
@@ -147,17 +147,17 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @param GetPaid_Payment_Form_Submission $submission |
149 | 149 | */ |
150 | - public function add_fees( $submission ) { |
|
150 | + public function add_fees($submission) { |
|
151 | 151 | |
152 | 152 | $fees = array(); |
153 | 153 | |
154 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
155 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
154 | + foreach ($submission->get_fees() as $name => $data) { |
|
155 | + $fees[$name] = $submission->format_amount($data['initial_fee']); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | $this->response = array_merge( |
159 | 159 | $this->response, |
160 | - array( 'fees' => $fees ) |
|
160 | + array('fees' => $fees) |
|
161 | 161 | ); |
162 | 162 | |
163 | 163 | } |
@@ -167,17 +167,17 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param GetPaid_Payment_Form_Submission $submission |
169 | 169 | */ |
170 | - public function add_discounts( $submission ) { |
|
170 | + public function add_discounts($submission) { |
|
171 | 171 | |
172 | 172 | $discounts = array(); |
173 | 173 | |
174 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
175 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
174 | + foreach ($submission->get_discounts() as $name => $data) { |
|
175 | + $discounts[$name] = $submission->format_amount($data['initial_discount']); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $this->response = array_merge( |
179 | 179 | $this->response, |
180 | - array( 'discounts' => $discounts ) |
|
180 | + array('discounts' => $discounts) |
|
181 | 181 | ); |
182 | 182 | |
183 | 183 | } |
@@ -187,24 +187,24 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @param GetPaid_Payment_Form_Submission $submission |
189 | 189 | */ |
190 | - public function add_taxes( $submission ) { |
|
190 | + public function add_taxes($submission) { |
|
191 | 191 | |
192 | 192 | $taxes = array(); |
193 | 193 | $markup = ''; |
194 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
195 | - $name = sanitize_text_field( $name ); |
|
196 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
194 | + foreach ($submission->get_taxes() as $name => $data) { |
|
195 | + $name = sanitize_text_field($name); |
|
196 | + $amount = $submission->format_amount($data['initial_tax']); |
|
197 | 197 | $taxes[$name] = $amount; |
198 | 198 | $markup .= "<small class='form-text'>$name : $amount</small>"; |
199 | 199 | } |
200 | 200 | |
201 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
201 | + if (wpinv_display_individual_tax_rates() && !empty($taxes)) { |
|
202 | 202 | $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
203 | 203 | } |
204 | 204 | |
205 | 205 | $this->response = array_merge( |
206 | 206 | $this->response, |
207 | - array( 'taxes' => $taxes ) |
|
207 | + array('taxes' => $taxes) |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | } |
@@ -214,16 +214,16 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @param GetPaid_Payment_Form_Submission $submission |
216 | 216 | */ |
217 | - public function add_gateways( $submission ) { |
|
217 | + public function add_gateways($submission) { |
|
218 | 218 | |
219 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
219 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
220 | 220 | |
221 | - if ( $this->response['has_recurring'] ) { |
|
221 | + if ($this->response['has_recurring']) { |
|
222 | 222 | |
223 | - foreach ( $gateways as $i => $gateway ) { |
|
223 | + foreach ($gateways as $i => $gateway) { |
|
224 | 224 | |
225 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
226 | - unset( $gateways[ $i ] ); |
|
225 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
226 | + unset($gateways[$i]); |
|
227 | 227 | } |
228 | 228 | |
229 | 229 | } |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | } |
232 | 232 | |
233 | 233 | |
234 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
234 | + $gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission); |
|
235 | 235 | $this->response = array_merge( |
236 | 236 | $this->response, |
237 | - array( 'gateways' => $gateways ) |
|
237 | + array('gateways' => $gateways) |
|
238 | 238 | ); |
239 | 239 | |
240 | 240 | } |
@@ -247,22 +247,22 @@ discard block |
||
247 | 247 | * @param string $discount_code |
248 | 248 | * @param bool $recurring |
249 | 249 | */ |
250 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
250 | + public function standardize_price($item_id, $item_total, $discount_code, $recurring = false) { |
|
251 | 251 | |
252 | 252 | $standardadized_price = $item_total; |
253 | 253 | |
254 | 254 | // Do we have a $discount_code? |
255 | - if ( ! empty( $discount_code ) ) { |
|
255 | + if (!empty($discount_code)) { |
|
256 | 256 | |
257 | - $discount = new WPInv_Discount( $discount_code ); |
|
257 | + $discount = new WPInv_Discount($discount_code); |
|
258 | 258 | |
259 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
260 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
259 | + if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) { |
|
260 | + $standardadized_price = $item_total - $discount->get_discounted_amount($item_total); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
264 | 264 | |
265 | - return max( 0, $standardadized_price ); |
|
265 | + return max(0, $standardadized_price); |
|
266 | 266 | |
267 | 267 | } |
268 | 268 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @param GetPaid_Payment_Form_Submission $submission |
273 | 273 | */ |
274 | - public function add_data( $submission ) { |
|
274 | + public function add_data($submission) { |
|
275 | 275 | |
276 | 276 | $this->response = array_merge( |
277 | 277 | $this->response, |