@@ -12,281 +12,281 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | - 'has_multiple_subscriptions' => $submission->has_recurring && 1 < count( getpaid_get_subscription_groups( $submission ) ), |
|
| 31 | + 'has_multiple_subscriptions' => $submission->has_recurring && 1 < count( getpaid_get_subscription_groups( $submission ) ), |
|
| 32 | 32 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 33 | - ); |
|
| 34 | - |
|
| 35 | - $this->add_totals( $submission ); |
|
| 36 | - $this->add_texts( $submission ); |
|
| 37 | - $this->add_items( $submission ); |
|
| 38 | - $this->add_fees( $submission ); |
|
| 39 | - $this->add_discounts( $submission ); |
|
| 40 | - $this->add_taxes( $submission ); |
|
| 41 | - $this->add_gateways( $submission ); |
|
| 42 | - $this->add_data( $submission ); |
|
| 43 | - |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Adds totals to a response for submission refresh prices. |
|
| 48 | - * |
|
| 49 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 50 | - */ |
|
| 51 | - public function add_totals( $submission ) { |
|
| 52 | - |
|
| 53 | - $this->response = array_merge( |
|
| 54 | - $this->response, |
|
| 55 | - array( |
|
| 56 | - |
|
| 57 | - 'totals' => array( |
|
| 58 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 59 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 60 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 61 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 62 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 63 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 64 | - ), |
|
| 65 | - |
|
| 66 | - 'recurring' => array( |
|
| 67 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 68 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 69 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 70 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 71 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 72 | - ), |
|
| 73 | - |
|
| 74 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 75 | - 'currency' => $submission->get_currency(), |
|
| 76 | - |
|
| 77 | - ) |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Adds texts to a response for submission refresh prices. |
|
| 84 | - * |
|
| 85 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | - */ |
|
| 87 | - public function add_texts( $submission ) { |
|
| 88 | - |
|
| 89 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 90 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 91 | - |
|
| 92 | - if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
| 93 | - |
|
| 94 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 95 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 96 | - |
|
| 97 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 98 | - $payable = "$payable / $period"; |
|
| 99 | - } else { |
|
| 100 | - $payable = sprintf( |
|
| 101 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 102 | - $submission->format_amount( $submission->get_total() ), |
|
| 103 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 104 | - $period |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $texts = array( |
|
| 111 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - foreach ( $submission->get_items() as $item ) { |
|
| 115 | - $item_id = $item->get_id(); |
|
| 116 | - $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 117 | - $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 118 | - $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 122 | - |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Adds items to a response for submission refresh prices. |
|
| 127 | - * |
|
| 128 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 129 | - */ |
|
| 130 | - public function add_items( $submission ) { |
|
| 131 | - |
|
| 132 | - // Add items. |
|
| 133 | - $items = array(); |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + $this->add_totals( $submission ); |
|
| 36 | + $this->add_texts( $submission ); |
|
| 37 | + $this->add_items( $submission ); |
|
| 38 | + $this->add_fees( $submission ); |
|
| 39 | + $this->add_discounts( $submission ); |
|
| 40 | + $this->add_taxes( $submission ); |
|
| 41 | + $this->add_gateways( $submission ); |
|
| 42 | + $this->add_data( $submission ); |
|
| 43 | + |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Adds totals to a response for submission refresh prices. |
|
| 48 | + * |
|
| 49 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 50 | + */ |
|
| 51 | + public function add_totals( $submission ) { |
|
| 52 | + |
|
| 53 | + $this->response = array_merge( |
|
| 54 | + $this->response, |
|
| 55 | + array( |
|
| 56 | + |
|
| 57 | + 'totals' => array( |
|
| 58 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 59 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 60 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 61 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 62 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 63 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 64 | + ), |
|
| 65 | + |
|
| 66 | + 'recurring' => array( |
|
| 67 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 68 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 69 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 70 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 71 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 72 | + ), |
|
| 73 | + |
|
| 74 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 75 | + 'currency' => $submission->get_currency(), |
|
| 76 | + |
|
| 77 | + ) |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Adds texts to a response for submission refresh prices. |
|
| 84 | + * |
|
| 85 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 86 | + */ |
|
| 87 | + public function add_texts( $submission ) { |
|
| 88 | + |
|
| 89 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 90 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
| 91 | + |
|
| 92 | + if ( $submission->has_recurring != 0 && 2 > $groups ) { |
|
| 93 | + |
|
| 94 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 95 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 96 | + |
|
| 97 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 98 | + $payable = "$payable / $period"; |
|
| 99 | + } else { |
|
| 100 | + $payable = sprintf( |
|
| 101 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 102 | + $submission->format_amount( $submission->get_total() ), |
|
| 103 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 104 | + $period |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $texts = array( |
|
| 111 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 112 | + ); |
|
| 134 | 113 | |
| 135 | 114 | foreach ( $submission->get_items() as $item ) { |
| 136 | - $item_id = $item->get_id(); |
|
| 137 | - $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 138 | - } |
|
| 115 | + $item_id = $item->get_id(); |
|
| 116 | + $initial_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ) ); |
|
| 117 | + $recurring_price = $submission->format_amount( $this->standardize_price( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ) ); |
|
| 118 | + $texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 119 | + } |
|
| 139 | 120 | |
| 140 | - $this->response = array_merge( |
|
| 141 | - $this->response, |
|
| 142 | - array( 'items' => $items ) |
|
| 143 | - ); |
|
| 121 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 144 | 122 | |
| 145 | - } |
|
| 123 | + } |
|
| 146 | 124 | |
| 147 | - /** |
|
| 148 | - * Adds fees to a response for submission refresh prices. |
|
| 149 | - * |
|
| 150 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 151 | - */ |
|
| 152 | - public function add_fees( $submission ) { |
|
| 125 | + /** |
|
| 126 | + * Adds items to a response for submission refresh prices. |
|
| 127 | + * |
|
| 128 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 129 | + */ |
|
| 130 | + public function add_items( $submission ) { |
|
| 153 | 131 | |
| 154 | - $fees = array(); |
|
| 132 | + // Add items. |
|
| 133 | + $items = array(); |
|
| 155 | 134 | |
| 156 | - foreach ( $submission->get_fees() as $name => $data ) { |
|
| 157 | - $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 158 | - } |
|
| 135 | + foreach ( $submission->get_items() as $item ) { |
|
| 136 | + $item_id = $item->get_id(); |
|
| 137 | + $items["$item_id"] = $submission->format_amount( $item->get_sub_total() ); |
|
| 138 | + } |
|
| 159 | 139 | |
| 160 | - $this->response = array_merge( |
|
| 161 | - $this->response, |
|
| 162 | - array( 'fees' => $fees ) |
|
| 163 | - ); |
|
| 140 | + $this->response = array_merge( |
|
| 141 | + $this->response, |
|
| 142 | + array( 'items' => $items ) |
|
| 143 | + ); |
|
| 164 | 144 | |
| 165 | - } |
|
| 145 | + } |
|
| 166 | 146 | |
| 167 | - /** |
|
| 168 | - * Adds discounts to a response for submission refresh prices. |
|
| 169 | - * |
|
| 170 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | - */ |
|
| 172 | - public function add_discounts( $submission ) { |
|
| 147 | + /** |
|
| 148 | + * Adds fees to a response for submission refresh prices. |
|
| 149 | + * |
|
| 150 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 151 | + */ |
|
| 152 | + public function add_fees( $submission ) { |
|
| 173 | 153 | |
| 174 | - $discounts = array(); |
|
| 154 | + $fees = array(); |
|
| 175 | 155 | |
| 176 | - foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 177 | - $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 178 | - } |
|
| 156 | + foreach ( $submission->get_fees() as $name => $data ) { |
|
| 157 | + $fees[$name] = $submission->format_amount( $data['initial_fee'] ); |
|
| 158 | + } |
|
| 179 | 159 | |
| 180 | - $this->response = array_merge( |
|
| 181 | - $this->response, |
|
| 182 | - array( 'discounts' => $discounts ) |
|
| 183 | - ); |
|
| 160 | + $this->response = array_merge( |
|
| 161 | + $this->response, |
|
| 162 | + array( 'fees' => $fees ) |
|
| 163 | + ); |
|
| 184 | 164 | |
| 185 | - } |
|
| 165 | + } |
|
| 186 | 166 | |
| 187 | - /** |
|
| 188 | - * Adds taxes to a response for submission refresh prices. |
|
| 189 | - * |
|
| 190 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 191 | - */ |
|
| 192 | - public function add_taxes( $submission ) { |
|
| 167 | + /** |
|
| 168 | + * Adds discounts to a response for submission refresh prices. |
|
| 169 | + * |
|
| 170 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 171 | + */ |
|
| 172 | + public function add_discounts( $submission ) { |
|
| 193 | 173 | |
| 194 | - $taxes = array(); |
|
| 195 | - $markup = ''; |
|
| 196 | - foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 197 | - $name = sanitize_text_field( $name ); |
|
| 198 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 199 | - $taxes[$name] = $amount; |
|
| 200 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 201 | - } |
|
| 174 | + $discounts = array(); |
|
| 175 | + |
|
| 176 | + foreach ( $submission->get_discounts() as $name => $data ) { |
|
| 177 | + $discounts[$name] = $submission->format_amount( $data['initial_discount'] ); |
|
| 178 | + } |
|
| 202 | 179 | |
| 203 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 204 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 205 | - } |
|
| 180 | + $this->response = array_merge( |
|
| 181 | + $this->response, |
|
| 182 | + array( 'discounts' => $discounts ) |
|
| 183 | + ); |
|
| 206 | 184 | |
| 207 | - $this->response = array_merge( |
|
| 208 | - $this->response, |
|
| 209 | - array( 'taxes' => $taxes ) |
|
| 210 | - ); |
|
| 185 | + } |
|
| 211 | 186 | |
| 212 | - } |
|
| 187 | + /** |
|
| 188 | + * Adds taxes to a response for submission refresh prices. |
|
| 189 | + * |
|
| 190 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 191 | + */ |
|
| 192 | + public function add_taxes( $submission ) { |
|
| 193 | + |
|
| 194 | + $taxes = array(); |
|
| 195 | + $markup = ''; |
|
| 196 | + foreach ( $submission->get_taxes() as $name => $data ) { |
|
| 197 | + $name = sanitize_text_field( $name ); |
|
| 198 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 199 | + $taxes[$name] = $amount; |
|
| 200 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 201 | + } |
|
| 213 | 202 | |
| 214 | - /** |
|
| 215 | - * Adds gateways to a response for submission refresh prices. |
|
| 216 | - * |
|
| 217 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 218 | - */ |
|
| 219 | - public function add_gateways( $submission ) { |
|
| 203 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 204 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 205 | + } |
|
| 220 | 206 | |
| 221 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 207 | + $this->response = array_merge( |
|
| 208 | + $this->response, |
|
| 209 | + array( 'taxes' => $taxes ) |
|
| 210 | + ); |
|
| 222 | 211 | |
| 223 | - if ( $this->response['has_recurring'] ) { |
|
| 212 | + } |
|
| 224 | 213 | |
| 225 | - foreach ( $gateways as $i => $gateway ) { |
|
| 214 | + /** |
|
| 215 | + * Adds gateways to a response for submission refresh prices. |
|
| 216 | + * |
|
| 217 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 218 | + */ |
|
| 219 | + public function add_gateways( $submission ) { |
|
| 226 | 220 | |
| 227 | - if ( ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) || ( $this->response['has_multiple_subscriptions'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscriptions' ) ) ) { |
|
| 228 | - unset( $gateways[ $i ] ); |
|
| 229 | - } |
|
| 221 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 230 | 222 | |
| 231 | - } |
|
| 223 | + if ( $this->response['has_recurring'] ) { |
|
| 232 | 224 | |
| 233 | - } |
|
| 225 | + foreach ( $gateways as $i => $gateway ) { |
|
| 234 | 226 | |
| 235 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 236 | - $this->response = array_merge( |
|
| 237 | - $this->response, |
|
| 238 | - array( 'gateways' => $gateways ) |
|
| 239 | - ); |
|
| 227 | + if ( ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) || ( $this->response['has_multiple_subscriptions'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscriptions' ) ) ) { |
|
| 228 | + unset( $gateways[ $i ] ); |
|
| 229 | + } |
|
| 240 | 230 | |
| 241 | - } |
|
| 231 | + } |
|
| 242 | 232 | |
| 243 | - /** |
|
| 244 | - * Standardizes prices. |
|
| 245 | - * |
|
| 246 | - * @param int $item_id |
|
| 247 | - * @param float $item_total |
|
| 248 | - * @param string $discount_code |
|
| 249 | - * @param bool $recurring |
|
| 250 | - */ |
|
| 251 | - public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 233 | + } |
|
| 252 | 234 | |
| 253 | - $standardadized_price = $item_total; |
|
| 235 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 236 | + $this->response = array_merge( |
|
| 237 | + $this->response, |
|
| 238 | + array( 'gateways' => $gateways ) |
|
| 239 | + ); |
|
| 254 | 240 | |
| 255 | - // Do we have a $discount_code? |
|
| 256 | - if ( ! empty( $discount_code ) ) { |
|
| 241 | + } |
|
| 257 | 242 | |
| 258 | - $discount = new WPInv_Discount( $discount_code ); |
|
| 243 | + /** |
|
| 244 | + * Standardizes prices. |
|
| 245 | + * |
|
| 246 | + * @param int $item_id |
|
| 247 | + * @param float $item_total |
|
| 248 | + * @param string $discount_code |
|
| 249 | + * @param bool $recurring |
|
| 250 | + */ |
|
| 251 | + public function standardize_price( $item_id, $item_total, $discount_code, $recurring = false ) { |
|
| 252 | + |
|
| 253 | + $standardadized_price = $item_total; |
|
| 259 | 254 | |
| 260 | - if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 261 | - $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 262 | - } |
|
| 255 | + // Do we have a $discount_code? |
|
| 256 | + if ( ! empty( $discount_code ) ) { |
|
| 263 | 257 | |
| 264 | - } |
|
| 258 | + $discount = new WPInv_Discount( $discount_code ); |
|
| 265 | 259 | |
| 266 | - return max( 0, $standardadized_price ); |
|
| 260 | + if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) { |
|
| 261 | + $standardadized_price = $item_total - $discount->get_discounted_amount( $item_total ); |
|
| 262 | + } |
|
| 267 | 263 | |
| 268 | - } |
|
| 264 | + } |
|
| 269 | 265 | |
| 270 | - /** |
|
| 271 | - * Adds data to a response for submission refresh prices. |
|
| 272 | - * |
|
| 273 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 274 | - */ |
|
| 275 | - public function add_data( $submission ) { |
|
| 266 | + return max( 0, $standardadized_price ); |
|
| 276 | 267 | |
| 277 | - $this->response = array_merge( |
|
| 278 | - $this->response, |
|
| 279 | - array( |
|
| 280 | - 'js_data' => apply_filters( |
|
| 281 | - 'getpaid_submission_js_data', |
|
| 282 | - array( |
|
| 283 | - 'is_recurring' => $this->response['has_recurring'], |
|
| 284 | - ), |
|
| 285 | - $submission |
|
| 286 | - ) |
|
| 287 | - ) |
|
| 288 | - ); |
|
| 268 | + } |
|
| 289 | 269 | |
| 290 | - } |
|
| 270 | + /** |
|
| 271 | + * Adds data to a response for submission refresh prices. |
|
| 272 | + * |
|
| 273 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 274 | + */ |
|
| 275 | + public function add_data( $submission ) { |
|
| 276 | + |
|
| 277 | + $this->response = array_merge( |
|
| 278 | + $this->response, |
|
| 279 | + array( |
|
| 280 | + 'js_data' => apply_filters( |
|
| 281 | + 'getpaid_submission_js_data', |
|
| 282 | + array( |
|
| 283 | + 'is_recurring' => $this->response['has_recurring'], |
|
| 284 | + ), |
|
| 285 | + $submission |
|
| 286 | + ) |
|
| 287 | + ) |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | 292 | } |
@@ -13,30 +13,30 @@ discard block |
||
| 13 | 13 | class GetPaid_Manual_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 = 'manual'; |
| 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', 'addons', 'multiple_subscriptions' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 34 | - public $order = 11; |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | + public $order = 11; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Class constructor. |
|
| 38 | - */ |
|
| 39 | - public function __construct() { |
|
| 37 | + * Class constructor. |
|
| 38 | + */ |
|
| 39 | + public function __construct() { |
|
| 40 | 40 | parent::__construct(); |
| 41 | 41 | |
| 42 | 42 | $this->title = __( 'Test Gateway', 'invoicing' ); |
@@ -46,15 +46,15 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Process Payment. |
|
| 50 | - * |
|
| 51 | - * |
|
| 52 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | - * @param array $submission_data Posted checkout fields. |
|
| 54 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 49 | + * Process Payment. |
|
| 50 | + * |
|
| 51 | + * |
|
| 52 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 53 | + * @param array $submission_data Posted checkout fields. |
|
| 54 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 58 | 58 | |
| 59 | 59 | // Mark it as paid. |
| 60 | 60 | $invoice->mark_paid(); |
@@ -68,13 +68,13 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
| 71 | - * (Maybe) renews a manual subscription profile. |
|
| 72 | - * |
|
| 73 | - * |
|
| 74 | - * @param bool $should_expire |
|
| 71 | + * (Maybe) renews a manual subscription profile. |
|
| 72 | + * |
|
| 73 | + * |
|
| 74 | + * @param bool $should_expire |
|
| 75 | 75 | * @param WPInv_Subscription $subscription |
| 76 | - */ |
|
| 77 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 76 | + */ |
|
| 77 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 78 | 78 | |
| 79 | 79 | // Ensure its our subscription && it's active. |
| 80 | 80 | if ( 'manual' != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
| 105 | - * Processes invoice addons. |
|
| 106 | - * |
|
| 107 | - * @param WPInv_Invoice $invoice |
|
| 108 | - * @param GetPaid_Form_Item[] $items |
|
| 109 | - * @return WPInv_Invoice |
|
| 110 | - */ |
|
| 111 | - public function process_addons( $invoice, $items ) { |
|
| 105 | + * Processes invoice addons. |
|
| 106 | + * |
|
| 107 | + * @param WPInv_Invoice $invoice |
|
| 108 | + * @param GetPaid_Form_Item[] $items |
|
| 109 | + * @return WPInv_Invoice |
|
| 110 | + */ |
|
| 111 | + public function process_addons( $invoice, $items ) { |
|
| 112 | 112 | |
| 113 | 113 | foreach ( $items as $item ) { |
| 114 | 114 | $invoice->add_item( $item ); |
@@ -13,461 +13,461 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GetPaid_Payment_Gateway { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Set if the place checkout button should be renamed on selection. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $checkout_button_text; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Boolean whether the method is enabled. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - public $enabled = true; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Payment method id. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Payment method order. |
|
| 39 | - * |
|
| 40 | - * @var int |
|
| 41 | - */ |
|
| 42 | - public $order = 10; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Payment method title for the frontend. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $title; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Payment method description for the frontend. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $description; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gateway title. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $method_title = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gateway description. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $method_description = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Countries this gateway is allowed for. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - public $countries; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Currencies this gateway is allowed for. |
|
| 81 | - * |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 84 | - public $currencies; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Currencies this gateway is not allowed for. |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - public $exclude_currencies; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | - * |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - public $max_amount = 0; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Optional URL to view a transaction. |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $view_transaction_url = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Optional URL to view a subscription. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - public $view_subscription_url = ''; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Optional label to show for "new payment method" in the payment |
|
| 116 | - * method/token selection radio selection. |
|
| 117 | - * |
|
| 118 | - * @var string |
|
| 119 | - */ |
|
| 120 | - public $new_method_label = ''; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Contains a user's saved tokens for this gateway. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $tokens = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * An array of features that this gateway supports. |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - protected $supports = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Class constructor. |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - |
|
| 141 | - // Register gateway. |
|
| 142 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | - |
|
| 144 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | - |
|
| 146 | - // Add support for various features. |
|
| 147 | - foreach ( $this->supports as $feature ) { |
|
| 148 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Invoice addons. |
|
| 152 | - if ( $this->supports( 'addons' ) ) { |
|
| 153 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // Gateway settings. |
|
| 157 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 16 | + /** |
|
| 17 | + * Set if the place checkout button should be renamed on selection. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $checkout_button_text; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Boolean whether the method is enabled. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + public $enabled = true; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Payment method id. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Payment method order. |
|
| 39 | + * |
|
| 40 | + * @var int |
|
| 41 | + */ |
|
| 42 | + public $order = 10; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Payment method title for the frontend. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $title; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Payment method description for the frontend. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $description; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gateway title. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $method_title = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gateway description. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $method_description = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Countries this gateway is allowed for. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + public $countries; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Currencies this gateway is allowed for. |
|
| 81 | + * |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | + public $currencies; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Currencies this gateway is not allowed for. |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + public $exclude_currencies; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | + * |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + public $max_amount = 0; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Optional URL to view a transaction. |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $view_transaction_url = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Optional URL to view a subscription. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + public $view_subscription_url = ''; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Optional label to show for "new payment method" in the payment |
|
| 116 | + * method/token selection radio selection. |
|
| 117 | + * |
|
| 118 | + * @var string |
|
| 119 | + */ |
|
| 120 | + public $new_method_label = ''; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Contains a user's saved tokens for this gateway. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $tokens = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * An array of features that this gateway supports. |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + protected $supports = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Class constructor. |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + |
|
| 141 | + // Register gateway. |
|
| 142 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 143 | + |
|
| 144 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 145 | + |
|
| 146 | + // Add support for various features. |
|
| 147 | + foreach ( $this->supports as $feature ) { |
|
| 148 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Invoice addons. |
|
| 152 | + if ( $this->supports( 'addons' ) ) { |
|
| 153 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // Gateway settings. |
|
| 157 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - // Gateway checkout fiellds. |
|
| 161 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 162 | - |
|
| 163 | - // Process payment. |
|
| 164 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 160 | + // Gateway checkout fiellds. |
|
| 161 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 162 | + |
|
| 163 | + // Process payment. |
|
| 164 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 165 | + |
|
| 166 | + // Change the checkout button text. |
|
| 167 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 168 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + // Check if a gateway is valid for a given currency. |
|
| 172 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 173 | + |
|
| 174 | + // Generate the transaction url. |
|
| 175 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 176 | + |
|
| 177 | + // Generate the subscription url. |
|
| 178 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 179 | + |
|
| 180 | + // Confirm payments. |
|
| 181 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 182 | + |
|
| 183 | + // Verify IPNs. |
|
| 184 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 185 | + |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Checks if this gateway is a given gateway. |
|
| 190 | + * |
|
| 191 | + * @since 1.0.19 |
|
| 192 | + * @return bool |
|
| 193 | + */ |
|
| 194 | + public function is( $gateway ) { |
|
| 195 | + return $gateway == $this->id; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Returns a users saved tokens for this gateway. |
|
| 200 | + * |
|
| 201 | + * @since 1.0.19 |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function get_tokens( $sandbox = null ) { |
|
| 205 | + |
|
| 206 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 207 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 208 | + |
|
| 209 | + if ( is_array( $tokens ) ) { |
|
| 210 | + $this->tokens = $tokens; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + if ( ! is_bool( $sandbox ) ) { |
|
| 216 | + return $this->tokens; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 220 | + return wp_list_filter( $this->tokens, $args ); |
|
| 221 | + |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Saves a token for this gateway. |
|
| 226 | + * |
|
| 227 | + * @since 1.0.19 |
|
| 228 | + */ |
|
| 229 | + public function save_token( $token ) { |
|
| 230 | + |
|
| 231 | + $tokens = $this->get_tokens(); |
|
| 232 | + $tokens[] = $token; |
|
| 233 | + |
|
| 234 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 235 | + |
|
| 236 | + $this->tokens = $tokens; |
|
| 237 | + |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Return the title for admin screens. |
|
| 242 | + * |
|
| 243 | + * @return string |
|
| 244 | + */ |
|
| 245 | + public function get_method_title() { |
|
| 246 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Return the description for admin screens. |
|
| 251 | + * |
|
| 252 | + * @return string |
|
| 253 | + */ |
|
| 254 | + public function get_method_description() { |
|
| 255 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Get the success url. |
|
| 260 | + * |
|
| 261 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function get_return_url( $invoice ) { |
|
| 265 | + |
|
| 266 | + // Payment success url |
|
| 267 | + $return_url = add_query_arg( |
|
| 268 | + array( |
|
| 269 | + 'payment-confirm' => $this->id, |
|
| 270 | + 'invoice_key' => $invoice->get_key(), |
|
| 271 | + 'utm_nooverride' => 1 |
|
| 272 | + ), |
|
| 273 | + wpinv_get_success_page_uri() |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Confirms payments when rendering the success page. |
|
| 281 | + * |
|
| 282 | + * @param string $content Success page content. |
|
| 283 | + * @return string |
|
| 284 | + */ |
|
| 285 | + public function confirm_payment( $content ) { |
|
| 286 | + |
|
| 287 | + // Retrieve the invoice. |
|
| 288 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 289 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 290 | + |
|
| 291 | + // Ensure that it exists and that it is pending payment. |
|
| 292 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 293 | + return $content; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + // Can the user view this invoice?? |
|
| 297 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 298 | + return $content; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + // Show payment processing indicator. |
|
| 302 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Processes ipns and marks payments as complete. |
|
| 307 | + * |
|
| 308 | + * @return void |
|
| 309 | + */ |
|
| 310 | + public function verify_ipn() {} |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Processes invoice addons. |
|
| 314 | + * |
|
| 315 | + * @param WPInv_Invoice $invoice |
|
| 316 | + * @param GetPaid_Form_Item[] $items |
|
| 317 | + * @return WPInv_Invoice |
|
| 318 | + */ |
|
| 319 | + public function process_addons( $invoice, $items ) { |
|
| 320 | + |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 325 | + * |
|
| 326 | + * @param string $transaction_url transaction url. |
|
| 327 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 328 | + * @return string transaction URL, or empty string. |
|
| 329 | + */ |
|
| 330 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 331 | + |
|
| 332 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 333 | + |
|
| 334 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 335 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 336 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 337 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + return $transaction_url; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 345 | + * |
|
| 346 | + * @param string $subscription_url transaction url. |
|
| 347 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 348 | + * @return string subscription URL, or empty string. |
|
| 349 | + */ |
|
| 350 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 351 | + |
|
| 352 | + $profile_id = $subscription->get_profile_id(); |
|
| 165 | 353 | |
| 166 | - // Change the checkout button text. |
|
| 167 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 168 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - // Check if a gateway is valid for a given currency. |
|
| 172 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 173 | - |
|
| 174 | - // Generate the transaction url. |
|
| 175 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 176 | - |
|
| 177 | - // Generate the subscription url. |
|
| 178 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 179 | - |
|
| 180 | - // Confirm payments. |
|
| 181 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 182 | - |
|
| 183 | - // Verify IPNs. |
|
| 184 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 185 | - |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Checks if this gateway is a given gateway. |
|
| 190 | - * |
|
| 191 | - * @since 1.0.19 |
|
| 192 | - * @return bool |
|
| 193 | - */ |
|
| 194 | - public function is( $gateway ) { |
|
| 195 | - return $gateway == $this->id; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Returns a users saved tokens for this gateway. |
|
| 200 | - * |
|
| 201 | - * @since 1.0.19 |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function get_tokens( $sandbox = null ) { |
|
| 205 | - |
|
| 206 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 207 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 208 | - |
|
| 209 | - if ( is_array( $tokens ) ) { |
|
| 210 | - $this->tokens = $tokens; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - if ( ! is_bool( $sandbox ) ) { |
|
| 216 | - return $this->tokens; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 220 | - return wp_list_filter( $this->tokens, $args ); |
|
| 221 | - |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Saves a token for this gateway. |
|
| 226 | - * |
|
| 227 | - * @since 1.0.19 |
|
| 228 | - */ |
|
| 229 | - public function save_token( $token ) { |
|
| 230 | - |
|
| 231 | - $tokens = $this->get_tokens(); |
|
| 232 | - $tokens[] = $token; |
|
| 233 | - |
|
| 234 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 235 | - |
|
| 236 | - $this->tokens = $tokens; |
|
| 237 | - |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Return the title for admin screens. |
|
| 242 | - * |
|
| 243 | - * @return string |
|
| 244 | - */ |
|
| 245 | - public function get_method_title() { |
|
| 246 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Return the description for admin screens. |
|
| 251 | - * |
|
| 252 | - * @return string |
|
| 253 | - */ |
|
| 254 | - public function get_method_description() { |
|
| 255 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Get the success url. |
|
| 260 | - * |
|
| 261 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function get_return_url( $invoice ) { |
|
| 265 | - |
|
| 266 | - // Payment success url |
|
| 267 | - $return_url = add_query_arg( |
|
| 268 | - array( |
|
| 269 | - 'payment-confirm' => $this->id, |
|
| 270 | - 'invoice_key' => $invoice->get_key(), |
|
| 271 | - 'utm_nooverride' => 1 |
|
| 272 | - ), |
|
| 273 | - wpinv_get_success_page_uri() |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Confirms payments when rendering the success page. |
|
| 281 | - * |
|
| 282 | - * @param string $content Success page content. |
|
| 283 | - * @return string |
|
| 284 | - */ |
|
| 285 | - public function confirm_payment( $content ) { |
|
| 286 | - |
|
| 287 | - // Retrieve the invoice. |
|
| 288 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 289 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 290 | - |
|
| 291 | - // Ensure that it exists and that it is pending payment. |
|
| 292 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 293 | - return $content; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - // Can the user view this invoice?? |
|
| 297 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 298 | - return $content; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - // Show payment processing indicator. |
|
| 302 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Processes ipns and marks payments as complete. |
|
| 307 | - * |
|
| 308 | - * @return void |
|
| 309 | - */ |
|
| 310 | - public function verify_ipn() {} |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Processes invoice addons. |
|
| 314 | - * |
|
| 315 | - * @param WPInv_Invoice $invoice |
|
| 316 | - * @param GetPaid_Form_Item[] $items |
|
| 317 | - * @return WPInv_Invoice |
|
| 318 | - */ |
|
| 319 | - public function process_addons( $invoice, $items ) { |
|
| 320 | - |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 325 | - * |
|
| 326 | - * @param string $transaction_url transaction url. |
|
| 327 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 328 | - * @return string transaction URL, or empty string. |
|
| 329 | - */ |
|
| 330 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 331 | - |
|
| 332 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 333 | - |
|
| 334 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 335 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 336 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 337 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - return $transaction_url; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 345 | - * |
|
| 346 | - * @param string $subscription_url transaction url. |
|
| 347 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 348 | - * @return string subscription URL, or empty string. |
|
| 349 | - */ |
|
| 350 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 351 | - |
|
| 352 | - $profile_id = $subscription->get_profile_id(); |
|
| 353 | - |
|
| 354 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 355 | - |
|
| 356 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 357 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 358 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 359 | - |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $subscription_url; |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * Check if the gateway is available for use. |
|
| 367 | - * |
|
| 368 | - * @return bool |
|
| 369 | - */ |
|
| 370 | - public function is_available() { |
|
| 371 | - return ! empty( $this->enabled ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Return the gateway's title. |
|
| 376 | - * |
|
| 377 | - * @return string |
|
| 378 | - */ |
|
| 379 | - public function get_title() { |
|
| 380 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Return the gateway's description. |
|
| 385 | - * |
|
| 386 | - * @return string |
|
| 387 | - */ |
|
| 388 | - public function get_description() { |
|
| 389 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Process Payment. |
|
| 394 | - * |
|
| 395 | - * |
|
| 396 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 397 | - * @param array $submission_data Posted checkout fields. |
|
| 398 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 399 | - * @return void |
|
| 400 | - */ |
|
| 401 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 402 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 403 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Process refund. |
|
| 408 | - * |
|
| 409 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 410 | - * a passed in amount. |
|
| 411 | - * |
|
| 412 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 413 | - * @param float $amount Refund amount. |
|
| 414 | - * @param string $reason Refund reason. |
|
| 415 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 416 | - */ |
|
| 417 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 418 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Displays the payment fields, credit cards etc. |
|
| 423 | - * |
|
| 424 | - * @param int $invoice_id 0 or invoice id. |
|
| 425 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 426 | - */ |
|
| 427 | - public function payment_fields( $invoice_id, $form ) { |
|
| 428 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * Filters the gateway settings. |
|
| 433 | - * |
|
| 434 | - * @param array $admin_settings |
|
| 435 | - */ |
|
| 436 | - public function admin_settings( $admin_settings ) { |
|
| 437 | - return $admin_settings; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Retrieves the value of a gateway setting. |
|
| 442 | - * |
|
| 443 | - * @param string $option |
|
| 444 | - */ |
|
| 445 | - public function get_option( $option, $default = false ) { |
|
| 446 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Check if a gateway supports a given feature. |
|
| 451 | - * |
|
| 452 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 453 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 454 | - * |
|
| 455 | - * @param string $feature string The name of a feature to test support for. |
|
| 456 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 457 | - * @since 1.0.19 |
|
| 458 | - */ |
|
| 459 | - public function supports( $feature ) { |
|
| 460 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Returns the credit card form html. |
|
| 465 | - * |
|
| 466 | - * @param bool $save whether or not to display the save button. |
|
| 467 | - */ |
|
| 354 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 355 | + |
|
| 356 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 357 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 358 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 359 | + |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $subscription_url; |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + /** |
|
| 366 | + * Check if the gateway is available for use. |
|
| 367 | + * |
|
| 368 | + * @return bool |
|
| 369 | + */ |
|
| 370 | + public function is_available() { |
|
| 371 | + return ! empty( $this->enabled ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Return the gateway's title. |
|
| 376 | + * |
|
| 377 | + * @return string |
|
| 378 | + */ |
|
| 379 | + public function get_title() { |
|
| 380 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Return the gateway's description. |
|
| 385 | + * |
|
| 386 | + * @return string |
|
| 387 | + */ |
|
| 388 | + public function get_description() { |
|
| 389 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Process Payment. |
|
| 394 | + * |
|
| 395 | + * |
|
| 396 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 397 | + * @param array $submission_data Posted checkout fields. |
|
| 398 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 399 | + * @return void |
|
| 400 | + */ |
|
| 401 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 402 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 403 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Process refund. |
|
| 408 | + * |
|
| 409 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 410 | + * a passed in amount. |
|
| 411 | + * |
|
| 412 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 413 | + * @param float $amount Refund amount. |
|
| 414 | + * @param string $reason Refund reason. |
|
| 415 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 416 | + */ |
|
| 417 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 418 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Displays the payment fields, credit cards etc. |
|
| 423 | + * |
|
| 424 | + * @param int $invoice_id 0 or invoice id. |
|
| 425 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 426 | + */ |
|
| 427 | + public function payment_fields( $invoice_id, $form ) { |
|
| 428 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * Filters the gateway settings. |
|
| 433 | + * |
|
| 434 | + * @param array $admin_settings |
|
| 435 | + */ |
|
| 436 | + public function admin_settings( $admin_settings ) { |
|
| 437 | + return $admin_settings; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Retrieves the value of a gateway setting. |
|
| 442 | + * |
|
| 443 | + * @param string $option |
|
| 444 | + */ |
|
| 445 | + public function get_option( $option, $default = false ) { |
|
| 446 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Check if a gateway supports a given feature. |
|
| 451 | + * |
|
| 452 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 453 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 454 | + * |
|
| 455 | + * @param string $feature string The name of a feature to test support for. |
|
| 456 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 457 | + * @since 1.0.19 |
|
| 458 | + */ |
|
| 459 | + public function supports( $feature ) { |
|
| 460 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Returns the credit card form html. |
|
| 465 | + * |
|
| 466 | + * @param bool $save whether or not to display the save button. |
|
| 467 | + */ |
|
| 468 | 468 | public function get_cc_form( $save = false ) { |
| 469 | 469 | |
| 470 | - ob_start(); |
|
| 470 | + ob_start(); |
|
| 471 | 471 | |
| 472 | 472 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 473 | 473 | |
@@ -562,11 +562,11 @@ discard block |
||
| 562 | 562 | 'name' => $this->id . '[cc_cvv2]', |
| 563 | 563 | 'id' => "$id_prefix-cc-cvv2", |
| 564 | 564 | 'label' => __( 'CCV', 'invoicing' ), |
| 565 | - 'label_type' => 'vertical', |
|
| 566 | - 'class' => 'form-control-sm', |
|
| 567 | - 'extra_attributes' => array( |
|
| 568 | - 'autocomplete' => "cc-csc", |
|
| 569 | - ), |
|
| 565 | + 'label_type' => 'vertical', |
|
| 566 | + 'class' => 'form-control-sm', |
|
| 567 | + 'extra_attributes' => array( |
|
| 568 | + 'autocomplete' => "cc-csc", |
|
| 569 | + ), |
|
| 570 | 570 | ) |
| 571 | 571 | ); |
| 572 | 572 | ?> |
@@ -576,191 +576,191 @@ discard block |
||
| 576 | 576 | |
| 577 | 577 | <?php |
| 578 | 578 | |
| 579 | - if ( $save ) { |
|
| 580 | - echo $this->save_payment_method_checkbox(); |
|
| 581 | - } |
|
| 579 | + if ( $save ) { |
|
| 580 | + echo $this->save_payment_method_checkbox(); |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - ?> |
|
| 583 | + ?> |
|
| 584 | 584 | </div> |
| 585 | 585 | |
| 586 | 586 | </div> |
| 587 | 587 | <?php |
| 588 | 588 | |
| 589 | - return ob_get_clean(); |
|
| 589 | + return ob_get_clean(); |
|
| 590 | + |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Displays a new payment method entry form. |
|
| 595 | + * |
|
| 596 | + * @since 1.0.19 |
|
| 597 | + */ |
|
| 598 | + public function new_payment_method_entry( $form ) { |
|
| 599 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Grab and display our saved payment methods. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + */ |
|
| 607 | + public function saved_payment_methods() { |
|
| 608 | + $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 609 | + |
|
| 610 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 611 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 612 | + } |
|
| 590 | 613 | |
| 614 | + $html .= $this->get_new_payment_method_option_html(); |
|
| 615 | + $html .= '</ul>'; |
|
| 616 | + |
|
| 617 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 591 | 618 | } |
| 592 | 619 | |
| 593 | - /** |
|
| 594 | - * Displays a new payment method entry form. |
|
| 595 | - * |
|
| 596 | - * @since 1.0.19 |
|
| 597 | - */ |
|
| 598 | - public function new_payment_method_entry( $form ) { |
|
| 599 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Grab and display our saved payment methods. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - */ |
|
| 607 | - public function saved_payment_methods() { |
|
| 608 | - $html = '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 609 | - |
|
| 610 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 611 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - $html .= $this->get_new_payment_method_option_html(); |
|
| 615 | - $html .= '</ul>'; |
|
| 616 | - |
|
| 617 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Gets saved payment method HTML from a token. |
|
| 622 | - * |
|
| 623 | - * @since 1.0.19 |
|
| 624 | - * @param array $token Payment Token. |
|
| 625 | - * @return string Generated payment method HTML |
|
| 626 | - */ |
|
| 627 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 628 | - |
|
| 629 | - return sprintf( |
|
| 630 | - '<li class="getpaid-payment-method form-group"> |
|
| 620 | + /** |
|
| 621 | + * Gets saved payment method HTML from a token. |
|
| 622 | + * |
|
| 623 | + * @since 1.0.19 |
|
| 624 | + * @param array $token Payment Token. |
|
| 625 | + * @return string Generated payment method HTML |
|
| 626 | + */ |
|
| 627 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 628 | + |
|
| 629 | + return sprintf( |
|
| 630 | + '<li class="getpaid-payment-method form-group"> |
|
| 631 | 631 | <label> |
| 632 | 632 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 633 | 633 | <span>%3$s</span> |
| 634 | 634 | </label> |
| 635 | 635 | </li>', |
| 636 | - esc_attr( $this->id ), |
|
| 637 | - esc_attr( $token['id'] ), |
|
| 638 | - esc_html( $token['name'] ), |
|
| 639 | - checked( empty( $token['default'] ), false, false ) |
|
| 640 | - ); |
|
| 636 | + esc_attr( $this->id ), |
|
| 637 | + esc_attr( $token['id'] ), |
|
| 638 | + esc_html( $token['name'] ), |
|
| 639 | + checked( empty( $token['default'] ), false, false ) |
|
| 640 | + ); |
|
| 641 | 641 | |
| 642 | - } |
|
| 642 | + } |
|
| 643 | 643 | |
| 644 | - /** |
|
| 645 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 646 | - * |
|
| 647 | - * @since 1.0.19 |
|
| 648 | - */ |
|
| 649 | - public function get_new_payment_method_option_html() { |
|
| 644 | + /** |
|
| 645 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 646 | + * |
|
| 647 | + * @since 1.0.19 |
|
| 648 | + */ |
|
| 649 | + public function get_new_payment_method_option_html() { |
|
| 650 | 650 | |
| 651 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 651 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 652 | 652 | |
| 653 | - return sprintf( |
|
| 654 | - '<li class="getpaid-new-payment-method"> |
|
| 653 | + return sprintf( |
|
| 654 | + '<li class="getpaid-new-payment-method"> |
|
| 655 | 655 | <label> |
| 656 | 656 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
| 657 | 657 | <span>%2$s</span> |
| 658 | 658 | </label> |
| 659 | 659 | </li>', |
| 660 | - esc_attr( $this->id ), |
|
| 661 | - esc_html( $label ) |
|
| 662 | - ); |
|
| 663 | - |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 668 | - * |
|
| 669 | - * @since 1.0.19 |
|
| 670 | - */ |
|
| 671 | - public function save_payment_method_checkbox() { |
|
| 672 | - |
|
| 673 | - return aui()->input( |
|
| 674 | - array( |
|
| 675 | - 'type' => 'checkbox', |
|
| 676 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 677 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 678 | - 'required' => false, |
|
| 679 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 680 | - 'value' => 'true', |
|
| 681 | - 'checked' => true, |
|
| 682 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 683 | - ) |
|
| 684 | - ); |
|
| 685 | - |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Registers the gateway. |
|
| 690 | - * |
|
| 691 | - * @return array |
|
| 692 | - */ |
|
| 693 | - public function register_gateway( $gateways ) { |
|
| 694 | - |
|
| 695 | - $gateways[ $this->id ] = array( |
|
| 696 | - |
|
| 697 | - 'admin_label' => $this->method_title, |
|
| 660 | + esc_attr( $this->id ), |
|
| 661 | + esc_html( $label ) |
|
| 662 | + ); |
|
| 663 | + |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 668 | + * |
|
| 669 | + * @since 1.0.19 |
|
| 670 | + */ |
|
| 671 | + public function save_payment_method_checkbox() { |
|
| 672 | + |
|
| 673 | + return aui()->input( |
|
| 674 | + array( |
|
| 675 | + 'type' => 'checkbox', |
|
| 676 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 677 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 678 | + 'required' => false, |
|
| 679 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 680 | + 'value' => 'true', |
|
| 681 | + 'checked' => true, |
|
| 682 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 683 | + ) |
|
| 684 | + ); |
|
| 685 | + |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Registers the gateway. |
|
| 690 | + * |
|
| 691 | + * @return array |
|
| 692 | + */ |
|
| 693 | + public function register_gateway( $gateways ) { |
|
| 694 | + |
|
| 695 | + $gateways[ $this->id ] = array( |
|
| 696 | + |
|
| 697 | + 'admin_label' => $this->method_title, |
|
| 698 | 698 | 'checkout_label' => $this->title, |
| 699 | - 'ordering' => $this->order, |
|
| 699 | + 'ordering' => $this->order, |
|
| 700 | 700 | |
| 701 | - ); |
|
| 701 | + ); |
|
| 702 | 702 | |
| 703 | - return $gateways; |
|
| 703 | + return $gateways; |
|
| 704 | 704 | |
| 705 | - } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | - /** |
|
| 708 | - * Checks whether or not this is a sandbox request. |
|
| 709 | - * |
|
| 710 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 711 | - * @return bool |
|
| 712 | - */ |
|
| 713 | - public function is_sandbox( $invoice = null ) { |
|
| 707 | + /** |
|
| 708 | + * Checks whether or not this is a sandbox request. |
|
| 709 | + * |
|
| 710 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 711 | + * @return bool |
|
| 712 | + */ |
|
| 713 | + public function is_sandbox( $invoice = null ) { |
|
| 714 | 714 | |
| 715 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 716 | - return $invoice->get_mode() == 'test'; |
|
| 717 | - } |
|
| 715 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
| 716 | + return $invoice->get_mode() == 'test'; |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | - return wpinv_is_test_mode( $this->id ); |
|
| 719 | + return wpinv_is_test_mode( $this->id ); |
|
| 720 | 720 | |
| 721 | - } |
|
| 721 | + } |
|
| 722 | 722 | |
| 723 | - /** |
|
| 724 | - * Renames the checkout button |
|
| 725 | - * |
|
| 726 | - * @return string |
|
| 727 | - */ |
|
| 728 | - public function rename_checkout_button() { |
|
| 729 | - return $this->checkout_button_text; |
|
| 730 | - } |
|
| 723 | + /** |
|
| 724 | + * Renames the checkout button |
|
| 725 | + * |
|
| 726 | + * @return string |
|
| 727 | + */ |
|
| 728 | + public function rename_checkout_button() { |
|
| 729 | + return $this->checkout_button_text; |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * Validate gateway currency |
|
| 734 | - * |
|
| 735 | - * @return bool |
|
| 736 | - */ |
|
| 737 | - public function validate_currency( $validation, $currency ) { |
|
| 732 | + /** |
|
| 733 | + * Validate gateway currency |
|
| 734 | + * |
|
| 735 | + * @return bool |
|
| 736 | + */ |
|
| 737 | + public function validate_currency( $validation, $currency ) { |
|
| 738 | 738 | |
| 739 | - // Required currencies. |
|
| 740 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 741 | - return false; |
|
| 742 | - } |
|
| 739 | + // Required currencies. |
|
| 740 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 741 | + return false; |
|
| 742 | + } |
|
| 743 | 743 | |
| 744 | - // Excluded currencies. |
|
| 745 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 746 | - return false; |
|
| 747 | - } |
|
| 744 | + // Excluded currencies. |
|
| 745 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 746 | + return false; |
|
| 747 | + } |
|
| 748 | 748 | |
| 749 | - return $validation; |
|
| 750 | - } |
|
| 749 | + return $validation; |
|
| 750 | + } |
|
| 751 | 751 | |
| 752 | - /** |
|
| 753 | - * Displays an error |
|
| 754 | - * |
|
| 755 | - */ |
|
| 756 | - public function show_error( $code, $message, $type ) { |
|
| 752 | + /** |
|
| 753 | + * Displays an error |
|
| 754 | + * |
|
| 755 | + */ |
|
| 756 | + public function show_error( $code, $message, $type ) { |
|
| 757 | 757 | |
| 758 | - if ( is_admin() ) { |
|
| 759 | - getpaid_admin()->{"show_$type"}( $message ); |
|
| 760 | - } |
|
| 758 | + if ( is_admin() ) { |
|
| 759 | + getpaid_admin()->{"show_$type"}( $message ); |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - wpinv_set_error( $code, $message, $type ); |
|
| 762 | + wpinv_set_error( $code, $message, $type ); |
|
| 763 | 763 | |
| 764 | - } |
|
| 764 | + } |
|
| 765 | 765 | |
| 766 | 766 | } |
@@ -12,8 +12,8 @@ discard block |
||
| 12 | 12 | class WPInv_Subscriptions { |
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | - * Class constructor. |
|
| 16 | - */ |
|
| 15 | + * Class constructor. |
|
| 16 | + */ |
|
| 17 | 17 | public function __construct(){ |
| 18 | 18 | |
| 19 | 19 | // Fire gateway specific hooks when a subscription changes. |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | - * Processes subscription status changes. |
|
| 92 | + * Processes subscription status changes. |
|
| 93 | 93 | * |
| 94 | 94 | * @param WPInv_Subscription $subscription |
| 95 | 95 | * @param string $from |
| 96 | 96 | * @param string $to |
| 97 | - */ |
|
| 97 | + */ |
|
| 98 | 98 | public function process_subscription_status_change( $subscription, $from, $to ) { |
| 99 | 99 | |
| 100 | 100 | $gateway = $subscription->get_gateway(); |