@@ -160,50 +160,50 @@ |
||
| 160 | 160 | */ |
| 161 | 161 | function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
| 162 | 162 | |
| 163 | - $initial_discount = 0; |
|
| 164 | - $recurring_discount = 0; |
|
| 163 | + $initial_discount = 0; |
|
| 164 | + $recurring_discount = 0; |
|
| 165 | 165 | |
| 166 | - foreach ( $invoice->get_items() as $item ) { |
|
| 166 | + foreach ( $invoice->get_items() as $item ) { |
|
| 167 | 167 | |
| 168 | - // Abort if it is not valid for this item. |
|
| 169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | - continue; |
|
| 171 | - } |
|
| 168 | + // Abort if it is not valid for this item. |
|
| 169 | + if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 170 | + continue; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - // Calculate the initial amount... |
|
| 174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | - $recurring_item_discount = 0; |
|
| 173 | + // Calculate the initial amount... |
|
| 174 | + $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 175 | + $recurring_item_discount = 0; |
|
| 176 | 176 | |
| 177 | - // ... and maybe the recurring amount. |
|
| 178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | - } |
|
| 177 | + // ... and maybe the recurring amount. |
|
| 178 | + if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | + $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - // Discount should not exceed discounted amount. |
|
| 183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
| 182 | + // Discount should not exceed discounted amount. |
|
| 183 | + if ( ! $discount->is_type( 'percent' ) ) { |
|
| 184 | 184 | |
| 185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | - $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | - } |
|
| 185 | + if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 186 | + $item_discount = $discount->get_amount() - $initial_discount; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | - $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | - } |
|
| 189 | + if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 190 | + $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
|
| 191 | + } |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - $initial_discount += $item_discount; |
|
| 195 | - $recurring_discount += $recurring_item_discount; |
|
| 196 | - $item->item_discount = $item_discount; |
|
| 197 | - $item->recurring_item_discount = $recurring_item_discount; |
|
| 194 | + $initial_discount += $item_discount; |
|
| 195 | + $recurring_discount += $recurring_item_discount; |
|
| 196 | + $item->item_discount = $item_discount; |
|
| 197 | + $item->recurring_item_discount = $recurring_item_discount; |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return array( |
|
| 202 | - 'name' => 'discount_code', |
|
| 203 | - 'discount_code' => $discount->get_code(), |
|
| 204 | - 'initial_discount' => $initial_discount, |
|
| 205 | - 'recurring_discount' => $recurring_discount, |
|
| 206 | - ); |
|
| 201 | + return array( |
|
| 202 | + 'name' => 'discount_code', |
|
| 203 | + 'discount_code' => $discount->get_code(), |
|
| 204 | + 'initial_discount' => $initial_discount, |
|
| 205 | + 'recurring_discount' => $recurring_discount, |
|
| 206 | + ); |
|
| 207 | 207 | |
| 208 | 208 | } |
| 209 | 209 | |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Returns an array of discount type. |
@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | return apply_filters( |
| 18 | 18 | 'wpinv_discount_types', |
| 19 | 19 | array( |
| 20 | - 'percent' => __( 'Percentage', 'invoicing' ), |
|
| 21 | - 'flat' => __( 'Flat Amount', 'invoicing' ), |
|
| 20 | + 'percent' => __('Percentage', 'invoicing'), |
|
| 21 | + 'flat' => __('Flat Amount', 'invoicing'), |
|
| 22 | 22 | ) |
| 23 | 23 | ); |
| 24 | 24 | } |
@@ -28,46 +28,46 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | -function wpinv_get_discount_type_name( $type = '' ) { |
|
| 31 | +function wpinv_get_discount_type_name($type = '') { |
|
| 32 | 32 | $types = wpinv_get_discount_types(); |
| 33 | - return isset( $types[ $type ] ) ? $types[ $type ] : $type; |
|
| 33 | + return isset($types[$type]) ? $types[$type] : $type; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * Deletes a discount via the admin page. |
| 38 | 38 | * |
| 39 | 39 | */ |
| 40 | -function wpinv_delete_discount( $data ) { |
|
| 40 | +function wpinv_delete_discount($data) { |
|
| 41 | 41 | |
| 42 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
| 43 | - $discount->delete( true ); |
|
| 42 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
| 43 | + $discount->delete(true); |
|
| 44 | 44 | |
| 45 | 45 | } |
| 46 | -add_action( 'getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount' ); |
|
| 46 | +add_action('getpaid_authenticated_admin_action_delete_discount', 'wpinv_delete_discount'); |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * Deactivates a discount via the admin page. |
| 50 | 50 | */ |
| 51 | -function wpinv_activate_discount( $data ) { |
|
| 51 | +function wpinv_activate_discount($data) { |
|
| 52 | 52 | |
| 53 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
| 54 | - $discount->set_status( 'publish' ); |
|
| 53 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
| 54 | + $discount->set_status('publish'); |
|
| 55 | 55 | $discount->save(); |
| 56 | 56 | |
| 57 | 57 | } |
| 58 | -add_action( 'getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount' ); |
|
| 58 | +add_action('getpaid_authenticated_admin_action_activate_discount', 'wpinv_activate_discount'); |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * Activates a discount via the admin page. |
| 62 | 62 | */ |
| 63 | -function wpinv_deactivate_discount( $data ) { |
|
| 63 | +function wpinv_deactivate_discount($data) { |
|
| 64 | 64 | |
| 65 | - $discount = new WPInv_Discount( absint( $data['discount'] ) ); |
|
| 66 | - $discount->set_status( 'pending' ); |
|
| 65 | + $discount = new WPInv_Discount(absint($data['discount'])); |
|
| 66 | + $discount->set_status('pending'); |
|
| 67 | 67 | $discount->save(); |
| 68 | 68 | |
| 69 | 69 | } |
| 70 | -add_action( 'getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount' ); |
|
| 70 | +add_action('getpaid_authenticated_admin_action_deactivate_discount', 'wpinv_deactivate_discount'); |
|
| 71 | 71 | |
| 72 | 72 | /** |
| 73 | 73 | * Fetches a discount object. |
@@ -76,8 +76,8 @@ discard block |
||
| 76 | 76 | * @since 1.0.15 |
| 77 | 77 | * @return WPInv_Discount |
| 78 | 78 | */ |
| 79 | -function wpinv_get_discount( $discount ) { |
|
| 80 | - return new WPInv_Discount( $discount ); |
|
| 79 | +function wpinv_get_discount($discount) { |
|
| 80 | + return new WPInv_Discount($discount); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * @since 1.0.15 |
| 88 | 88 | * @return WPInv_Discount |
| 89 | 89 | */ |
| 90 | -function wpinv_get_discount_obj( $discount = 0 ) { |
|
| 91 | - return new WPInv_Discount( $discount ); |
|
| 90 | +function wpinv_get_discount_obj($discount = 0) { |
|
| 91 | + return new WPInv_Discount($discount); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -98,10 +98,10 @@ discard block |
||
| 98 | 98 | * @param string|int $value The field value |
| 99 | 99 | * @return bool|WPInv_Discount |
| 100 | 100 | */ |
| 101 | -function wpinv_get_discount_by( $deprecated = null, $value = '' ) { |
|
| 102 | - $discount = new WPInv_Discount( $value ); |
|
| 101 | +function wpinv_get_discount_by($deprecated = null, $value = '') { |
|
| 102 | + $discount = new WPInv_Discount($value); |
|
| 103 | 103 | |
| 104 | - if ( $discount->get_id() != 0 ) { |
|
| 104 | + if ($discount->get_id() != 0) { |
|
| 105 | 105 | return $discount; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | function wpinv_get_discount_statuses() { |
| 117 | 117 | |
| 118 | 118 | return array( |
| 119 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
| 120 | - 'publish' => __( 'Active', 'invoicing' ), |
|
| 121 | - 'inactive' => __( 'Inactive', 'invoicing' ), |
|
| 119 | + 'expired' => __('Expired', 'invoicing'), |
|
| 120 | + 'publish' => __('Active', 'invoicing'), |
|
| 121 | + 'inactive' => __('Inactive', 'invoicing'), |
|
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | 124 | } |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | /** |
| 127 | 127 | * Retrieves an invoice status label. |
| 128 | 128 | */ |
| 129 | -function wpinv_discount_status( $status ) { |
|
| 129 | +function wpinv_discount_status($status) { |
|
| 130 | 130 | $statuses = wpinv_get_discount_statuses(); |
| 131 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'Inactive', 'invoicing' ); |
|
| 131 | + return isset($statuses[$status]) ? $statuses[$status] : __('Inactive', 'invoicing'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | * @param int|array|string|WPInv_Discount $code discount data, object, ID or code. |
| 139 | 139 | * @return bool |
| 140 | 140 | */ |
| 141 | -function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) { |
|
| 141 | +function wpinv_discount_is_recurring($discount = 0, $code = 0) { |
|
| 142 | 142 | |
| 143 | - if ( ! empty( $discount ) ) { |
|
| 144 | - $discount = wpinv_get_discount_obj( $discount ); |
|
| 143 | + if (!empty($discount)) { |
|
| 144 | + $discount = wpinv_get_discount_obj($discount); |
|
| 145 | 145 | } else { |
| 146 | - $discount = wpinv_get_discount_obj( $code ); |
|
| 146 | + $discount = wpinv_get_discount_obj($code); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | return $discount->get_is_recurring(); |
@@ -158,35 +158,35 @@ discard block |
||
| 158 | 158 | * @param WPInv_Discount $discount |
| 159 | 159 | * @return array |
| 160 | 160 | */ |
| 161 | -function getpaid_calculate_invoice_discount( $invoice, $discount ) { |
|
| 161 | +function getpaid_calculate_invoice_discount($invoice, $discount) { |
|
| 162 | 162 | |
| 163 | 163 | $initial_discount = 0; |
| 164 | 164 | $recurring_discount = 0; |
| 165 | 165 | |
| 166 | - foreach ( $invoice->get_items() as $item ) { |
|
| 166 | + foreach ($invoice->get_items() as $item) { |
|
| 167 | 167 | |
| 168 | 168 | // Abort if it is not valid for this item. |
| 169 | - if ( ! $discount->is_valid_for_items( array( $item->get_id() ) ) ) { |
|
| 169 | + if (!$discount->is_valid_for_items(array($item->get_id()))) { |
|
| 170 | 170 | continue; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Calculate the initial amount... |
| 174 | - $item_discount = $discount->get_discounted_amount( $item->get_sub_total() ); |
|
| 174 | + $item_discount = $discount->get_discounted_amount($item->get_sub_total()); |
|
| 175 | 175 | $recurring_item_discount = 0; |
| 176 | 176 | |
| 177 | 177 | // ... and maybe the recurring amount. |
| 178 | - if ( $item->is_recurring() && $discount->is_recurring() ) { |
|
| 179 | - $recurring_item_discount = $discount->get_discounted_amount( $item->get_recurring_sub_total() ); |
|
| 178 | + if ($item->is_recurring() && $discount->is_recurring()) { |
|
| 179 | + $recurring_item_discount = $discount->get_discounted_amount($item->get_recurring_sub_total()); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // Discount should not exceed discounted amount. |
| 183 | - if ( ! $discount->is_type( 'percent' ) ) { |
|
| 183 | + if (!$discount->is_type('percent')) { |
|
| 184 | 184 | |
| 185 | - if ( ( $initial_discount + $item_discount ) > $discount->get_amount() ) { |
|
| 185 | + if (($initial_discount + $item_discount) > $discount->get_amount()) { |
|
| 186 | 186 | $item_discount = $discount->get_amount() - $initial_discount; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( ( $recurring_discount + $recurring_item_discount ) > $discount->get_amount() ) { |
|
| 189 | + if (($recurring_discount + $recurring_item_discount) > $discount->get_amount()) { |
|
| 190 | 190 | $recurring_item_discount = $discount->get_amount() - $recurring_discount; |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -218,10 +218,10 @@ discard block |
||
| 218 | 218 | array( |
| 219 | 219 | 'post_type' => 'wpi_discount', |
| 220 | 220 | 'numberposts' => 1, |
| 221 | - 'fields' => array( 'ids' ), |
|
| 221 | + 'fields' => array('ids'), |
|
| 222 | 222 | ) |
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | - return ! empty( $discounts ); |
|
| 225 | + return !empty($discounts); |
|
| 226 | 226 | |
| 227 | 227 | } |
@@ -15,125 +15,125 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $data_store_name = 'subscription'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'subscription'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'customer_id' => 0, |
|
| 40 | - 'frequency' => 1, |
|
| 41 | - 'period' => 'D', |
|
| 42 | - 'initial_amount' => null, |
|
| 43 | - 'recurring_amount' => null, |
|
| 44 | - 'bill_times' => 0, |
|
| 45 | - 'transaction_id' => '', |
|
| 46 | - 'parent_payment_id' => null, |
|
| 47 | - 'product_id' => 0, |
|
| 48 | - 'created' => '0000-00-00 00:00:00', |
|
| 49 | - 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | - 'trial_period' => '', |
|
| 51 | - 'status' => 'pending', |
|
| 52 | - 'profile_id' => '', |
|
| 53 | - 'gateway' => '', |
|
| 54 | - 'customer' => '', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Stores the status transition information. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - protected $status_transition = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | - * |
|
| 68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | - * @param bool $deprecated |
|
| 70 | - */ |
|
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | - |
|
| 73 | - parent::__construct( $subscription ); |
|
| 74 | - |
|
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 83 | - } else { |
|
| 84 | - $this->set_object_read( true ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Load the datastore. |
|
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | - |
|
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @static |
|
| 101 | - * @param string $value |
|
| 102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | - * @since 1.0.19 |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $data_store_name = 'subscription'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'subscription'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'customer_id' => 0, |
|
| 40 | + 'frequency' => 1, |
|
| 41 | + 'period' => 'D', |
|
| 42 | + 'initial_amount' => null, |
|
| 43 | + 'recurring_amount' => null, |
|
| 44 | + 'bill_times' => 0, |
|
| 45 | + 'transaction_id' => '', |
|
| 46 | + 'parent_payment_id' => null, |
|
| 47 | + 'product_id' => 0, |
|
| 48 | + 'created' => '0000-00-00 00:00:00', |
|
| 49 | + 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | + 'trial_period' => '', |
|
| 51 | + 'status' => 'pending', |
|
| 52 | + 'profile_id' => '', |
|
| 53 | + 'gateway' => '', |
|
| 54 | + 'customer' => '', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Stores the status transition information. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + protected $status_transition = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | + * |
|
| 68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | + * @param bool $deprecated |
|
| 70 | + */ |
|
| 71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | + |
|
| 73 | + parent::__construct( $subscription ); |
|
| 74 | + |
|
| 75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | + $this->set_id( $subscription ); |
|
| 77 | + } elseif ( $subscription instanceof self ) { |
|
| 78 | + $this->set_id( $subscription->get_id() ); |
|
| 79 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | + $this->set_id( $subscription_id ); |
|
| 81 | + } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | + $this->set_id( $subscription->id ); |
|
| 83 | + } else { |
|
| 84 | + $this->set_object_read( true ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Load the datastore. |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | + |
|
| 90 | + if ( $this->get_id() > 0 ) { |
|
| 91 | + $this->data_store->read( $this ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @static |
|
| 101 | + * @param string $value |
|
| 102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | + * @since 1.0.19 |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - // Trim the value. |
|
| 110 | - $value = trim( $value ); |
|
| 109 | + // Trim the value. |
|
| 110 | + $value = trim( $value ); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 113 | - return 0; |
|
| 114 | - } |
|
| 112 | + if ( empty( $value ) ) { |
|
| 113 | + return 0; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 117 | - $field = 'parent_payment_id'; |
|
| 118 | - } |
|
| 116 | + if ( 'invoice_id' == $field ) { |
|
| 117 | + $field = 'parent_payment_id'; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | // Valid fields. |
| 121 | 121 | $fields = array( |
| 122 | - 'parent_payment_id', |
|
| 123 | - 'transaction_id', |
|
| 124 | - 'profile_id', |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Ensure a field has been passed. |
|
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Maybe retrieve from the cache. |
|
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 135 | - return $subscription_id; |
|
| 136 | - } |
|
| 122 | + 'parent_payment_id', |
|
| 123 | + 'transaction_id', |
|
| 124 | + 'profile_id', |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Ensure a field has been passed. |
|
| 128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Maybe retrieve from the cache. |
|
| 133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | + if ( ! empty( $subscription_id ) ) { |
|
| 135 | + return $subscription_id; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
| 141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 145 | - return 0; |
|
| 146 | - } |
|
| 144 | + if ( empty( $subscription_id ) ) { |
|
| 145 | + return 0; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - // Update the cache with our data. |
|
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 148 | + // Update the cache with our data. |
|
| 149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 150 | 150 | |
| 151 | - return $subscription_id; |
|
| 152 | - } |
|
| 151 | + return $subscription_id; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | + /** |
|
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | - } |
|
| 158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | + /** |
|
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | 167 | public function _isset( $key ) { |
| 168 | 168 | return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /* |
|
| 171 | + /* |
|
| 172 | 172 | |-------------------------------------------------------------------------- |
| 173 | 173 | | CRUD methods |
| 174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,57 +177,57 @@ discard block |
||
| 177 | 177 | | |
| 178 | 178 | */ |
| 179 | 179 | |
| 180 | - /* |
|
| 180 | + /* |
|
| 181 | 181 | |-------------------------------------------------------------------------- |
| 182 | 182 | | Getters |
| 183 | 183 | |-------------------------------------------------------------------------- |
| 184 | 184 | */ |
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Get customer id. |
|
| 188 | - * |
|
| 189 | - * @since 1.0.19 |
|
| 190 | - * @param string $context View or edit context. |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Get customer information. |
|
| 199 | - * |
|
| 200 | - * @since 1.0.19 |
|
| 201 | - * @param string $context View or edit context. |
|
| 202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | - */ |
|
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get parent invoice id. |
|
| 210 | - * |
|
| 211 | - * @since 1.0.19 |
|
| 212 | - * @param string $context View or edit context. |
|
| 213 | - * @return int |
|
| 214 | - */ |
|
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Alias for self::get_parent_invoice_id(). |
|
| 221 | - * |
|
| 222 | - * @since 1.0.19 |
|
| 223 | - * @param string $context View or edit context. |
|
| 224 | - * @return int |
|
| 225 | - */ |
|
| 186 | + /** |
|
| 187 | + * Get customer id. |
|
| 188 | + * |
|
| 189 | + * @since 1.0.19 |
|
| 190 | + * @param string $context View or edit context. |
|
| 191 | + * @return int |
|
| 192 | + */ |
|
| 193 | + public function get_customer_id( $context = 'view' ) { |
|
| 194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Get customer information. |
|
| 199 | + * |
|
| 200 | + * @since 1.0.19 |
|
| 201 | + * @param string $context View or edit context. |
|
| 202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | + */ |
|
| 204 | + public function get_customer( $context = 'view' ) { |
|
| 205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get parent invoice id. |
|
| 210 | + * |
|
| 211 | + * @since 1.0.19 |
|
| 212 | + * @param string $context View or edit context. |
|
| 213 | + * @return int |
|
| 214 | + */ |
|
| 215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Alias for self::get_parent_invoice_id(). |
|
| 221 | + * |
|
| 222 | + * @since 1.0.19 |
|
| 223 | + * @param string $context View or edit context. |
|
| 224 | + * @return int |
|
| 225 | + */ |
|
| 226 | 226 | public function get_parent_payment_id( $context = 'view' ) { |
| 227 | 227 | return $this->get_parent_invoice_id( $context ); |
| 228 | - } |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 230 | + /** |
|
| 231 | 231 | * Alias for self::get_parent_invoice_id(). |
| 232 | 232 | * |
| 233 | 233 | * @since 1.0.0 |
@@ -237,484 +237,484 @@ discard block |
||
| 237 | 237 | return $this->get_parent_invoice_id( $context ); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * Get parent invoice. |
|
| 242 | - * |
|
| 243 | - * @since 1.0.19 |
|
| 244 | - * @param string $context View or edit context. |
|
| 245 | - * @return WPInv_Invoice |
|
| 246 | - */ |
|
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Alias for self::get_parent_invoice(). |
|
| 253 | - * |
|
| 254 | - * @since 1.0.19 |
|
| 255 | - * @param string $context View or edit context. |
|
| 256 | - * @return WPInv_Invoice |
|
| 257 | - */ |
|
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Get subscription's product id. |
|
| 264 | - * |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @param string $context View or edit context. |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Get the subscription product. |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @param string $context View or edit context. |
|
| 278 | - * @return WPInv_Item |
|
| 279 | - */ |
|
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Get parent invoice's gateway. |
|
| 286 | - * |
|
| 287 | - * Here for backwards compatibility. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @param string $context View or edit context. |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Get the period of a renewal. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @param string $context View or edit context. |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Get number of periods each renewal is valid for. |
|
| 310 | - * |
|
| 311 | - * @since 1.0.19 |
|
| 312 | - * @param string $context View or edit context. |
|
| 313 | - * @return int |
|
| 314 | - */ |
|
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the initial amount for the subscription. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @param string $context View or edit context. |
|
| 324 | - * @return float |
|
| 325 | - */ |
|
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get the recurring amount for the subscription. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return float |
|
| 336 | - */ |
|
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Get number of times that this subscription can be renewed. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - * @param string $context View or edit context. |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Get transaction id of this subscription's parent invoice. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param string $context View or edit context. |
|
| 357 | - * @return string |
|
| 358 | - */ |
|
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Get the date that the subscription was created. |
|
| 365 | - * |
|
| 366 | - * @since 1.0.19 |
|
| 367 | - * @param string $context View or edit context. |
|
| 368 | - * @return string |
|
| 369 | - */ |
|
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Alias for self::get_created(). |
|
| 376 | - * |
|
| 377 | - * @since 1.0.19 |
|
| 378 | - * @param string $context View or edit context. |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Retrieves the creation date in a timestamp |
|
| 387 | - * |
|
| 388 | - * @since 1.0.0 |
|
| 389 | - * @return int |
|
| 390 | - */ |
|
| 391 | - public function get_time_created() { |
|
| 392 | - $created = $this->get_date_created(); |
|
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get GMT date when the subscription was created. |
|
| 398 | - * |
|
| 399 | - * @since 1.0.19 |
|
| 400 | - * @param string $context View or edit context. |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 240 | + /** |
|
| 241 | + * Get parent invoice. |
|
| 242 | + * |
|
| 243 | + * @since 1.0.19 |
|
| 244 | + * @param string $context View or edit context. |
|
| 245 | + * @return WPInv_Invoice |
|
| 246 | + */ |
|
| 247 | + public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Alias for self::get_parent_invoice(). |
|
| 253 | + * |
|
| 254 | + * @since 1.0.19 |
|
| 255 | + * @param string $context View or edit context. |
|
| 256 | + * @return WPInv_Invoice |
|
| 257 | + */ |
|
| 258 | + public function get_parent_payment( $context = 'view' ) { |
|
| 259 | + return $this->get_parent_invoice( $context ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Get subscription's product id. |
|
| 264 | + * |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @param string $context View or edit context. |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function get_product_id( $context = 'view' ) { |
|
| 270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Get the subscription product. |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @param string $context View or edit context. |
|
| 278 | + * @return WPInv_Item |
|
| 279 | + */ |
|
| 280 | + public function get_product( $context = 'view' ) { |
|
| 281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Get parent invoice's gateway. |
|
| 286 | + * |
|
| 287 | + * Here for backwards compatibility. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @param string $context View or edit context. |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function get_gateway( $context = 'view' ) { |
|
| 294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Get the period of a renewal. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @param string $context View or edit context. |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function get_period( $context = 'view' ) { |
|
| 305 | + return $this->get_prop( 'period', $context ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Get number of periods each renewal is valid for. |
|
| 310 | + * |
|
| 311 | + * @since 1.0.19 |
|
| 312 | + * @param string $context View or edit context. |
|
| 313 | + * @return int |
|
| 314 | + */ |
|
| 315 | + public function get_frequency( $context = 'view' ) { |
|
| 316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the initial amount for the subscription. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @param string $context View or edit context. |
|
| 324 | + * @return float |
|
| 325 | + */ |
|
| 326 | + public function get_initial_amount( $context = 'view' ) { |
|
| 327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get the recurring amount for the subscription. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return float |
|
| 336 | + */ |
|
| 337 | + public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Get number of times that this subscription can be renewed. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + * @param string $context View or edit context. |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function get_bill_times( $context = 'view' ) { |
|
| 349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Get transaction id of this subscription's parent invoice. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param string $context View or edit context. |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + public function get_transaction_id( $context = 'view' ) { |
|
| 360 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Get the date that the subscription was created. |
|
| 365 | + * |
|
| 366 | + * @since 1.0.19 |
|
| 367 | + * @param string $context View or edit context. |
|
| 368 | + * @return string |
|
| 369 | + */ |
|
| 370 | + public function get_created( $context = 'view' ) { |
|
| 371 | + return $this->get_prop( 'created', $context ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Alias for self::get_created(). |
|
| 376 | + * |
|
| 377 | + * @since 1.0.19 |
|
| 378 | + * @param string $context View or edit context. |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function get_date_created( $context = 'view' ) { |
|
| 382 | + return $this->get_created( $context ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Retrieves the creation date in a timestamp |
|
| 387 | + * |
|
| 388 | + * @since 1.0.0 |
|
| 389 | + * @return int |
|
| 390 | + */ |
|
| 391 | + public function get_time_created() { |
|
| 392 | + $created = $this->get_date_created(); |
|
| 393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get GMT date when the subscription was created. |
|
| 398 | + * |
|
| 399 | + * @since 1.0.19 |
|
| 400 | + * @param string $context View or edit context. |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | + $date = $this->get_date_created( $context ); |
|
| 405 | + |
|
| 406 | + if ( $date ) { |
|
| 407 | + $date = get_gmt_from_date( $date ); |
|
| 408 | + } |
|
| 409 | + return $date; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get the date that the subscription will renew. |
|
| 414 | + * |
|
| 415 | + * @since 1.0.19 |
|
| 416 | + * @param string $context View or edit context. |
|
| 417 | + * @return string |
|
| 418 | + */ |
|
| 419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | + return $this->get_prop( 'expiration', $context ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Alias for self::get_next_renewal_date(). |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + * @param string $context View or edit context. |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function get_expiration( $context = 'view' ) { |
|
| 431 | + return $this->get_next_renewal_date( $context ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Retrieves the expiration date in a timestamp |
|
| 436 | + * |
|
| 437 | + * @since 1.0.0 |
|
| 438 | + * @return int |
|
| 439 | + */ |
|
| 440 | + public function get_expiration_time() { |
|
| 441 | + $expiration = $this->get_expiration(); |
|
| 442 | + |
|
| 443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | + return current_time( 'timestamp' ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Get GMT date when the subscription will renew. |
|
| 453 | + * |
|
| 454 | + * @since 1.0.19 |
|
| 455 | + * @param string $context View or edit context. |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | + $date = $this->get_next_renewal_date( $context ); |
|
| 460 | + |
|
| 461 | + if ( $date ) { |
|
| 462 | + $date = get_gmt_from_date( $date ); |
|
| 463 | + } |
|
| 464 | + return $date; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Get the subscription's trial period. |
|
| 469 | + * |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + * @param string $context View or edit context. |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function get_trial_period( $context = 'view' ) { |
|
| 475 | + return $this->get_prop( 'trial_period', $context ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Get the subscription's status. |
|
| 480 | + * |
|
| 481 | + * @since 1.0.19 |
|
| 482 | + * @param string $context View or edit context. |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + public function get_status( $context = 'view' ) { |
|
| 486 | + return $this->get_prop( 'status', $context ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Get the subscription's profile id. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $context View or edit context. |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + public function get_profile_id( $context = 'view' ) { |
|
| 497 | + return $this->get_prop( 'profile_id', $context ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /* |
|
| 501 | + |-------------------------------------------------------------------------- |
|
| 502 | + | Setters |
|
| 503 | + |-------------------------------------------------------------------------- |
|
| 504 | + */ |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Set customer id. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param int $value The customer's id. |
|
| 511 | + */ |
|
| 512 | + public function set_customer_id( $value ) { |
|
| 513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Set parent invoice id. |
|
| 518 | + * |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + * @param int $value The parent invoice id. |
|
| 521 | + */ |
|
| 522 | + public function set_parent_invoice_id( $value ) { |
|
| 523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Alias for self::set_parent_invoice_id(). |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + * @param int $value The parent invoice id. |
|
| 531 | + */ |
|
| 532 | + public function set_parent_payment_id( $value ) { |
|
| 533 | + $this->set_parent_invoice_id( $value ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Alias for self::set_parent_invoice_id(). |
|
| 538 | + * |
|
| 539 | + * @since 1.0.19 |
|
| 540 | + * @param int $value The parent invoice id. |
|
| 541 | + */ |
|
| 542 | + public function set_original_payment_id( $value ) { |
|
| 543 | + $this->set_parent_invoice_id( $value ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Set subscription's product id. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param int $value The subscription product id. |
|
| 551 | + */ |
|
| 552 | + public function set_product_id( $value ) { |
|
| 553 | + $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Set the period of a renewal. |
|
| 558 | + * |
|
| 559 | + * @since 1.0.19 |
|
| 560 | + * @param string $value The renewal period. |
|
| 561 | + */ |
|
| 562 | + public function set_period( $value ) { |
|
| 563 | + $this->set_prop( 'period', $value ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Set number of periods each renewal is valid for. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + * @param int $value The subscription frequency. |
|
| 571 | + */ |
|
| 572 | + public function set_frequency( $value ) { |
|
| 573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Set the initial amount for the subscription. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @param float $value The initial subcription amount. |
|
| 582 | + */ |
|
| 583 | + public function set_initial_amount( $value ) { |
|
| 584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Set the recurring amount for the subscription. |
|
| 589 | + * |
|
| 590 | + * @since 1.0.19 |
|
| 591 | + * @param float $value The recurring subcription amount. |
|
| 592 | + */ |
|
| 593 | + public function set_recurring_amount( $value ) { |
|
| 594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Set number of times that this subscription can be renewed. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + * @param int $value Bill times. |
|
| 602 | + */ |
|
| 603 | + public function set_bill_times( $value ) { |
|
| 604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Get transaction id of this subscription's parent invoice. |
|
| 609 | + * |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param string $value Bill times. |
|
| 612 | + */ |
|
| 613 | + public function set_transaction_id( $value ) { |
|
| 614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + /** |
|
| 618 | + * Set date when this subscription started. |
|
| 619 | + * |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + * @param string $value strtotime compliant date. |
|
| 622 | + */ |
|
| 623 | + public function set_created( $value ) { |
|
| 624 | + $date = strtotime( $value ); |
|
| 405 | 625 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | + return; |
|
| 408 | 629 | } |
| 409 | - return $date; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get the date that the subscription will renew. |
|
| 414 | - * |
|
| 415 | - * @since 1.0.19 |
|
| 416 | - * @param string $context View or edit context. |
|
| 417 | - * @return string |
|
| 418 | - */ |
|
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Alias for self::get_next_renewal_date(). |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - * @param string $context View or edit context. |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Retrieves the expiration date in a timestamp |
|
| 436 | - * |
|
| 437 | - * @since 1.0.0 |
|
| 438 | - * @return int |
|
| 439 | - */ |
|
| 440 | - public function get_expiration_time() { |
|
| 441 | - $expiration = $this->get_expiration(); |
|
| 442 | - |
|
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Get GMT date when the subscription will renew. |
|
| 453 | - * |
|
| 454 | - * @since 1.0.19 |
|
| 455 | - * @param string $context View or edit context. |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 460 | 630 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 463 | - } |
|
| 464 | - return $date; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Get the subscription's trial period. |
|
| 469 | - * |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - * @param string $context View or edit context. |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Get the subscription's status. |
|
| 480 | - * |
|
| 481 | - * @since 1.0.19 |
|
| 482 | - * @param string $context View or edit context. |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Get the subscription's profile id. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $context View or edit context. |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /* |
|
| 501 | - |-------------------------------------------------------------------------- |
|
| 502 | - | Setters |
|
| 503 | - |-------------------------------------------------------------------------- |
|
| 504 | - */ |
|
| 631 | + $this->set_prop( 'created', '' ); |
|
| 505 | 632 | |
| 506 | - /** |
|
| 507 | - * Set customer id. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param int $value The customer's id. |
|
| 511 | - */ |
|
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Set parent invoice id. |
|
| 518 | - * |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - * @param int $value The parent invoice id. |
|
| 521 | - */ |
|
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Alias for self::set_parent_invoice_id(). |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - * @param int $value The parent invoice id. |
|
| 531 | - */ |
|
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 534 | - } |
|
| 633 | + } |
|
| 535 | 634 | |
| 536 | - /** |
|
| 537 | - * Alias for self::set_parent_invoice_id(). |
|
| 635 | + /** |
|
| 636 | + * Alias for self::set_created(). |
|
| 538 | 637 | * |
| 539 | 638 | * @since 1.0.19 |
| 540 | - * @param int $value The parent invoice id. |
|
| 639 | + * @param string $value strtotime compliant date. |
|
| 541 | 640 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Set subscription's product id. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param int $value The subscription product id. |
|
| 551 | - */ |
|
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Set the period of a renewal. |
|
| 558 | - * |
|
| 559 | - * @since 1.0.19 |
|
| 560 | - * @param string $value The renewal period. |
|
| 561 | - */ |
|
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Set number of periods each renewal is valid for. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - * @param int $value The subscription frequency. |
|
| 571 | - */ |
|
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Set the initial amount for the subscription. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @param float $value The initial subcription amount. |
|
| 582 | - */ |
|
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Set the recurring amount for the subscription. |
|
| 589 | - * |
|
| 590 | - * @since 1.0.19 |
|
| 591 | - * @param float $value The recurring subcription amount. |
|
| 592 | - */ |
|
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Set number of times that this subscription can be renewed. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - * @param int $value Bill times. |
|
| 602 | - */ |
|
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get transaction id of this subscription's parent invoice. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param string $value Bill times. |
|
| 612 | - */ |
|
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set date when this subscription started. |
|
| 619 | - * |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - * @param string $value strtotime compliant date. |
|
| 622 | - */ |
|
| 623 | - public function set_created( $value ) { |
|
| 641 | + public function set_date_created( $value ) { |
|
| 642 | + $this->set_created( $value ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Set the date that the subscription will renew. |
|
| 647 | + * |
|
| 648 | + * @since 1.0.19 |
|
| 649 | + * @param string $value strtotime compliant date. |
|
| 650 | + */ |
|
| 651 | + public function set_next_renewal_date( $value ) { |
|
| 624 | 652 | $date = strtotime( $value ); |
| 625 | 653 | |
| 626 | 654 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | 656 | return; |
| 629 | 657 | } |
| 630 | 658 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 659 | + $this->set_prop( 'expiration', '' ); |
|
| 632 | 660 | |
| 633 | - } |
|
| 661 | + } |
|
| 634 | 662 | |
| 635 | - /** |
|
| 636 | - * Alias for self::set_created(). |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $value strtotime compliant date. |
|
| 640 | - */ |
|
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 663 | + /** |
|
| 664 | + * Alias for self::set_next_renewal_date(). |
|
| 665 | + * |
|
| 666 | + * @since 1.0.19 |
|
| 667 | + * @param string $value strtotime compliant date. |
|
| 668 | + */ |
|
| 669 | + public function set_expiration( $value ) { |
|
| 670 | + $this->set_next_renewal_date( $value ); |
|
| 643 | 671 | } |
| 644 | 672 | |
| 645 | - /** |
|
| 646 | - * Set the date that the subscription will renew. |
|
| 647 | - * |
|
| 648 | - * @since 1.0.19 |
|
| 649 | - * @param string $value strtotime compliant date. |
|
| 650 | - */ |
|
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 673 | + /** |
|
| 674 | + * Set the subscription's trial period. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @param string $value trial period e.g 1 year. |
|
| 678 | + */ |
|
| 679 | + public function set_trial_period( $value ) { |
|
| 680 | + $this->set_prop( 'trial_period', $value ); |
|
| 681 | + } |
|
| 653 | 682 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 683 | + /** |
|
| 684 | + * Set the subscription's status. |
|
| 685 | + * |
|
| 686 | + * @since 1.0.19 |
|
| 687 | + * @param string $new_status New subscription status. |
|
| 688 | + */ |
|
| 689 | + public function set_status( $new_status ) { |
|
| 690 | + |
|
| 691 | + // Abort if this is not a valid status; |
|
| 692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 656 | 693 | return; |
| 657 | - } |
|
| 658 | - |
|
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 660 | - |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Alias for self::set_next_renewal_date(). |
|
| 665 | - * |
|
| 666 | - * @since 1.0.19 |
|
| 667 | - * @param string $value strtotime compliant date. |
|
| 668 | - */ |
|
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Set the subscription's trial period. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @param string $value trial period e.g 1 year. |
|
| 678 | - */ |
|
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Set the subscription's status. |
|
| 685 | - * |
|
| 686 | - * @since 1.0.19 |
|
| 687 | - * @param string $new_status New subscription status. |
|
| 688 | - */ |
|
| 689 | - public function set_status( $new_status ) { |
|
| 690 | - |
|
| 691 | - // Abort if this is not a valid status; |
|
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
| 697 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 698 | - $this->status_transition = array( |
|
| 699 | - 'from' => $old_status, |
|
| 700 | - 'to' => $new_status, |
|
| 701 | - ); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - $this->set_prop( 'status', $new_status ); |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * Set the subscription's (remote) profile id. |
|
| 709 | - * |
|
| 710 | - * @since 1.0.19 |
|
| 711 | - * @param string $value the remote profile id. |
|
| 712 | - */ |
|
| 713 | - public function set_profile_id( $value ) { |
|
| 714 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - /* |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
| 697 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 698 | + $this->status_transition = array( |
|
| 699 | + 'from' => $old_status, |
|
| 700 | + 'to' => $new_status, |
|
| 701 | + ); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + $this->set_prop( 'status', $new_status ); |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * Set the subscription's (remote) profile id. |
|
| 709 | + * |
|
| 710 | + * @since 1.0.19 |
|
| 711 | + * @param string $value the remote profile id. |
|
| 712 | + */ |
|
| 713 | + public function set_profile_id( $value ) { |
|
| 714 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + /* |
|
| 718 | 718 | |-------------------------------------------------------------------------- |
| 719 | 719 | | Boolean methods |
| 720 | 720 | |-------------------------------------------------------------------------- |
@@ -723,55 +723,55 @@ discard block |
||
| 723 | 723 | | |
| 724 | 724 | */ |
| 725 | 725 | |
| 726 | - /** |
|
| 726 | + /** |
|
| 727 | 727 | * Checks if the subscription has a given status. |
| 728 | - * |
|
| 729 | - * @param string|array String or array of strings to check for. |
|
| 730 | - * @return bool |
|
| 728 | + * |
|
| 729 | + * @param string|array String or array of strings to check for. |
|
| 730 | + * @return bool |
|
| 731 | 731 | */ |
| 732 | 732 | public function has_status( $status ) { |
| 733 | 733 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
| 734 | - } |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | - /** |
|
| 736 | + /** |
|
| 737 | 737 | * Checks if the subscription has a trial period. |
| 738 | - * |
|
| 739 | - * @return bool |
|
| 738 | + * |
|
| 739 | + * @return bool |
|
| 740 | 740 | */ |
| 741 | 741 | public function has_trial_period() { |
| 742 | - $period = $this->get_trial_period(); |
|
| 742 | + $period = $this->get_trial_period(); |
|
| 743 | 743 | return ! empty( $period ); |
| 744 | - } |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Is the subscription active? |
|
| 748 | - * |
|
| 749 | - * @return bool |
|
| 750 | - */ |
|
| 751 | - public function is_active() { |
|
| 752 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Is the subscription expired? |
|
| 757 | - * |
|
| 758 | - * @return bool |
|
| 759 | - */ |
|
| 760 | - public function is_expired() { |
|
| 761 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * Is this the last renewals? |
|
| 766 | - * |
|
| 767 | - * @return bool |
|
| 768 | - */ |
|
| 769 | - public function is_last_renewal() { |
|
| 770 | - $max_bills = $this->get_bill_times(); |
|
| 771 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - /* |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Is the subscription active? |
|
| 748 | + * |
|
| 749 | + * @return bool |
|
| 750 | + */ |
|
| 751 | + public function is_active() { |
|
| 752 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Is the subscription expired? |
|
| 757 | + * |
|
| 758 | + * @return bool |
|
| 759 | + */ |
|
| 760 | + public function is_expired() { |
|
| 761 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * Is this the last renewals? |
|
| 766 | + * |
|
| 767 | + * @return bool |
|
| 768 | + */ |
|
| 769 | + public function is_last_renewal() { |
|
| 770 | + $max_bills = $this->get_bill_times(); |
|
| 771 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + /* |
|
| 775 | 775 | |-------------------------------------------------------------------------- |
| 776 | 776 | | Additional methods |
| 777 | 777 | |-------------------------------------------------------------------------- |
@@ -780,27 +780,27 @@ discard block |
||
| 780 | 780 | | |
| 781 | 781 | */ |
| 782 | 782 | |
| 783 | - /** |
|
| 784 | - * Backwards compatibilty. |
|
| 785 | - */ |
|
| 786 | - public function create( $data = array() ) { |
|
| 783 | + /** |
|
| 784 | + * Backwards compatibilty. |
|
| 785 | + */ |
|
| 786 | + public function create( $data = array() ) { |
|
| 787 | 787 | |
| 788 | - // Set the properties. |
|
| 789 | - if ( is_array( $data ) ) { |
|
| 790 | - $this->set_props( $data ); |
|
| 791 | - } |
|
| 788 | + // Set the properties. |
|
| 789 | + if ( is_array( $data ) ) { |
|
| 790 | + $this->set_props( $data ); |
|
| 791 | + } |
|
| 792 | 792 | |
| 793 | - // Save the item. |
|
| 794 | - return $this->save(); |
|
| 793 | + // Save the item. |
|
| 794 | + return $this->save(); |
|
| 795 | 795 | |
| 796 | - } |
|
| 796 | + } |
|
| 797 | 797 | |
| 798 | - /** |
|
| 799 | - * Backwards compatibilty. |
|
| 800 | - */ |
|
| 801 | - public function update( $args = array() ) { |
|
| 802 | - return $this->create( $args ); |
|
| 803 | - } |
|
| 798 | + /** |
|
| 799 | + * Backwards compatibilty. |
|
| 800 | + */ |
|
| 801 | + public function update( $args = array() ) { |
|
| 802 | + return $this->create( $args ); |
|
| 803 | + } |
|
| 804 | 804 | |
| 805 | 805 | /** |
| 806 | 806 | * Retrieve renewal payments for a subscription |
@@ -810,22 +810,22 @@ discard block |
||
| 810 | 810 | */ |
| 811 | 811 | public function get_child_payments( $hide_pending = true ) { |
| 812 | 812 | |
| 813 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 813 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | 814 | |
| 815 | - if ( ! $hide_pending ) { |
|
| 816 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 817 | - } |
|
| 815 | + if ( ! $hide_pending ) { |
|
| 816 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 817 | + } |
|
| 818 | 818 | |
| 819 | 819 | return get_posts( |
| 820 | - array( |
|
| 821 | - 'post_parent' => $this->get_parent_payment_id(), |
|
| 822 | - 'numberposts' => -1, |
|
| 823 | - 'post_status' => $statuses, |
|
| 824 | - 'orderby' => 'ID', |
|
| 825 | - 'order' => 'ASC', |
|
| 826 | - 'post_type' => 'wpi_invoice', |
|
| 827 | - ) |
|
| 828 | - ); |
|
| 820 | + array( |
|
| 821 | + 'post_parent' => $this->get_parent_payment_id(), |
|
| 822 | + 'numberposts' => -1, |
|
| 823 | + 'post_status' => $statuses, |
|
| 824 | + 'orderby' => 'ID', |
|
| 825 | + 'order' => 'ASC', |
|
| 826 | + 'post_type' => 'wpi_invoice', |
|
| 827 | + ) |
|
| 828 | + ); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | /** |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * @return int |
| 836 | 836 | */ |
| 837 | 837 | public function get_total_payments() { |
| 838 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
| 838 | + return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
@@ -859,56 +859,56 @@ discard block |
||
| 859 | 859 | * |
| 860 | 860 | * @since 2.4 |
| 861 | 861 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 862 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 862 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 863 | 863 | * @return bool |
| 864 | 864 | */ |
| 865 | 865 | public function add_payment( $args = array(), $invoice = false ) { |
| 866 | 866 | |
| 867 | - // Process each payment once. |
|
| 867 | + // Process each payment once. |
|
| 868 | 868 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 869 | 869 | return false; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | - // Are we creating a new invoice? |
|
| 873 | - if ( empty( $invoice ) ) { |
|
| 874 | - $invoice = $this->create_payment(); |
|
| 872 | + // Are we creating a new invoice? |
|
| 873 | + if ( empty( $invoice ) ) { |
|
| 874 | + $invoice = $this->create_payment(); |
|
| 875 | 875 | |
| 876 | - if ( empty( $invoice ) ) { |
|
| 877 | - return false; |
|
| 878 | - } |
|
| 876 | + if ( empty( $invoice ) ) { |
|
| 877 | + return false; |
|
| 878 | + } |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 881 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 882 | 882 | |
| 883 | - // Maybe set a transaction id. |
|
| 884 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 885 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 886 | - } |
|
| 883 | + // Maybe set a transaction id. |
|
| 884 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 885 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 886 | + } |
|
| 887 | 887 | |
| 888 | - // Set the completed date. |
|
| 889 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 888 | + // Set the completed date. |
|
| 889 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 890 | 890 | |
| 891 | - // And the gateway. |
|
| 892 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 893 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 894 | - } |
|
| 891 | + // And the gateway. |
|
| 892 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 893 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 894 | + } |
|
| 895 | 895 | |
| 896 | - $invoice->save(); |
|
| 896 | + $invoice->save(); |
|
| 897 | 897 | |
| 898 | - if ( ! $invoice->exists() ) { |
|
| 899 | - return false; |
|
| 900 | - } |
|
| 898 | + if ( ! $invoice->exists() ) { |
|
| 899 | + return false; |
|
| 900 | + } |
|
| 901 | 901 | |
| 902 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 903 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 902 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 903 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 904 | 904 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 905 | 905 | |
| 906 | 906 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 907 | 907 | |
| 908 | 908 | return $invoice->get_id(); |
| 909 | - } |
|
| 909 | + } |
|
| 910 | 910 | |
| 911 | - /** |
|
| 911 | + /** |
|
| 912 | 912 | * Creates a new invoice and returns it. |
| 913 | 913 | * |
| 914 | 914 | * @since 1.0.19 |
@@ -916,124 +916,124 @@ discard block |
||
| 916 | 916 | */ |
| 917 | 917 | public function create_payment() { |
| 918 | 918 | |
| 919 | - $parent_invoice = $this->get_parent_payment(); |
|
| 920 | - |
|
| 921 | - if ( ! $parent_invoice->exists() ) { |
|
| 922 | - return false; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - // Duplicate the parent invoice. |
|
| 926 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 927 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 928 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 929 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 930 | - |
|
| 931 | - // Set invoice items. |
|
| 932 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 933 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 934 | - $invoice_items = array(); |
|
| 935 | - |
|
| 936 | - foreach ( $invoice->get_items() as $item ) { |
|
| 937 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 938 | - $invoice_items[] = $item; |
|
| 939 | - } |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - $invoice->set_items( $invoice_items ); |
|
| 943 | - |
|
| 944 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 945 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 949 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 950 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 951 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - $invoice->recalculate_total(); |
|
| 955 | - $invoice->set_status( 'wpi-pending' ); |
|
| 956 | - $invoice->save(); |
|
| 957 | - |
|
| 958 | - return $invoice->exists() ? $invoice : false; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - /** |
|
| 962 | - * Renews or completes a subscription |
|
| 963 | - * |
|
| 964 | - * @since 1.0.0 |
|
| 965 | - * @return int The subscription's id |
|
| 966 | - */ |
|
| 967 | - public function renew() { |
|
| 968 | - |
|
| 969 | - // Complete subscription if applicable |
|
| 970 | - if ( $this->is_last_renewal() ) { |
|
| 971 | - return $this->complete(); |
|
| 972 | - } |
|
| 973 | - |
|
| 974 | - // Calculate new expiration |
|
| 975 | - $frequency = $this->get_frequency(); |
|
| 976 | - $period = $this->get_period(); |
|
| 977 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 978 | - |
|
| 979 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
| 980 | - $this->set_status( 'active' ); |
|
| 981 | - $this->save(); |
|
| 982 | - |
|
| 983 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 984 | - |
|
| 985 | - return $this->get_id(); |
|
| 986 | - } |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Marks a subscription as completed |
|
| 990 | - * |
|
| 991 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 992 | - * |
|
| 993 | - * @since 1.0.0 |
|
| 994 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 995 | - */ |
|
| 996 | - public function complete() { |
|
| 997 | - |
|
| 998 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 999 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 1000 | - return false; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - $this->set_status( 'completed' ); |
|
| 1004 | - return $this->save(); |
|
| 1005 | - |
|
| 1006 | - } |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * Marks a subscription as expired |
|
| 1010 | - * |
|
| 1011 | - * @since 1.0.0 |
|
| 1012 | - * @param bool $check_expiration |
|
| 1013 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1014 | - */ |
|
| 1015 | - public function expire( $check_expiration = false ) { |
|
| 1016 | - |
|
| 1017 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1018 | - // Do not mark as expired since real expiration date is in the future |
|
| 1019 | - return false; |
|
| 1020 | - } |
|
| 1021 | - |
|
| 1022 | - $this->set_status( 'expired' ); |
|
| 1023 | - return $this->save(); |
|
| 1024 | - |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * Marks a subscription as failing |
|
| 1029 | - * |
|
| 1030 | - * @since 2.4.2 |
|
| 1031 | - * @return int Subscription id. |
|
| 1032 | - */ |
|
| 1033 | - public function failing() { |
|
| 1034 | - $this->set_status( 'failing' ); |
|
| 1035 | - return $this->save(); |
|
| 1036 | - } |
|
| 919 | + $parent_invoice = $this->get_parent_payment(); |
|
| 920 | + |
|
| 921 | + if ( ! $parent_invoice->exists() ) { |
|
| 922 | + return false; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + // Duplicate the parent invoice. |
|
| 926 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 927 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 928 | + $invoice->set_subscription_id( $this->get_id() ); |
|
| 929 | + $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 930 | + |
|
| 931 | + // Set invoice items. |
|
| 932 | + $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 933 | + $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 934 | + $invoice_items = array(); |
|
| 935 | + |
|
| 936 | + foreach ( $invoice->get_items() as $item ) { |
|
| 937 | + if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 938 | + $invoice_items[] = $item; |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + $invoice->set_items( $invoice_items ); |
|
| 943 | + |
|
| 944 | + if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 945 | + $invoice->set_fees( $subscription_group['fees'] ); |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + // Maybe recalculate discount (Pre-GetPaid Fix). |
|
| 949 | + $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 950 | + if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 951 | + $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + $invoice->recalculate_total(); |
|
| 955 | + $invoice->set_status( 'wpi-pending' ); |
|
| 956 | + $invoice->save(); |
|
| 957 | + |
|
| 958 | + return $invoice->exists() ? $invoice : false; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + /** |
|
| 962 | + * Renews or completes a subscription |
|
| 963 | + * |
|
| 964 | + * @since 1.0.0 |
|
| 965 | + * @return int The subscription's id |
|
| 966 | + */ |
|
| 967 | + public function renew() { |
|
| 968 | + |
|
| 969 | + // Complete subscription if applicable |
|
| 970 | + if ( $this->is_last_renewal() ) { |
|
| 971 | + return $this->complete(); |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + // Calculate new expiration |
|
| 975 | + $frequency = $this->get_frequency(); |
|
| 976 | + $period = $this->get_period(); |
|
| 977 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 978 | + |
|
| 979 | + $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
| 980 | + $this->set_status( 'active' ); |
|
| 981 | + $this->save(); |
|
| 982 | + |
|
| 983 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 984 | + |
|
| 985 | + return $this->get_id(); |
|
| 986 | + } |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Marks a subscription as completed |
|
| 990 | + * |
|
| 991 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 992 | + * |
|
| 993 | + * @since 1.0.0 |
|
| 994 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 995 | + */ |
|
| 996 | + public function complete() { |
|
| 997 | + |
|
| 998 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 999 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 1000 | + return false; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + $this->set_status( 'completed' ); |
|
| 1004 | + return $this->save(); |
|
| 1005 | + |
|
| 1006 | + } |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * Marks a subscription as expired |
|
| 1010 | + * |
|
| 1011 | + * @since 1.0.0 |
|
| 1012 | + * @param bool $check_expiration |
|
| 1013 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1014 | + */ |
|
| 1015 | + public function expire( $check_expiration = false ) { |
|
| 1016 | + |
|
| 1017 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1018 | + // Do not mark as expired since real expiration date is in the future |
|
| 1019 | + return false; |
|
| 1020 | + } |
|
| 1021 | + |
|
| 1022 | + $this->set_status( 'expired' ); |
|
| 1023 | + return $this->save(); |
|
| 1024 | + |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * Marks a subscription as failing |
|
| 1029 | + * |
|
| 1030 | + * @since 2.4.2 |
|
| 1031 | + * @return int Subscription id. |
|
| 1032 | + */ |
|
| 1033 | + public function failing() { |
|
| 1034 | + $this->set_status( 'failing' ); |
|
| 1035 | + return $this->save(); |
|
| 1036 | + } |
|
| 1037 | 1037 | |
| 1038 | 1038 | /** |
| 1039 | 1039 | * Marks a subscription as cancelled |
@@ -1042,19 +1042,19 @@ discard block |
||
| 1042 | 1042 | * @return int Subscription id. |
| 1043 | 1043 | */ |
| 1044 | 1044 | public function cancel() { |
| 1045 | - $this->set_status( 'cancelled' ); |
|
| 1046 | - return $this->save(); |
|
| 1045 | + $this->set_status( 'cancelled' ); |
|
| 1046 | + return $this->save(); |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | - /** |
|
| 1050 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1051 | - * |
|
| 1052 | - * @since 1.0.0 |
|
| 1053 | - * @return bool |
|
| 1054 | - */ |
|
| 1055 | - public function can_cancel() { |
|
| 1056 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1057 | - } |
|
| 1049 | + /** |
|
| 1050 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1051 | + * |
|
| 1052 | + * @since 1.0.0 |
|
| 1053 | + * @return bool |
|
| 1054 | + */ |
|
| 1055 | + public function can_cancel() { |
|
| 1056 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1057 | + } |
|
| 1058 | 1058 | |
| 1059 | 1059 | /** |
| 1060 | 1060 | * Returns an array of subscription statuses that can be cancelled |
@@ -1067,109 +1067,109 @@ discard block |
||
| 1067 | 1067 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | - /** |
|
| 1071 | - * Retrieves the URL to cancel subscription |
|
| 1072 | - * |
|
| 1073 | - * @since 1.0.0 |
|
| 1074 | - * @return string |
|
| 1075 | - */ |
|
| 1076 | - public function get_cancel_url() { |
|
| 1077 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1078 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * Retrieves the URL to view a subscription |
|
| 1083 | - * |
|
| 1084 | - * @since 1.0.19 |
|
| 1085 | - * @return string |
|
| 1086 | - */ |
|
| 1087 | - public function get_view_url() { |
|
| 1088 | - |
|
| 1089 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1090 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1091 | - |
|
| 1092 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1093 | - } |
|
| 1094 | - |
|
| 1095 | - /** |
|
| 1096 | - * Determines if subscription can be manually renewed |
|
| 1097 | - * |
|
| 1098 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1099 | - * that can be renewed manually |
|
| 1100 | - * |
|
| 1101 | - * @since 2.5 |
|
| 1102 | - * @return bool |
|
| 1103 | - */ |
|
| 1104 | - public function can_renew() { |
|
| 1105 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Retrieves the URL to renew a subscription |
|
| 1110 | - * |
|
| 1111 | - * @since 2.5 |
|
| 1112 | - * @return string |
|
| 1113 | - */ |
|
| 1114 | - public function get_renew_url() { |
|
| 1115 | - $url = wp_nonce_url( |
|
| 1070 | + /** |
|
| 1071 | + * Retrieves the URL to cancel subscription |
|
| 1072 | + * |
|
| 1073 | + * @since 1.0.0 |
|
| 1074 | + * @return string |
|
| 1075 | + */ |
|
| 1076 | + public function get_cancel_url() { |
|
| 1077 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1078 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * Retrieves the URL to view a subscription |
|
| 1083 | + * |
|
| 1084 | + * @since 1.0.19 |
|
| 1085 | + * @return string |
|
| 1086 | + */ |
|
| 1087 | + public function get_view_url() { |
|
| 1088 | + |
|
| 1089 | + $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1090 | + $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1091 | + |
|
| 1092 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1093 | + } |
|
| 1094 | + |
|
| 1095 | + /** |
|
| 1096 | + * Determines if subscription can be manually renewed |
|
| 1097 | + * |
|
| 1098 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1099 | + * that can be renewed manually |
|
| 1100 | + * |
|
| 1101 | + * @since 2.5 |
|
| 1102 | + * @return bool |
|
| 1103 | + */ |
|
| 1104 | + public function can_renew() { |
|
| 1105 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Retrieves the URL to renew a subscription |
|
| 1110 | + * |
|
| 1111 | + * @since 2.5 |
|
| 1112 | + * @return string |
|
| 1113 | + */ |
|
| 1114 | + public function get_renew_url() { |
|
| 1115 | + $url = wp_nonce_url( |
|
| 1116 | 1116 | add_query_arg( |
| 1117 | 1117 | array( |
| 1118 | - 'getpaid-action' => 'renew_subscription', |
|
| 1119 | - 'sub_id' => $this->get_id, |
|
| 1118 | + 'getpaid-action' => 'renew_subscription', |
|
| 1119 | + 'sub_id' => $this->get_id, |
|
| 1120 | 1120 | ) |
| 1121 | 1121 | ), |
| 1122 | 1122 | 'getpaid-nonce' |
| 1123 | 1123 | ); |
| 1124 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * Determines if subscription can have their payment method updated |
|
| 1129 | - * |
|
| 1130 | - * @since 1.0.0 |
|
| 1131 | - * @return bool |
|
| 1132 | - */ |
|
| 1133 | - public function can_update() { |
|
| 1134 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * Retrieves the URL to update subscription |
|
| 1139 | - * |
|
| 1140 | - * @since 1.0.0 |
|
| 1141 | - * @return string |
|
| 1142 | - */ |
|
| 1143 | - public function get_update_url() { |
|
| 1144 | - $url = add_query_arg( |
|
| 1124 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * Determines if subscription can have their payment method updated |
|
| 1129 | + * |
|
| 1130 | + * @since 1.0.0 |
|
| 1131 | + * @return bool |
|
| 1132 | + */ |
|
| 1133 | + public function can_update() { |
|
| 1134 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * Retrieves the URL to update subscription |
|
| 1139 | + * |
|
| 1140 | + * @since 1.0.0 |
|
| 1141 | + * @return string |
|
| 1142 | + */ |
|
| 1143 | + public function get_update_url() { |
|
| 1144 | + $url = add_query_arg( |
|
| 1145 | 1145 | array( |
| 1146 | - 'action' => 'update', |
|
| 1147 | - 'subscription_id' => $this->get_id(), |
|
| 1146 | + 'action' => 'update', |
|
| 1147 | + 'subscription_id' => $this->get_id(), |
|
| 1148 | 1148 | ) |
| 1149 | 1149 | ); |
| 1150 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1151 | - } |
|
| 1152 | - |
|
| 1153 | - /** |
|
| 1154 | - * Retrieves the subscription status label |
|
| 1155 | - * |
|
| 1156 | - * @since 1.0.0 |
|
| 1157 | - * @return string |
|
| 1158 | - */ |
|
| 1159 | - public function get_status_label() { |
|
| 1160 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * Retrieves the subscription status class |
|
| 1165 | - * |
|
| 1166 | - * @since 1.0.19 |
|
| 1167 | - * @return string |
|
| 1168 | - */ |
|
| 1169 | - public function get_status_class() { |
|
| 1170 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1171 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1172 | - } |
|
| 1150 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1151 | + } |
|
| 1152 | + |
|
| 1153 | + /** |
|
| 1154 | + * Retrieves the subscription status label |
|
| 1155 | + * |
|
| 1156 | + * @since 1.0.0 |
|
| 1157 | + * @return string |
|
| 1158 | + */ |
|
| 1159 | + public function get_status_label() { |
|
| 1160 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * Retrieves the subscription status class |
|
| 1165 | + * |
|
| 1166 | + * @since 1.0.19 |
|
| 1167 | + * @return string |
|
| 1168 | + */ |
|
| 1169 | + public function get_status_class() { |
|
| 1170 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1171 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1172 | + } |
|
| 1173 | 1173 | |
| 1174 | 1174 | /** |
| 1175 | 1175 | * Retrieves the subscription status label |
@@ -1179,11 +1179,11 @@ discard block |
||
| 1179 | 1179 | */ |
| 1180 | 1180 | public function get_status_label_html() { |
| 1181 | 1181 | |
| 1182 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1183 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1184 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1182 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1183 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1184 | + $status = sanitize_html_class( $this->get_status() ); |
|
| 1185 | 1185 | |
| 1186 | - return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1186 | + return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /** |
@@ -1194,75 +1194,75 @@ discard block |
||
| 1194 | 1194 | * @return bool |
| 1195 | 1195 | */ |
| 1196 | 1196 | public function payment_exists( $txn_id = '' ) { |
| 1197 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1197 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1198 | 1198 | return ! empty( $invoice_id ); |
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - /** |
|
| 1202 | - * Handle the status transition. |
|
| 1203 | - */ |
|
| 1204 | - protected function status_transition() { |
|
| 1205 | - $status_transition = $this->status_transition; |
|
| 1206 | - |
|
| 1207 | - // Reset status transition variable. |
|
| 1208 | - $this->status_transition = false; |
|
| 1209 | - |
|
| 1210 | - if ( $status_transition ) { |
|
| 1211 | - try { |
|
| 1212 | - |
|
| 1213 | - // Fire a hook for the status change. |
|
| 1214 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1215 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1216 | - |
|
| 1217 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1218 | - |
|
| 1219 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1220 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1221 | - |
|
| 1222 | - // Note the transition occurred. |
|
| 1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1224 | - |
|
| 1225 | - // Fire another hook. |
|
| 1226 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1227 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1228 | - |
|
| 1229 | - } else { |
|
| 1230 | - /* translators: %s: new invoice status */ |
|
| 1231 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1232 | - |
|
| 1233 | - // Note the transition occurred. |
|
| 1234 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1235 | - |
|
| 1236 | - } |
|
| 1237 | - } catch ( Exception $e ) { |
|
| 1238 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1239 | - } |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * Save data to the database. |
|
| 1246 | - * |
|
| 1247 | - * @since 1.0.19 |
|
| 1248 | - * @return int subscription ID |
|
| 1249 | - */ |
|
| 1250 | - public function save() { |
|
| 1251 | - parent::save(); |
|
| 1252 | - $this->status_transition(); |
|
| 1253 | - return $this->get_id(); |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - /** |
|
| 1257 | - * Activates a subscription. |
|
| 1258 | - * |
|
| 1259 | - * @since 1.0.19 |
|
| 1260 | - * @return int subscription ID |
|
| 1261 | - */ |
|
| 1262 | - public function activate() { |
|
| 1263 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1264 | - $this->set_status( $status ); |
|
| 1265 | - return $this->save(); |
|
| 1266 | - } |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + /** |
|
| 1202 | + * Handle the status transition. |
|
| 1203 | + */ |
|
| 1204 | + protected function status_transition() { |
|
| 1205 | + $status_transition = $this->status_transition; |
|
| 1206 | + |
|
| 1207 | + // Reset status transition variable. |
|
| 1208 | + $this->status_transition = false; |
|
| 1209 | + |
|
| 1210 | + if ( $status_transition ) { |
|
| 1211 | + try { |
|
| 1212 | + |
|
| 1213 | + // Fire a hook for the status change. |
|
| 1214 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1215 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1216 | + |
|
| 1217 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1218 | + |
|
| 1219 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1220 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1221 | + |
|
| 1222 | + // Note the transition occurred. |
|
| 1223 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1224 | + |
|
| 1225 | + // Fire another hook. |
|
| 1226 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1227 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1228 | + |
|
| 1229 | + } else { |
|
| 1230 | + /* translators: %s: new invoice status */ |
|
| 1231 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1232 | + |
|
| 1233 | + // Note the transition occurred. |
|
| 1234 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1235 | + |
|
| 1236 | + } |
|
| 1237 | + } catch ( Exception $e ) { |
|
| 1238 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1239 | + } |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * Save data to the database. |
|
| 1246 | + * |
|
| 1247 | + * @since 1.0.19 |
|
| 1248 | + * @return int subscription ID |
|
| 1249 | + */ |
|
| 1250 | + public function save() { |
|
| 1251 | + parent::save(); |
|
| 1252 | + $this->status_transition(); |
|
| 1253 | + return $this->get_id(); |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + /** |
|
| 1257 | + * Activates a subscription. |
|
| 1258 | + * |
|
| 1259 | + * @since 1.0.19 |
|
| 1260 | + * @return int subscription ID |
|
| 1261 | + */ |
|
| 1262 | + public function activate() { |
|
| 1263 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1264 | + $this->set_status( $status ); |
|
| 1265 | + return $this->save(); |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | 1268 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
| 68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
| 69 | 69 | * @param bool $deprecated |
| 70 | 70 | */ |
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 71 | + function __construct($subscription = 0, $deprecated = false) { |
|
| 72 | 72 | |
| 73 | - parent::__construct( $subscription ); |
|
| 73 | + parent::__construct($subscription); |
|
| 74 | 74 | |
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 80 | - $this->set_id( $subscription_id ); |
|
| 81 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 82 | - $this->set_id( $subscription->id ); |
|
| 75 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
| 76 | + $this->set_id($subscription); |
|
| 77 | + } elseif ($subscription instanceof self) { |
|
| 78 | + $this->set_id($subscription->get_id()); |
|
| 79 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
| 80 | + $this->set_id($subscription_id); |
|
| 81 | + } elseif (!empty($subscription->id)) { |
|
| 82 | + $this->set_id($subscription->id); |
|
| 83 | 83 | } else { |
| 84 | - $this->set_object_read( true ); |
|
| 84 | + $this->set_object_read(true); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Load the datastore. |
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 89 | 89 | |
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 90 | + if ($this->get_id() > 0) { |
|
| 91 | + $this->data_store->read($this); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
| 103 | 103 | * @since 1.0.19 |
| 104 | 104 | * @return int |
| 105 | 105 | */ |
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | 109 | // Trim the value. |
| 110 | - $value = trim( $value ); |
|
| 110 | + $value = trim($value); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 112 | + if (empty($value)) { |
|
| 113 | 113 | return 0; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 116 | + if ('invoice_id' == $field) { |
|
| 117 | 117 | $field = 'parent_payment_id'; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | // Ensure a field has been passed. |
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 128 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 129 | 129 | return 0; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Maybe retrieve from the cache. |
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 134 | + if (!empty($subscription_id)) { |
|
| 135 | 135 | return $subscription_id; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
| 140 | 140 | $subscription_id = (int) $wpdb->get_var( |
| 141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
| 141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 144 | + if (empty($subscription_id)) { |
|
| 145 | 145 | return 0; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Update the cache with our data. |
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 150 | 150 | |
| 151 | 151 | return $subscription_id; |
| 152 | 152 | } |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 158 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
| 159 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
| 160 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
| 161 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | - public function _isset( $key ) { |
|
| 168 | - return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" ); |
|
| 167 | + public function _isset($key) { |
|
| 168 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /* |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | * @param string $context View or edit context. |
| 191 | 191 | * @return int |
| 192 | 192 | */ |
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 193 | + public function get_customer_id($context = 'view') { |
|
| 194 | + return (int) $this->get_prop('customer_id', $context); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | * @param string $context View or edit context. |
| 202 | 202 | * @return WP_User|false WP_User object on success, false on failure. |
| 203 | 203 | */ |
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 204 | + public function get_customer($context = 'view') { |
|
| 205 | + return get_userdata($this->get_customer_id($context)); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @param string $context View or edit context. |
| 213 | 213 | * @return int |
| 214 | 214 | */ |
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 215 | + public function get_parent_invoice_id($context = 'view') { |
|
| 216 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $context View or edit context. |
| 224 | 224 | * @return int |
| 225 | 225 | */ |
| 226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | - return $this->get_parent_invoice_id( $context ); |
|
| 226 | + public function get_parent_payment_id($context = 'view') { |
|
| 227 | + return $this->get_parent_invoice_id($context); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @since 1.0.0 |
| 234 | 234 | * @return int |
| 235 | 235 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 236 | + public function get_original_payment_id($context = 'view') { |
|
| 237 | + return $this->get_parent_invoice_id($context); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | * @param string $context View or edit context. |
| 245 | 245 | * @return WPInv_Invoice |
| 246 | 246 | */ |
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 247 | + public function get_parent_invoice($context = 'view') { |
|
| 248 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | * @param string $context View or edit context. |
| 256 | 256 | * @return WPInv_Invoice |
| 257 | 257 | */ |
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 258 | + public function get_parent_payment($context = 'view') { |
|
| 259 | + return $this->get_parent_invoice($context); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | * @param string $context View or edit context. |
| 267 | 267 | * @return int |
| 268 | 268 | */ |
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 269 | + public function get_product_id($context = 'view') { |
|
| 270 | + return (int) $this->get_prop('product_id', $context); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | * @param string $context View or edit context. |
| 278 | 278 | * @return WPInv_Item |
| 279 | 279 | */ |
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 280 | + public function get_product($context = 'view') { |
|
| 281 | + return new WPInv_Item($this->get_product_id($context)); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param string $context View or edit context. |
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 293 | + public function get_gateway($context = 'view') { |
|
| 294 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | * @param string $context View or edit context. |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 304 | + public function get_period($context = 'view') { |
|
| 305 | + return $this->get_prop('period', $context); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | * @param string $context View or edit context. |
| 313 | 313 | * @return int |
| 314 | 314 | */ |
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 315 | + public function get_frequency($context = 'view') { |
|
| 316 | + return (int) $this->get_prop('frequency', $context); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | * @param string $context View or edit context. |
| 324 | 324 | * @return float |
| 325 | 325 | */ |
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 326 | + public function get_initial_amount($context = 'view') { |
|
| 327 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * @param string $context View or edit context. |
| 335 | 335 | * @return float |
| 336 | 336 | */ |
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 337 | + public function get_recurring_amount($context = 'view') { |
|
| 338 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @param string $context View or edit context. |
| 346 | 346 | * @return int |
| 347 | 347 | */ |
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 348 | + public function get_bill_times($context = 'view') { |
|
| 349 | + return (int) $this->get_prop('bill_times', $context); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
| 356 | 356 | * @param string $context View or edit context. |
| 357 | 357 | * @return string |
| 358 | 358 | */ |
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 359 | + public function get_transaction_id($context = 'view') { |
|
| 360 | + return $this->get_prop('transaction_id', $context); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * @param string $context View or edit context. |
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 370 | + public function get_created($context = 'view') { |
|
| 371 | + return $this->get_prop('created', $context); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | * @param string $context View or edit context. |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 381 | + public function get_date_created($context = 'view') { |
|
| 382 | + return $this->get_created($context); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | public function get_time_created() { |
| 392 | 392 | $created = $this->get_date_created(); |
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 393 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | * @param string $context View or edit context. |
| 401 | 401 | * @return string |
| 402 | 402 | */ |
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 403 | + public function get_date_created_gmt($context = 'view') { |
|
| 404 | + $date = $this->get_date_created($context); |
|
| 405 | 405 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 406 | + if ($date) { |
|
| 407 | + $date = get_gmt_from_date($date); |
|
| 408 | 408 | } |
| 409 | 409 | return $date; |
| 410 | 410 | } |
@@ -416,8 +416,8 @@ discard block |
||
| 416 | 416 | * @param string $context View or edit context. |
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 419 | + public function get_next_renewal_date($context = 'view') { |
|
| 420 | + return $this->get_prop('expiration', $context); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
| 427 | 427 | * @param string $context View or edit context. |
| 428 | 428 | * @return string |
| 429 | 429 | */ |
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 430 | + public function get_expiration($context = 'view') { |
|
| 431 | + return $this->get_next_renewal_date($context); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
| 440 | 440 | public function get_expiration_time() { |
| 441 | 441 | $expiration = $this->get_expiration(); |
| 442 | 442 | |
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 443 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
| 444 | + return current_time('timestamp'); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 447 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
| 448 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -455,11 +455,11 @@ discard block |
||
| 455 | 455 | * @param string $context View or edit context. |
| 456 | 456 | * @return string |
| 457 | 457 | */ |
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 458 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
| 459 | + $date = $this->get_next_renewal_date($context); |
|
| 460 | 460 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 461 | + if ($date) { |
|
| 462 | + $date = get_gmt_from_date($date); |
|
| 463 | 463 | } |
| 464 | 464 | return $date; |
| 465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * @param string $context View or edit context. |
| 472 | 472 | * @return string |
| 473 | 473 | */ |
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 474 | + public function get_trial_period($context = 'view') { |
|
| 475 | + return $this->get_prop('trial_period', $context); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param string $context View or edit context. |
| 483 | 483 | * @return string |
| 484 | 484 | */ |
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 485 | + public function get_status($context = 'view') { |
|
| 486 | + return $this->get_prop('status', $context); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -493,8 +493,8 @@ discard block |
||
| 493 | 493 | * @param string $context View or edit context. |
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 496 | + public function get_profile_id($context = 'view') { |
|
| 497 | + return $this->get_prop('profile_id', $context); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /* |
@@ -509,8 +509,8 @@ discard block |
||
| 509 | 509 | * @since 1.0.19 |
| 510 | 510 | * @param int $value The customer's id. |
| 511 | 511 | */ |
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 512 | + public function set_customer_id($value) { |
|
| 513 | + $this->set_prop('customer_id', (int) $value); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @since 1.0.19 |
| 520 | 520 | * @param int $value The parent invoice id. |
| 521 | 521 | */ |
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 522 | + public function set_parent_invoice_id($value) { |
|
| 523 | + $this->set_prop('parent_payment_id', (int) $value); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | * @since 1.0.19 |
| 530 | 530 | * @param int $value The parent invoice id. |
| 531 | 531 | */ |
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 532 | + public function set_parent_payment_id($value) { |
|
| 533 | + $this->set_parent_invoice_id($value); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | * @since 1.0.19 |
| 540 | 540 | * @param int $value The parent invoice id. |
| 541 | 541 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 542 | + public function set_original_payment_id($value) { |
|
| 543 | + $this->set_parent_invoice_id($value); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
| 549 | 549 | * @since 1.0.19 |
| 550 | 550 | * @param int $value The subscription product id. |
| 551 | 551 | */ |
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 552 | + public function set_product_id($value) { |
|
| 553 | + $this->set_prop('product_id', (int) $value); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @since 1.0.19 |
| 560 | 560 | * @param string $value The renewal period. |
| 561 | 561 | */ |
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 562 | + public function set_period($value) { |
|
| 563 | + $this->set_prop('period', $value); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,9 +569,9 @@ discard block |
||
| 569 | 569 | * @since 1.0.19 |
| 570 | 570 | * @param int $value The subscription frequency. |
| 571 | 571 | */ |
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 572 | + public function set_frequency($value) { |
|
| 573 | + $value = empty($value) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop('frequency', absint($value)); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | * @since 1.0.19 |
| 581 | 581 | * @param float $value The initial subcription amount. |
| 582 | 582 | */ |
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 583 | + public function set_initial_amount($value) { |
|
| 584 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * @since 1.0.19 |
| 591 | 591 | * @param float $value The recurring subcription amount. |
| 592 | 592 | */ |
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 593 | + public function set_recurring_amount($value) { |
|
| 594 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -600,8 +600,8 @@ discard block |
||
| 600 | 600 | * @since 1.0.19 |
| 601 | 601 | * @param int $value Bill times. |
| 602 | 602 | */ |
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 603 | + public function set_bill_times($value) { |
|
| 604 | + $this->set_prop('bill_times', (int) $value); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -610,8 +610,8 @@ discard block |
||
| 610 | 610 | * @since 1.0.19 |
| 611 | 611 | * @param string $value Bill times. |
| 612 | 612 | */ |
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 613 | + public function set_transaction_id($value) { |
|
| 614 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -620,15 +620,15 @@ discard block |
||
| 620 | 620 | * @since 1.0.19 |
| 621 | 621 | * @param string $value strtotime compliant date. |
| 622 | 622 | */ |
| 623 | - public function set_created( $value ) { |
|
| 624 | - $date = strtotime( $value ); |
|
| 623 | + public function set_created($value) { |
|
| 624 | + $date = strtotime($value); |
|
| 625 | 625 | |
| 626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 626 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 627 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
| 628 | 628 | return; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 631 | + $this->set_prop('created', ''); |
|
| 632 | 632 | |
| 633 | 633 | } |
| 634 | 634 | |
@@ -638,8 +638,8 @@ discard block |
||
| 638 | 638 | * @since 1.0.19 |
| 639 | 639 | * @param string $value strtotime compliant date. |
| 640 | 640 | */ |
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 641 | + public function set_date_created($value) { |
|
| 642 | + $this->set_created($value); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | /** |
@@ -648,15 +648,15 @@ discard block |
||
| 648 | 648 | * @since 1.0.19 |
| 649 | 649 | * @param string $value strtotime compliant date. |
| 650 | 650 | */ |
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 651 | + public function set_next_renewal_date($value) { |
|
| 652 | + $date = strtotime($value); |
|
| 653 | 653 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 654 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 655 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
| 656 | 656 | return; |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 659 | + $this->set_prop('expiration', ''); |
|
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
@@ -666,8 +666,8 @@ discard block |
||
| 666 | 666 | * @since 1.0.19 |
| 667 | 667 | * @param string $value strtotime compliant date. |
| 668 | 668 | */ |
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 669 | + public function set_expiration($value) { |
|
| 670 | + $this->set_next_renewal_date($value); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | * @since 1.0.19 |
| 677 | 677 | * @param string $value trial period e.g 1 year. |
| 678 | 678 | */ |
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 679 | + public function set_trial_period($value) { |
|
| 680 | + $this->set_prop('trial_period', $value); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -686,22 +686,22 @@ discard block |
||
| 686 | 686 | * @since 1.0.19 |
| 687 | 687 | * @param string $new_status New subscription status. |
| 688 | 688 | */ |
| 689 | - public function set_status( $new_status ) { |
|
| 689 | + public function set_status($new_status) { |
|
| 690 | 690 | |
| 691 | 691 | // Abort if this is not a valid status; |
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 692 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
| 693 | 693 | return; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | - $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status(); |
|
| 697 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 696 | + $old_status = !empty($this->status_transition['from']) ? $this->status_transition['from'] : $this->get_status(); |
|
| 697 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
| 698 | 698 | $this->status_transition = array( |
| 699 | 699 | 'from' => $old_status, |
| 700 | 700 | 'to' => $new_status, |
| 701 | 701 | ); |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - $this->set_prop( 'status', $new_status ); |
|
| 704 | + $this->set_prop('status', $new_status); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
@@ -710,8 +710,8 @@ discard block |
||
| 710 | 710 | * @since 1.0.19 |
| 711 | 711 | * @param string $value the remote profile id. |
| 712 | 712 | */ |
| 713 | - public function set_profile_id( $value ) { |
|
| 714 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 713 | + public function set_profile_id($value) { |
|
| 714 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | /* |
@@ -729,8 +729,8 @@ discard block |
||
| 729 | 729 | * @param string|array String or array of strings to check for. |
| 730 | 730 | * @return bool |
| 731 | 731 | */ |
| 732 | - public function has_status( $status ) { |
|
| 733 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
| 732 | + public function has_status($status) { |
|
| 733 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | /** |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | */ |
| 741 | 741 | public function has_trial_period() { |
| 742 | 742 | $period = $this->get_trial_period(); |
| 743 | - return ! empty( $period ); |
|
| 743 | + return !empty($period); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | * @return bool |
| 750 | 750 | */ |
| 751 | 751 | public function is_active() { |
| 752 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 752 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | * @return bool |
| 759 | 759 | */ |
| 760 | 760 | public function is_expired() { |
| 761 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) ); |
|
| 761 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('timestamp')); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | /** |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | */ |
| 769 | 769 | public function is_last_renewal() { |
| 770 | 770 | $max_bills = $this->get_bill_times(); |
| 771 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 771 | + return !empty($max_bills) && $max_bills <= $this->get_times_billed(); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | /* |
@@ -783,11 +783,11 @@ discard block |
||
| 783 | 783 | /** |
| 784 | 784 | * Backwards compatibilty. |
| 785 | 785 | */ |
| 786 | - public function create( $data = array() ) { |
|
| 786 | + public function create($data = array()) { |
|
| 787 | 787 | |
| 788 | 788 | // Set the properties. |
| 789 | - if ( is_array( $data ) ) { |
|
| 790 | - $this->set_props( $data ); |
|
| 789 | + if (is_array($data)) { |
|
| 790 | + $this->set_props($data); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | // Save the item. |
@@ -798,8 +798,8 @@ discard block |
||
| 798 | 798 | /** |
| 799 | 799 | * Backwards compatibilty. |
| 800 | 800 | */ |
| 801 | - public function update( $args = array() ) { |
|
| 802 | - return $this->create( $args ); |
|
| 801 | + public function update($args = array()) { |
|
| 802 | + return $this->create($args); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | /** |
@@ -808,12 +808,12 @@ discard block |
||
| 808 | 808 | * @since 1.0.0 |
| 809 | 809 | * @return WP_Post[] |
| 810 | 810 | */ |
| 811 | - public function get_child_payments( $hide_pending = true ) { |
|
| 811 | + public function get_child_payments($hide_pending = true) { |
|
| 812 | 812 | |
| 813 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 813 | + $statuses = array('publish', 'wpi-processing', 'wpi-renewal'); |
|
| 814 | 814 | |
| 815 | - if ( ! $hide_pending ) { |
|
| 816 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 815 | + if (!$hide_pending) { |
|
| 816 | + $statuses = array_keys(wpinv_get_invoice_statuses()); |
|
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | return get_posts( |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * @return int |
| 836 | 836 | */ |
| 837 | 837 | public function get_total_payments() { |
| 838 | - return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() ); |
|
| 838 | + return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id()); |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | public function get_times_billed() { |
| 848 | 848 | $times_billed = $this->get_total_payments(); |
| 849 | 849 | |
| 850 | - if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) { |
|
| 850 | + if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) { |
|
| 851 | 851 | $times_billed--; |
| 852 | 852 | } |
| 853 | 853 | |
@@ -862,48 +862,48 @@ discard block |
||
| 862 | 862 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
| 863 | 863 | * @return bool |
| 864 | 864 | */ |
| 865 | - public function add_payment( $args = array(), $invoice = false ) { |
|
| 865 | + public function add_payment($args = array(), $invoice = false) { |
|
| 866 | 866 | |
| 867 | 867 | // Process each payment once. |
| 868 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 868 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
| 869 | 869 | return false; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | // Are we creating a new invoice? |
| 873 | - if ( empty( $invoice ) ) { |
|
| 873 | + if (empty($invoice)) { |
|
| 874 | 874 | $invoice = $this->create_payment(); |
| 875 | 875 | |
| 876 | - if ( empty( $invoice ) ) { |
|
| 876 | + if (empty($invoice)) { |
|
| 877 | 877 | return false; |
| 878 | 878 | } |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 881 | + $invoice->set_status('wpi-renewal'); |
|
| 882 | 882 | |
| 883 | 883 | // Maybe set a transaction id. |
| 884 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 885 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 884 | + if (!empty($args['transaction_id'])) { |
|
| 885 | + $invoice->set_transaction_id($args['transaction_id']); |
|
| 886 | 886 | } |
| 887 | 887 | |
| 888 | 888 | // Set the completed date. |
| 889 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 889 | + $invoice->set_completed_date(current_time('mysql')); |
|
| 890 | 890 | |
| 891 | 891 | // And the gateway. |
| 892 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 893 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 892 | + if (!empty($args['gateway'])) { |
|
| 893 | + $invoice->set_gateway($args['gateway']); |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | $invoice->save(); |
| 897 | 897 | |
| 898 | - if ( ! $invoice->exists() ) { |
|
| 898 | + if (!$invoice->exists()) { |
|
| 899 | 899 | return false; |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 903 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 904 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
| 902 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
| 903 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 904 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
| 905 | 905 | |
| 906 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
| 906 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
| 907 | 907 | |
| 908 | 908 | return $invoice->get_id(); |
| 909 | 909 | } |
@@ -918,41 +918,41 @@ discard block |
||
| 918 | 918 | |
| 919 | 919 | $parent_invoice = $this->get_parent_payment(); |
| 920 | 920 | |
| 921 | - if ( ! $parent_invoice->exists() ) { |
|
| 921 | + if (!$parent_invoice->exists()) { |
|
| 922 | 922 | return false; |
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | // Duplicate the parent invoice. |
| 926 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 927 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 928 | - $invoice->set_subscription_id( $this->get_id() ); |
|
| 929 | - $invoice->set_remote_subscription_id( $this->get_profile_id() ); |
|
| 926 | + $invoice = getpaid_duplicate_invoice($parent_invoice); |
|
| 927 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
| 928 | + $invoice->set_subscription_id($this->get_id()); |
|
| 929 | + $invoice->set_remote_subscription_id($this->get_profile_id()); |
|
| 930 | 930 | |
| 931 | 931 | // Set invoice items. |
| 932 | - $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() ); |
|
| 933 | - $allowed_items = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] ); |
|
| 932 | + $subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id()); |
|
| 933 | + $allowed_items = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']); |
|
| 934 | 934 | $invoice_items = array(); |
| 935 | 935 | |
| 936 | - foreach ( $invoice->get_items() as $item ) { |
|
| 937 | - if ( in_array( $item->get_id(), $allowed_items ) ) { |
|
| 936 | + foreach ($invoice->get_items() as $item) { |
|
| 937 | + if (in_array($item->get_id(), $allowed_items)) { |
|
| 938 | 938 | $invoice_items[] = $item; |
| 939 | 939 | } |
| 940 | 940 | } |
| 941 | 941 | |
| 942 | - $invoice->set_items( $invoice_items ); |
|
| 942 | + $invoice->set_items($invoice_items); |
|
| 943 | 943 | |
| 944 | - if ( ! empty( $subscription_group['fees'] ) ) { |
|
| 945 | - $invoice->set_fees( $subscription_group['fees'] ); |
|
| 944 | + if (!empty($subscription_group['fees'])) { |
|
| 945 | + $invoice->set_fees($subscription_group['fees']); |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | // Maybe recalculate discount (Pre-GetPaid Fix). |
| 949 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
| 950 | - if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) { |
|
| 951 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
| 949 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
| 950 | + if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) { |
|
| 951 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | $invoice->recalculate_total(); |
| 955 | - $invoice->set_status( 'wpi-pending' ); |
|
| 955 | + $invoice->set_status('wpi-pending'); |
|
| 956 | 956 | $invoice->save(); |
| 957 | 957 | |
| 958 | 958 | return $invoice->exists() ? $invoice : false; |
@@ -967,20 +967,20 @@ discard block |
||
| 967 | 967 | public function renew() { |
| 968 | 968 | |
| 969 | 969 | // Complete subscription if applicable |
| 970 | - if ( $this->is_last_renewal() ) { |
|
| 970 | + if ($this->is_last_renewal()) { |
|
| 971 | 971 | return $this->complete(); |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | // Calculate new expiration |
| 975 | 975 | $frequency = $this->get_frequency(); |
| 976 | 976 | $period = $this->get_period(); |
| 977 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 977 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
| 978 | 978 | |
| 979 | - $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) ); |
|
| 980 | - $this->set_status( 'active' ); |
|
| 979 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
| 980 | + $this->set_status('active'); |
|
| 981 | 981 | $this->save(); |
| 982 | 982 | |
| 983 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 983 | + do_action('getpaid_subscription_renewed', $this); |
|
| 984 | 984 | |
| 985 | 985 | return $this->get_id(); |
| 986 | 986 | } |
@@ -996,11 +996,11 @@ discard block |
||
| 996 | 996 | public function complete() { |
| 997 | 997 | |
| 998 | 998 | // Only mark a subscription as complete if it's not already cancelled. |
| 999 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 999 | + if ($this->has_status('cancelled')) { |
|
| 1000 | 1000 | return false; |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - $this->set_status( 'completed' ); |
|
| 1003 | + $this->set_status('completed'); |
|
| 1004 | 1004 | return $this->save(); |
| 1005 | 1005 | |
| 1006 | 1006 | } |
@@ -1012,14 +1012,14 @@ discard block |
||
| 1012 | 1012 | * @param bool $check_expiration |
| 1013 | 1013 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
| 1014 | 1014 | */ |
| 1015 | - public function expire( $check_expiration = false ) { |
|
| 1015 | + public function expire($check_expiration = false) { |
|
| 1016 | 1016 | |
| 1017 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1017 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
| 1018 | 1018 | // Do not mark as expired since real expiration date is in the future |
| 1019 | 1019 | return false; |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | - $this->set_status( 'expired' ); |
|
| 1022 | + $this->set_status('expired'); |
|
| 1023 | 1023 | return $this->save(); |
| 1024 | 1024 | |
| 1025 | 1025 | } |
@@ -1031,7 +1031,7 @@ discard block |
||
| 1031 | 1031 | * @return int Subscription id. |
| 1032 | 1032 | */ |
| 1033 | 1033 | public function failing() { |
| 1034 | - $this->set_status( 'failing' ); |
|
| 1034 | + $this->set_status('failing'); |
|
| 1035 | 1035 | return $this->save(); |
| 1036 | 1036 | } |
| 1037 | 1037 | |
@@ -1042,7 +1042,7 @@ discard block |
||
| 1042 | 1042 | * @return int Subscription id. |
| 1043 | 1043 | */ |
| 1044 | 1044 | public function cancel() { |
| 1045 | - $this->set_status( 'cancelled' ); |
|
| 1045 | + $this->set_status('cancelled'); |
|
| 1046 | 1046 | return $this->save(); |
| 1047 | 1047 | } |
| 1048 | 1048 | |
@@ -1053,7 +1053,7 @@ discard block |
||
| 1053 | 1053 | * @return bool |
| 1054 | 1054 | */ |
| 1055 | 1055 | public function can_cancel() { |
| 1056 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1056 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | /** |
@@ -1064,7 +1064,7 @@ discard block |
||
| 1064 | 1064 | * @return array |
| 1065 | 1065 | */ |
| 1066 | 1066 | public function get_cancellable_statuses() { |
| 1067 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 1067 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | /** |
@@ -1074,8 +1074,8 @@ discard block |
||
| 1074 | 1074 | * @return string |
| 1075 | 1075 | */ |
| 1076 | 1076 | public function get_cancel_url() { |
| 1077 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1078 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1077 | + $url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url()); |
|
| 1078 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
@@ -1086,10 +1086,10 @@ discard block |
||
| 1086 | 1086 | */ |
| 1087 | 1087 | public function get_view_url() { |
| 1088 | 1088 | |
| 1089 | - $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1090 | - $url = add_query_arg( 'subscription', $this->get_id(), $url ); |
|
| 1089 | + $url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
| 1090 | + $url = add_query_arg('subscription', $this->get_id(), $url); |
|
| 1091 | 1091 | |
| 1092 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1092 | + return apply_filters('getpaid_get_subscription_view_url', $url, $this); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1102,7 +1102,7 @@ discard block |
||
| 1102 | 1102 | * @return bool |
| 1103 | 1103 | */ |
| 1104 | 1104 | public function can_renew() { |
| 1105 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1105 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1121,7 +1121,7 @@ discard block |
||
| 1121 | 1121 | ), |
| 1122 | 1122 | 'getpaid-nonce' |
| 1123 | 1123 | ); |
| 1124 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1124 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | 1127 | /** |
@@ -1131,7 +1131,7 @@ discard block |
||
| 1131 | 1131 | * @return bool |
| 1132 | 1132 | */ |
| 1133 | 1133 | public function can_update() { |
| 1134 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1134 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1147,7 +1147,7 @@ discard block |
||
| 1147 | 1147 | 'subscription_id' => $this->get_id(), |
| 1148 | 1148 | ) |
| 1149 | 1149 | ); |
| 1150 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1150 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 1151 | 1151 | } |
| 1152 | 1152 | |
| 1153 | 1153 | /** |
@@ -1157,7 +1157,7 @@ discard block |
||
| 1157 | 1157 | * @return string |
| 1158 | 1158 | */ |
| 1159 | 1159 | public function get_status_label() { |
| 1160 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1160 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | 1163 | /** |
@@ -1168,7 +1168,7 @@ discard block |
||
| 1168 | 1168 | */ |
| 1169 | 1169 | public function get_status_class() { |
| 1170 | 1170 | $statuses = getpaid_get_subscription_status_classes(); |
| 1171 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark'; |
|
| 1171 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark'; |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | /** |
@@ -1179,9 +1179,9 @@ discard block |
||
| 1179 | 1179 | */ |
| 1180 | 1180 | public function get_status_label_html() { |
| 1181 | 1181 | |
| 1182 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1183 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1184 | - $status = sanitize_html_class( $this->get_status() ); |
|
| 1182 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
| 1183 | + $class = esc_attr($this->get_status_class()); |
|
| 1184 | + $status = sanitize_html_class($this->get_status()); |
|
| 1185 | 1185 | |
| 1186 | 1186 | return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>"; |
| 1187 | 1187 | } |
@@ -1193,9 +1193,9 @@ discard block |
||
| 1193 | 1193 | * @param string $txn_id The transaction ID from the merchant processor |
| 1194 | 1194 | * @return bool |
| 1195 | 1195 | */ |
| 1196 | - public function payment_exists( $txn_id = '' ) { |
|
| 1197 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1198 | - return ! empty( $invoice_id ); |
|
| 1196 | + public function payment_exists($txn_id = '') { |
|
| 1197 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
| 1198 | + return !empty($invoice_id); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | 1201 | /** |
@@ -1207,35 +1207,35 @@ discard block |
||
| 1207 | 1207 | // Reset status transition variable. |
| 1208 | 1208 | $this->status_transition = false; |
| 1209 | 1209 | |
| 1210 | - if ( $status_transition ) { |
|
| 1210 | + if ($status_transition) { |
|
| 1211 | 1211 | try { |
| 1212 | 1212 | |
| 1213 | 1213 | // Fire a hook for the status change. |
| 1214 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1215 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1214 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
| 1215 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
| 1216 | 1216 | |
| 1217 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1217 | + if (!empty($status_transition['from'])) { |
|
| 1218 | 1218 | |
| 1219 | 1219 | /* translators: 1: old subscription status 2: new subscription status */ |
| 1220 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1220 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1221 | 1221 | |
| 1222 | 1222 | // Note the transition occurred. |
| 1223 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1223 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1224 | 1224 | |
| 1225 | 1225 | // Fire another hook. |
| 1226 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1227 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1226 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
| 1227 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
| 1228 | 1228 | |
| 1229 | 1229 | } else { |
| 1230 | 1230 | /* translators: %s: new invoice status */ |
| 1231 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1231 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1232 | 1232 | |
| 1233 | 1233 | // Note the transition occurred. |
| 1234 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1234 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1235 | 1235 | |
| 1236 | 1236 | } |
| 1237 | - } catch ( Exception $e ) { |
|
| 1238 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1237 | + } catch (Exception $e) { |
|
| 1238 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | } |
| 1241 | 1241 | |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | */ |
| 1262 | 1262 | public function activate() { |
| 1263 | 1263 | $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
| 1264 | - $this->set_status( $status ); |
|
| 1264 | + $this->set_status($status); |
|
| 1265 | 1265 | return $this->save(); |
| 1266 | 1266 | } |
| 1267 | 1267 | |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | - include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 112 | + if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 113 | + include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | $message = wpinv_email_style_body( $message ); |
| 190 | 190 | $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
| 191 | 191 | |
| 192 | - return $mailer->send( |
|
| 192 | + return $mailer->send( |
|
| 193 | 193 | $to, |
| 194 | 194 | $subject, |
| 195 | 195 | $message, |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * Please use GetPaid_Notification_Email_Sender |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /* |
| 12 | 12 | |-------------------------------------------------------------------------- |
@@ -17,19 +17,19 @@ discard block |
||
| 17 | 17 | /** |
| 18 | 18 | * Generates the email header. |
| 19 | 19 | */ |
| 20 | -function wpinv_email_header( $email_heading ) { |
|
| 21 | - wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) ); |
|
| 20 | +function wpinv_email_header($email_heading) { |
|
| 21 | + wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading')); |
|
| 22 | 22 | } |
| 23 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
| 23 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * Generates the email footer. |
| 28 | 28 | */ |
| 29 | 29 | function wpinv_email_footer() { |
| 30 | - wpinv_get_template( 'emails/wpinv-email-footer.php' ); |
|
| 30 | + wpinv_get_template('emails/wpinv-email-footer.php'); |
|
| 31 | 31 | } |
| 32 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
| 32 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | * @param string $email_type |
| 40 | 40 | * @param bool $sent_to_admin |
| 41 | 41 | */ |
| 42 | -function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) { |
|
| 42 | +function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) { |
|
| 43 | 43 | |
| 44 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
| 45 | - wpinv_get_template( 'emails/invoice-details.php', $args ); |
|
| 44 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
| 45 | + wpinv_get_template('emails/invoice-details.php', $args); |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
| 48 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Display line items in emails. |
@@ -54,17 +54,17 @@ discard block |
||
| 54 | 54 | * @param string $email_type |
| 55 | 55 | * @param bool $sent_to_admin |
| 56 | 56 | */ |
| 57 | -function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) { |
|
| 57 | +function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) { |
|
| 58 | 58 | |
| 59 | 59 | // Prepare line items. |
| 60 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
| 61 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
| 60 | + $columns = getpaid_invoice_item_columns($invoice); |
|
| 61 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
| 62 | 62 | |
| 63 | 63 | // Load the template. |
| 64 | - wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) ); |
|
| 64 | + wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin')); |
|
| 65 | 65 | |
| 66 | 66 | } |
| 67 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
| 67 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | * @param string $email_type |
| 75 | 75 | * @param bool $sent_to_admin |
| 76 | 76 | */ |
| 77 | -function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) { |
|
| 77 | +function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) { |
|
| 78 | 78 | |
| 79 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
| 80 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args ); |
|
| 79 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
| 80 | + wpinv_get_template('emails/wpinv-email-billing-details.php', $args); |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
| 83 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Returns email css. |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | function getpaid_get_email_css() { |
| 90 | 90 | |
| 91 | - $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' ); |
|
| 92 | - return apply_filters( 'wpinv_email_styles', $css ); |
|
| 91 | + $css = wpinv_get_template_html('emails/wpinv-email-styles.php'); |
|
| 92 | + return apply_filters('wpinv_email_styles', $css); |
|
| 93 | 93 | |
| 94 | 94 | } |
| 95 | 95 | |
@@ -100,26 +100,26 @@ discard block |
||
| 100 | 100 | * @return string |
| 101 | 101 | * |
| 102 | 102 | */ |
| 103 | -function wpinv_email_style_body( $content ) { |
|
| 103 | +function wpinv_email_style_body($content) { |
|
| 104 | 104 | |
| 105 | - if ( ! class_exists( 'DOMDocument' ) ) { |
|
| 105 | + if (!class_exists('DOMDocument')) { |
|
| 106 | 106 | return $content; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | $css = getpaid_get_email_css(); |
| 110 | 110 | |
| 111 | 111 | // include css inliner |
| 112 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
| 112 | + if (!class_exists('Emogrifier')) { |
|
| 113 | 113 | include_once WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Inline the css. |
| 117 | 117 | try { |
| 118 | - $emogrifier = new Emogrifier( $content, $css ); |
|
| 118 | + $emogrifier = new Emogrifier($content, $css); |
|
| 119 | 119 | $_content = $emogrifier->emogrify(); |
| 120 | 120 | $content = $_content; |
| 121 | - } catch ( Exception $e ) { |
|
| 122 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
| 121 | + } catch (Exception $e) { |
|
| 122 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | return $content; |
@@ -128,37 +128,37 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | // Backwards compatibility. |
| 130 | 130 | function wpinv_init_transactional_emails() { |
| 131 | - foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) { |
|
| 132 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
| 131 | + foreach (apply_filters('wpinv_email_actions', array()) as $action) { |
|
| 132 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
| 135 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
| 136 | 136 | |
| 137 | 137 | function wpinv_send_transactional_email() { |
| 138 | 138 | $args = func_get_args(); |
| 139 | 139 | $function = current_filter() . '_notification'; |
| 140 | - do_action_ref_array( $function, $args ); |
|
| 140 | + do_action_ref_array($function, $args); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | function wpinv_mail_get_from_address() { |
| 144 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from', get_option( 'admin_email' ) ) ); |
|
| 145 | - return sanitize_email( $from_address ); |
|
| 144 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from', get_option('admin_email'))); |
|
| 145 | + return sanitize_email($from_address); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | function wpinv_mail_get_from_name() { |
| 149 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name', get_bloginfo( 'name', 'display' ) ) ); |
|
| 150 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
| 149 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name', get_bloginfo('name', 'display'))); |
|
| 150 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
| 154 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
| 155 | - return ( $active ? true : false ); |
|
| 153 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
| 154 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
| 155 | + return ($active ? true : false); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
| 159 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
| 158 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
| 159 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
| 160 | 160 | |
| 161 | - switch ( $email_type ) { |
|
| 161 | + switch ($email_type) { |
|
| 162 | 162 | case 'html': |
| 163 | 163 | $content_type = 'text/html'; |
| 164 | 164 | break; |
@@ -183,11 +183,11 @@ discard block |
||
| 183 | 183 | * @param array $attachments Any files to attach to the email. |
| 184 | 184 | * @param string|array $cc An email or array of extra emails to send a copy of the email to. |
| 185 | 185 | */ |
| 186 | -function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) { |
|
| 186 | +function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) { |
|
| 187 | 187 | |
| 188 | 188 | $mailer = new GetPaid_Notification_Email_Sender(); |
| 189 | - $message = wpinv_email_style_body( $message ); |
|
| 190 | - $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
|
| 189 | + $message = wpinv_email_style_body($message); |
|
| 190 | + $to = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc)); |
|
| 191 | 191 | |
| 192 | 192 | return $mailer->send( |
| 193 | 193 | $to, |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @return array |
| 205 | 205 | */ |
| 206 | 206 | function wpinv_get_emails() { |
| 207 | - return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) ); |
|
| 207 | + return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings')); |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | /** |
@@ -213,172 +213,172 @@ discard block |
||
| 213 | 213 | * @param array $settings |
| 214 | 214 | * @return array |
| 215 | 215 | */ |
| 216 | -function wpinv_settings_emails( $settings = array() ) { |
|
| 217 | - $settings = array_merge( $settings, wpinv_get_emails() ); |
|
| 218 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
| 216 | +function wpinv_settings_emails($settings = array()) { |
|
| 217 | + $settings = array_merge($settings, wpinv_get_emails()); |
|
| 218 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
| 219 | 219 | } |
| 220 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
| 220 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
| 221 | 221 | |
| 222 | 222 | /** |
| 223 | 223 | * Filter email section names. |
| 224 | 224 | * |
| 225 | 225 | */ |
| 226 | -function wpinv_settings_sections_emails( $settings ) { |
|
| 227 | - foreach ( wpinv_get_emails() as $key => $email ) { |
|
| 228 | - $settings[ $key ] = ! empty( $email[ 'email_' . $key . '_header' ]['name'] ) ? strip_tags( $email[ 'email_' . $key . '_header' ]['name'] ) : strip_tags( $key ); |
|
| 226 | +function wpinv_settings_sections_emails($settings) { |
|
| 227 | + foreach (wpinv_get_emails() as $key => $email) { |
|
| 228 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | return $settings; |
| 232 | 232 | } |
| 233 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
| 233 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
| 234 | 234 | |
| 235 | -function wpinv_email_is_enabled( $email_type ) { |
|
| 235 | +function wpinv_email_is_enabled($email_type) { |
|
| 236 | 236 | $emails = wpinv_get_emails(); |
| 237 | - $enabled = isset( $emails[ $email_type ] ) && wpinv_get_option( 'email_' . $email_type . '_active', 0 ) ? true : false; |
|
| 237 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
| 238 | 238 | |
| 239 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
| 239 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 243 | - switch ( $email_type ) { |
|
| 242 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 243 | + switch ($email_type) { |
|
| 244 | 244 | case 'new_invoice': |
| 245 | 245 | case 'cancelled_invoice': |
| 246 | 246 | case 'failed_invoice': |
| 247 | 247 | $recipient = wpinv_get_admin_email(); |
| 248 | 248 | break; |
| 249 | 249 | default: |
| 250 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 251 | - $recipient = ! empty( $invoice ) ? $invoice->get_email() : ''; |
|
| 250 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 251 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
| 252 | 252 | break; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
| 255 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | 259 | * Returns invoice CC recipients |
| 260 | 260 | */ |
| 261 | -function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 262 | - switch ( $email_type ) { |
|
| 261 | +function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 262 | + switch ($email_type) { |
|
| 263 | 263 | case 'new_invoice': |
| 264 | 264 | case 'cancelled_invoice': |
| 265 | 265 | case 'failed_invoice': |
| 266 | 266 | return array(); |
| 267 | 267 | break; |
| 268 | 268 | default: |
| 269 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 270 | - $recipient = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true ); |
|
| 271 | - if ( empty( $recipient ) ) { |
|
| 269 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 270 | + $recipient = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true); |
|
| 271 | + if (empty($recipient)) { |
|
| 272 | 272 | return array(); |
| 273 | 273 | } |
| 274 | - return array_filter( array_map( 'trim', explode( ',', $recipient ) ) ); |
|
| 274 | + return array_filter(array_map('trim', explode(',', $recipient))); |
|
| 275 | 275 | break; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 281 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
| 282 | - $subject = __( $subject, 'invoicing' ); |
|
| 280 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 281 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
| 282 | + $subject = __($subject, 'invoicing'); |
|
| 283 | 283 | |
| 284 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
| 284 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
| 285 | 285 | |
| 286 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
| 286 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 290 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
| 291 | - $email_heading = __( $email_heading, 'invoicing' ); |
|
| 289 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 290 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
| 291 | + $email_heading = __($email_heading, 'invoicing'); |
|
| 292 | 292 | |
| 293 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
| 293 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
| 294 | 294 | |
| 295 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
| 295 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 299 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
| 300 | - $content = __( $content, 'invoicing' ); |
|
| 298 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 299 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
| 300 | + $content = __($content, 'invoicing'); |
|
| 301 | 301 | |
| 302 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
| 302 | + $content = wpinv_email_format_text($content, $invoice); |
|
| 303 | 303 | |
| 304 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
| 304 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 307 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 308 | 308 | $from_name = wpinv_mail_get_from_address(); |
| 309 | 309 | $from_email = wpinv_mail_get_from_address(); |
| 310 | 310 | |
| 311 | - $invoice = ! empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : null ); |
|
| 311 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : null); |
|
| 312 | 312 | |
| 313 | - $headers = 'From: ' . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
| 313 | + $headers = 'From: ' . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
| 314 | 314 | $headers .= 'Reply-To: ' . $from_email . "\r\n"; |
| 315 | 315 | $headers .= 'Content-Type: ' . wpinv_mail_get_content_type() . "\r\n"; |
| 316 | 316 | |
| 317 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
| 317 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
| 320 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
| 321 | 321 | $attachments = array(); |
| 322 | 322 | |
| 323 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
| 323 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
| 327 | 327 | * Searches for and replaces certain placeholders in an email. |
| 328 | 328 | */ |
| 329 | -function wpinv_email_format_text( $content, $invoice ) { |
|
| 329 | +function wpinv_email_format_text($content, $invoice) { |
|
| 330 | 330 | |
| 331 | 331 | $replace_array = array( |
| 332 | 332 | '{site_title}' => wpinv_get_blogname(), |
| 333 | - '{date}' => getpaid_format_date( current_time( 'mysql' ) ), |
|
| 333 | + '{date}' => getpaid_format_date(current_time('mysql')), |
|
| 334 | 334 | ); |
| 335 | 335 | |
| 336 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 336 | + $invoice = new WPInv_Invoice($invoice); |
|
| 337 | 337 | |
| 338 | - if ( $invoice->get_id() ) { |
|
| 338 | + if ($invoice->get_id()) { |
|
| 339 | 339 | |
| 340 | 340 | $replace_array = array_merge( |
| 341 | 341 | $replace_array, |
| 342 | 342 | array( |
| 343 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 344 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
| 345 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
| 346 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
| 347 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
| 348 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
| 349 | - '{invoice_total}' => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ), |
|
| 350 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
| 351 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
| 352 | - '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
| 353 | - '{invoice_due_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
| 354 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_invoice_quote_type() ), |
|
| 355 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ), |
|
| 356 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
| 343 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
| 344 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
| 345 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
| 346 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
| 347 | + '{email}' => sanitize_email($invoice->get_email()), |
|
| 348 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
| 349 | + '{invoice_total}' => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())), |
|
| 350 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
| 351 | + '{invoice_pay_link}' => esc_url($invoice->get_checkout_payment_url()), |
|
| 352 | + '{invoice_date}' => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))), |
|
| 353 | + '{invoice_due_date}' => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))), |
|
| 354 | + '{invoice_quote}' => sanitize_text_field($invoice->get_invoice_quote_type()), |
|
| 355 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())), |
|
| 356 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
| 357 | 357 | ) |
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // Let third party plugins filter the arra. |
| 363 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
| 363 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
| 364 | 364 | |
| 365 | - foreach ( $replace_array as $key => $value ) { |
|
| 366 | - $content = str_replace( $key, $value, $content ); |
|
| 365 | + foreach ($replace_array as $key => $value) { |
|
| 366 | + $content = str_replace($key, $value, $content); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
| 369 | + return apply_filters('wpinv_email_content_replace', $content); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | |
| 373 | -function wpinv_email_wrap_message( $message ) { |
|
| 373 | +function wpinv_email_wrap_message($message) { |
|
| 374 | 374 | // Buffer |
| 375 | 375 | ob_start(); |
| 376 | 376 | |
| 377 | - do_action( 'wpinv_email_header' ); |
|
| 377 | + do_action('wpinv_email_header'); |
|
| 378 | 378 | |
| 379 | - echo wp_kses_post( wpautop( wptexturize( $message ) ) ); |
|
| 379 | + echo wp_kses_post(wpautop(wptexturize($message))); |
|
| 380 | 380 | |
| 381 | - do_action( 'wpinv_email_footer' ); |
|
| 381 | + do_action('wpinv_email_footer'); |
|
| 382 | 382 | |
| 383 | 383 | // Get contents |
| 384 | 384 | $message = ob_get_clean(); |
@@ -386,21 +386,21 @@ discard block |
||
| 386 | 386 | return $message; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) { |
|
| 390 | - if ( ! empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) { |
|
| 391 | - $date_format = get_option( 'date_format' ); |
|
| 392 | - $time_format = get_option( 'time_format' ); |
|
| 389 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type) { |
|
| 390 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) { |
|
| 391 | + $date_format = get_option('date_format'); |
|
| 392 | + $time_format = get_option('time_format'); |
|
| 393 | 393 | ?> |
| 394 | 394 | <div id="wpinv-email-notes"> |
| 395 | - <h3 class="wpinv-notes-t"><?php echo esc_html( apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ) ); ?></h3> |
|
| 395 | + <h3 class="wpinv-notes-t"><?php echo esc_html(apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing'))); ?></h3> |
|
| 396 | 396 | <ol class="wpinv-notes-lists"> |
| 397 | 397 | <?php |
| 398 | - foreach ( $invoice_notes as $note ) { |
|
| 399 | - $note_time = strtotime( $note->comment_date ); |
|
| 398 | + foreach ($invoice_notes as $note) { |
|
| 399 | + $note_time = strtotime($note->comment_date); |
|
| 400 | 400 | ?> |
| 401 | 401 | <li class="comment wpinv-note"> |
| 402 | - <p class="wpinv-note-date meta"><?php printf( esc_html__( '%2$s at %3$s', 'invoicing' ), esc_html( $note->comment_author ), esc_html( date_i18n( $date_format, $note_time ) ), esc_html( date_i18n( $time_format, $note_time ) ), esc_html( $note_time ) ); ?></p> |
|
| 403 | - <div class="wpinv-note-desc description"><?php echo wp_kses_post( wpautop( wptexturize( $note->comment_content ) ) ); ?></div> |
|
| 402 | + <p class="wpinv-note-date meta"><?php printf(esc_html__('%2$s at %3$s', 'invoicing'), esc_html($note->comment_author), esc_html(date_i18n($date_format, $note_time)), esc_html(date_i18n($time_format, $note_time)), esc_html($note_time)); ?></p> |
|
| 403 | + <div class="wpinv-note-desc description"><?php echo wp_kses_post(wpautop(wptexturize($note->comment_content))); ?></div> |
|
| 404 | 404 | </li> |
| 405 | 405 | <?php |
| 406 | 406 | } |
@@ -410,4 +410,4 @@ discard block |
||
| 410 | 410 | <?php |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
| 413 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
|
@@ -12,207 +12,207 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Notes { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class constructor. |
|
| 17 | - */ |
|
| 18 | - public function __construct() { |
|
| 19 | - |
|
| 20 | - // Filter inovice notes. |
|
| 21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | - |
|
| 24 | - // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | - |
|
| 28 | - // Count comments. |
|
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | - |
|
| 31 | - // Fires after notes are loaded. |
|
| 32 | - do_action( 'wpinv_notes_init', $this ); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Filters invoice notes query to only include our notes. |
|
| 37 | - * |
|
| 38 | - * @param WP_Comment_Query $query |
|
| 39 | - */ |
|
| 40 | - public function set_invoice_note_type( $query ) { |
|
| 41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | - |
|
| 43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | - $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | - } else { |
|
| 46 | - |
|
| 47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | - $query->query_vars['type__not_in'] = array(); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $query; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Exclude notes from the comments feed. |
|
| 60 | - */ |
|
| 61 | - function wpinv_comment_feed_where( $where ) { |
|
| 62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Delete comments count cache whenever there is |
|
| 67 | - * new comment or the status of a comment changes. Cache |
|
| 68 | - * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | - * is called. |
|
| 70 | - */ |
|
| 71 | - public function delete_comments_count_cache() { |
|
| 72 | - delete_transient( 'getpaid_count_comments' ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Remove invoice notes from wp_count_comments(). |
|
| 77 | - * |
|
| 78 | - * @since 2.2 |
|
| 79 | - * @param object $stats Comment stats. |
|
| 80 | - * @param int $post_id Post ID. |
|
| 81 | - * @return object |
|
| 82 | - */ |
|
| 83 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | - global $wpdb; |
|
| 85 | - |
|
| 86 | - if ( empty( $post_id ) ) { |
|
| 87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | - |
|
| 89 | - if ( ! $stats ) { |
|
| 90 | - $stats = array( |
|
| 91 | - 'total_comments' => 0, |
|
| 92 | - 'all' => 0, |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $count = $wpdb->get_results( |
|
| 96 | - " |
|
| 15 | + /** |
|
| 16 | + * Class constructor. |
|
| 17 | + */ |
|
| 18 | + public function __construct() { |
|
| 19 | + |
|
| 20 | + // Filter inovice notes. |
|
| 21 | + add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | + add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 23 | + |
|
| 24 | + // Delete comments count cache whenever there is a new comment or a comment status changes. |
|
| 25 | + add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | + add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 27 | + |
|
| 28 | + // Count comments. |
|
| 29 | + add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 30 | + |
|
| 31 | + // Fires after notes are loaded. |
|
| 32 | + do_action( 'wpinv_notes_init', $this ); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Filters invoice notes query to only include our notes. |
|
| 37 | + * |
|
| 38 | + * @param WP_Comment_Query $query |
|
| 39 | + */ |
|
| 40 | + public function set_invoice_note_type( $query ) { |
|
| 41 | + $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | + |
|
| 43 | + if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 44 | + $query->query_vars['type'] = 'wpinv_note'; |
|
| 45 | + } else { |
|
| 46 | + |
|
| 47 | + if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 48 | + $query->query_vars['type__not_in'] = array(); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | + $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $query; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Exclude notes from the comments feed. |
|
| 60 | + */ |
|
| 61 | + function wpinv_comment_feed_where( $where ) { |
|
| 62 | + return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Delete comments count cache whenever there is |
|
| 67 | + * new comment or the status of a comment changes. Cache |
|
| 68 | + * will be regenerated next time WPInv_Notes::wp_count_comments() |
|
| 69 | + * is called. |
|
| 70 | + */ |
|
| 71 | + public function delete_comments_count_cache() { |
|
| 72 | + delete_transient( 'getpaid_count_comments' ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Remove invoice notes from wp_count_comments(). |
|
| 77 | + * |
|
| 78 | + * @since 2.2 |
|
| 79 | + * @param object $stats Comment stats. |
|
| 80 | + * @param int $post_id Post ID. |
|
| 81 | + * @return object |
|
| 82 | + */ |
|
| 83 | + public function wp_count_comments( $stats, $post_id ) { |
|
| 84 | + global $wpdb; |
|
| 85 | + |
|
| 86 | + if ( empty( $post_id ) ) { |
|
| 87 | + $stats = get_transient( 'getpaid_count_comments' ); |
|
| 88 | + |
|
| 89 | + if ( ! $stats ) { |
|
| 90 | + $stats = array( |
|
| 91 | + 'total_comments' => 0, |
|
| 92 | + 'all' => 0, |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $count = $wpdb->get_results( |
|
| 96 | + " |
|
| 97 | 97 | SELECT comment_approved, COUNT(*) AS num_comments |
| 98 | 98 | FROM {$wpdb->comments} |
| 99 | 99 | WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery', 'wpinv_note') |
| 100 | 100 | GROUP BY comment_approved |
| 101 | 101 | ", |
| 102 | - ARRAY_A |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $approved = array( |
|
| 106 | - '0' => 'moderated', |
|
| 107 | - '1' => 'approved', |
|
| 108 | - 'spam' => 'spam', |
|
| 109 | - 'trash' => 'trash', |
|
| 110 | - 'post-trashed' => 'post-trashed', |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - foreach ( (array) $count as $row ) { |
|
| 114 | - // Don't count post-trashed toward totals. |
|
| 115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | - $stats['all'] += $row['num_comments']; |
|
| 117 | - $stats['total_comments'] += $row['num_comments']; |
|
| 118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | - $stats['total_comments'] += $row['num_comments']; |
|
| 120 | - } |
|
| 121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - foreach ( $approved as $key ) { |
|
| 127 | - if ( empty( $stats[ $key ] ) ) { |
|
| 128 | - $stats[ $key ] = 0; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - $stats = (object) $stats; |
|
| 133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | - } |
|
| 102 | + ARRAY_A |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $approved = array( |
|
| 106 | + '0' => 'moderated', |
|
| 107 | + '1' => 'approved', |
|
| 108 | + 'spam' => 'spam', |
|
| 109 | + 'trash' => 'trash', |
|
| 110 | + 'post-trashed' => 'post-trashed', |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + foreach ( (array) $count as $row ) { |
|
| 114 | + // Don't count post-trashed toward totals. |
|
| 115 | + if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 116 | + $stats['all'] += $row['num_comments']; |
|
| 117 | + $stats['total_comments'] += $row['num_comments']; |
|
| 118 | + } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 119 | + $stats['total_comments'] += $row['num_comments']; |
|
| 120 | + } |
|
| 121 | + if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | + $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + foreach ( $approved as $key ) { |
|
| 127 | + if ( empty( $stats[ $key ] ) ) { |
|
| 128 | + $stats[ $key ] = 0; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + $stats = (object) $stats; |
|
| 133 | + set_transient( 'getpaid_count_comments', $stats ); |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - return $stats; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns an array of invoice notes. |
|
| 142 | - * |
|
| 143 | - * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | - * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | - * @return WP_Comment[] |
|
| 146 | - */ |
|
| 147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | - |
|
| 149 | - // Default comment args. |
|
| 150 | - $args = array( |
|
| 151 | - 'post_id' => $invoice_id, |
|
| 152 | - 'orderby' => 'comment_ID', |
|
| 153 | - 'order' => 'ASC', |
|
| 154 | - ); |
|
| 155 | - |
|
| 156 | - // Maybe only show customer comments. |
|
| 157 | - if ( $type == 'customer' ) { |
|
| 158 | - $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | - $args['meta_value'] = 1; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | - |
|
| 164 | - return get_comments( $args ); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Saves an invoice comment. |
|
| 169 | - * |
|
| 170 | - * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | - * @param string $note The note content. |
|
| 172 | - * @param string $note_author The name of the author of the note. |
|
| 173 | - * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | - * @return int|false The new note's ID on success, false on failure. |
|
| 175 | - */ |
|
| 176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | - |
|
| 178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * Insert the comment. |
|
| 182 | - */ |
|
| 183 | - $note_id = wp_insert_comment( |
|
| 184 | - wp_filter_comment( |
|
| 185 | - array( |
|
| 186 | - 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | - 'comment_content' => $note, |
|
| 188 | - 'comment_agent' => 'Invoicing', |
|
| 189 | - 'user_id' => get_current_user_id(), |
|
| 190 | - 'comment_author' => $note_author, |
|
| 191 | - 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | - 'comment_author_email' => $author_email, |
|
| 193 | - 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | - 'comment_type' => 'wpinv_note', |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ); |
|
| 198 | - |
|
| 199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | - |
|
| 201 | - // Are we notifying the customer? |
|
| 202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | - return $note_id; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | - do_action( |
|
| 137 | + return $stats; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns an array of invoice notes. |
|
| 142 | + * |
|
| 143 | + * @param int $invoice_id The invoice ID whose notes to retrieve. |
|
| 144 | + * @param string $type Optional. Pass in customer to only return customer notes. |
|
| 145 | + * @return WP_Comment[] |
|
| 146 | + */ |
|
| 147 | + public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 148 | + |
|
| 149 | + // Default comment args. |
|
| 150 | + $args = array( |
|
| 151 | + 'post_id' => $invoice_id, |
|
| 152 | + 'orderby' => 'comment_ID', |
|
| 153 | + 'order' => 'ASC', |
|
| 154 | + ); |
|
| 155 | + |
|
| 156 | + // Maybe only show customer comments. |
|
| 157 | + if ( $type == 'customer' ) { |
|
| 158 | + $args['meta_key'] = '_wpi_customer_note'; |
|
| 159 | + $args['meta_value'] = 1; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 163 | + |
|
| 164 | + return get_comments( $args ); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Saves an invoice comment. |
|
| 169 | + * |
|
| 170 | + * @param WPInv_Invoice $invoice The invoice to add the comment to. |
|
| 171 | + * @param string $note The note content. |
|
| 172 | + * @param string $note_author The name of the author of the note. |
|
| 173 | + * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
|
| 174 | + * @return int|false The new note's ID on success, false on failure. |
|
| 175 | + */ |
|
| 176 | + function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 177 | + |
|
| 178 | + do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * Insert the comment. |
|
| 182 | + */ |
|
| 183 | + $note_id = wp_insert_comment( |
|
| 184 | + wp_filter_comment( |
|
| 185 | + array( |
|
| 186 | + 'comment_post_ID' => $invoice->get_id(), |
|
| 187 | + 'comment_content' => $note, |
|
| 188 | + 'comment_agent' => 'Invoicing', |
|
| 189 | + 'user_id' => get_current_user_id(), |
|
| 190 | + 'comment_author' => $note_author, |
|
| 191 | + 'comment_author_IP' => wpinv_get_ip(), |
|
| 192 | + 'comment_author_email' => $author_email, |
|
| 193 | + 'comment_author_url' => $invoice->get_view_url(), |
|
| 194 | + 'comment_type' => 'wpinv_note', |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ); |
|
| 198 | + |
|
| 199 | + do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 200 | + |
|
| 201 | + // Are we notifying the customer? |
|
| 202 | + if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 203 | + return $note_id; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 207 | + do_action( |
|
| 208 | 208 | 'wpinv_new_customer_note', |
| 209 | 209 | array( |
| 210 | - 'invoice_id' => $invoice->get_id(), |
|
| 211 | - 'user_note' => $note, |
|
| 210 | + 'invoice_id' => $invoice->get_id(), |
|
| 211 | + 'user_note' => $note, |
|
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | - return $note_id; |
|
| 216 | - } |
|
| 214 | + do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 215 | + return $note_id; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | } |
@@ -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 | * Handles invoice notes. |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | public function __construct() { |
| 19 | 19 | |
| 20 | 20 | // Filter inovice notes. |
| 21 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
| 22 | - add_action( 'comment_feed_where', array( $this, 'wpinv_comment_feed_where' ), 10, 1 ); |
|
| 21 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
| 22 | + add_action('comment_feed_where', array($this, 'wpinv_comment_feed_where'), 10, 1); |
|
| 23 | 23 | |
| 24 | 24 | // Delete comments count cache whenever there is a new comment or a comment status changes. |
| 25 | - add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) ); |
|
| 26 | - add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) ); |
|
| 25 | + add_action('wp_insert_comment', array($this, 'delete_comments_count_cache')); |
|
| 26 | + add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache')); |
|
| 27 | 27 | |
| 28 | 28 | // Count comments. |
| 29 | - add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 100, 2 ); |
|
| 29 | + add_filter('wp_count_comments', array($this, 'wp_count_comments'), 100, 2); |
|
| 30 | 30 | |
| 31 | 31 | // Fires after notes are loaded. |
| 32 | - do_action( 'wpinv_notes_init', $this ); |
|
| 32 | + do_action('wpinv_notes_init', $this); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -37,19 +37,19 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @param WP_Comment_Query $query |
| 39 | 39 | */ |
| 40 | - public function set_invoice_note_type( $query ) { |
|
| 41 | - $post_id = ! empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 40 | + public function set_invoice_note_type($query) { |
|
| 41 | + $post_id = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
| 42 | 42 | |
| 43 | - if ( $post_id && getpaid_is_invoice_post_type( get_post_type( $post_id ) ) ) { |
|
| 43 | + if ($post_id && getpaid_is_invoice_post_type(get_post_type($post_id))) { |
|
| 44 | 44 | $query->query_vars['type'] = 'wpinv_note'; |
| 45 | 45 | } else { |
| 46 | 46 | |
| 47 | - if ( empty( $query->query_vars['type__not_in'] ) ) { |
|
| 47 | + if (empty($query->query_vars['type__not_in'])) { |
|
| 48 | 48 | $query->query_vars['type__not_in'] = array(); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - $query->query_vars['type__not_in'] = wpinv_parse_list( $query->query_vars['type__not_in'] ); |
|
| 52 | - $query->query_vars['type__not_in'] = array_merge( array( 'wpinv_note' ), $query->query_vars['type__not_in'] ); |
|
| 51 | + $query->query_vars['type__not_in'] = wpinv_parse_list($query->query_vars['type__not_in']); |
|
| 52 | + $query->query_vars['type__not_in'] = array_merge(array('wpinv_note'), $query->query_vars['type__not_in']); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $query; |
@@ -58,8 +58,8 @@ discard block |
||
| 58 | 58 | /** |
| 59 | 59 | * Exclude notes from the comments feed. |
| 60 | 60 | */ |
| 61 | - function wpinv_comment_feed_where( $where ) { |
|
| 62 | - return $where . ( $where ? ' AND ' : '' ) . " comment_type != 'wpinv_note' "; |
|
| 61 | + function wpinv_comment_feed_where($where) { |
|
| 62 | + return $where . ($where ? ' AND ' : '') . " comment_type != 'wpinv_note' "; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * is called. |
| 70 | 70 | */ |
| 71 | 71 | public function delete_comments_count_cache() { |
| 72 | - delete_transient( 'getpaid_count_comments' ); |
|
| 72 | + delete_transient('getpaid_count_comments'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | * @param int $post_id Post ID. |
| 81 | 81 | * @return object |
| 82 | 82 | */ |
| 83 | - public function wp_count_comments( $stats, $post_id ) { |
|
| 83 | + public function wp_count_comments($stats, $post_id) { |
|
| 84 | 84 | global $wpdb; |
| 85 | 85 | |
| 86 | - if ( empty( $post_id ) ) { |
|
| 87 | - $stats = get_transient( 'getpaid_count_comments' ); |
|
| 86 | + if (empty($post_id)) { |
|
| 87 | + $stats = get_transient('getpaid_count_comments'); |
|
| 88 | 88 | |
| 89 | - if ( ! $stats ) { |
|
| 89 | + if (!$stats) { |
|
| 90 | 90 | $stats = array( |
| 91 | 91 | 'total_comments' => 0, |
| 92 | 92 | 'all' => 0, |
@@ -110,27 +110,27 @@ discard block |
||
| 110 | 110 | 'post-trashed' => 'post-trashed', |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | - foreach ( (array) $count as $row ) { |
|
| 113 | + foreach ((array) $count as $row) { |
|
| 114 | 114 | // Don't count post-trashed toward totals. |
| 115 | - if ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) { |
|
| 115 | + if (!in_array($row['comment_approved'], array('post-trashed', 'trash', 'spam'), true)) { |
|
| 116 | 116 | $stats['all'] += $row['num_comments']; |
| 117 | 117 | $stats['total_comments'] += $row['num_comments']; |
| 118 | - } elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) { |
|
| 118 | + } elseif (!in_array($row['comment_approved'], array('post-trashed', 'trash'), true)) { |
|
| 119 | 119 | $stats['total_comments'] += $row['num_comments']; |
| 120 | 120 | } |
| 121 | - if ( isset( $approved[ $row['comment_approved'] ] ) ) { |
|
| 122 | - $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments']; |
|
| 121 | + if (isset($approved[$row['comment_approved']])) { |
|
| 122 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - foreach ( $approved as $key ) { |
|
| 127 | - if ( empty( $stats[ $key ] ) ) { |
|
| 128 | - $stats[ $key ] = 0; |
|
| 126 | + foreach ($approved as $key) { |
|
| 127 | + if (empty($stats[$key])) { |
|
| 128 | + $stats[$key] = 0; |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $stats = (object) $stats; |
| 133 | - set_transient( 'getpaid_count_comments', $stats ); |
|
| 133 | + set_transient('getpaid_count_comments', $stats); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param string $type Optional. Pass in customer to only return customer notes. |
| 145 | 145 | * @return WP_Comment[] |
| 146 | 146 | */ |
| 147 | - public function get_invoice_notes( $invoice_id = 0, $type = 'all' ) { |
|
| 147 | + public function get_invoice_notes($invoice_id = 0, $type = 'all') { |
|
| 148 | 148 | |
| 149 | 149 | // Default comment args. |
| 150 | 150 | $args = array( |
@@ -154,14 +154,14 @@ discard block |
||
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | 156 | // Maybe only show customer comments. |
| 157 | - if ( $type == 'customer' ) { |
|
| 157 | + if ($type == 'customer') { |
|
| 158 | 158 | $args['meta_key'] = '_wpi_customer_note'; |
| 159 | 159 | $args['meta_value'] = 1; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
| 162 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
| 163 | 163 | |
| 164 | - return get_comments( $args ); |
|
| 164 | + return get_comments($args); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | * @param bool $for_customer Whether or not this comment is meant to be sent to the customer. |
| 174 | 174 | * @return int|false The new note's ID on success, false on failure. |
| 175 | 175 | */ |
| 176 | - function add_invoice_note( $invoice, $note, $note_author, $author_email, $for_customer = false ) { |
|
| 176 | + function add_invoice_note($invoice, $note, $note_author, $author_email, $for_customer = false) { |
|
| 177 | 177 | |
| 178 | - do_action( 'wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer ); |
|
| 178 | + do_action('wpinv_pre_insert_invoice_note', $invoice->get_id(), $note, $for_customer); |
|
| 179 | 179 | |
| 180 | 180 | /** |
| 181 | 181 | * Insert the comment. |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | ) |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - do_action( 'wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer ); |
|
| 199 | + do_action('wpinv_insert_payment_note', $note_id, $invoice->get_id(), $note, $for_customer); |
|
| 200 | 200 | |
| 201 | 201 | // Are we notifying the customer? |
| 202 | - if ( empty( $note_id ) || empty( $for_customer ) ) { |
|
| 202 | + if (empty($note_id) || empty($for_customer)) { |
|
| 203 | 203 | return $note_id; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 206 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
| 207 | 207 | do_action( |
| 208 | 208 | 'wpinv_new_customer_note', |
| 209 | 209 | array( |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | 'user_note' => $note, |
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | - do_action( 'getpaid_new_customer_note', $invoice, $note ); |
|
| 214 | + do_action('getpaid_new_customer_note', $invoice, $note); |
|
| 215 | 215 | return $note_id; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -17,45 +17,45 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class BP_GetPaid_Component extends BP_Component { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Start the component setup process. |
|
| 22 | - * |
|
| 23 | - * @since 2.1.5 |
|
| 24 | - */ |
|
| 25 | - public function __construct() { |
|
| 26 | - parent::start( |
|
| 27 | - 'getpaid', |
|
| 28 | - 'GetPaid', |
|
| 29 | - buddypress()->plugin_dir, |
|
| 30 | - array( |
|
| 31 | - 'adminbar_myaccount_order' => 30, |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 34 | - } |
|
| 20 | + /** |
|
| 21 | + * Start the component setup process. |
|
| 22 | + * |
|
| 23 | + * @since 2.1.5 |
|
| 24 | + */ |
|
| 25 | + public function __construct() { |
|
| 26 | + parent::start( |
|
| 27 | + 'getpaid', |
|
| 28 | + 'GetPaid', |
|
| 29 | + buddypress()->plugin_dir, |
|
| 30 | + array( |
|
| 31 | + 'adminbar_myaccount_order' => 30, |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Set up component global variables. |
|
| 38 | - * |
|
| 39 | - * @since 2.1.5 |
|
| 40 | - * |
|
| 41 | - * |
|
| 42 | - * @param array $args { |
|
| 43 | - * All values are optional. |
|
| 44 | - * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
| 45 | - * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
| 46 | - * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
| 47 | - * component has a root directory (the slug will be overridden by the |
|
| 48 | - * post_name of the directory page). Default: the slug of the directory page |
|
| 49 | - * if one is found, otherwise an empty string. |
|
| 50 | - * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
| 51 | - * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
| 52 | - * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
| 53 | - * 'Search Groups...'. |
|
| 54 | - * @type array $global_tables Optional. An array of database table names. |
|
| 55 | - * @type array $meta_tables Optional. An array of metadata table names. |
|
| 56 | - * } |
|
| 57 | - */ |
|
| 58 | - public function setup_globals( $args = array() ) { |
|
| 37 | + * Set up component global variables. |
|
| 38 | + * |
|
| 39 | + * @since 2.1.5 |
|
| 40 | + * |
|
| 41 | + * |
|
| 42 | + * @param array $args { |
|
| 43 | + * All values are optional. |
|
| 44 | + * @type string $slug The component slug. Used to construct certain URLs, such as 'friends' in |
|
| 45 | + * http://example.com/members/joe/friends/. Default: the value of $this->id. |
|
| 46 | + * @type string $root_slug The component root slug. Note that this value is generally unused if the |
|
| 47 | + * component has a root directory (the slug will be overridden by the |
|
| 48 | + * post_name of the directory page). Default: the slug of the directory page |
|
| 49 | + * if one is found, otherwise an empty string. |
|
| 50 | + * @type bool $has_directory Set to true if the component requires an associated WordPress page. |
|
| 51 | + * @type callable $notification_callback Optional. The callable function that formats the component's notifications. |
|
| 52 | + * @type string $search_term Optional. The placeholder text in the component directory search box. Eg, |
|
| 53 | + * 'Search Groups...'. |
|
| 54 | + * @type array $global_tables Optional. An array of database table names. |
|
| 55 | + * @type array $meta_tables Optional. An array of metadata table names. |
|
| 56 | + * } |
|
| 57 | + */ |
|
| 58 | + public function setup_globals( $args = array() ) { |
|
| 59 | 59 | parent::setup_globals( |
| 60 | 60 | array( |
| 61 | 61 | 'id' => 'getpaid', |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | 'has_directory' => false, |
| 65 | 65 | ) |
| 66 | 66 | ); |
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Set up component navigation. |
|
| 71 | - * |
|
| 72 | - * @since 2.1.5 |
|
| 73 | - * |
|
| 74 | - * @see BP_Component::setup_nav() for a description of arguments. |
|
| 75 | - * |
|
| 76 | - * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
| 77 | - * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
| 78 | - */ |
|
| 79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
| 80 | - |
|
| 81 | - // Abort if the integration is inactive. |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Set up component navigation. |
|
| 71 | + * |
|
| 72 | + * @since 2.1.5 |
|
| 73 | + * |
|
| 74 | + * @see BP_Component::setup_nav() for a description of arguments. |
|
| 75 | + * |
|
| 76 | + * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
|
| 77 | + * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
|
| 78 | + */ |
|
| 79 | + public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
| 80 | + |
|
| 81 | + // Abort if the integration is inactive. |
|
| 82 | 82 | if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
| 83 | 83 | return; |
| 84 | 84 | } |
@@ -88,25 +88,25 @@ discard block |
||
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - // Determine user to use. |
|
| 92 | - $user_domain = bp_loggedin_user_domain(); |
|
| 93 | - $slug = 'getpaid'; |
|
| 94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
| 95 | - |
|
| 96 | - // Add 'Payments' to the main navigation. |
|
| 97 | - $main_nav = array( |
|
| 98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
| 99 | - 'slug' => $slug, |
|
| 100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
| 101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
| 102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
| 91 | + // Determine user to use. |
|
| 92 | + $user_domain = bp_loggedin_user_domain(); |
|
| 93 | + $slug = 'getpaid'; |
|
| 94 | + $payments_link = trailingslashit( $user_domain . $slug ); |
|
| 95 | + |
|
| 96 | + // Add 'Payments' to the main navigation. |
|
| 97 | + $main_nav = array( |
|
| 98 | + 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
| 99 | + 'slug' => $slug, |
|
| 100 | + 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
| 101 | + 'screen_function' => array( $this, 'display_current_tab' ), |
|
| 102 | + 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
| 103 | 103 | 'show_for_displayed_user' => false, |
| 104 | - 'item_css_id' => $this->id, |
|
| 105 | - 'parent_url' => $user_domain, |
|
| 106 | - 'parent_slug' => buddypress()->slug, |
|
| 107 | - ); |
|
| 104 | + 'item_css_id' => $this->id, |
|
| 105 | + 'parent_url' => $user_domain, |
|
| 106 | + 'parent_slug' => buddypress()->slug, |
|
| 107 | + ); |
|
| 108 | 108 | |
| 109 | - // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
| 109 | + // Add the subnav items to the payments nav item if we are using a theme that supports this. |
|
| 110 | 110 | foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
| 111 | 111 | |
| 112 | 112 | $sub_nav[] = array( |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | 'parent_slug' => $slug, |
| 117 | 117 | 'position' => 10, |
| 118 | 118 | 'screen_function' => function() use ( $tab ) { |
| 119 | - $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
| 120 | - $this->display_current_tab(); |
|
| 119 | + $GLOBALS['getpaid_bp_current_tab'] = $tab; |
|
| 120 | + $this->display_current_tab(); |
|
| 121 | 121 | }, |
| 122 | 122 | 'show_for_displayed_user' => false, |
| 123 | 123 | 'item_css_id' => "getpaid-bp-$_slug", |
@@ -125,27 +125,27 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Set up the component entries in the WordPress Admin Bar. |
|
| 133 | - * |
|
| 134 | - * @since 2.1.5 |
|
| 135 | - * |
|
| 136 | - * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
| 137 | - * parameter array. |
|
| 138 | - * |
|
| 139 | - * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
| 140 | - * description. |
|
| 141 | - */ |
|
| 142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
| 128 | + parent::setup_nav( $main_nav, $sub_nav ); |
|
| 129 | + } |
|
| 143 | 130 | |
| 144 | - // Menus for logged in user. |
|
| 145 | - if ( is_user_logged_in() ) { |
|
| 146 | - |
|
| 147 | - // Setup the logged in user variables. |
|
| 148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
| 131 | + /** |
|
| 132 | + * Set up the component entries in the WordPress Admin Bar. |
|
| 133 | + * |
|
| 134 | + * @since 2.1.5 |
|
| 135 | + * |
|
| 136 | + * @see BP_Component::setup_nav() for a description of the $wp_admin_nav |
|
| 137 | + * parameter array. |
|
| 138 | + * |
|
| 139 | + * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
|
| 140 | + * description. |
|
| 141 | + */ |
|
| 142 | + public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
| 143 | + |
|
| 144 | + // Menus for logged in user. |
|
| 145 | + if ( is_user_logged_in() ) { |
|
| 146 | + |
|
| 147 | + // Setup the logged in user variables. |
|
| 148 | + $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
| 149 | 149 | |
| 150 | 150 | // Add the "Payments" sub menu. |
| 151 | 151 | $wp_admin_nav[] = array( |
@@ -168,48 +168,48 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Retrieves the current tab. |
|
| 176 | - * |
|
| 177 | - * @since 2.1.5 |
|
| 178 | - */ |
|
| 179 | - public function get_current_tab() { |
|
| 180 | - global $getpaid_bp_current_tab; |
|
| 181 | - |
|
| 182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
| 183 | - return array( |
|
| 184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
| 185 | - 'content' => '[wpinv_history]', |
|
| 186 | - 'icon' => 'fas fa-file-invoice', |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return $getpaid_bp_current_tab; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Displays the current tab. |
|
| 195 | - * |
|
| 196 | - * @since 2.1.5 |
|
| 197 | - */ |
|
| 198 | - public function display_current_tab() { |
|
| 199 | - |
|
| 200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
| 201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
| 171 | + parent::setup_admin_bar( $wp_admin_nav ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Retrieves the current tab. |
|
| 176 | + * |
|
| 177 | + * @since 2.1.5 |
|
| 178 | + */ |
|
| 179 | + public function get_current_tab() { |
|
| 180 | + global $getpaid_bp_current_tab; |
|
| 181 | + |
|
| 182 | + if ( empty( $getpaid_bp_current_tab ) ) { |
|
| 183 | + return array( |
|
| 184 | + 'label' => __( 'Invoices', 'invoicing' ), |
|
| 185 | + 'content' => '[wpinv_history]', |
|
| 186 | + 'icon' => 'fas fa-file-invoice', |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return $getpaid_bp_current_tab; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Displays the current tab. |
|
| 195 | + * |
|
| 196 | + * @since 2.1.5 |
|
| 197 | + */ |
|
| 198 | + public function display_current_tab() { |
|
| 199 | + |
|
| 200 | + add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
| 201 | + $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
| 202 | 202 | |
| 203 | 203 | bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Handles the actual display of the current tab. |
|
| 208 | - * |
|
| 209 | - * @since 2.1.5 |
|
| 210 | - */ |
|
| 211 | - public function handle_display_current_tab() { |
|
| 212 | - getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
| 213 | - } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Handles the actual display of the current tab. |
|
| 208 | + * |
|
| 209 | + * @since 2.1.5 |
|
| 210 | + */ |
|
| 211 | + public function handle_display_current_tab() { |
|
| 212 | + getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | // Exit if accessed directly. |
| 11 | -defined( 'ABSPATH' ) || exit; |
|
| 11 | +defined('ABSPATH') || exit; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Main GetPaid Class. |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @type array $meta_tables Optional. An array of metadata table names. |
| 56 | 56 | * } |
| 57 | 57 | */ |
| 58 | - public function setup_globals( $args = array() ) { |
|
| 58 | + public function setup_globals($args = array()) { |
|
| 59 | 59 | parent::setup_globals( |
| 60 | 60 | array( |
| 61 | 61 | 'id' => 'getpaid', |
@@ -76,30 +76,30 @@ discard block |
||
| 76 | 76 | * @param array $main_nav Optional. See BP_Component::setup_nav() for description. |
| 77 | 77 | * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. |
| 78 | 78 | */ |
| 79 | - public function setup_nav( $main_nav = array(), $sub_nav = array() ) { |
|
| 79 | + public function setup_nav($main_nav = array(), $sub_nav = array()) { |
|
| 80 | 80 | |
| 81 | 81 | // Abort if the integration is inactive. |
| 82 | - if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) { |
|
| 82 | + if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) { |
|
| 83 | 83 | return; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // Or a user is not viewing their profile. |
| 87 | - if ( bp_displayed_user_id() != bp_loggedin_user_id() ) { |
|
| 87 | + if (bp_displayed_user_id() != bp_loggedin_user_id()) { |
|
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | // Determine user to use. |
| 92 | 92 | $user_domain = bp_loggedin_user_domain(); |
| 93 | 93 | $slug = 'getpaid'; |
| 94 | - $payments_link = trailingslashit( $user_domain . $slug ); |
|
| 94 | + $payments_link = trailingslashit($user_domain . $slug); |
|
| 95 | 95 | |
| 96 | 96 | // Add 'Payments' to the main navigation. |
| 97 | 97 | $main_nav = array( |
| 98 | - 'name' => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ), |
|
| 98 | + 'name' => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'), |
|
| 99 | 99 | 'slug' => $slug, |
| 100 | - 'position' => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ), |
|
| 101 | - 'screen_function' => array( $this, 'display_current_tab' ), |
|
| 102 | - 'default_subnav_slug' => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
| 100 | + 'position' => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug), |
|
| 101 | + 'screen_function' => array($this, 'display_current_tab'), |
|
| 102 | + 'default_subnav_slug' => apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
| 103 | 103 | 'show_for_displayed_user' => false, |
| 104 | 104 | 'item_css_id' => $this->id, |
| 105 | 105 | 'parent_url' => $user_domain, |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | 109 | // Add the subnav items to the payments nav item if we are using a theme that supports this. |
| 110 | - foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) { |
|
| 110 | + foreach (getpaid_get_user_content_tabs() as $_slug => $tab) { |
|
| 111 | 111 | |
| 112 | 112 | $sub_nav[] = array( |
| 113 | 113 | 'name' => $tab['label'], |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | 'parent_url' => $payments_link, |
| 116 | 116 | 'parent_slug' => $slug, |
| 117 | 117 | 'position' => 10, |
| 118 | - 'screen_function' => function() use ( $tab ) { |
|
| 118 | + 'screen_function' => function() use ($tab) { |
|
| 119 | 119 | $GLOBALS['getpaid_bp_current_tab'] = $tab; |
| 120 | 120 | $this->display_current_tab(); |
| 121 | 121 | }, |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - parent::setup_nav( $main_nav, $sub_nav ); |
|
| 128 | + parent::setup_nav($main_nav, $sub_nav); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -139,36 +139,36 @@ discard block |
||
| 139 | 139 | * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a |
| 140 | 140 | * description. |
| 141 | 141 | */ |
| 142 | - public function setup_admin_bar( $wp_admin_nav = array() ) { |
|
| 142 | + public function setup_admin_bar($wp_admin_nav = array()) { |
|
| 143 | 143 | |
| 144 | 144 | // Menus for logged in user. |
| 145 | - if ( is_user_logged_in() ) { |
|
| 145 | + if (is_user_logged_in()) { |
|
| 146 | 146 | |
| 147 | 147 | // Setup the logged in user variables. |
| 148 | - $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' ); |
|
| 148 | + $payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/'); |
|
| 149 | 149 | |
| 150 | 150 | // Add the "Payments" sub menu. |
| 151 | 151 | $wp_admin_nav[] = array( |
| 152 | 152 | 'parent' => buddypress()->my_account_menu_id, |
| 153 | 153 | 'id' => 'my-account-getpaid', |
| 154 | - 'title' => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ), |
|
| 155 | - 'href' => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ), |
|
| 154 | + 'title' => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'), |
|
| 155 | + 'href' => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'), |
|
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | - foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) { |
|
| 158 | + foreach (getpaid_get_user_content_tabs() as $slug => $tab) { |
|
| 159 | 159 | |
| 160 | 160 | $wp_admin_nav[] = array( |
| 161 | 161 | 'parent' => 'my-account-getpaid', |
| 162 | 162 | 'id' => 'my-account-getpaid' . $slug, |
| 163 | 163 | 'title' => $tab['label'], |
| 164 | - 'href' => trailingslashit( $payments_link . $slug ), |
|
| 164 | + 'href' => trailingslashit($payments_link . $slug), |
|
| 165 | 165 | 'position' => 20, |
| 166 | 166 | ); |
| 167 | 167 | |
| 168 | 168 | } |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - parent::setup_admin_bar( $wp_admin_nav ); |
|
| 171 | + parent::setup_admin_bar($wp_admin_nav); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -179,9 +179,9 @@ discard block |
||
| 179 | 179 | public function get_current_tab() { |
| 180 | 180 | global $getpaid_bp_current_tab; |
| 181 | 181 | |
| 182 | - if ( empty( $getpaid_bp_current_tab ) ) { |
|
| 182 | + if (empty($getpaid_bp_current_tab)) { |
|
| 183 | 183 | return array( |
| 184 | - 'label' => __( 'Invoices', 'invoicing' ), |
|
| 184 | + 'label' => __('Invoices', 'invoicing'), |
|
| 185 | 185 | 'content' => '[wpinv_history]', |
| 186 | 186 | 'icon' => 'fas fa-file-invoice', |
| 187 | 187 | ); |
@@ -197,10 +197,10 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function display_current_tab() { |
| 199 | 199 | |
| 200 | - add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) ); |
|
| 201 | - $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ); |
|
| 200 | + add_action('bp_template_content', array($this, 'handle_display_current_tab')); |
|
| 201 | + $template = apply_filters('bp_core_template_plugin', 'members/single/plugins'); |
|
| 202 | 202 | |
| 203 | - bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) ); |
|
| 203 | + bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template)); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * @since 2.1.5 |
| 210 | 210 | */ |
| 211 | 211 | public function handle_display_current_tab() { |
| 212 | - getpaid_prepare_user_content_tab( $this->get_current_tab() ); |
|
| 212 | + getpaid_prepare_user_content_tab($this->get_current_tab()); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | } |
@@ -15,31 +15,31 @@ discard block |
||
| 15 | 15 | abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway { |
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | - * Class constructor. |
|
| 19 | - */ |
|
| 20 | - public function __construct() { |
|
| 18 | + * Class constructor. |
|
| 19 | + */ |
|
| 20 | + public function __construct() { |
|
| 21 | 21 | parent::__construct(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | - * Returns the API URL. |
|
| 26 | - * |
|
| 27 | - * |
|
| 28 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public function get_api_url( $invoice ) { |
|
| 25 | + * Returns the API URL. |
|
| 26 | + * |
|
| 27 | + * |
|
| 28 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public function get_api_url( $invoice ) { |
|
| 32 | 32 | return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * Communicates with authorize.net |
|
| 37 | - * |
|
| 38 | - * |
|
| 39 | - * @param array $post Data to post. |
|
| 36 | + * Communicates with authorize.net |
|
| 37 | + * |
|
| 38 | + * |
|
| 39 | + * @param array $post Data to post. |
|
| 40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
| 41 | - * @return stdClass|WP_Error |
|
| 42 | - */ |
|
| 41 | + * @return stdClass|WP_Error |
|
| 42 | + */ |
|
| 43 | 43 | public function post( $post, $invoice ) { |
| 44 | 44 | |
| 45 | 45 | $url = $this->get_api_url( $invoice ); |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Returns the API authentication params. |
|
| 93 | - * |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function get_auth_params() { |
|
| 92 | + * Returns the API authentication params. |
|
| 93 | + * |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function get_auth_params() { |
|
| 98 | 98 | |
| 99 | 99 | return array( |
| 100 | 100 | 'name' => $this->get_option( 'login_id' ), |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * Cancels a subscription remotely |
|
| 108 | - * |
|
| 109 | - * |
|
| 110 | - * @param WPInv_Subscription $subscription Subscription. |
|
| 107 | + * Cancels a subscription remotely |
|
| 108 | + * |
|
| 109 | + * |
|
| 110 | + * @param WPInv_Subscription $subscription Subscription. |
|
| 111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
| 112 | - */ |
|
| 113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
| 112 | + */ |
|
| 113 | + public function cancel_subscription( $subscription, $invoice ) { |
|
| 114 | 114 | |
| 115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
| 116 | 116 | $this->post( |
@@ -126,17 +126,17 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | - * Processes ipns. |
|
| 130 | - * |
|
| 131 | - * @return void |
|
| 132 | - */ |
|
| 133 | - public function verify_ipn() { |
|
| 129 | + * Processes ipns. |
|
| 130 | + * |
|
| 131 | + * @return void |
|
| 132 | + */ |
|
| 133 | + public function verify_ipn() { |
|
| 134 | 134 | |
| 135 | 135 | $this->maybe_process_old_ipn(); |
| 136 | 136 | |
| 137 | 137 | // Validate the IPN. |
| 138 | 138 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 139 | + wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Event type. |
@@ -175,24 +175,24 @@ discard block |
||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | - * Validates IPN invoices. |
|
| 179 | - * |
|
| 178 | + * Validates IPN invoices. |
|
| 179 | + * |
|
| 180 | 180 | * @param WPInv_Invoice $invoice |
| 181 | 181 | * @param object $payload |
| 182 | - * @return void |
|
| 183 | - */ |
|
| 184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 182 | + * @return void |
|
| 183 | + */ |
|
| 184 | + public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 185 | 185 | if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
| 186 | 186 | exit; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
| 191 | - * Process subscriptio IPNS. |
|
| 192 | - * |
|
| 193 | - * @return void |
|
| 194 | - */ |
|
| 195 | - public function maybe_process_old_ipn() { |
|
| 191 | + * Process subscriptio IPNS. |
|
| 192 | + * |
|
| 193 | + * @return void |
|
| 194 | + */ |
|
| 195 | + public function maybe_process_old_ipn() { |
|
| 196 | 196 | |
| 197 | 197 | $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
| 198 | 198 | |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
| 237 | - * Validates the old IPN signature. |
|
| 237 | + * Validates the old IPN signature. |
|
| 238 | 238 | * |
| 239 | 239 | * @param array $posted |
| 240 | - */ |
|
| 241 | - public function validate_old_ipn_signature( $posted ) { |
|
| 240 | + */ |
|
| 241 | + public function validate_old_ipn_signature( $posted ) { |
|
| 242 | 242 | |
| 243 | 243 | $signature = $this->get_option( 'signature_key' ); |
| 244 | 244 | if ( ! empty( $signature ) ) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
| 259 | - * Check Authorize.NET IPN validity. |
|
| 260 | - */ |
|
| 261 | - public function validate_ipn() { |
|
| 259 | + * Check Authorize.NET IPN validity. |
|
| 260 | + */ |
|
| 261 | + public function validate_ipn() { |
|
| 262 | 262 | |
| 263 | 263 | wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
| 264 | 264 | |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Authorize.net Legacy Payment Gateway class. |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param WPInv_Invoice $invoice Invoice. |
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | - public function get_api_url( $invoice ) { |
|
| 32 | - return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
| 31 | + public function get_api_url($invoice) { |
|
| 32 | + return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api'; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -40,48 +40,48 @@ discard block |
||
| 40 | 40 | * @param WPInv_Invoice $invoice Invoice. |
| 41 | 41 | * @return stdClass|WP_Error |
| 42 | 42 | */ |
| 43 | - public function post( $post, $invoice ) { |
|
| 43 | + public function post($post, $invoice) { |
|
| 44 | 44 | |
| 45 | - $url = $this->get_api_url( $invoice ); |
|
| 45 | + $url = $this->get_api_url($invoice); |
|
| 46 | 46 | $response = wp_remote_post( |
| 47 | 47 | $url, |
| 48 | 48 | array( |
| 49 | 49 | 'headers' => array( |
| 50 | 50 | 'Content-Type' => 'application/json; charset=utf-8', |
| 51 | 51 | ), |
| 52 | - 'body' => json_encode( $post ), |
|
| 52 | + 'body' => json_encode($post), |
|
| 53 | 53 | 'method' => 'POST', |
| 54 | 54 | ) |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - if ( is_wp_error( $response ) ) { |
|
| 57 | + if (is_wp_error($response)) { |
|
| 58 | 58 | return $response; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - $response = wp_unslash( wp_remote_retrieve_body( $response ) ); |
|
| 62 | - $response = preg_replace( '/\xEF\xBB\xBF/', '', $response ); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
| 63 | - $response = json_decode( $response ); |
|
| 61 | + $response = wp_unslash(wp_remote_retrieve_body($response)); |
|
| 62 | + $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851 |
|
| 63 | + $response = json_decode($response); |
|
| 64 | 64 | |
| 65 | - if ( empty( $response ) ) { |
|
| 66 | - return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) ); |
|
| 65 | + if (empty($response)) { |
|
| 66 | + return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing')); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if ( $response->messages->resultCode == 'Error' ) { |
|
| 69 | + if ($response->messages->resultCode == 'Error') { |
|
| 70 | 70 | |
| 71 | - if ( $this->is_sandbox( $invoice ) ) { |
|
| 72 | - wpinv_error_log( $response ); |
|
| 71 | + if ($this->is_sandbox($invoice)) { |
|
| 72 | + wpinv_error_log($response); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId ) && ! empty( $response->customerPaymentProfileId ) ) { |
|
| 76 | - return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId ); |
|
| 75 | + if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) { |
|
| 76 | + return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) { |
|
| 79 | + if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) { |
|
| 80 | 80 | $error = $response->transactionResponse->errors[0]; |
| 81 | - return new WP_Error( $error->errorCode, $error->errorText ); |
|
| 81 | + return new WP_Error($error->errorCode, $error->errorText); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text ); |
|
| 84 | + return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | return $response; |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | public function get_auth_params() { |
| 98 | 98 | |
| 99 | 99 | return array( |
| 100 | - 'name' => $this->get_option( 'login_id' ), |
|
| 101 | - 'transactionKey' => $this->get_option( 'transaction_key' ), |
|
| 100 | + 'name' => $this->get_option('login_id'), |
|
| 101 | + 'transactionKey' => $this->get_option('transaction_key'), |
|
| 102 | 102 | ); |
| 103 | 103 | |
| 104 | 104 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param WPInv_Subscription $subscription Subscription. |
| 111 | 111 | * @param WPInv_Invoice $invoice Invoice. |
| 112 | 112 | */ |
| 113 | - public function cancel_subscription( $subscription, $invoice ) { |
|
| 113 | + public function cancel_subscription($subscription, $invoice) { |
|
| 114 | 114 | |
| 115 | 115 | // Backwards compatibility. New version do not use authorize.net subscriptions. |
| 116 | 116 | $this->post( |
@@ -135,38 +135,38 @@ discard block |
||
| 135 | 135 | $this->maybe_process_old_ipn(); |
| 136 | 136 | |
| 137 | 137 | // Validate the IPN. |
| 138 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 139 | - wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 138 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 139 | + wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 200)); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // Event type. |
| 143 | - $posted = json_decode( file_get_contents( 'php://input' ) ); |
|
| 144 | - if ( empty( $posted ) ) { |
|
| 145 | - wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 200 ) ); |
|
| 143 | + $posted = json_decode(file_get_contents('php://input')); |
|
| 144 | + if (empty($posted)) { |
|
| 145 | + wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 200)); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Process the IPN. |
| 149 | - $posted = (object) wp_unslash( $posted ); |
|
| 149 | + $posted = (object) wp_unslash($posted); |
|
| 150 | 150 | |
| 151 | 151 | // Process refunds. |
| 152 | - if ( 'net.authorize.payment.refund.created' == $posted->eventType ) { |
|
| 153 | - $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId ); |
|
| 154 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 152 | + if ('net.authorize.payment.refund.created' == $posted->eventType) { |
|
| 153 | + $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId); |
|
| 154 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 155 | 155 | $invoice->refund(); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Held funds approved. |
| 159 | - if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) { |
|
| 160 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
| 161 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 162 | - $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) ); |
|
| 159 | + if ('net.authorize.payment.fraud.approved' == $posted->eventType) { |
|
| 160 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
| 161 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 162 | + $invoice->mark_paid(false, __('Payment released', 'invoicing')); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Held funds declined. |
| 166 | - if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) { |
|
| 167 | - $invoice = new WPInv_Invoice( $posted->payload->id ); |
|
| 168 | - $this->validate_ipn_invoice( $invoice, $posted->payload ); |
|
| 169 | - $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) ); |
|
| 166 | + if ('net.authorize.payment.fraud.declined' == $posted->eventType) { |
|
| 167 | + $invoice = new WPInv_Invoice($posted->payload->id); |
|
| 168 | + $this->validate_ipn_invoice($invoice, $posted->payload); |
|
| 169 | + $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing')); |
|
| 170 | 170 | $invoice->save(); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -181,8 +181,8 @@ discard block |
||
| 181 | 181 | * @param object $payload |
| 182 | 182 | * @return void |
| 183 | 183 | */ |
| 184 | - public function validate_ipn_invoice( $invoice, $payload ) { |
|
| 185 | - if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) { |
|
| 184 | + public function validate_ipn_invoice($invoice, $payload) { |
|
| 185 | + if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) { |
|
| 186 | 186 | exit; |
| 187 | 187 | } |
| 188 | 188 | } |
@@ -194,32 +194,32 @@ discard block |
||
| 194 | 194 | */ |
| 195 | 195 | public function maybe_process_old_ipn() { |
| 196 | 196 | |
| 197 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 197 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 198 | 198 | |
| 199 | 199 | // Only process subscriptions subscriptions. |
| 200 | - if ( empty( $data['x_subscription_id'] ) ) { |
|
| 200 | + if (empty($data['x_subscription_id'])) { |
|
| 201 | 201 | return; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // Check validity. |
| 205 | - $this->validate_old_ipn_signature( $data ); |
|
| 205 | + $this->validate_old_ipn_signature($data); |
|
| 206 | 206 | |
| 207 | 207 | // Fetch the associated subscription. |
| 208 | - $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] ); |
|
| 209 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
| 208 | + $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']); |
|
| 209 | + $subscription = new WPInv_Subscription($subscription_id); |
|
| 210 | 210 | |
| 211 | 211 | // Abort if it is missing or completed. |
| 212 | - if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) { |
|
| 212 | + if (!$subscription->get_id() || $subscription->has_status('completed')) { |
|
| 213 | 213 | return; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // Payment status. |
| 217 | - if ( 1 == $data['x_response_code'] ) { |
|
| 217 | + if (1 == $data['x_response_code']) { |
|
| 218 | 218 | |
| 219 | 219 | // Renew the subscription. |
| 220 | 220 | $subscription->add_payment( |
| 221 | 221 | array( |
| 222 | - 'transaction_id' => sanitize_text_field( $data['x_trans_id'] ), |
|
| 222 | + 'transaction_id' => sanitize_text_field($data['x_trans_id']), |
|
| 223 | 223 | 'gateway' => $this->id, |
| 224 | 224 | ) |
| 225 | 225 | ); |
@@ -238,17 +238,17 @@ discard block |
||
| 238 | 238 | * |
| 239 | 239 | * @param array $posted |
| 240 | 240 | */ |
| 241 | - public function validate_old_ipn_signature( $posted ) { |
|
| 241 | + public function validate_old_ipn_signature($posted) { |
|
| 242 | 242 | |
| 243 | - $signature = $this->get_option( 'signature_key' ); |
|
| 244 | - if ( ! empty( $signature ) ) { |
|
| 245 | - $login_id = $this->get_option( 'login_id' ); |
|
| 246 | - $trans_id = wpinv_clean( $_POST['x_trans_id'] ); |
|
| 247 | - $amount = wpinv_clean( $_POST['x_amount'] ); |
|
| 248 | - $hash = hash_hmac( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) ); |
|
| 243 | + $signature = $this->get_option('signature_key'); |
|
| 244 | + if (!empty($signature)) { |
|
| 245 | + $login_id = $this->get_option('login_id'); |
|
| 246 | + $trans_id = wpinv_clean($_POST['x_trans_id']); |
|
| 247 | + $amount = wpinv_clean($_POST['x_amount']); |
|
| 248 | + $hash = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature)); |
|
| 249 | 249 | |
| 250 | - if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) { |
|
| 251 | - wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" ); |
|
| 250 | + if (!hash_equals($hash, $posted['x_SHA2_Hash'])) { |
|
| 251 | + wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash"); |
|
| 252 | 252 | exit; |
| 253 | 253 | } |
| 254 | 254 | } |
@@ -260,28 +260,28 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public function validate_ipn() { |
| 262 | 262 | |
| 263 | - wpinv_error_log( 'Validating Authorize.NET IPN response' ); |
|
| 263 | + wpinv_error_log('Validating Authorize.NET IPN response'); |
|
| 264 | 264 | |
| 265 | - if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
| 265 | + if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
| 266 | 266 | return false; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - $signature = $this->get_option( 'signature_key' ); |
|
| 269 | + $signature = $this->get_option('signature_key'); |
|
| 270 | 270 | |
| 271 | - if ( empty( $signature ) ) { |
|
| 272 | - wpinv_error_log( 'Error: You have not set a signature key' ); |
|
| 271 | + if (empty($signature)) { |
|
| 272 | + wpinv_error_log('Error: You have not set a signature key'); |
|
| 273 | 273 | return false; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - $hash = hash_hmac( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) ); |
|
| 276 | + $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature)); |
|
| 277 | 277 | |
| 278 | - if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) { |
|
| 279 | - wpinv_error_log( 'Successfully validated the IPN' ); |
|
| 278 | + if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) { |
|
| 279 | + wpinv_error_log('Successfully validated the IPN'); |
|
| 280 | 280 | return true; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - wpinv_error_log( 'IPN hash is not valid' ); |
|
| 284 | - wpinv_error_log( $_SERVER['HTTP_X_ANET_SIGNATURE'] ); |
|
| 283 | + wpinv_error_log('IPN hash is not valid'); |
|
| 284 | + wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']); |
|
| 285 | 285 | return false; |
| 286 | 286 | |
| 287 | 287 | } |
@@ -12,473 +12,473 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $id = 'paypal'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Payment method object. |
|
| 24 | - * |
|
| 25 | - * @var GetPaid_Paypal_Gateway |
|
| 26 | - */ |
|
| 27 | - protected $gateway; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Class constructor. |
|
| 31 | - * |
|
| 32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | - */ |
|
| 34 | - public function __construct( $gateway ) { |
|
| 35 | - $this->gateway = $gateway; |
|
| 36 | - $this->verify_ipn(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Processes ipns and marks payments as complete. |
|
| 41 | - * |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function verify_ipn() { |
|
| 45 | - |
|
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 47 | - |
|
| 48 | - // Validate the IPN. |
|
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Process the IPN. |
|
| 54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | - |
|
| 57 | - // Abort if it was not paid by our gateway. |
|
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | - |
|
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 68 | - |
|
| 69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | - wp_die( 'Processed', 200 ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | - |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Retrieves IPN Invoice. |
|
| 82 | - * |
|
| 83 | - * @param array $posted |
|
| 84 | - * @return WPInv_Invoice |
|
| 85 | - */ |
|
| 86 | - protected function get_ipn_invoice( $posted ) { |
|
| 87 | - |
|
| 88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 89 | - |
|
| 90 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | - |
|
| 93 | - if ( $invoice->exists() ) { |
|
| 94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 95 | - return $invoice; |
|
| 96 | - } |
|
| 15 | + /** |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $id = 'paypal'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Payment method object. |
|
| 24 | + * |
|
| 25 | + * @var GetPaid_Paypal_Gateway |
|
| 26 | + */ |
|
| 27 | + protected $gateway; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Class constructor. |
|
| 31 | + * |
|
| 32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
| 33 | + */ |
|
| 34 | + public function __construct( $gateway ) { |
|
| 35 | + $this->gateway = $gateway; |
|
| 36 | + $this->verify_ipn(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Processes ipns and marks payments as complete. |
|
| 41 | + * |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function verify_ipn() { |
|
| 45 | + |
|
| 46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 47 | + |
|
| 48 | + // Validate the IPN. |
|
| 49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Process the IPN. |
|
| 54 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 56 | + |
|
| 57 | + // Abort if it was not paid by our gateway. |
|
| 58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 65 | + |
|
| 66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 68 | + |
|
| 69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | + wp_die( 'Processed', 200 ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
| 77 | + |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Retrieves IPN Invoice. |
|
| 82 | + * |
|
| 83 | + * @param array $posted |
|
| 84 | + * @return WPInv_Invoice |
|
| 85 | + */ |
|
| 86 | + protected function get_ipn_invoice( $posted ) { |
|
| 87 | + |
|
| 88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 89 | + |
|
| 90 | + if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 92 | + |
|
| 93 | + if ( $invoice->exists() ) { |
|
| 94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 95 | + return $invoice; |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Check PayPal IPN validity. |
|
| 105 | - */ |
|
| 106 | - protected function validate_ipn() { |
|
| 99 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 100 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Check PayPal IPN validity. |
|
| 105 | + */ |
|
| 106 | + protected function validate_ipn() { |
|
| 107 | 107 | |
| 108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 109 | - |
|
| 110 | - // Retrieve the associated invoice. |
|
| 111 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 113 | - |
|
| 114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Validate the IPN. |
|
| 119 | - $posted['cmd'] = '_notify-validate'; |
|
| 120 | - |
|
| 121 | - // Send back post vars to paypal. |
|
| 122 | - $params = array( |
|
| 123 | - 'body' => $posted, |
|
| 124 | - 'timeout' => 60, |
|
| 125 | - 'httpversion' => '1.1', |
|
| 126 | - 'compress' => false, |
|
| 127 | - 'decompress' => false, |
|
| 128 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 129 | - ); |
|
| 130 | - |
|
| 131 | - // Post back to get a response. |
|
| 132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 133 | - |
|
| 134 | - // Check to see if the request was valid. |
|
| 135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 137 | - return true; |
|
| 138 | - } |
|
| 108 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 109 | + |
|
| 110 | + // Retrieve the associated invoice. |
|
| 111 | + $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 112 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
| 113 | + |
|
| 114 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 115 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // Validate the IPN. |
|
| 119 | + $posted['cmd'] = '_notify-validate'; |
|
| 120 | + |
|
| 121 | + // Send back post vars to paypal. |
|
| 122 | + $params = array( |
|
| 123 | + 'body' => $posted, |
|
| 124 | + 'timeout' => 60, |
|
| 125 | + 'httpversion' => '1.1', |
|
| 126 | + 'compress' => false, |
|
| 127 | + 'decompress' => false, |
|
| 128 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
| 129 | + ); |
|
| 130 | + |
|
| 131 | + // Post back to get a response. |
|
| 132 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 133 | + |
|
| 134 | + // Check to see if the request was valid. |
|
| 135 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 136 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - if ( is_wp_error( $response ) ) { |
|
| 141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 142 | - return false; |
|
| 143 | - } |
|
| 140 | + if ( is_wp_error( $response ) ) { |
|
| 141 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 142 | + return false; |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 146 | - return false; |
|
| 145 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 146 | + return false; |
|
| 147 | 147 | |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Check currency from IPN matches the invoice. |
|
| 152 | - * |
|
| 153 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 154 | - * @param string $currency currency to validate. |
|
| 155 | - */ |
|
| 156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 150 | + /** |
|
| 151 | + * Check currency from IPN matches the invoice. |
|
| 152 | + * |
|
| 153 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 154 | + * @param string $currency currency to validate. |
|
| 155 | + */ |
|
| 156 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 157 | 157 | |
| 158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 158 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 159 | 159 | |
| 160 | - /* translators: %s: currency code. */ |
|
| 161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 160 | + /* translators: %s: currency code. */ |
|
| 161 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 162 | 162 | |
| 163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 164 | - } |
|
| 163 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 167 | - } |
|
| 166 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * Check payment amount from IPN matches the invoice. |
|
| 171 | - * |
|
| 172 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 173 | - * @param float $amount amount to validate. |
|
| 174 | - */ |
|
| 175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 169 | + /** |
|
| 170 | + * Check payment amount from IPN matches the invoice. |
|
| 171 | + * |
|
| 172 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 173 | + * @param float $amount amount to validate. |
|
| 174 | + */ |
|
| 175 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 176 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 177 | 177 | |
| 178 | - /* translators: %s: Amount. */ |
|
| 179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 178 | + /* translators: %s: Amount. */ |
|
| 179 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 180 | 180 | |
| 181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 182 | - } |
|
| 181 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 185 | - } |
|
| 184 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * Verify receiver email from PayPal. |
|
| 189 | - * |
|
| 190 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 191 | - * @param string $receiver_email Email to validate. |
|
| 192 | - */ |
|
| 193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 187 | + /** |
|
| 188 | + * Verify receiver email from PayPal. |
|
| 189 | + * |
|
| 190 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 191 | + * @param string $receiver_email Email to validate. |
|
| 192 | + */ |
|
| 193 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 194 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 195 | 195 | |
| 196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 196 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 197 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 198 | 198 | |
| 199 | - /* translators: %s: email address . */ |
|
| 200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 199 | + /* translators: %s: email address . */ |
|
| 200 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 201 | 201 | |
| 202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 203 | - } |
|
| 202 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 206 | - } |
|
| 205 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Handles one time payments. |
|
| 210 | - * |
|
| 211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | - * @param array $posted Posted data. |
|
| 213 | - */ |
|
| 214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 208 | + /** |
|
| 209 | + * Handles one time payments. |
|
| 210 | + * |
|
| 211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 212 | + * @param array $posted Posted data. |
|
| 213 | + */ |
|
| 214 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 215 | 215 | |
| 216 | - // Collect payment details |
|
| 217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 216 | + // Collect payment details |
|
| 217 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
| 218 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 219 | 219 | |
| 220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 220 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 221 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 222 | 222 | |
| 223 | - // Update the transaction id. |
|
| 224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 226 | - $invoice->save(); |
|
| 227 | - } |
|
| 223 | + // Update the transaction id. |
|
| 224 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 225 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 226 | + $invoice->save(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
| 229 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
| 230 | 230 | |
| 231 | - // Process a refund. |
|
| 232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 231 | + // Process a refund. |
|
| 232 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 233 | 233 | |
| 234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 234 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 235 | 235 | |
| 236 | - if ( ! $invoice->is_refunded() ) { |
|
| 237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 238 | - } |
|
| 236 | + if ( ! $invoice->is_refunded() ) { |
|
| 237 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
| 241 | - } |
|
| 240 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - // Process payments. |
|
| 244 | - if ( $payment_status == 'completed' ) { |
|
| 243 | + // Process payments. |
|
| 244 | + if ( $payment_status == 'completed' ) { |
|
| 245 | 245 | |
| 246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 248 | - } |
|
| 246 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 247 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 250 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 251 | 251 | |
| 252 | - $note = ''; |
|
| 252 | + $note = ''; |
|
| 253 | 253 | |
| 254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 256 | - } |
|
| 254 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 255 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 260 | - } |
|
| 258 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
| 259 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 262 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 263 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 264 | 264 | |
| 265 | - } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - // Pending payments. |
|
| 268 | - if ( $payment_status == 'pending' ) { |
|
| 267 | + // Pending payments. |
|
| 268 | + if ( $payment_status == 'pending' ) { |
|
| 269 | 269 | |
| 270 | - /* translators: %s: pending reason. */ |
|
| 271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 270 | + /* translators: %s: pending reason. */ |
|
| 271 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 272 | 272 | |
| 273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 274 | - } |
|
| 273 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - /* translators: %s: payment status. */ |
|
| 277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 276 | + /* translators: %s: payment status. */ |
|
| 277 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 278 | 278 | |
| 279 | - } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Handles one time payments. |
|
| 283 | - * |
|
| 284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 285 | - * @param array $posted Posted data. |
|
| 286 | - */ |
|
| 287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 289 | - } |
|
| 281 | + /** |
|
| 282 | + * Handles one time payments. |
|
| 283 | + * |
|
| 284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 285 | + * @param array $posted Posted data. |
|
| 286 | + */ |
|
| 287 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 288 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Handles subscription sign ups. |
|
| 293 | - * |
|
| 294 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 295 | - * @param array $posted Posted data. |
|
| 296 | - */ |
|
| 297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 291 | + /** |
|
| 292 | + * Handles subscription sign ups. |
|
| 293 | + * |
|
| 294 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 295 | + * @param array $posted Posted data. |
|
| 296 | + */ |
|
| 297 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 298 | 298 | |
| 299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
| 299 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
| 300 | 300 | |
| 301 | - // Make sure the invoice has a subscription. |
|
| 302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 301 | + // Make sure the invoice has a subscription. |
|
| 302 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 303 | 303 | |
| 304 | - if ( empty( $subscription ) ) { |
|
| 305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 306 | - } |
|
| 304 | + if ( empty( $subscription ) ) { |
|
| 305 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 308 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 309 | 309 | |
| 310 | - // Validate the IPN. |
|
| 311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 310 | + // Validate the IPN. |
|
| 311 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 312 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 313 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 314 | 314 | |
| 315 | - // Activate the subscription. |
|
| 316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 320 | - $subscription->activate(); |
|
| 315 | + // Activate the subscription. |
|
| 316 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 317 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 318 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 319 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 320 | + $subscription->activate(); |
|
| 321 | 321 | |
| 322 | - // Set the transaction id. |
|
| 323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 326 | - } |
|
| 322 | + // Set the transaction id. |
|
| 323 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 324 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 325 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - // Update the payment status. |
|
| 329 | - $invoice->mark_paid(); |
|
| 328 | + // Update the payment status. |
|
| 329 | + $invoice->mark_paid(); |
|
| 330 | 330 | |
| 331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 331 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 332 | 332 | |
| 333 | - wpinv_error_log( 'Subscription started.', false ); |
|
| 334 | - } |
|
| 333 | + wpinv_error_log( 'Subscription started.', false ); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * Handles subscription renewals. |
|
| 338 | - * |
|
| 339 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 340 | - * @param array $posted Posted data. |
|
| 341 | - */ |
|
| 342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 336 | + /** |
|
| 337 | + * Handles subscription renewals. |
|
| 338 | + * |
|
| 339 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 340 | + * @param array $posted Posted data. |
|
| 341 | + */ |
|
| 342 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 343 | 343 | |
| 344 | - // Make sure the invoice has a subscription. |
|
| 345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 344 | + // Make sure the invoice has a subscription. |
|
| 345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 346 | 346 | |
| 347 | - if ( empty( $subscription ) ) { |
|
| 348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 349 | - } |
|
| 347 | + if ( empty( $subscription ) ) { |
|
| 348 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 351 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 352 | 352 | |
| 353 | - // PayPal sends a subscr_payment for the first payment too. |
|
| 354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 353 | + // PayPal sends a subscr_payment for the first payment too. |
|
| 354 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 355 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 356 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 357 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 358 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 359 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 360 | 360 | |
| 361 | - foreach ( $dates as $date ) { |
|
| 361 | + foreach ( $dates as $date ) { |
|
| 362 | 362 | |
| 363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 364 | - continue; |
|
| 365 | - } |
|
| 363 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 364 | + continue; |
|
| 365 | + } |
|
| 366 | 366 | |
| 367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 370 | - } |
|
| 367 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
| 368 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 369 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | - return $invoice->mark_paid(); |
|
| 373 | - |
|
| 374 | - } |
|
| 372 | + return $invoice->mark_paid(); |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 377 | - |
|
| 378 | - // Abort if the payment is already recorded. |
|
| 379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - $args = array( |
|
| 384 | - 'transaction_id' => $posted['txn_id'], |
|
| 385 | - 'gateway' => $this->id, |
|
| 386 | - ); |
|
| 387 | - |
|
| 388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 376 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 377 | + |
|
| 378 | + // Abort if the payment is already recorded. |
|
| 379 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 380 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + $args = array( |
|
| 384 | + 'transaction_id' => $posted['txn_id'], |
|
| 385 | + 'gateway' => $this->id, |
|
| 386 | + ); |
|
| 387 | + |
|
| 388 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 389 | 389 | |
| 390 | - if ( empty( $invoice ) ) { |
|
| 391 | - return; |
|
| 392 | - } |
|
| 390 | + if ( empty( $invoice ) ) { |
|
| 391 | + return; |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 396 | 396 | |
| 397 | - $subscription->renew(); |
|
| 398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
| 397 | + $subscription->renew(); |
|
| 398 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
| 399 | 399 | |
| 400 | - } |
|
| 400 | + } |
|
| 401 | 401 | |
| 402 | - /** |
|
| 403 | - * Handles subscription cancelations. |
|
| 404 | - * |
|
| 405 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 406 | - */ |
|
| 407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 402 | + /** |
|
| 403 | + * Handles subscription cancelations. |
|
| 404 | + * |
|
| 405 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 406 | + */ |
|
| 407 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 408 | 408 | |
| 409 | - // Make sure the invoice has a subscription. |
|
| 410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 411 | - |
|
| 412 | - if ( empty( $subscription ) ) { |
|
| 413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 417 | - $subscription->cancel(); |
|
| 418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 409 | + // Make sure the invoice has a subscription. |
|
| 410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 411 | + |
|
| 412 | + if ( empty( $subscription ) ) { |
|
| 413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 417 | + $subscription->cancel(); |
|
| 418 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 419 | 419 | |
| 420 | - } |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - /** |
|
| 423 | - * Handles subscription completions. |
|
| 424 | - * |
|
| 425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 426 | - * @param array $posted Posted data. |
|
| 427 | - */ |
|
| 428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 422 | + /** |
|
| 423 | + * Handles subscription completions. |
|
| 424 | + * |
|
| 425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 426 | + * @param array $posted Posted data. |
|
| 427 | + */ |
|
| 428 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 429 | 429 | |
| 430 | - // Make sure the invoice has a subscription. |
|
| 431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 430 | + // Make sure the invoice has a subscription. |
|
| 431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 432 | 432 | |
| 433 | - if ( empty( $subscription ) ) { |
|
| 434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 435 | - } |
|
| 433 | + if ( empty( $subscription ) ) { |
|
| 434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 438 | - $subscription->complete(); |
|
| 439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
| 437 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 438 | + $subscription->complete(); |
|
| 439 | + wpinv_error_log( 'Subscription completed.', false ); |
|
| 440 | 440 | |
| 441 | - } |
|
| 441 | + } |
|
| 442 | 442 | |
| 443 | - /** |
|
| 444 | - * Handles subscription fails. |
|
| 445 | - * |
|
| 446 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 447 | - * @param array $posted Posted data. |
|
| 448 | - */ |
|
| 449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 443 | + /** |
|
| 444 | + * Handles subscription fails. |
|
| 445 | + * |
|
| 446 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 447 | + * @param array $posted Posted data. |
|
| 448 | + */ |
|
| 449 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 450 | 450 | |
| 451 | - // Make sure the invoice has a subscription. |
|
| 452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 451 | + // Make sure the invoice has a subscription. |
|
| 452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 453 | 453 | |
| 454 | - if ( empty( $subscription ) ) { |
|
| 455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 456 | - } |
|
| 454 | + if ( empty( $subscription ) ) { |
|
| 455 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 456 | + } |
|
| 457 | 457 | |
| 458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 459 | - $subscription->failing(); |
|
| 460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 458 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 459 | + $subscription->failing(); |
|
| 460 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 461 | 461 | |
| 462 | - } |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - /** |
|
| 465 | - * Handles subscription suspensions. |
|
| 466 | - * |
|
| 467 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 468 | - * @param array $posted Posted data. |
|
| 469 | - */ |
|
| 470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 464 | + /** |
|
| 465 | + * Handles subscription suspensions. |
|
| 466 | + * |
|
| 467 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 468 | + * @param array $posted Posted data. |
|
| 469 | + */ |
|
| 470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 471 | 471 | |
| 472 | - // Make sure the invoice has a subscription. |
|
| 473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 472 | + // Make sure the invoice has a subscription. |
|
| 473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 474 | 474 | |
| 475 | - if ( empty( $subscription ) ) { |
|
| 476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 480 | - $subscription->cancel(); |
|
| 481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 482 | - } |
|
| 475 | + if ( empty( $subscription ) ) { |
|
| 476 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 480 | + $subscription->cancel(); |
|
| 481 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 482 | + } |
|
| 483 | 483 | |
| 484 | 484 | } |
@@ -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 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
| 33 | 33 | */ |
| 34 | - public function __construct( $gateway ) { |
|
| 34 | + public function __construct($gateway) { |
|
| 35 | 35 | $this->gateway = $gateway; |
| 36 | 36 | $this->verify_ipn(); |
| 37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function verify_ipn() { |
| 45 | 45 | |
| 46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
| 46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
| 47 | 47 | |
| 48 | 48 | // Validate the IPN. |
| 49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
| 49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 50 | + wp_die('PayPal IPN Request Failure', 500); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | // Process the IPN. |
| 54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 54 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 55 | + $invoice = $this->get_ipn_invoice($posted); |
|
| 56 | 56 | |
| 57 | 57 | // Abort if it was not paid by our gateway. |
| 58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
| 59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
| 60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
| 58 | + if ($this->id != $invoice->get_gateway()) { |
|
| 59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
| 60 | + wp_die('Invoice not paid via PayPal', 200); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
| 64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
| 63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
| 64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
| 65 | 65 | |
| 66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
| 67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
| 66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
| 67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
| 68 | 68 | |
| 69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
| 70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
| 71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
| 72 | - wp_die( 'Processed', 200 ); |
|
| 69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
| 70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
| 71 | + wpinv_error_log('Done processing IPN', false); |
|
| 72 | + wp_die('Processed', 200); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
| 76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
| 75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
| 76 | + wp_die('Unsupported IPN type', 200); |
|
| 77 | 77 | |
| 78 | 78 | } |
| 79 | 79 | |
@@ -83,21 +83,21 @@ discard block |
||
| 83 | 83 | * @param array $posted |
| 84 | 84 | * @return WPInv_Invoice |
| 85 | 85 | */ |
| 86 | - protected function get_ipn_invoice( $posted ) { |
|
| 86 | + protected function get_ipn_invoice($posted) { |
|
| 87 | 87 | |
| 88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
| 88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
| 89 | 89 | |
| 90 | - if ( ! empty( $posted['custom'] ) ) { |
|
| 91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
| 90 | + if (!empty($posted['custom'])) { |
|
| 91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
| 92 | 92 | |
| 93 | - if ( $invoice->exists() ) { |
|
| 94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
| 93 | + if ($invoice->exists()) { |
|
| 94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
| 95 | 95 | return $invoice; |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
| 100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
| 99 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
| 100 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | protected function validate_ipn() { |
| 107 | 107 | |
| 108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
| 108 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
| 109 | 109 | |
| 110 | 110 | // Retrieve the associated invoice. |
| 111 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
| 111 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 112 | + $invoice = $this->get_ipn_invoice($posted); |
|
| 113 | 113 | |
| 114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
| 115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
| 114 | + if ($this->gateway->is_sandbox($invoice)) { |
|
| 115 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // Validate the IPN. |
@@ -129,20 +129,20 @@ discard block |
||
| 129 | 129 | ); |
| 130 | 130 | |
| 131 | 131 | // Post back to get a response. |
| 132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
| 132 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
| 133 | 133 | |
| 134 | 134 | // Check to see if the request was valid. |
| 135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
| 136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
| 135 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
| 136 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
| 137 | 137 | return true; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( is_wp_error( $response ) ) { |
|
| 141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
| 140 | + if (is_wp_error($response)) { |
|
| 141 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
| 145 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
| 146 | 146 | return false; |
| 147 | 147 | |
| 148 | 148 | } |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | * @param WPInv_Invoice $invoice Invoice object. |
| 154 | 154 | * @param string $currency currency to validate. |
| 155 | 155 | */ |
| 156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
| 156 | + protected function validate_ipn_currency($invoice, $currency) { |
|
| 157 | 157 | |
| 158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
| 158 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
| 159 | 159 | |
| 160 | 160 | /* translators: %s: currency code. */ |
| 161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
| 161 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
| 162 | 162 | |
| 163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 163 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
| 166 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -172,16 +172,16 @@ discard block |
||
| 172 | 172 | * @param WPInv_Invoice $invoice Invoice object. |
| 173 | 173 | * @param float $amount amount to validate. |
| 174 | 174 | */ |
| 175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
| 176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
| 175 | + protected function validate_ipn_amount($invoice, $amount) { |
|
| 176 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
| 177 | 177 | |
| 178 | 178 | /* translators: %s: Amount. */ |
| 179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
| 179 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
| 180 | 180 | |
| 181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 181 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
| 184 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -190,19 +190,19 @@ discard block |
||
| 190 | 190 | * @param WPInv_Invoice $invoice Invoice object. |
| 191 | 191 | * @param string $receiver_email Email to validate. |
| 192 | 192 | */ |
| 193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
| 194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
| 193 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
| 194 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
| 195 | 195 | |
| 196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
| 197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
| 196 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
| 197 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
| 198 | 198 | |
| 199 | 199 | /* translators: %s: email address . */ |
| 200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
| 200 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
| 201 | 201 | |
| 202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
| 202 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
| 205 | + wpinv_error_log('Validated PayPal Email', false); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -211,70 +211,70 @@ discard block |
||
| 211 | 211 | * @param WPInv_Invoice $invoice Invoice object. |
| 212 | 212 | * @param array $posted Posted data. |
| 213 | 213 | */ |
| 214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
| 214 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
| 215 | 215 | |
| 216 | 216 | // Collect payment details |
| 217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
| 218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 217 | + $payment_status = strtolower($posted['payment_status']); |
|
| 218 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
| 219 | 219 | |
| 220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 220 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
| 221 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 222 | 222 | |
| 223 | 223 | // Update the transaction id. |
| 224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
| 224 | + if (!empty($posted['txn_id'])) { |
|
| 225 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
| 226 | 226 | $invoice->save(); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
| 229 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
| 230 | 230 | |
| 231 | 231 | // Process a refund. |
| 232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 232 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 233 | 233 | |
| 234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
| 234 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
| 235 | 235 | |
| 236 | - if ( ! $invoice->is_refunded() ) { |
|
| 237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
| 236 | + if (!$invoice->is_refunded()) { |
|
| 237 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
| 240 | + return wpinv_error_log($posted['reason_code'], false); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Process payments. |
| 244 | - if ( $payment_status == 'completed' ) { |
|
| 244 | + if ($payment_status == 'completed') { |
|
| 245 | 245 | |
| 246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
| 247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
| 246 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
| 247 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
| 250 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
| 251 | 251 | |
| 252 | 252 | $note = ''; |
| 253 | 253 | |
| 254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
| 255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
| 254 | + if (!empty($posted['mc_fee'])) { |
|
| 255 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
| 259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
| 258 | + if (!empty($posted['payer_status'])) { |
|
| 259 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
| 263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
| 262 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
| 263 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
| 264 | 264 | |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | // Pending payments. |
| 268 | - if ( $payment_status == 'pending' ) { |
|
| 268 | + if ($payment_status == 'pending') { |
|
| 269 | 269 | |
| 270 | 270 | /* translators: %s: pending reason. */ |
| 271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
| 271 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
| 272 | 272 | |
| 273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
| 273 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /* translators: %s: payment status. */ |
| 277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
| 277 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
| 278 | 278 | |
| 279 | 279 | } |
| 280 | 280 | |
@@ -284,8 +284,8 @@ discard block |
||
| 284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
| 285 | 285 | * @param array $posted Posted data. |
| 286 | 286 | */ |
| 287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
| 288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
| 287 | + protected function ipn_txn_cart($invoice, $posted) { |
|
| 288 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -294,43 +294,43 @@ discard block |
||
| 294 | 294 | * @param WPInv_Invoice $invoice Invoice object. |
| 295 | 295 | * @param array $posted Posted data. |
| 296 | 296 | */ |
| 297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
| 297 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
| 298 | 298 | |
| 299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
| 299 | + wpinv_error_log('Processing subscription signup', false); |
|
| 300 | 300 | |
| 301 | 301 | // Make sure the invoice has a subscription. |
| 302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 302 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
| 303 | 303 | |
| 304 | - if ( empty( $subscription ) ) { |
|
| 305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 304 | + if (empty($subscription)) { |
|
| 305 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 308 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
| 309 | 309 | |
| 310 | 310 | // Validate the IPN. |
| 311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
| 312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
| 313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
| 311 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
| 312 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
| 313 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
| 314 | 314 | |
| 315 | 315 | // Activate the subscription. |
| 316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
| 319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
| 316 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
| 317 | + $subscription->set_date_created(current_time('mysql')); |
|
| 318 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
| 319 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
| 320 | 320 | $subscription->activate(); |
| 321 | 321 | |
| 322 | 322 | // Set the transaction id. |
| 323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
| 323 | + if (!empty($posted['txn_id'])) { |
|
| 324 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
| 325 | + $invoice->set_transaction_id($posted['txn_id']); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // Update the payment status. |
| 329 | 329 | $invoice->mark_paid(); |
| 330 | 330 | |
| 331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 331 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 332 | 332 | |
| 333 | - wpinv_error_log( 'Subscription started.', false ); |
|
| 333 | + wpinv_error_log('Subscription started.', false); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -339,45 +339,45 @@ discard block |
||
| 339 | 339 | * @param WPInv_Invoice $invoice Invoice object. |
| 340 | 340 | * @param array $posted Posted data. |
| 341 | 341 | */ |
| 342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
| 342 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
| 343 | 343 | |
| 344 | 344 | // Make sure the invoice has a subscription. |
| 345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 346 | 346 | |
| 347 | - if ( empty( $subscription ) ) { |
|
| 348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 347 | + if (empty($subscription)) { |
|
| 348 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
| 351 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
| 352 | 352 | |
| 353 | 353 | // PayPal sends a subscr_payment for the first payment too. |
| 354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
| 355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
| 356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
| 357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
| 358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
| 359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
| 354 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
| 355 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
| 356 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
| 357 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
| 358 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
| 359 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
| 360 | 360 | |
| 361 | - foreach ( $dates as $date ) { |
|
| 361 | + foreach ($dates as $date) { |
|
| 362 | 362 | |
| 363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
| 363 | + if ($date !== $today_date && $date !== $payment_date) { |
|
| 364 | 364 | continue; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
| 368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
| 369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
| 367 | + if (!empty($posted['txn_id'])) { |
|
| 368 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
| 369 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | return $invoice->mark_paid(); |
| 373 | 373 | |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
| 376 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
| 377 | 377 | |
| 378 | 378 | // Abort if the payment is already recorded. |
| 379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
| 380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
| 379 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
| 380 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | $args = array( |
@@ -385,17 +385,17 @@ discard block |
||
| 385 | 385 | 'gateway' => $this->id, |
| 386 | 386 | ); |
| 387 | 387 | |
| 388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
| 388 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
| 389 | 389 | |
| 390 | - if ( empty( $invoice ) ) { |
|
| 390 | + if (empty($invoice)) { |
|
| 391 | 391 | return; |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
| 395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
| 394 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
| 395 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
| 396 | 396 | |
| 397 | 397 | $subscription->renew(); |
| 398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
| 398 | + wpinv_error_log('Subscription renewed.', false); |
|
| 399 | 399 | |
| 400 | 400 | } |
| 401 | 401 | |
@@ -404,18 +404,18 @@ discard block |
||
| 404 | 404 | * |
| 405 | 405 | * @param WPInv_Invoice $invoice Invoice object. |
| 406 | 406 | */ |
| 407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
| 407 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
| 408 | 408 | |
| 409 | 409 | // Make sure the invoice has a subscription. |
| 410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 411 | 411 | |
| 412 | - if ( empty( $subscription ) ) { |
|
| 413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 412 | + if (empty($subscription)) { |
|
| 413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
| 416 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
| 417 | 417 | $subscription->cancel(); |
| 418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 418 | + wpinv_error_log('Subscription cancelled.', false); |
|
| 419 | 419 | |
| 420 | 420 | } |
| 421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
| 425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
| 426 | 426 | * @param array $posted Posted data. |
| 427 | 427 | */ |
| 428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
| 428 | + protected function ipn_txn_subscr_eot($invoice) { |
|
| 429 | 429 | |
| 430 | 430 | // Make sure the invoice has a subscription. |
| 431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 432 | 432 | |
| 433 | - if ( empty( $subscription ) ) { |
|
| 434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 433 | + if (empty($subscription)) { |
|
| 434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
| 437 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
| 438 | 438 | $subscription->complete(); |
| 439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
| 439 | + wpinv_error_log('Subscription completed.', false); |
|
| 440 | 440 | |
| 441 | 441 | } |
| 442 | 442 | |
@@ -446,18 +446,18 @@ discard block |
||
| 446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
| 447 | 447 | * @param array $posted Posted data. |
| 448 | 448 | */ |
| 449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
| 449 | + protected function ipn_txn_subscr_failed($invoice) { |
|
| 450 | 450 | |
| 451 | 451 | // Make sure the invoice has a subscription. |
| 452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 453 | 453 | |
| 454 | - if ( empty( $subscription ) ) { |
|
| 455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 454 | + if (empty($subscription)) { |
|
| 455 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
| 458 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
| 459 | 459 | $subscription->failing(); |
| 460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
| 460 | + wpinv_error_log('Subscription marked as failing.', false); |
|
| 461 | 461 | |
| 462 | 462 | } |
| 463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
| 467 | 467 | * @param WPInv_Invoice $invoice Invoice object. |
| 468 | 468 | * @param array $posted Posted data. |
| 469 | 469 | */ |
| 470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
| 470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
| 471 | 471 | |
| 472 | 472 | // Make sure the invoice has a subscription. |
| 473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
| 473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
| 474 | 474 | |
| 475 | - if ( empty( $subscription ) ) { |
|
| 476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
| 475 | + if (empty($subscription)) { |
|
| 476 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
| 479 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
| 480 | 480 | $subscription->cancel(); |
| 481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
| 481 | + wpinv_error_log('Subscription cancelled.', false); |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | } |
@@ -13,58 +13,58 @@ discard block |
||
| 13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'authorizenet'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 4; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Endpoint for requests from Authorize.net. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $notify_url; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Endpoint for requests to Authorize.net. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 37 | + * Endpoint for requests from Authorize.net. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $notify_url; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Endpoint for requests to Authorize.net. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | protected $endpoint; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Class constructor. |
|
| 66 | - */ |
|
| 67 | - public function __construct() { |
|
| 65 | + * Class constructor. |
|
| 66 | + */ |
|
| 67 | + public function __construct() { |
|
| 68 | 68 | |
| 69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
| 70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Displays the payment method select field. |
|
| 80 | - * |
|
| 81 | - * @param int $invoice_id 0 or invoice id. |
|
| 82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | - */ |
|
| 79 | + * Displays the payment method select field. |
|
| 80 | + * |
|
| 81 | + * @param int $invoice_id 0 or invoice id. |
|
| 82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | + */ |
|
| 84 | 84 | public function payment_fields( $invoice_id, $form ) { |
| 85 | 85 | |
| 86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * Creates a customer profile. |
|
| 95 | - * |
|
| 96 | - * |
|
| 97 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 94 | + * Creates a customer profile. |
|
| 95 | + * |
|
| 96 | + * |
|
| 97 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 98 | 98 | * @param array $submission_data Posted checkout fields. |
| 99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
| 100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 101 | - * @return string|WP_Error Payment profile id. |
|
| 102 | - */ |
|
| 103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 101 | + * @return string|WP_Error Payment profile id. |
|
| 102 | + */ |
|
| 103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 104 | 104 | |
| 105 | 105 | // Remove non-digits from the number |
| 106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * Retrieves a customer profile. |
|
| 186 | - * |
|
| 187 | - * |
|
| 188 | - * @param string $profile_id profile id. |
|
| 189 | - * @return string|WP_Error Profile id. |
|
| 185 | + * Retrieves a customer profile. |
|
| 186 | + * |
|
| 187 | + * |
|
| 188 | + * @param string $profile_id profile id. |
|
| 189 | + * @return string|WP_Error Profile id. |
|
| 190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
| 191 | - */ |
|
| 192 | - public function get_customer_profile( $profile_id ) { |
|
| 191 | + */ |
|
| 192 | + public function get_customer_profile( $profile_id ) { |
|
| 193 | 193 | |
| 194 | 194 | // Generate args. |
| 195 | 195 | $args = array( |
@@ -204,17 +204,17 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Creates a customer profile. |
|
| 208 | - * |
|
| 209 | - * |
|
| 207 | + * Creates a customer profile. |
|
| 208 | + * |
|
| 209 | + * |
|
| 210 | 210 | * @param string $profile_id profile id. |
| 211 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 211 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 212 | 212 | * @param array $submission_data Posted checkout fields. |
| 213 | 213 | * @param bool $save Whether or not to save the payment as a token. |
| 214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 215 | - * @return string|WP_Error Profile id. |
|
| 216 | - */ |
|
| 217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 215 | + * @return string|WP_Error Profile id. |
|
| 216 | + */ |
|
| 217 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 218 | 218 | |
| 219 | 219 | // Remove non-digits from the number |
| 220 | 220 | $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | - * Retrieves payment details from cache. |
|
| 306 | - * |
|
| 307 | - * |
|
| 305 | + * Retrieves payment details from cache. |
|
| 306 | + * |
|
| 307 | + * |
|
| 308 | 308 | * @param array $payment_details. |
| 309 | - * @return array|false Profile id. |
|
| 310 | - */ |
|
| 311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 309 | + * @return array|false Profile id. |
|
| 310 | + */ |
|
| 311 | + public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 312 | 312 | |
| 313 | 313 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
| 314 | 314 | $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
@@ -333,13 +333,13 @@ discard block |
||
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | - * Securely adds payment details to cache. |
|
| 337 | - * |
|
| 338 | - * |
|
| 336 | + * Securely adds payment details to cache. |
|
| 337 | + * |
|
| 338 | + * |
|
| 339 | 339 | * @param array $payment_details. |
| 340 | 340 | * @param string $payment_profile_id. |
| 341 | - */ |
|
| 342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 341 | + */ |
|
| 342 | + public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 343 | 343 | |
| 344 | 344 | $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
| 345 | 345 | $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
@@ -351,15 +351,15 @@ discard block |
||
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
| 354 | - * Retrieves a customer payment profile. |
|
| 355 | - * |
|
| 356 | - * |
|
| 357 | - * @param string $customer_profile_id customer profile id. |
|
| 354 | + * Retrieves a customer payment profile. |
|
| 355 | + * |
|
| 356 | + * |
|
| 357 | + * @param string $customer_profile_id customer profile id. |
|
| 358 | 358 | * @param string $payment_profile_id payment profile id. |
| 359 | - * @return string|WP_Error Profile id. |
|
| 359 | + * @return string|WP_Error Profile id. |
|
| 360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 361 | - */ |
|
| 362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 361 | + */ |
|
| 362 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 363 | 363 | |
| 364 | 364 | // Generate args. |
| 365 | 365 | $args = array( |
@@ -375,15 +375,15 @@ discard block |
||
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
| 378 | - * Charges a customer payment profile. |
|
| 379 | - * |
|
| 378 | + * Charges a customer payment profile. |
|
| 379 | + * |
|
| 380 | 380 | * @param string $customer_profile_id customer profile id. |
| 381 | 381 | * @param string $payment_profile_id payment profile id. |
| 382 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 382 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 384 | - * @return WP_Error|object |
|
| 385 | - */ |
|
| 386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 384 | + * @return WP_Error|object |
|
| 385 | + */ |
|
| 386 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 387 | 387 | |
| 388 | 388 | // Generate args. |
| 389 | 389 | $args = array( |
@@ -429,41 +429,41 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
| 432 | - * Processes a customer charge. |
|
| 433 | - * |
|
| 432 | + * Processes a customer charge. |
|
| 433 | + * |
|
| 434 | 434 | * @param stdClass $result Api response. |
| 435 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 436 | - */ |
|
| 437 | - public function process_charge_response( $result, $invoice ) { |
|
| 435 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 436 | + */ |
|
| 437 | + public function process_charge_response( $result, $invoice ) { |
|
| 438 | 438 | |
| 439 | 439 | wpinv_clear_errors(); |
| 440 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
| 440 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
| 441 | 441 | |
| 442 | - // Succeeded. |
|
| 443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 442 | + // Succeeded. |
|
| 443 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
| 444 | 444 | |
| 445 | - // Maybe set a transaction id. |
|
| 446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 448 | - } |
|
| 445 | + // Maybe set a transaction id. |
|
| 446 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 447 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 448 | + } |
|
| 449 | 449 | |
| 450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 450 | + $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 451 | 451 | |
| 452 | - if ( 1 == $response_code ) { |
|
| 453 | - return $invoice->mark_paid(); |
|
| 454 | - } |
|
| 452 | + if ( 1 == $response_code ) { |
|
| 453 | + return $invoice->mark_paid(); |
|
| 454 | + } |
|
| 455 | 455 | |
| 456 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 457 | - $invoice->add_note( |
|
| 456 | + $invoice->set_status( 'wpi-onhold' ); |
|
| 457 | + $invoice->add_note( |
|
| 458 | 458 | sprintf( |
| 459 | 459 | __( 'Held for review: %s', 'invoicing' ), |
| 460 | 460 | $result->transactionResponse->messages->message[0]->description |
| 461 | 461 | ) |
| 462 | - ); |
|
| 462 | + ); |
|
| 463 | 463 | |
| 464 | - return $invoice->save(); |
|
| 464 | + return $invoice->save(); |
|
| 465 | 465 | |
| 466 | - } |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | 468 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
| 469 | 469 | |
@@ -475,13 +475,13 @@ discard block |
||
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | - * Returns payment information. |
|
| 479 | - * |
|
| 480 | - * |
|
| 481 | - * @param array $card Card details. |
|
| 482 | - * @return array |
|
| 483 | - */ |
|
| 484 | - public function get_payment_information( $card ) { |
|
| 478 | + * Returns payment information. |
|
| 479 | + * |
|
| 480 | + * |
|
| 481 | + * @param array $card Card details. |
|
| 482 | + * @return array |
|
| 483 | + */ |
|
| 484 | + public function get_payment_information( $card ) { |
|
| 485 | 485 | return array( |
| 486 | 486 | |
| 487 | 487 | 'creditCard' => array( |
@@ -494,25 +494,25 @@ discard block |
||
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
| 497 | - * Returns the customer profile meta name. |
|
| 498 | - * |
|
| 499 | - * |
|
| 500 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 501 | - * @return string |
|
| 502 | - */ |
|
| 503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 497 | + * Returns the customer profile meta name. |
|
| 498 | + * |
|
| 499 | + * |
|
| 500 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 501 | + * @return string |
|
| 502 | + */ |
|
| 503 | + public function get_customer_profile_meta_name( $invoice ) { |
|
| 504 | 504 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
| 508 | - * Validates the submitted data. |
|
| 509 | - * |
|
| 510 | - * |
|
| 511 | - * @param array $submission_data Posted checkout fields. |
|
| 508 | + * Validates the submitted data. |
|
| 509 | + * |
|
| 510 | + * |
|
| 511 | + * @param array $submission_data Posted checkout fields. |
|
| 512 | 512 | * @param WPInv_Invoice $invoice |
| 513 | - * @return WP_Error|string The payment profile id |
|
| 514 | - */ |
|
| 515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 513 | + * @return WP_Error|string The payment profile id |
|
| 514 | + */ |
|
| 515 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
| 516 | 516 | |
| 517 | 517 | // Validate authentication details. |
| 518 | 518 | $auth = $this->get_auth_params(); |
@@ -544,13 +544,13 @@ discard block |
||
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Returns invoice line items. |
|
| 548 | - * |
|
| 549 | - * |
|
| 550 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 551 | - * @return array |
|
| 552 | - */ |
|
| 553 | - public function get_line_items( $invoice ) { |
|
| 547 | + * Returns invoice line items. |
|
| 548 | + * |
|
| 549 | + * |
|
| 550 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 551 | + * @return array |
|
| 552 | + */ |
|
| 553 | + public function get_line_items( $invoice ) { |
|
| 554 | 554 | $items = array(); |
| 555 | 555 | |
| 556 | 556 | foreach ( $invoice->get_items() as $item ) { |
@@ -587,15 +587,15 @@ discard block |
||
| 587 | 587 | } |
| 588 | 588 | |
| 589 | 589 | /** |
| 590 | - * Process Payment. |
|
| 591 | - * |
|
| 592 | - * |
|
| 593 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 594 | - * @param array $submission_data Posted checkout fields. |
|
| 595 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 596 | - * @return array |
|
| 597 | - */ |
|
| 598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 590 | + * Process Payment. |
|
| 591 | + * |
|
| 592 | + * |
|
| 593 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 594 | + * @param array $submission_data Posted checkout fields. |
|
| 595 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 596 | + * @return array |
|
| 597 | + */ |
|
| 598 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 599 | 599 | |
| 600 | 600 | // Validate the submitted data. |
| 601 | 601 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -628,45 +628,45 @@ discard block |
||
| 628 | 628 | |
| 629 | 629 | exit; |
| 630 | 630 | |
| 631 | - } |
|
| 631 | + } |
|
| 632 | 632 | |
| 633 | - /** |
|
| 634 | - * Processes the initial payment. |
|
| 635 | - * |
|
| 633 | + /** |
|
| 634 | + * Processes the initial payment. |
|
| 635 | + * |
|
| 636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
| 637 | - */ |
|
| 638 | - protected function process_initial_payment( $invoice ) { |
|
| 637 | + */ |
|
| 638 | + protected function process_initial_payment( $invoice ) { |
|
| 639 | 639 | |
| 640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 640 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 641 | 641 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
| 642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 642 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 643 | 643 | |
| 644 | - // Do we have an error? |
|
| 645 | - if ( is_wp_error( $result ) ) { |
|
| 646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 647 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 648 | - } |
|
| 644 | + // Do we have an error? |
|
| 645 | + if ( is_wp_error( $result ) ) { |
|
| 646 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 647 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 648 | + } |
|
| 649 | 649 | |
| 650 | - // Process the response. |
|
| 651 | - $this->process_charge_response( $result, $invoice ); |
|
| 650 | + // Process the response. |
|
| 651 | + $this->process_charge_response( $result, $invoice ); |
|
| 652 | 652 | |
| 653 | - if ( wpinv_get_errors() ) { |
|
| 654 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 655 | - } |
|
| 653 | + if ( wpinv_get_errors() ) { |
|
| 654 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 655 | + } |
|
| 656 | 656 | |
| 657 | - } |
|
| 657 | + } |
|
| 658 | 658 | |
| 659 | 659 | /** |
| 660 | - * Processes recurring payments. |
|
| 661 | - * |
|
| 660 | + * Processes recurring payments. |
|
| 661 | + * |
|
| 662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
| 663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
| 664 | - */ |
|
| 665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
| 664 | + */ |
|
| 665 | + public function process_subscription( $invoice, $subscriptions ) { |
|
| 666 | 666 | |
| 667 | 667 | // Check if there is an initial amount to charge. |
| 668 | 668 | if ( (float) $invoice->get_total() > 0 ) { |
| 669 | - $this->process_initial_payment( $invoice ); |
|
| 669 | + $this->process_initial_payment( $invoice ); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // Activate the subscriptions. |
@@ -684,36 +684,36 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - // Redirect to the success page. |
|
| 687 | + // Redirect to the success page. |
|
| 688 | 688 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
| 689 | 689 | |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - /** |
|
| 693 | - * (Maybe) renews an authorize.net subscription profile. |
|
| 694 | - * |
|
| 695 | - * |
|
| 692 | + /** |
|
| 693 | + * (Maybe) renews an authorize.net subscription profile. |
|
| 694 | + * |
|
| 695 | + * |
|
| 696 | 696 | * @param WPInv_Subscription $subscription |
| 697 | - */ |
|
| 698 | - public function maybe_renew_subscription( $subscription ) { |
|
| 697 | + */ |
|
| 698 | + public function maybe_renew_subscription( $subscription ) { |
|
| 699 | 699 | |
| 700 | 700 | // Ensure its our subscription && it's active. |
| 701 | 701 | if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
| 702 | 702 | $this->renew_subscription( $subscription ); |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | 707 | /** |
| 708 | - * Renews a subscription. |
|
| 709 | - * |
|
| 708 | + * Renews a subscription. |
|
| 709 | + * |
|
| 710 | 710 | * @param WPInv_Subscription $subscription |
| 711 | - */ |
|
| 712 | - public function renew_subscription( $subscription ) { |
|
| 711 | + */ |
|
| 712 | + public function renew_subscription( $subscription ) { |
|
| 713 | 713 | |
| 714 | - // Generate the renewal invoice. |
|
| 715 | - $new_invoice = $subscription->create_payment(); |
|
| 716 | - $old_invoice = $subscription->get_parent_payment(); |
|
| 714 | + // Generate the renewal invoice. |
|
| 715 | + $new_invoice = $subscription->create_payment(); |
|
| 716 | + $old_invoice = $subscription->get_parent_payment(); |
|
| 717 | 717 | |
| 718 | 718 | if ( empty( $new_invoice ) ) { |
| 719 | 719 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -722,37 +722,37 @@ discard block |
||
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | // Charge the payment method. |
| 725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 728 | - |
|
| 729 | - // Do we have an error? |
|
| 730 | - if ( is_wp_error( $result ) ) { |
|
| 731 | - |
|
| 732 | - $old_invoice->add_note( |
|
| 733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 734 | - true, |
|
| 735 | - false, |
|
| 736 | - true |
|
| 737 | - ); |
|
| 738 | - $subscription->failing(); |
|
| 739 | - return; |
|
| 740 | - |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // Process the response. |
|
| 744 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 745 | - |
|
| 746 | - if ( wpinv_get_errors() ) { |
|
| 747 | - |
|
| 748 | - $old_invoice->add_note( |
|
| 749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 750 | - true, |
|
| 751 | - false, |
|
| 752 | - true |
|
| 753 | - ); |
|
| 754 | - $subscription->failing(); |
|
| 755 | - return; |
|
| 725 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 726 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 727 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 728 | + |
|
| 729 | + // Do we have an error? |
|
| 730 | + if ( is_wp_error( $result ) ) { |
|
| 731 | + |
|
| 732 | + $old_invoice->add_note( |
|
| 733 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 734 | + true, |
|
| 735 | + false, |
|
| 736 | + true |
|
| 737 | + ); |
|
| 738 | + $subscription->failing(); |
|
| 739 | + return; |
|
| 740 | + |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // Process the response. |
|
| 744 | + $this->process_charge_response( $result, $new_invoice ); |
|
| 745 | + |
|
| 746 | + if ( wpinv_get_errors() ) { |
|
| 747 | + |
|
| 748 | + $old_invoice->add_note( |
|
| 749 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 750 | + true, |
|
| 751 | + false, |
|
| 752 | + true |
|
| 753 | + ); |
|
| 754 | + $subscription->failing(); |
|
| 755 | + return; |
|
| 756 | 756 | |
| 757 | 757 | } |
| 758 | 758 | |
@@ -761,13 +761,13 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
| 764 | - * Processes invoice addons. |
|
| 765 | - * |
|
| 766 | - * @param WPInv_Invoice $invoice |
|
| 767 | - * @param GetPaid_Form_Item[] $items |
|
| 768 | - * @return WPInv_Invoice |
|
| 769 | - */ |
|
| 770 | - public function process_addons( $invoice, $items ) { |
|
| 764 | + * Processes invoice addons. |
|
| 765 | + * |
|
| 766 | + * @param WPInv_Invoice $invoice |
|
| 767 | + * @param GetPaid_Form_Item[] $items |
|
| 768 | + * @return WPInv_Invoice |
|
| 769 | + */ |
|
| 770 | + public function process_addons( $invoice, $items ) { |
|
| 771 | 771 | |
| 772 | 772 | global $getpaid_authorize_addons; |
| 773 | 773 | |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | $invoice->recalculate_total(); |
| 787 | 787 | |
| 788 | 788 | $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
| 789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 789 | + $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 790 | 790 | |
| 791 | 791 | add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
| 792 | 792 | $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
@@ -801,11 +801,11 @@ discard block |
||
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
| 804 | - * Processes invoice addons. |
|
| 805 | - * |
|
| 804 | + * Processes invoice addons. |
|
| 805 | + * |
|
| 806 | 806 | * @param array $args |
| 807 | - * @return array |
|
| 808 | - */ |
|
| 807 | + * @return array |
|
| 808 | + */ |
|
| 809 | 809 | public function filter_addons_request( $args ) { |
| 810 | 810 | |
| 811 | 811 | global $getpaid_authorize_addons; |
@@ -839,11 +839,11 @@ discard block |
||
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | /** |
| 842 | - * Filters the gateway settings. |
|
| 843 | - * |
|
| 844 | - * @param array $admin_settings |
|
| 845 | - */ |
|
| 846 | - public function admin_settings( $admin_settings ) { |
|
| 842 | + * Filters the gateway settings. |
|
| 843 | + * |
|
| 844 | + * @param array $admin_settings |
|
| 845 | + */ |
|
| 846 | + public function admin_settings( $admin_settings ) { |
|
| 847 | 847 | |
| 848 | 848 | $currencies = sprintf( |
| 849 | 849 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -883,7 +883,7 @@ discard block |
||
| 883 | 883 | 'readonly' => true, |
| 884 | 884 | ); |
| 885 | 885 | |
| 886 | - return $admin_settings; |
|
| 887 | - } |
|
| 886 | + return $admin_settings; |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | 889 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' ); |
|
| 27 | + protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function __construct() { |
| 68 | 68 | |
| 69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
| 70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
| 71 | - $this->notify_url = getpaid_get_non_query_string_ipn_url( $this->id ); |
|
| 69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
| 70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
| 71 | + $this->notify_url = getpaid_get_non_query_string_ipn_url($this->id); |
|
| 72 | 72 | |
| 73 | - add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) ); |
|
| 74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
| 73 | + add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription')); |
|
| 74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
| 75 | 75 | parent::__construct(); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | * @param int $invoice_id 0 or invoice id. |
| 82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
| 83 | 83 | */ |
| 84 | - public function payment_fields( $invoice_id, $form ) { |
|
| 84 | + public function payment_fields($invoice_id, $form) { |
|
| 85 | 85 | |
| 86 | 86 | // Let the user select a payment method. |
| 87 | 87 | $this->saved_payment_methods(); |
| 88 | 88 | |
| 89 | 89 | // Show the credit card entry form. |
| 90 | - $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
| 90 | + $this->new_payment_method_entry($this->get_cc_form(true)); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -100,79 +100,79 @@ discard block |
||
| 100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 101 | 101 | * @return string|WP_Error Payment profile id. |
| 102 | 102 | */ |
| 103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
| 104 | 104 | |
| 105 | 105 | // Remove non-digits from the number |
| 106 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
| 106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
| 107 | 107 | |
| 108 | 108 | // Generate args. |
| 109 | 109 | $args = array( |
| 110 | 110 | 'createCustomerProfileRequest' => array( |
| 111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
| 112 | 112 | 'profile' => array( |
| 113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
| 114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
| 115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
| 113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
| 114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
| 115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
| 116 | 116 | 'paymentProfiles' => array( |
| 117 | 117 | 'customerType' => 'individual', |
| 118 | 118 | |
| 119 | 119 | // Billing information. |
| 120 | 120 | 'billTo' => array( |
| 121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
| 122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
| 123 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
| 124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
| 125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
| 126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
| 127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
| 121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
| 122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
| 123 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
| 124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
| 125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
| 126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
| 127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
| 128 | 128 | ), |
| 129 | 129 | |
| 130 | 130 | // Payment information. |
| 131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
| 131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
| 132 | 132 | ), |
| 133 | 133 | ), |
| 134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
| 134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
| 135 | 135 | ), |
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
| 138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
| 139 | 139 | |
| 140 | - if ( is_wp_error( $response ) ) { |
|
| 140 | + if (is_wp_error($response)) { |
|
| 141 | 141 | |
| 142 | 142 | // In case the payment profile already exists remotely. |
| 143 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
| 144 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
| 145 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
| 146 | - return strtok( '.' ); |
|
| 143 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
| 144 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
| 145 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
| 146 | + return strtok('.'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | // In case the customer profile already exists remotely. |
| 150 | - if ( 'E00039' == $response->get_error_code() ) { |
|
| 151 | - $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() ); |
|
| 152 | - $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id ); |
|
| 153 | - return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save ); |
|
| 150 | + if ('E00039' == $response->get_error_code()) { |
|
| 151 | + $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message()); |
|
| 152 | + $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id); |
|
| 153 | + return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | return $response; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
| 159 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
| 160 | 160 | |
| 161 | 161 | // Save the payment token. |
| 162 | - if ( $save ) { |
|
| 162 | + if ($save) { |
|
| 163 | 163 | $this->save_token( |
| 164 | 164 | array( |
| 165 | 165 | 'id' => $response->customerPaymentProfileIdList[0], |
| 166 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
| 166 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
| 167 | 167 | 'default' => true, |
| 168 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
| 168 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
| 169 | 169 | ) |
| 170 | 170 | ); |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Add a note about the validation response. |
| 174 | 174 | $invoice->add_note( |
| 175 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
| 175 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
| 176 | 176 | false, |
| 177 | 177 | false, |
| 178 | 178 | true |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | * @return string|WP_Error Profile id. |
| 190 | 190 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
| 191 | 191 | */ |
| 192 | - public function get_customer_profile( $profile_id ) { |
|
| 192 | + public function get_customer_profile($profile_id) { |
|
| 193 | 193 | |
| 194 | 194 | // Generate args. |
| 195 | 195 | $args = array( |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | ), |
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | - return $this->post( $args, false ); |
|
| 202 | + return $this->post($args, false); |
|
| 203 | 203 | |
| 204 | 204 | } |
| 205 | 205 | |
@@ -214,18 +214,18 @@ discard block |
||
| 214 | 214 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 215 | 215 | * @return string|WP_Error Profile id. |
| 216 | 216 | */ |
| 217 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 217 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
| 218 | 218 | |
| 219 | 219 | // Remove non-digits from the number |
| 220 | - $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
| 220 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
| 221 | 221 | |
| 222 | 222 | // Prepare card details. |
| 223 | - $payment_information = $this->get_payment_information( $submission_data['authorizenet'] ); |
|
| 223 | + $payment_information = $this->get_payment_information($submission_data['authorizenet']); |
|
| 224 | 224 | |
| 225 | 225 | // Authorize.NET does not support saving the same card twice. |
| 226 | - $cached_information = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice ); |
|
| 226 | + $cached_information = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice); |
|
| 227 | 227 | |
| 228 | - if ( $cached_information ) { |
|
| 228 | + if ($cached_information) { |
|
| 229 | 229 | return $cached_information; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -238,34 +238,34 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | // Billing information. |
| 240 | 240 | 'billTo' => array( |
| 241 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
| 242 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
| 243 | - 'address' => getpaid_limit_length( $invoice->get_address(), 60 ), |
|
| 244 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
| 245 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
| 246 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
| 247 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
| 241 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
| 242 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
| 243 | + 'address' => getpaid_limit_length($invoice->get_address(), 60), |
|
| 244 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
| 245 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
| 246 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
| 247 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
| 248 | 248 | ), |
| 249 | 249 | |
| 250 | 250 | // Payment information. |
| 251 | 251 | 'payment' => $payment_information, |
| 252 | 252 | ), |
| 253 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
| 253 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
| 254 | 254 | ), |
| 255 | 255 | ); |
| 256 | 256 | |
| 257 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
| 257 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
| 258 | 258 | |
| 259 | - if ( is_wp_error( $response ) ) { |
|
| 259 | + if (is_wp_error($response)) { |
|
| 260 | 260 | |
| 261 | 261 | // In case the payment profile already exists remotely. |
| 262 | - if ( 'dup_payment_profile' == $response->get_error_code() ) { |
|
| 263 | - $customer_profile_id = strtok( $response->get_error_message(), '.' ); |
|
| 264 | - $payment_profile_id = strtok( '.' ); |
|
| 265 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id ); |
|
| 262 | + if ('dup_payment_profile' == $response->get_error_code()) { |
|
| 263 | + $customer_profile_id = strtok($response->get_error_message(), '.'); |
|
| 264 | + $payment_profile_id = strtok('.'); |
|
| 265 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id); |
|
| 266 | 266 | |
| 267 | 267 | // Cache payment profile id. |
| 268 | - $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id ); |
|
| 268 | + $this->add_payment_profile_to_cache($payment_information, $payment_profile_id); |
|
| 269 | 269 | |
| 270 | 270 | return $payment_profile_id; |
| 271 | 271 | } |
@@ -274,29 +274,29 @@ discard block |
||
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // Save the payment token. |
| 277 | - if ( $save ) { |
|
| 277 | + if ($save) { |
|
| 278 | 278 | $this->save_token( |
| 279 | 279 | array( |
| 280 | 280 | 'id' => $response->customerPaymentProfileId, |
| 281 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
| 281 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
| 282 | 282 | 'default' => true, |
| 283 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
| 283 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
| 284 | 284 | ) |
| 285 | 285 | ); |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Cache payment profile id. |
| 289 | - $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId ); |
|
| 289 | + $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId); |
|
| 290 | 290 | |
| 291 | 291 | // Add a note about the validation response. |
| 292 | 292 | $invoice->add_note( |
| 293 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
| 293 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
| 294 | 294 | false, |
| 295 | 295 | false, |
| 296 | 296 | true |
| 297 | 297 | ); |
| 298 | 298 | |
| 299 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile ); |
|
| 299 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile); |
|
| 300 | 300 | |
| 301 | 301 | return $response->customerPaymentProfileId; |
| 302 | 302 | } |
@@ -308,12 +308,12 @@ discard block |
||
| 308 | 308 | * @param array $payment_details. |
| 309 | 309 | * @return array|false Profile id. |
| 310 | 310 | */ |
| 311 | - public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) { |
|
| 311 | + public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) { |
|
| 312 | 312 | |
| 313 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
| 314 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
| 313 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
| 314 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
| 315 | 315 | |
| 316 | - if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) { |
|
| 316 | + if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) { |
|
| 317 | 317 | return false; |
| 318 | 318 | } |
| 319 | 319 | |
@@ -322,13 +322,13 @@ discard block |
||
| 322 | 322 | 'getCustomerPaymentProfileRequest' => array( |
| 323 | 323 | 'merchantAuthentication' => $this->get_auth_params(), |
| 324 | 324 | 'customerProfileId' => $customer_profile, |
| 325 | - 'customerPaymentProfileId' => $cached_information[ $payment_details ], |
|
| 325 | + 'customerPaymentProfileId' => $cached_information[$payment_details], |
|
| 326 | 326 | ), |
| 327 | 327 | ); |
| 328 | 328 | |
| 329 | - $response = $this->post( $args, $invoice ); |
|
| 329 | + $response = $this->post($args, $invoice); |
|
| 330 | 330 | |
| 331 | - return is_wp_error( $response ) ? false : $cached_information[ $payment_details ]; |
|
| 331 | + return is_wp_error($response) ? false : $cached_information[$payment_details]; |
|
| 332 | 332 | |
| 333 | 333 | } |
| 334 | 334 | |
@@ -339,14 +339,14 @@ discard block |
||
| 339 | 339 | * @param array $payment_details. |
| 340 | 340 | * @param string $payment_profile_id. |
| 341 | 341 | */ |
| 342 | - public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) { |
|
| 342 | + public function add_payment_profile_to_cache($payment_details, $payment_profile_id) { |
|
| 343 | 343 | |
| 344 | - $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() ); |
|
| 345 | - $cached_information = is_array( $cached_information ) ? $cached_information : array(); |
|
| 346 | - $payment_details = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY ); |
|
| 344 | + $cached_information = get_option('getpaid_authorize_net_cached_profiles', array()); |
|
| 345 | + $cached_information = is_array($cached_information) ? $cached_information : array(); |
|
| 346 | + $payment_details = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY); |
|
| 347 | 347 | |
| 348 | - $cached_information[ $payment_details ] = $payment_profile_id; |
|
| 349 | - update_option( 'getpaid_authorize_net_cached_profiles', $cached_information ); |
|
| 348 | + $cached_information[$payment_details] = $payment_profile_id; |
|
| 349 | + update_option('getpaid_authorize_net_cached_profiles', $cached_information); |
|
| 350 | 350 | |
| 351 | 351 | } |
| 352 | 352 | |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * @return string|WP_Error Profile id. |
| 360 | 360 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 361 | 361 | */ |
| 362 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 362 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
| 363 | 363 | |
| 364 | 364 | // Generate args. |
| 365 | 365 | $args = array( |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | ), |
| 371 | 371 | ); |
| 372 | 372 | |
| 373 | - return $this->post( $args, false ); |
|
| 373 | + return $this->post($args, false); |
|
| 374 | 374 | |
| 375 | 375 | } |
| 376 | 376 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 384 | 384 | * @return WP_Error|object |
| 385 | 385 | */ |
| 386 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 386 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
| 387 | 387 | |
| 388 | 388 | // Generate args. |
| 389 | 389 | $args = array( |
@@ -403,28 +403,28 @@ discard block |
||
| 403 | 403 | ), |
| 404 | 404 | ), |
| 405 | 405 | 'order' => array( |
| 406 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
| 406 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
| 407 | 407 | ), |
| 408 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
| 408 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
| 409 | 409 | 'tax' => array( |
| 410 | 410 | 'amount' => $invoice->get_total_tax(), |
| 411 | - 'name' => __( 'TAX', 'invoicing' ), |
|
| 411 | + 'name' => __('TAX', 'invoicing'), |
|
| 412 | 412 | ), |
| 413 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
| 413 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
| 414 | 414 | 'customer' => array( |
| 415 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
| 416 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
| 415 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
| 416 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
| 417 | 417 | ), |
| 418 | 418 | 'customerIP' => $invoice->get_ip(), |
| 419 | 419 | ), |
| 420 | 420 | ), |
| 421 | 421 | ); |
| 422 | 422 | |
| 423 | - if ( 0 == $invoice->get_total_tax() ) { |
|
| 424 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
| 423 | + if (0 == $invoice->get_total_tax()) { |
|
| 424 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
| 427 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
| 428 | 428 | |
| 429 | 429 | } |
| 430 | 430 | |
@@ -434,29 +434,29 @@ discard block |
||
| 434 | 434 | * @param stdClass $result Api response. |
| 435 | 435 | * @param WPInv_Invoice $invoice Invoice. |
| 436 | 436 | */ |
| 437 | - public function process_charge_response( $result, $invoice ) { |
|
| 437 | + public function process_charge_response($result, $invoice) { |
|
| 438 | 438 | |
| 439 | 439 | wpinv_clear_errors(); |
| 440 | 440 | $response_code = (int) $result->transactionResponse->responseCode; |
| 441 | 441 | |
| 442 | 442 | // Succeeded. |
| 443 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 443 | + if (1 == $response_code || 4 == $response_code) { |
|
| 444 | 444 | |
| 445 | 445 | // Maybe set a transaction id. |
| 446 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 447 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 446 | + if (!empty($result->transactionResponse->transId)) { |
|
| 447 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 450 | + $invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
| 451 | 451 | |
| 452 | - if ( 1 == $response_code ) { |
|
| 452 | + if (1 == $response_code) { |
|
| 453 | 453 | return $invoice->mark_paid(); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 456 | + $invoice->set_status('wpi-onhold'); |
|
| 457 | 457 | $invoice->add_note( |
| 458 | 458 | sprintf( |
| 459 | - __( 'Held for review: %s', 'invoicing' ), |
|
| 459 | + __('Held for review: %s', 'invoicing'), |
|
| 460 | 460 | $result->transactionResponse->messages->message[0]->description |
| 461 | 461 | ) |
| 462 | 462 | ); |
@@ -465,11 +465,11 @@ discard block |
||
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
| 468 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
| 469 | 469 | |
| 470 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
| 470 | + if (!empty($result->transactionResponse->errors)) { |
|
| 471 | 471 | $errors = (object) $result->transactionResponse->errors; |
| 472 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
| 472 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | } |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | * @param array $card Card details. |
| 482 | 482 | * @return array |
| 483 | 483 | */ |
| 484 | - public function get_payment_information( $card ) { |
|
| 484 | + public function get_payment_information($card) { |
|
| 485 | 485 | return array( |
| 486 | 486 | |
| 487 | 487 | 'creditCard' => array( |
@@ -500,8 +500,8 @@ discard block |
||
| 500 | 500 | * @param WPInv_Invoice $invoice Invoice. |
| 501 | 501 | * @return string |
| 502 | 502 | */ |
| 503 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 504 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
| 503 | + public function get_customer_profile_meta_name($invoice) { |
|
| 504 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
@@ -512,34 +512,34 @@ discard block |
||
| 512 | 512 | * @param WPInv_Invoice $invoice |
| 513 | 513 | * @return WP_Error|string The payment profile id |
| 514 | 514 | */ |
| 515 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 515 | + public function validate_submission_data($submission_data, $invoice) { |
|
| 516 | 516 | |
| 517 | 517 | // Validate authentication details. |
| 518 | 518 | $auth = $this->get_auth_params(); |
| 519 | 519 | |
| 520 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
| 521 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) ); |
|
| 520 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
| 521 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | // Validate the payment method. |
| 525 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
| 526 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) ); |
|
| 525 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
| 526 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | // Are we adding a new payment method? |
| 530 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
| 530 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
| 531 | 531 | return $submission_data['getpaid-authorizenet-payment-method']; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | // Retrieve the customer profile id. |
| 535 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 535 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 536 | 536 | |
| 537 | 537 | // Create payment method. |
| 538 | - if ( empty( $profile_id ) ) { |
|
| 539 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
| 538 | + if (empty($profile_id)) { |
|
| 539 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
| 542 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
| 543 | 543 | |
| 544 | 544 | } |
| 545 | 545 | |
@@ -550,32 +550,32 @@ discard block |
||
| 550 | 550 | * @param WPInv_Invoice $invoice Invoice. |
| 551 | 551 | * @return array |
| 552 | 552 | */ |
| 553 | - public function get_line_items( $invoice ) { |
|
| 553 | + public function get_line_items($invoice) { |
|
| 554 | 554 | $items = array(); |
| 555 | 555 | |
| 556 | - foreach ( $invoice->get_items() as $item ) { |
|
| 556 | + foreach ($invoice->get_items() as $item) { |
|
| 557 | 557 | |
| 558 | 558 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
| 559 | 559 | $items[] = array( |
| 560 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
| 561 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
| 562 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
| 563 | - 'quantity' => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ), |
|
| 560 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
| 561 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
| 562 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
| 563 | + 'quantity' => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()), |
|
| 564 | 564 | 'unitPrice' => (float) $amount, |
| 565 | 565 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
| 566 | 566 | ); |
| 567 | 567 | |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
| 570 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
| 571 | 571 | |
| 572 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
| 572 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
| 573 | 573 | |
| 574 | - if ( $amount > 0 ) { |
|
| 574 | + if ($amount > 0) { |
|
| 575 | 575 | $items[] = array( |
| 576 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
| 577 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
| 578 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
| 576 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
| 577 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
| 578 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
| 579 | 579 | 'quantity' => '1', |
| 580 | 580 | 'unitPrice' => (float) $amount, |
| 581 | 581 | 'taxable' => false, |
@@ -595,36 +595,36 @@ discard block |
||
| 595 | 595 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 596 | 596 | * @return array |
| 597 | 597 | */ |
| 598 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 598 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 599 | 599 | |
| 600 | 600 | // Validate the submitted data. |
| 601 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
| 601 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
| 602 | 602 | |
| 603 | 603 | // Do we have an error? |
| 604 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
| 605 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
| 606 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 604 | + if (is_wp_error($payment_profile_id)) { |
|
| 605 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
| 606 | + wpinv_send_back_to_checkout($invoice); |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | // Save the payment method to the order. |
| 610 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
| 610 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
| 611 | 611 | |
| 612 | 612 | // Check if this is a subscription or not. |
| 613 | - $subscriptions = getpaid_get_invoice_subscriptions( $invoice ); |
|
| 614 | - if ( ! empty( $subscriptions ) ) { |
|
| 615 | - $this->process_subscription( $invoice, $subscriptions ); |
|
| 613 | + $subscriptions = getpaid_get_invoice_subscriptions($invoice); |
|
| 614 | + if (!empty($subscriptions)) { |
|
| 615 | + $this->process_subscription($invoice, $subscriptions); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | // If it is free, send to the success page. |
| 619 | - if ( ! $invoice->needs_payment() ) { |
|
| 619 | + if (!$invoice->needs_payment()) { |
|
| 620 | 620 | $invoice->mark_paid(); |
| 621 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 621 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | // Charge the payment profile. |
| 625 | - $this->process_initial_payment( $invoice ); |
|
| 625 | + $this->process_initial_payment($invoice); |
|
| 626 | 626 | |
| 627 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 627 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 628 | 628 | |
| 629 | 629 | exit; |
| 630 | 630 | |
@@ -635,23 +635,23 @@ discard block |
||
| 635 | 635 | * |
| 636 | 636 | * @param WPInv_Invoice $invoice Invoice. |
| 637 | 637 | */ |
| 638 | - protected function process_initial_payment( $invoice ) { |
|
| 638 | + protected function process_initial_payment($invoice) { |
|
| 639 | 639 | |
| 640 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 641 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 642 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 640 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 641 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 642 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
| 643 | 643 | |
| 644 | 644 | // Do we have an error? |
| 645 | - if ( is_wp_error( $result ) ) { |
|
| 646 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 647 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 645 | + if (is_wp_error($result)) { |
|
| 646 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
| 647 | + wpinv_send_back_to_checkout($invoice); |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | // Process the response. |
| 651 | - $this->process_charge_response( $result, $invoice ); |
|
| 651 | + $this->process_charge_response($result, $invoice); |
|
| 652 | 652 | |
| 653 | - if ( wpinv_get_errors() ) { |
|
| 654 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 653 | + if (wpinv_get_errors()) { |
|
| 654 | + wpinv_send_back_to_checkout($invoice); |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | } |
@@ -662,30 +662,30 @@ discard block |
||
| 662 | 662 | * @param WPInv_Invoice $invoice Invoice. |
| 663 | 663 | * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions. |
| 664 | 664 | */ |
| 665 | - public function process_subscription( $invoice, $subscriptions ) { |
|
| 665 | + public function process_subscription($invoice, $subscriptions) { |
|
| 666 | 666 | |
| 667 | 667 | // Check if there is an initial amount to charge. |
| 668 | - if ( (float) $invoice->get_total() > 0 ) { |
|
| 669 | - $this->process_initial_payment( $invoice ); |
|
| 668 | + if ((float) $invoice->get_total() > 0) { |
|
| 669 | + $this->process_initial_payment($invoice); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | // Activate the subscriptions. |
| 673 | - $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions ); |
|
| 673 | + $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions); |
|
| 674 | 674 | |
| 675 | - foreach ( $subscriptions as $subscription ) { |
|
| 676 | - if ( $subscription->exists() ) { |
|
| 677 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 678 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
| 675 | + foreach ($subscriptions as $subscription) { |
|
| 676 | + if ($subscription->exists()) { |
|
| 677 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
| 678 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
| 679 | 679 | |
| 680 | - $subscription->set_next_renewal_date( $expiry ); |
|
| 681 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 682 | - $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) ); |
|
| 680 | + $subscription->set_next_renewal_date($expiry); |
|
| 681 | + $subscription->set_date_created(current_time('mysql')); |
|
| 682 | + $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id())); |
|
| 683 | 683 | $subscription->activate(); |
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | // Redirect to the success page. |
| 688 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 688 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 689 | 689 | |
| 690 | 690 | } |
| 691 | 691 | |
@@ -695,11 +695,11 @@ discard block |
||
| 695 | 695 | * |
| 696 | 696 | * @param WPInv_Subscription $subscription |
| 697 | 697 | */ |
| 698 | - public function maybe_renew_subscription( $subscription ) { |
|
| 698 | + public function maybe_renew_subscription($subscription) { |
|
| 699 | 699 | |
| 700 | 700 | // Ensure its our subscription && it's active. |
| 701 | - if ( $this->id == $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) { |
|
| 702 | - $this->renew_subscription( $subscription ); |
|
| 701 | + if ($this->id == $subscription->get_gateway() && $subscription->has_status('active trialling')) { |
|
| 702 | + $this->renew_subscription($subscription); |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | } |
@@ -709,28 +709,28 @@ discard block |
||
| 709 | 709 | * |
| 710 | 710 | * @param WPInv_Subscription $subscription |
| 711 | 711 | */ |
| 712 | - public function renew_subscription( $subscription ) { |
|
| 712 | + public function renew_subscription($subscription) { |
|
| 713 | 713 | |
| 714 | 714 | // Generate the renewal invoice. |
| 715 | 715 | $new_invoice = $subscription->create_payment(); |
| 716 | 716 | $old_invoice = $subscription->get_parent_payment(); |
| 717 | 717 | |
| 718 | - if ( empty( $new_invoice ) ) { |
|
| 719 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
| 718 | + if (empty($new_invoice)) { |
|
| 719 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
| 720 | 720 | $subscription->failing(); |
| 721 | 721 | return; |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | // Charge the payment method. |
| 725 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 726 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 727 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 725 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 726 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
| 727 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
| 728 | 728 | |
| 729 | 729 | // Do we have an error? |
| 730 | - if ( is_wp_error( $result ) ) { |
|
| 730 | + if (is_wp_error($result)) { |
|
| 731 | 731 | |
| 732 | 732 | $old_invoice->add_note( |
| 733 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 733 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
| 734 | 734 | true, |
| 735 | 735 | false, |
| 736 | 736 | true |
@@ -741,12 +741,12 @@ discard block |
||
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | // Process the response. |
| 744 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 744 | + $this->process_charge_response($result, $new_invoice); |
|
| 745 | 745 | |
| 746 | - if ( wpinv_get_errors() ) { |
|
| 746 | + if (wpinv_get_errors()) { |
|
| 747 | 747 | |
| 748 | 748 | $old_invoice->add_note( |
| 749 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 749 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
| 750 | 750 | true, |
| 751 | 751 | false, |
| 752 | 752 | true |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | - $subscription->add_payment( array(), $new_invoice ); |
|
| 759 | + $subscription->add_payment(array(), $new_invoice); |
|
| 760 | 760 | $subscription->renew(); |
| 761 | 761 | } |
| 762 | 762 | |
@@ -767,33 +767,33 @@ discard block |
||
| 767 | 767 | * @param GetPaid_Form_Item[] $items |
| 768 | 768 | * @return WPInv_Invoice |
| 769 | 769 | */ |
| 770 | - public function process_addons( $invoice, $items ) { |
|
| 770 | + public function process_addons($invoice, $items) { |
|
| 771 | 771 | |
| 772 | 772 | global $getpaid_authorize_addons; |
| 773 | 773 | |
| 774 | 774 | $getpaid_authorize_addons = array(); |
| 775 | - foreach ( $items as $item ) { |
|
| 775 | + foreach ($items as $item) { |
|
| 776 | 776 | |
| 777 | - if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) { |
|
| 777 | + if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) { |
|
| 778 | 778 | $getpaid_authorize_addons[] = $item; |
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - if ( empty( $getpaid_authorize_addons ) ) { |
|
| 782 | + if (empty($getpaid_authorize_addons)) { |
|
| 783 | 783 | return; |
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | $invoice->recalculate_total(); |
| 787 | 787 | |
| 788 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 789 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 788 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 789 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 790 | 790 | |
| 791 | - add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 ); |
|
| 792 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 793 | - remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) ); |
|
| 791 | + add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2); |
|
| 792 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
| 793 | + remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request')); |
|
| 794 | 794 | |
| 795 | - if ( is_wp_error( $result ) ) { |
|
| 796 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 795 | + if (is_wp_error($result)) { |
|
| 796 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
| 797 | 797 | return; |
| 798 | 798 | } |
| 799 | 799 | |
@@ -806,19 +806,19 @@ discard block |
||
| 806 | 806 | * @param array $args |
| 807 | 807 | * @return array |
| 808 | 808 | */ |
| 809 | - public function filter_addons_request( $args ) { |
|
| 809 | + public function filter_addons_request($args) { |
|
| 810 | 810 | |
| 811 | 811 | global $getpaid_authorize_addons; |
| 812 | 812 | $total = 0; |
| 813 | 813 | |
| 814 | - foreach ( $getpaid_authorize_addons as $addon ) { |
|
| 814 | + foreach ($getpaid_authorize_addons as $addon) { |
|
| 815 | 815 | $total += $addon->get_sub_total(); |
| 816 | 816 | } |
| 817 | 817 | |
| 818 | 818 | $args['createTransactionRequest']['transactionRequest']['amount'] = $total; |
| 819 | 819 | |
| 820 | - if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) { |
|
| 821 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
| 820 | + if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) { |
|
| 821 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | return $args; |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | public function sandbox_notice() { |
| 832 | 832 | |
| 833 | 833 | return sprintf( |
| 834 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
| 834 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
| 835 | 835 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
| 836 | 836 | '</a>' |
| 837 | 837 | ); |
@@ -843,42 +843,42 @@ discard block |
||
| 843 | 843 | * |
| 844 | 844 | * @param array $admin_settings |
| 845 | 845 | */ |
| 846 | - public function admin_settings( $admin_settings ) { |
|
| 846 | + public function admin_settings($admin_settings) { |
|
| 847 | 847 | |
| 848 | 848 | $currencies = sprintf( |
| 849 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
| 850 | - implode( ', ', $this->currencies ) |
|
| 849 | + __('Supported Currencies: %s', 'invoicing'), |
|
| 850 | + implode(', ', $this->currencies) |
|
| 851 | 851 | ); |
| 852 | 852 | |
| 853 | 853 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
| 854 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
| 854 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
| 855 | 855 | |
| 856 | 856 | $admin_settings['authorizenet_login_id'] = array( |
| 857 | 857 | 'type' => 'text', |
| 858 | 858 | 'id' => 'authorizenet_login_id', |
| 859 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
| 860 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
| 859 | + 'name' => __('API Login ID', 'invoicing'), |
|
| 860 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
| 861 | 861 | ); |
| 862 | 862 | |
| 863 | 863 | $admin_settings['authorizenet_transaction_key'] = array( |
| 864 | 864 | 'type' => 'text', |
| 865 | 865 | 'id' => 'authorizenet_transaction_key', |
| 866 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
| 866 | + 'name' => __('Transaction Key', 'invoicing'), |
|
| 867 | 867 | ); |
| 868 | 868 | |
| 869 | 869 | $admin_settings['authorizenet_signature_key'] = array( |
| 870 | 870 | 'type' => 'text', |
| 871 | 871 | 'id' => 'authorizenet_signature_key', |
| 872 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
| 873 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
| 872 | + 'name' => __('Signature Key', 'invoicing'), |
|
| 873 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
| 874 | 874 | ); |
| 875 | 875 | |
| 876 | 876 | $admin_settings['authorizenet_ipn_url'] = array( |
| 877 | 877 | 'type' => 'ipn_url', |
| 878 | 878 | 'id' => 'authorizenet_ipn_url', |
| 879 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
| 879 | + 'name' => __('Webhook URL', 'invoicing'), |
|
| 880 | 880 | 'std' => $this->notify_url, |
| 881 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
| 881 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
| 882 | 882 | 'custom' => 'authorizenet', |
| 883 | 883 | 'readonly' => true, |
| 884 | 884 | ); |
@@ -13,65 +13,65 @@ discard block |
||
| 13 | 13 | class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'worldpay'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * Payment method order. |
|
| 24 | - * |
|
| 25 | - * @var int |
|
| 26 | - */ |
|
| 23 | + * Payment method order. |
|
| 24 | + * |
|
| 25 | + * @var int |
|
| 26 | + */ |
|
| 27 | 27 | public $order = 5; |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Endpoint for requests from Worldpay. |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $notify_url; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Endpoint for requests to Worldpay. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 30 | + * Endpoint for requests from Worldpay. |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $notify_url; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Endpoint for requests to Worldpay. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | 41 | protected $endpoint; |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * An array of features that this gateway supports. |
|
| 45 | - * |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 44 | + * An array of features that this gateway supports. |
|
| 45 | + * |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | 48 | protected $supports = array( 'sandbox' ); |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a subscription. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 65 | + * URL to view a subscription. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * Class constructor. |
|
| 73 | - */ |
|
| 74 | - public function __construct() { |
|
| 72 | + * Class constructor. |
|
| 73 | + */ |
|
| 74 | + public function __construct() { |
|
| 75 | 75 | |
| 76 | 76 | $this->method_title = __( 'Worldpay', 'invoicing' ); |
| 77 | 77 | $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | - * Process Payment. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | - * @param array $submission_data Posted checkout fields. |
|
| 93 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 88 | + * Process Payment. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 92 | + * @param array $submission_data Posted checkout fields. |
|
| 93 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 97 | 97 | |
| 98 | 98 | // Get redirect url. |
| 99 | 99 | $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
@@ -128,31 +128,31 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * Get the Worldpay request URL for an invoice. |
|
| 132 | - * |
|
| 133 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function get_request_url( $invoice ) { |
|
| 131 | + * Get the Worldpay request URL for an invoice. |
|
| 132 | + * |
|
| 133 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function get_request_url( $invoice ) { |
|
| 137 | 137 | |
| 138 | 138 | // Endpoint for this request |
| 139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 139 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 140 | 140 | |
| 141 | 141 | return $this->endpoint; |
| 142 | 142 | |
| 143 | - } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * Get Worldpay Args for passing to Worldpay. |
|
| 147 | - * |
|
| 148 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - protected function get_worldpay_args( $invoice ) { |
|
| 152 | - |
|
| 153 | - return apply_filters( |
|
| 154 | - 'getpaid_worldpay_args', |
|
| 155 | - array( |
|
| 146 | + * Get Worldpay Args for passing to Worldpay. |
|
| 147 | + * |
|
| 148 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + protected function get_worldpay_args( $invoice ) { |
|
| 152 | + |
|
| 153 | + return apply_filters( |
|
| 154 | + 'getpaid_worldpay_args', |
|
| 155 | + array( |
|
| 156 | 156 | 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
| 157 | 157 | 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
| 158 | 158 | 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
| 178 | 178 | 'compName' => wpinv_clean( $invoice->get_company() ), |
| 179 | 179 | ), |
| 180 | - $invoice |
|
| 181 | - ); |
|
| 180 | + $invoice |
|
| 181 | + ); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
| 186 | - * Secures worldpay args with an md5 hash. |
|
| 187 | - * |
|
| 188 | - * @param array $args Gateway args. |
|
| 189 | - * @return array |
|
| 190 | - */ |
|
| 191 | - public function hash_args( $args ) { |
|
| 186 | + * Secures worldpay args with an md5 hash. |
|
| 187 | + * |
|
| 188 | + * @param array $args Gateway args. |
|
| 189 | + * @return array |
|
| 190 | + */ |
|
| 191 | + public function hash_args( $args ) { |
|
| 192 | 192 | |
| 193 | 193 | $md5_secret = $this->get_option( 'md5_secret' ); |
| 194 | 194 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
| 207 | - * Processes ipns and marks payments as complete. |
|
| 208 | - * |
|
| 209 | - * @return void |
|
| 210 | - */ |
|
| 211 | - public function verify_ipn() { |
|
| 207 | + * Processes ipns and marks payments as complete. |
|
| 208 | + * |
|
| 209 | + * @return void |
|
| 210 | + */ |
|
| 211 | + public function verify_ipn() { |
|
| 212 | 212 | |
| 213 | 213 | // Validate the IPN. |
| 214 | 214 | if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
| 215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | - } |
|
| 215 | + wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | 218 | // Process the IPN. |
| 219 | 219 | $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - // Update the ip address. |
|
| 233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 232 | + // Update the ip address. |
|
| 233 | + if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 234 | 234 | $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | - * Check Worldpay IPN validity. |
|
| 261 | - */ |
|
| 262 | - public function validate_ipn() { |
|
| 260 | + * Check Worldpay IPN validity. |
|
| 261 | + */ |
|
| 262 | + public function validate_ipn() { |
|
| 263 | 263 | |
| 264 | 264 | wpinv_error_log( 'Validating Worldpay IPN response' ); |
| 265 | 265 | |
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
| 308 | - * Filters the gateway settings. |
|
| 309 | - * |
|
| 310 | - * @param array $admin_settings |
|
| 311 | - */ |
|
| 312 | - public function admin_settings( $admin_settings ) { |
|
| 308 | + * Filters the gateway settings. |
|
| 309 | + * |
|
| 310 | + * @param array $admin_settings |
|
| 311 | + */ |
|
| 312 | + public function admin_settings( $admin_settings ) { |
|
| 313 | 313 | |
| 314 | 314 | $currencies = sprintf( |
| 315 | 315 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | 'readonly' => true, |
| 351 | 351 | ); |
| 352 | 352 | |
| 353 | - return $admin_settings; |
|
| 354 | - } |
|
| 353 | + return $admin_settings; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | } |
@@ -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 | * Worldpay Payment Gateway class. |
@@ -45,14 +45,14 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @var array |
| 47 | 47 | */ |
| 48 | - protected $supports = array( 'sandbox' ); |
|
| 48 | + protected $supports = array('sandbox'); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Currencies this gateway is allowed for. |
| 52 | 52 | * |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' ); |
|
| 55 | + public $currencies = array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * URL to view a transaction. |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function __construct() { |
| 75 | 75 | |
| 76 | - $this->method_title = __( 'Worldpay', 'invoicing' ); |
|
| 77 | - $this->title = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ); |
|
| 78 | - $this->checkout_button_text = __( 'Proceed to Worldpay', 'invoicing' ); |
|
| 79 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
| 76 | + $this->method_title = __('Worldpay', 'invoicing'); |
|
| 77 | + $this->title = __('Worldpay - Credit Card / Debit Card', 'invoicing'); |
|
| 78 | + $this->checkout_button_text = __('Proceed to Worldpay', 'invoicing'); |
|
| 79 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
| 80 | 80 | |
| 81 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
| 82 | - add_filter( 'getpaid_worldpay_args', array( $this, 'hash_args' ) ); |
|
| 81 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
| 82 | + add_filter('getpaid_worldpay_args', array($this, 'hash_args')); |
|
| 83 | 83 | |
| 84 | 84 | parent::__construct(); |
| 85 | 85 | } |
@@ -93,24 +93,24 @@ discard block |
||
| 93 | 93 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 94 | 94 | * @return array |
| 95 | 95 | */ |
| 96 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 96 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 97 | 97 | |
| 98 | 98 | // Get redirect url. |
| 99 | - $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) ); |
|
| 99 | + $worldpay_redirect = esc_url($this->get_request_url($invoice)); |
|
| 100 | 100 | |
| 101 | 101 | // Get submission args. |
| 102 | - $worldpay_args = $this->get_worldpay_args( $invoice ); |
|
| 102 | + $worldpay_args = $this->get_worldpay_args($invoice); |
|
| 103 | 103 | |
| 104 | 104 | $form = "<form action='$worldpay_redirect' name='wpi_worldpay_form' method='POST'>"; |
| 105 | 105 | |
| 106 | - foreach ( $worldpay_args as $key => $value ) { |
|
| 106 | + foreach ($worldpay_args as $key => $value) { |
|
| 107 | 107 | |
| 108 | - if ( false === $value || '' === trim( $value ) ) { |
|
| 108 | + if (false === $value || '' === trim($value)) { |
|
| 109 | 109 | continue; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $value = esc_attr( $value ); |
|
| 113 | - $key = wpinv_clean( $key ); |
|
| 112 | + $value = esc_attr($value); |
|
| 113 | + $key = wpinv_clean($key); |
|
| 114 | 114 | $form .= "<input type='hidden' name='$key' value='$value'>"; |
| 115 | 115 | } |
| 116 | 116 | |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | * @param WPInv_Invoice $invoice Invoice object. |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - public function get_request_url( $invoice ) { |
|
| 136 | + public function get_request_url($invoice) { |
|
| 137 | 137 | |
| 138 | 138 | // Endpoint for this request |
| 139 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 139 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase'; |
|
| 140 | 140 | |
| 141 | 141 | return $this->endpoint; |
| 142 | 142 | |
@@ -148,34 +148,34 @@ discard block |
||
| 148 | 148 | * @param WPInv_Invoice $invoice Invoice object. |
| 149 | 149 | * @return array |
| 150 | 150 | */ |
| 151 | - protected function get_worldpay_args( $invoice ) { |
|
| 151 | + protected function get_worldpay_args($invoice) { |
|
| 152 | 152 | |
| 153 | 153 | return apply_filters( |
| 154 | 154 | 'getpaid_worldpay_args', |
| 155 | 155 | array( |
| 156 | - 'amount' => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory |
|
| 157 | - 'cartId' => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased |
|
| 158 | - 'currency' => wpinv_clean( $invoice->get_currency() ), // mandatory |
|
| 159 | - 'instId' => wpinv_clean( $this->get_option( 'instId', '' ) ), // mandatory |
|
| 160 | - 'testMode' => $this->is_sandbox( $invoice ) ? 100 : 0, // mandatory |
|
| 161 | - 'name' => wpinv_clean( $invoice->get_full_name() ), |
|
| 162 | - 'address' => wpinv_clean( $invoice->get_address() ), |
|
| 163 | - 'postcode' => wpinv_clean( $invoice->get_zip() ), |
|
| 164 | - 'tel' => wpinv_clean( $invoice->get_phone() ), |
|
| 165 | - 'email' => sanitize_email( $invoice->get_email() ), |
|
| 166 | - 'country' => wpinv_clean( $invoice->get_country() ), |
|
| 167 | - 'desc' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
| 168 | - 'MC_description' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ), |
|
| 169 | - 'MC_callback' => esc_url_raw( $this->notify_url ), |
|
| 170 | - 'resultfile' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
| 171 | - 'MC_key' => wpinv_clean( $invoice->get_key() ), |
|
| 156 | + 'amount' => wpinv_sanitize_amount($invoice->get_total()), // mandatory |
|
| 157 | + 'cartId' => wpinv_clean($invoice->get_number()), // mandatory reference for the item purchased |
|
| 158 | + 'currency' => wpinv_clean($invoice->get_currency()), // mandatory |
|
| 159 | + 'instId' => wpinv_clean($this->get_option('instId', '')), // mandatory |
|
| 160 | + 'testMode' => $this->is_sandbox($invoice) ? 100 : 0, // mandatory |
|
| 161 | + 'name' => wpinv_clean($invoice->get_full_name()), |
|
| 162 | + 'address' => wpinv_clean($invoice->get_address()), |
|
| 163 | + 'postcode' => wpinv_clean($invoice->get_zip()), |
|
| 164 | + 'tel' => wpinv_clean($invoice->get_phone()), |
|
| 165 | + 'email' => sanitize_email($invoice->get_email()), |
|
| 166 | + 'country' => wpinv_clean($invoice->get_country()), |
|
| 167 | + 'desc' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
| 168 | + 'MC_description' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())), |
|
| 169 | + 'MC_callback' => esc_url_raw($this->notify_url), |
|
| 170 | + 'resultfile' => esc_url_raw($this->get_return_url($invoice)), |
|
| 171 | + 'MC_key' => wpinv_clean($invoice->get_key()), |
|
| 172 | 172 | 'MC_invoice_id' => $invoice->get_id(), |
| 173 | - 'address1' => wpinv_clean( $invoice->get_address() ), |
|
| 174 | - 'town' => wpinv_clean( $invoice->get_city() ), |
|
| 175 | - 'region' => wpinv_clean( $invoice->get_state() ), |
|
| 176 | - 'amountString' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ), |
|
| 177 | - 'countryString' => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ), |
|
| 178 | - 'compName' => wpinv_clean( $invoice->get_company() ), |
|
| 173 | + 'address1' => wpinv_clean($invoice->get_address()), |
|
| 174 | + 'town' => wpinv_clean($invoice->get_city()), |
|
| 175 | + 'region' => wpinv_clean($invoice->get_state()), |
|
| 176 | + 'amountString' => wpinv_price($invoice->get_total(), $invoice->get_currency()), |
|
| 177 | + 'countryString' => wpinv_clean(wpinv_country_name($invoice->get_country())), |
|
| 178 | + 'compName' => wpinv_clean($invoice->get_company()), |
|
| 179 | 179 | ), |
| 180 | 180 | $invoice |
| 181 | 181 | ); |
@@ -188,17 +188,17 @@ discard block |
||
| 188 | 188 | * @param array $args Gateway args. |
| 189 | 189 | * @return array |
| 190 | 190 | */ |
| 191 | - public function hash_args( $args ) { |
|
| 191 | + public function hash_args($args) { |
|
| 192 | 192 | |
| 193 | - $md5_secret = $this->get_option( 'md5_secret' ); |
|
| 193 | + $md5_secret = $this->get_option('md5_secret'); |
|
| 194 | 194 | |
| 195 | 195 | // Abort if there is no secret. |
| 196 | - if ( empty( $md5_secret ) ) { |
|
| 196 | + if (empty($md5_secret)) { |
|
| 197 | 197 | return $args; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Hash the args. |
| 201 | - $args['signature'] = md5( "$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}" ); |
|
| 201 | + $args['signature'] = md5("$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}"); |
|
| 202 | 202 | |
| 203 | 203 | return $args; |
| 204 | 204 | } |
@@ -211,43 +211,43 @@ discard block |
||
| 211 | 211 | public function verify_ipn() { |
| 212 | 212 | |
| 213 | 213 | // Validate the IPN. |
| 214 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
| 215 | - wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) ); |
|
| 214 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
| 215 | + wp_die('Worldpay IPN Request Failure', 'Worldpay IPN', array('response' => 500)); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | // Process the IPN. |
| 219 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 220 | - $invoice = wpinv_get_invoice( $posted['MC_invoice_id'] ); |
|
| 219 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 220 | + $invoice = wpinv_get_invoice($posted['MC_invoice_id']); |
|
| 221 | 221 | |
| 222 | - if ( $invoice && $this->id == $invoice->get_gateway() ) { |
|
| 222 | + if ($invoice && $this->id == $invoice->get_gateway()) { |
|
| 223 | 223 | |
| 224 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
| 225 | - wpinv_error_log( 'Payment status:' . $posted['transStatus'] ); |
|
| 224 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
| 225 | + wpinv_error_log('Payment status:' . $posted['transStatus']); |
|
| 226 | 226 | |
| 227 | 227 | // Update the transaction id. |
| 228 | - if ( ! empty( $posted['transId'] ) ) { |
|
| 229 | - $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) ); |
|
| 228 | + if (!empty($posted['transId'])) { |
|
| 229 | + $invoice->set_transaction_id(wpinv_clean($posted['transId'])); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Update the ip address. |
| 233 | - if ( ! empty( $posted['ipAddress'] ) ) { |
|
| 234 | - $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) ); |
|
| 233 | + if (!empty($posted['ipAddress'])) { |
|
| 234 | + $invoice->set_ip(wpinv_clean($posted['ipAddress'])); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - if ( $posted['transStatus'] == 'Y' ) { |
|
| 238 | - $invoice->set_completed_date( date( 'Y-m-d H:i:s', $posted['transTime'] ) ); |
|
| 237 | + if ($posted['transStatus'] == 'Y') { |
|
| 238 | + $invoice->set_completed_date(date('Y-m-d H:i:s', $posted['transTime'])); |
|
| 239 | 239 | $invoice->mark_paid(); |
| 240 | 240 | return; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if ( $posted['transStatus'] == 'C' ) { |
|
| 244 | - $invoice->set_status( 'wpi-failed' ); |
|
| 245 | - $invoice->add_note( __( 'Payment transaction failed while processing Worldpay payment.', 'invoicing' ), false, false, true ); |
|
| 243 | + if ($posted['transStatus'] == 'C') { |
|
| 244 | + $invoice->set_status('wpi-failed'); |
|
| 245 | + $invoice->add_note(__('Payment transaction failed while processing Worldpay payment.', 'invoicing'), false, false, true); |
|
| 246 | 246 | $invoice->save(); |
| 247 | 247 | return; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - wpinv_error_log( 'Aborting, Invalid transaction status:' . $posted['transStatus'] ); |
|
| 250 | + wpinv_error_log('Aborting, Invalid transaction status:' . $posted['transStatus']); |
|
| 251 | 251 | $invoice->save(); |
| 252 | 252 | |
| 253 | 253 | } |
@@ -261,27 +261,27 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | public function validate_ipn() { |
| 263 | 263 | |
| 264 | - wpinv_error_log( 'Validating Worldpay IPN response' ); |
|
| 264 | + wpinv_error_log('Validating Worldpay IPN response'); |
|
| 265 | 265 | |
| 266 | - $data = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
| 266 | + $data = wp_kses_post_deep(wp_unslash($_POST)); |
|
| 267 | 267 | |
| 268 | 268 | // Verify installation. |
| 269 | - if ( empty( $data['instId'] ) || $data['instId'] != wpinv_clean( $this->get_option( 'instId', '' ) ) ) { |
|
| 270 | - wpinv_error_log( 'Received invalid installation ID from Worldpay IPN' ); |
|
| 269 | + if (empty($data['instId']) || $data['instId'] != wpinv_clean($this->get_option('instId', ''))) { |
|
| 270 | + wpinv_error_log('Received invalid installation ID from Worldpay IPN'); |
|
| 271 | 271 | return false; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // Verify invoice. |
| 275 | - if ( empty( $data['cartId'] ) || ! wpinv_get_id_by_invoice_number( $data['cartId'] ) ) { |
|
| 276 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
| 275 | + if (empty($data['cartId']) || !wpinv_get_id_by_invoice_number($data['cartId'])) { |
|
| 276 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
| 277 | 277 | return false; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | // (maybe) verify password. |
| 281 | - $password = $this->get_option( 'callback_password' ); |
|
| 281 | + $password = $this->get_option('callback_password'); |
|
| 282 | 282 | |
| 283 | - if ( ! empty( $password ) && ( empty( $data['callbackPW'] ) || $password != $data['callbackPW'] ) ) { |
|
| 284 | - wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' ); |
|
| 283 | + if (!empty($password) && (empty($data['callbackPW']) || $password != $data['callbackPW'])) { |
|
| 284 | + wpinv_error_log('Received invalid invoice number from Worldpay IPN'); |
|
| 285 | 285 | return false; |
| 286 | 286 | } |
| 287 | 287 | |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | /** |
| 293 | 293 | * Displays a notice on the checkout page if sandbox is enabled. |
| 294 | 294 | */ |
| 295 | - public function sandbox_notice( $description, $gateway ) { |
|
| 296 | - if ( 'worldpay' == $gateway && wpinv_is_test_mode( 'worldpay' ) ) { |
|
| 295 | + public function sandbox_notice($description, $gateway) { |
|
| 296 | + if ('worldpay' == $gateway && wpinv_is_test_mode('worldpay')) { |
|
| 297 | 297 | $description .= '<br>' . sprintf( |
| 298 | - __( 'SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
| 298 | + __('SANDBOX ENABLED. See the %1$sWorldpay Sandbox Testing Guide%2$s for more details.', 'invoicing'), |
|
| 299 | 299 | '<a href="https://developer.worldpay.com/docs/wpg/directintegration/abouttesting">', |
| 300 | 300 | '</a>' |
| 301 | 301 | ); |
@@ -309,43 +309,43 @@ discard block |
||
| 309 | 309 | * |
| 310 | 310 | * @param array $admin_settings |
| 311 | 311 | */ |
| 312 | - public function admin_settings( $admin_settings ) { |
|
| 312 | + public function admin_settings($admin_settings) { |
|
| 313 | 313 | |
| 314 | 314 | $currencies = sprintf( |
| 315 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
| 316 | - implode( ', ', $this->currencies ) |
|
| 315 | + __('Supported Currencies: %s', 'invoicing'), |
|
| 316 | + implode(', ', $this->currencies) |
|
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | 319 | $admin_settings['worldpay_active']['desc'] = $admin_settings['worldpay_active']['desc'] . " ($currencies)"; |
| 320 | - $admin_settings['worldpay_desc']['std'] = __( 'Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing' ); |
|
| 320 | + $admin_settings['worldpay_desc']['std'] = __('Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing'); |
|
| 321 | 321 | |
| 322 | 322 | $admin_settings['worldpay_instId'] = array( |
| 323 | 323 | 'type' => 'text', |
| 324 | 324 | 'id' => 'worldpay_instId', |
| 325 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
| 326 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
| 325 | + 'name' => __('Installation Id', 'invoicing'), |
|
| 326 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
| 327 | 327 | ); |
| 328 | 328 | |
| 329 | 329 | $admin_settings['worldpay_md5_secret'] = array( |
| 330 | 330 | 'type' => 'text', |
| 331 | 331 | 'id' => 'worldpay_md5_secret', |
| 332 | - 'name' => __( 'MD5 secret', 'invoicing' ), |
|
| 333 | - 'desc' => __( 'Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing' ) . '<code>instId:amount:currency:cartId</code>', |
|
| 332 | + 'name' => __('MD5 secret', 'invoicing'), |
|
| 333 | + 'desc' => __('Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing') . '<code>instId:amount:currency:cartId</code>', |
|
| 334 | 334 | ); |
| 335 | 335 | |
| 336 | 336 | $admin_settings['worldpay_callbackPW'] = array( |
| 337 | 337 | 'type' => 'text', |
| 338 | 338 | 'id' => 'worldpay_callbackPW', |
| 339 | - 'name' => __( 'Payment Response password', 'invoicing' ), |
|
| 340 | - 'desc' => __( 'Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing' ), |
|
| 339 | + 'name' => __('Payment Response password', 'invoicing'), |
|
| 340 | + 'desc' => __('Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing'), |
|
| 341 | 341 | ); |
| 342 | 342 | |
| 343 | 343 | $admin_settings['worldpay_ipn_url'] = array( |
| 344 | 344 | 'type' => 'ipn_url', |
| 345 | 345 | 'id' => 'worldpay_ipn_url', |
| 346 | - 'name' => __( 'Payment Response URL', 'invoicing' ), |
|
| 346 | + 'name' => __('Payment Response URL', 'invoicing'), |
|
| 347 | 347 | 'std' => $this->notify_url, |
| 348 | - 'desc' => __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing' ), |
|
| 348 | + 'desc' => __('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing'), |
|
| 349 | 349 | 'custom' => 'worldpay', |
| 350 | 350 | 'readonly' => true, |
| 351 | 351 | ); |