@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | strpos($arg_key, 'PAYMENTREQUEST_') !== false |
| 82 | 82 | && strpos($arg_key, 'NOTIFYURL') === false |
| 83 | 83 | ) { |
| 84 | - $this->order_items[ $arg_key ] = $arg_val; |
|
| 84 | + $this->order_items[$arg_key] = $arg_val; |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | // If we only get a few Items then something is not right. |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | // Digital item is sold. |
| 181 | 181 | $this->order_items['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
| 182 | 182 | // Item's sales S/H and tax amount. |
| 183 | - $this->order_items['PAYMENTREQUEST_0_ITEMAMT'] = $this->gateway_data_formatter->formatCurrency( |
|
| 183 | + $this->order_items['PAYMENTREQUEST_0_ITEMAMT'] = $this->gateway_data_formatter->formatCurrency( |
|
| 184 | 184 | $this->payment->amount(), |
| 185 | 185 | $this->decimal_precision |
| 186 | 186 | ); |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | if (EEH_Money::compare_floats($line_item->pretaxTotal(), '0.00', '==')) { |
| 207 | 207 | continue; |
| 208 | 208 | } |
| 209 | - $unit_price = $this->gateway_data_formatter->formatCurrency( |
|
| 209 | + $unit_price = $this->gateway_data_formatter->formatCurrency( |
|
| 210 | 210 | $line_item->unit_price(), |
| 211 | 211 | $this->decimal_precision |
| 212 | 212 | ); |
@@ -217,25 +217,25 @@ discard block |
||
| 217 | 217 | $line_item_quantity = 1; |
| 218 | 218 | } |
| 219 | 219 | // Item Name. |
| 220 | - $this->order_items[ "L_PAYMENTREQUEST_0_NAME{$item_num}" ] = mb_strcut( |
|
| 220 | + $this->order_items["L_PAYMENTREQUEST_0_NAME{$item_num}"] = mb_strcut( |
|
| 221 | 221 | $this->gateway_data_formatter->formatLineItemName($line_item, $this->payment), |
| 222 | 222 | 0, |
| 223 | 223 | 127 |
| 224 | 224 | ); |
| 225 | 225 | // Item description. |
| 226 | - $this->order_items[ "L_PAYMENTREQUEST_0_DESC{$item_num}" ] = mb_strcut( |
|
| 226 | + $this->order_items["L_PAYMENTREQUEST_0_DESC{$item_num}"] = mb_strcut( |
|
| 227 | 227 | $this->gateway_data_formatter->formatLineItemDesc($line_item, $this->payment), |
| 228 | 228 | 0, |
| 229 | 229 | 127 |
| 230 | 230 | ); |
| 231 | 231 | // Cost of individual item. |
| 232 | - $this->order_items[ "L_PAYMENTREQUEST_0_AMT{$item_num}" ] = $unit_price; |
|
| 232 | + $this->order_items["L_PAYMENTREQUEST_0_AMT{$item_num}"] = $unit_price; |
|
| 233 | 233 | // Item Number. |
| 234 | - $this->order_items[ "L_PAYMENTREQUEST_0_NUMBER{$item_num}" ] = $item_num + 1; |
|
| 234 | + $this->order_items["L_PAYMENTREQUEST_0_NUMBER{$item_num}"] = $item_num + 1; |
|
| 235 | 235 | // Item quantity. |
| 236 | - $this->order_items[ "L_PAYMENTREQUEST_0_QTY{$item_num}" ] = $line_item_quantity; |
|
| 236 | + $this->order_items["L_PAYMENTREQUEST_0_QTY{$item_num}"] = $line_item_quantity; |
|
| 237 | 237 | // Digital item is sold. |
| 238 | - $this->order_items[ "L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}" ] = 'Physical'; |
|
| 238 | + $this->order_items["L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}"] = 'Physical'; |
|
| 239 | 239 | // add item total to order sum |
| 240 | 240 | $this->itemized_order_sum += $unit_price * $line_item_quantity; |
| 241 | 241 | ++$item_num; |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | // add the difference as an extra line item. |
| 282 | 282 | if (EEH_Money::compare_floats($itemized_order_sum_difference, 0, '!=')) { |
| 283 | 283 | // Item Name. |
| 284 | - $this->order_items[ "L_PAYMENTREQUEST_0_NAME{$item_num}" ] = mb_strcut( |
|
| 284 | + $this->order_items["L_PAYMENTREQUEST_0_NAME{$item_num}"] = mb_strcut( |
|
| 285 | 285 | esc_html__( |
| 286 | 286 | 'Other (promotion/surcharge/cancellation)', |
| 287 | 287 | 'event_espresso' |
@@ -290,18 +290,18 @@ discard block |
||
| 290 | 290 | 127 |
| 291 | 291 | ); |
| 292 | 292 | // Item description. |
| 293 | - $this->order_items[ "L_PAYMENTREQUEST_0_DESC{$item_num}" ] = ''; |
|
| 293 | + $this->order_items["L_PAYMENTREQUEST_0_DESC{$item_num}"] = ''; |
|
| 294 | 294 | // Cost of individual item. |
| 295 | - $this->order_items[ "L_PAYMENTREQUEST_0_AMT{$item_num}" ] = $this->gateway_data_formatter->formatCurrency( |
|
| 295 | + $this->order_items["L_PAYMENTREQUEST_0_AMT{$item_num}"] = $this->gateway_data_formatter->formatCurrency( |
|
| 296 | 296 | $itemized_order_sum_difference, |
| 297 | 297 | $this->decimal_precision |
| 298 | 298 | ); |
| 299 | 299 | // Item Number. |
| 300 | - $this->order_items[ "L_PAYMENTREQUEST_0_NUMBER{$item_num}" ] = $item_num + 1; |
|
| 300 | + $this->order_items["L_PAYMENTREQUEST_0_NUMBER{$item_num}"] = $item_num + 1; |
|
| 301 | 301 | // Item quantity. |
| 302 | - $this->order_items[ "L_PAYMENTREQUEST_0_QTY{$item_num}" ] = 1; |
|
| 302 | + $this->order_items["L_PAYMENTREQUEST_0_QTY{$item_num}"] = 1; |
|
| 303 | 303 | // Digital item is sold. |
| 304 | - $this->order_items[ "L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}" ] = 'Physical'; |
|
| 304 | + $this->order_items["L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}"] = 'Physical'; |
|
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | } |
@@ -14,292 +14,292 @@ |
||
| 14 | 14 | |
| 15 | 15 | class ItemizedOrder |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * number of decimal places to round numbers to when performing calculations |
|
| 19 | - * |
|
| 20 | - * @var integer |
|
| 21 | - */ |
|
| 22 | - protected $decimal_precision = 6; |
|
| 17 | + /** |
|
| 18 | + * number of decimal places to round numbers to when performing calculations |
|
| 19 | + * |
|
| 20 | + * @var integer |
|
| 21 | + */ |
|
| 22 | + protected $decimal_precision = 6; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var GatewayDataFormatterInterface |
|
| 26 | - */ |
|
| 27 | - protected $gateway_data_formatter; |
|
| 24 | + /** |
|
| 25 | + * @var GatewayDataFormatterInterface |
|
| 26 | + */ |
|
| 27 | + protected $gateway_data_formatter; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * keeps track of exactly how much the itemized order amount equals |
|
| 31 | - * |
|
| 32 | - * @var float |
|
| 33 | - */ |
|
| 34 | - private $itemized_order_sum = 0.00; |
|
| 29 | + /** |
|
| 30 | + * keeps track of exactly how much the itemized order amount equals |
|
| 31 | + * |
|
| 32 | + * @var float |
|
| 33 | + */ |
|
| 34 | + private $itemized_order_sum = 0.00; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - private $order_items; |
|
| 36 | + /** |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + private $order_items; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * the payment being processed |
|
| 43 | - * |
|
| 44 | - * @var EE_Payment |
|
| 45 | - */ |
|
| 46 | - protected $payment; |
|
| 41 | + /** |
|
| 42 | + * the payment being processed |
|
| 43 | + * |
|
| 44 | + * @var EE_Payment |
|
| 45 | + */ |
|
| 46 | + protected $payment; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var EE_Transaction |
|
| 50 | - */ |
|
| 51 | - private $transaction; |
|
| 48 | + /** |
|
| 49 | + * @var EE_Transaction |
|
| 50 | + */ |
|
| 51 | + private $transaction; |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 56 | - */ |
|
| 57 | - public function __construct(GatewayDataFormatterInterface $gateway_data_formatter) |
|
| 58 | - { |
|
| 59 | - $this->decimal_precision = EE_Registry::instance()->CFG->currency->dec_plc; |
|
| 60 | - $this->gateway_data_formatter = $gateway_data_formatter; |
|
| 61 | - $this->order_items = []; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 56 | + */ |
|
| 57 | + public function __construct(GatewayDataFormatterInterface $gateway_data_formatter) |
|
| 58 | + { |
|
| 59 | + $this->decimal_precision = EE_Registry::instance()->CFG->currency->dec_plc; |
|
| 60 | + $this->gateway_data_formatter = $gateway_data_formatter; |
|
| 61 | + $this->order_items = []; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param array $request_response_args |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function getExistingItemizedOrder(array $request_response_args): array |
|
| 70 | - { |
|
| 71 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 72 | - if ( |
|
| 73 | - ! empty($request_response_args) |
|
| 74 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 75 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 76 | - ) { |
|
| 77 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 78 | - if ( |
|
| 79 | - strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 80 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
| 81 | - ) { |
|
| 82 | - $this->order_items[ $arg_key ] = $arg_val; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - // If we only get a few Items then something is not right. |
|
| 86 | - if (count($this->order_items) < 3) { |
|
| 87 | - throw new RuntimeException( |
|
| 88 | - sprintf( |
|
| 89 | - esc_html__( |
|
| 90 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 91 | - 'event_espresso' |
|
| 92 | - ), |
|
| 93 | - wp_json_encode($this->order_items) |
|
| 94 | - ) |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - return $this->order_items; |
|
| 99 | - } |
|
| 65 | + /** |
|
| 66 | + * @param array $request_response_args |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function getExistingItemizedOrder(array $request_response_args): array |
|
| 70 | + { |
|
| 71 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 72 | + if ( |
|
| 73 | + ! empty($request_response_args) |
|
| 74 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 75 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 76 | + ) { |
|
| 77 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 78 | + if ( |
|
| 79 | + strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 80 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
| 81 | + ) { |
|
| 82 | + $this->order_items[ $arg_key ] = $arg_val; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + // If we only get a few Items then something is not right. |
|
| 86 | + if (count($this->order_items) < 3) { |
|
| 87 | + throw new RuntimeException( |
|
| 88 | + sprintf( |
|
| 89 | + esc_html__( |
|
| 90 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
| 91 | + 'event_espresso' |
|
| 92 | + ), |
|
| 93 | + wp_json_encode($this->order_items) |
|
| 94 | + ) |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + return $this->order_items; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Make a list of items that are in the giver transaction. |
|
| 104 | - * |
|
| 105 | - * @param EE_Payment $payment |
|
| 106 | - * @return array |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws ReflectionException |
|
| 109 | - */ |
|
| 110 | - public function generateItemizedOrder(EE_Payment $payment): array |
|
| 111 | - { |
|
| 112 | - $this->payment = $payment; |
|
| 113 | - $this->transaction = $this->payment->transaction(); |
|
| 114 | - // reset order items |
|
| 115 | - $this->order_items = []; |
|
| 116 | - if ($this->paymentIsForTransactionTotal()) { |
|
| 117 | - $this->itemizeOrderForFullPayment(); |
|
| 118 | - } else { |
|
| 119 | - $this->handlePartialPayment(); |
|
| 120 | - } |
|
| 121 | - return $this->order_items; |
|
| 122 | - } |
|
| 102 | + /** |
|
| 103 | + * Make a list of items that are in the giver transaction. |
|
| 104 | + * |
|
| 105 | + * @param EE_Payment $payment |
|
| 106 | + * @return array |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws ReflectionException |
|
| 109 | + */ |
|
| 110 | + public function generateItemizedOrder(EE_Payment $payment): array |
|
| 111 | + { |
|
| 112 | + $this->payment = $payment; |
|
| 113 | + $this->transaction = $this->payment->transaction(); |
|
| 114 | + // reset order items |
|
| 115 | + $this->order_items = []; |
|
| 116 | + if ($this->paymentIsForTransactionTotal()) { |
|
| 117 | + $this->itemizeOrderForFullPayment(); |
|
| 118 | + } else { |
|
| 119 | + $this->handlePartialPayment(); |
|
| 120 | + } |
|
| 121 | + return $this->order_items; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @return bool |
|
| 127 | - * @throws ReflectionException |
|
| 128 | - * @throws EE_Error |
|
| 129 | - */ |
|
| 130 | - private function paymentIsForTransactionTotal(): bool |
|
| 131 | - { |
|
| 132 | - return EEH_Money::compare_floats($this->payment->amount(), $this->transaction->total(), '=='); |
|
| 133 | - } |
|
| 125 | + /** |
|
| 126 | + * @return bool |
|
| 127 | + * @throws ReflectionException |
|
| 128 | + * @throws EE_Error |
|
| 129 | + */ |
|
| 130 | + private function paymentIsForTransactionTotal(): bool |
|
| 131 | + { |
|
| 132 | + return EEH_Money::compare_floats($this->payment->amount(), $this->transaction->total(), '=='); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @return void |
|
| 138 | - * @throws EE_Error |
|
| 139 | - * @throws ReflectionException |
|
| 140 | - */ |
|
| 141 | - private function itemizeOrderForFullPayment() |
|
| 142 | - { |
|
| 143 | - $item_num = 0; |
|
| 144 | - $total_line_item = $this->transaction->total_line_item(); |
|
| 145 | - $item_num = $this->addOrderItemsForLineItems($total_line_item, $item_num); |
|
| 146 | - $this->addOrderItemsForAdditionalCharges($total_line_item); |
|
| 147 | - $this->handleItemizedOrderSumDifference($total_line_item, $item_num); |
|
| 148 | - } |
|
| 136 | + /** |
|
| 137 | + * @return void |
|
| 138 | + * @throws EE_Error |
|
| 139 | + * @throws ReflectionException |
|
| 140 | + */ |
|
| 141 | + private function itemizeOrderForFullPayment() |
|
| 142 | + { |
|
| 143 | + $item_num = 0; |
|
| 144 | + $total_line_item = $this->transaction->total_line_item(); |
|
| 145 | + $item_num = $this->addOrderItemsForLineItems($total_line_item, $item_num); |
|
| 146 | + $this->addOrderItemsForAdditionalCharges($total_line_item); |
|
| 147 | + $this->handleItemizedOrderSumDifference($total_line_item, $item_num); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * @return void |
|
| 153 | - * @throws EE_Error |
|
| 154 | - */ |
|
| 155 | - private function handlePartialPayment() |
|
| 156 | - { |
|
| 157 | - // Item Name. |
|
| 158 | - $this->order_items['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 159 | - $this->gateway_data_formatter->formatPartialPaymentLineItemName($this->payment), |
|
| 160 | - 0, |
|
| 161 | - 127 |
|
| 162 | - ); |
|
| 163 | - // Item description. |
|
| 164 | - $this->order_items['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 165 | - $this->gateway_data_formatter->formatPartialPaymentLineItemDesc($this->payment), |
|
| 166 | - 0, |
|
| 167 | - 127 |
|
| 168 | - ); |
|
| 169 | - // Cost of individual item. |
|
| 170 | - $this->order_items['L_PAYMENTREQUEST_0_AMT0'] = $this->gateway_data_formatter->formatCurrency( |
|
| 171 | - $this->payment->amount(), |
|
| 172 | - $this->decimal_precision |
|
| 173 | - ); |
|
| 174 | - // Item Number. |
|
| 175 | - $this->order_items['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 176 | - // Item quantity. |
|
| 177 | - $this->order_items['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 178 | - // Digital item is sold. |
|
| 179 | - $this->order_items['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 180 | - // Item's sales S/H and tax amount. |
|
| 181 | - $this->order_items['PAYMENTREQUEST_0_ITEMAMT'] = $this->gateway_data_formatter->formatCurrency( |
|
| 182 | - $this->payment->amount(), |
|
| 183 | - $this->decimal_precision |
|
| 184 | - ); |
|
| 185 | - $this->order_items['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 186 | - $this->order_items['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 187 | - $this->order_items['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 188 | - } |
|
| 151 | + /** |
|
| 152 | + * @return void |
|
| 153 | + * @throws EE_Error |
|
| 154 | + */ |
|
| 155 | + private function handlePartialPayment() |
|
| 156 | + { |
|
| 157 | + // Item Name. |
|
| 158 | + $this->order_items['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 159 | + $this->gateway_data_formatter->formatPartialPaymentLineItemName($this->payment), |
|
| 160 | + 0, |
|
| 161 | + 127 |
|
| 162 | + ); |
|
| 163 | + // Item description. |
|
| 164 | + $this->order_items['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 165 | + $this->gateway_data_formatter->formatPartialPaymentLineItemDesc($this->payment), |
|
| 166 | + 0, |
|
| 167 | + 127 |
|
| 168 | + ); |
|
| 169 | + // Cost of individual item. |
|
| 170 | + $this->order_items['L_PAYMENTREQUEST_0_AMT0'] = $this->gateway_data_formatter->formatCurrency( |
|
| 171 | + $this->payment->amount(), |
|
| 172 | + $this->decimal_precision |
|
| 173 | + ); |
|
| 174 | + // Item Number. |
|
| 175 | + $this->order_items['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 176 | + // Item quantity. |
|
| 177 | + $this->order_items['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 178 | + // Digital item is sold. |
|
| 179 | + $this->order_items['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 180 | + // Item's sales S/H and tax amount. |
|
| 181 | + $this->order_items['PAYMENTREQUEST_0_ITEMAMT'] = $this->gateway_data_formatter->formatCurrency( |
|
| 182 | + $this->payment->amount(), |
|
| 183 | + $this->decimal_precision |
|
| 184 | + ); |
|
| 185 | + $this->order_items['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 186 | + $this->order_items['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 187 | + $this->order_items['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * @param EE_Line_Item $total_line_item |
|
| 193 | - * @param int $item_num |
|
| 194 | - * @return int |
|
| 195 | - * @throws EE_Error |
|
| 196 | - * @throws ReflectionException |
|
| 197 | - */ |
|
| 198 | - private function addOrderItemsForLineItems(EE_Line_Item $total_line_item, int $item_num): int |
|
| 199 | - { |
|
| 200 | - // Go through each item in the list. |
|
| 201 | - foreach ($total_line_item->get_items() as $line_item) { |
|
| 202 | - if ($line_item instanceof EE_Line_Item) { |
|
| 203 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 204 | - if (EEH_Money::compare_floats($line_item->pretaxTotal(), '0.00', '==')) { |
|
| 205 | - continue; |
|
| 206 | - } |
|
| 207 | - $unit_price = $this->gateway_data_formatter->formatCurrency( |
|
| 208 | - $line_item->unit_price(), |
|
| 209 | - $this->decimal_precision |
|
| 210 | - ); |
|
| 211 | - $line_item_quantity = $line_item->quantity(); |
|
| 212 | - // This is a discount. |
|
| 213 | - if ($line_item->is_percent()) { |
|
| 214 | - $unit_price = $line_item->pretaxTotal(); |
|
| 215 | - $line_item_quantity = 1; |
|
| 216 | - } |
|
| 217 | - // Item Name. |
|
| 218 | - $this->order_items[ "L_PAYMENTREQUEST_0_NAME{$item_num}" ] = mb_strcut( |
|
| 219 | - $this->gateway_data_formatter->formatLineItemName($line_item, $this->payment), |
|
| 220 | - 0, |
|
| 221 | - 127 |
|
| 222 | - ); |
|
| 223 | - // Item description. |
|
| 224 | - $this->order_items[ "L_PAYMENTREQUEST_0_DESC{$item_num}" ] = mb_strcut( |
|
| 225 | - $this->gateway_data_formatter->formatLineItemDesc($line_item, $this->payment), |
|
| 226 | - 0, |
|
| 227 | - 127 |
|
| 228 | - ); |
|
| 229 | - // Cost of individual item. |
|
| 230 | - $this->order_items[ "L_PAYMENTREQUEST_0_AMT{$item_num}" ] = $unit_price; |
|
| 231 | - // Item Number. |
|
| 232 | - $this->order_items[ "L_PAYMENTREQUEST_0_NUMBER{$item_num}" ] = $item_num + 1; |
|
| 233 | - // Item quantity. |
|
| 234 | - $this->order_items[ "L_PAYMENTREQUEST_0_QTY{$item_num}" ] = $line_item_quantity; |
|
| 235 | - // Digital item is sold. |
|
| 236 | - $this->order_items[ "L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}" ] = 'Physical'; |
|
| 237 | - // add item total to order sum |
|
| 238 | - $this->itemized_order_sum += $unit_price * $line_item_quantity; |
|
| 239 | - ++$item_num; |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - return $item_num; |
|
| 243 | - } |
|
| 191 | + /** |
|
| 192 | + * @param EE_Line_Item $total_line_item |
|
| 193 | + * @param int $item_num |
|
| 194 | + * @return int |
|
| 195 | + * @throws EE_Error |
|
| 196 | + * @throws ReflectionException |
|
| 197 | + */ |
|
| 198 | + private function addOrderItemsForLineItems(EE_Line_Item $total_line_item, int $item_num): int |
|
| 199 | + { |
|
| 200 | + // Go through each item in the list. |
|
| 201 | + foreach ($total_line_item->get_items() as $line_item) { |
|
| 202 | + if ($line_item instanceof EE_Line_Item) { |
|
| 203 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 204 | + if (EEH_Money::compare_floats($line_item->pretaxTotal(), '0.00', '==')) { |
|
| 205 | + continue; |
|
| 206 | + } |
|
| 207 | + $unit_price = $this->gateway_data_formatter->formatCurrency( |
|
| 208 | + $line_item->unit_price(), |
|
| 209 | + $this->decimal_precision |
|
| 210 | + ); |
|
| 211 | + $line_item_quantity = $line_item->quantity(); |
|
| 212 | + // This is a discount. |
|
| 213 | + if ($line_item->is_percent()) { |
|
| 214 | + $unit_price = $line_item->pretaxTotal(); |
|
| 215 | + $line_item_quantity = 1; |
|
| 216 | + } |
|
| 217 | + // Item Name. |
|
| 218 | + $this->order_items[ "L_PAYMENTREQUEST_0_NAME{$item_num}" ] = mb_strcut( |
|
| 219 | + $this->gateway_data_formatter->formatLineItemName($line_item, $this->payment), |
|
| 220 | + 0, |
|
| 221 | + 127 |
|
| 222 | + ); |
|
| 223 | + // Item description. |
|
| 224 | + $this->order_items[ "L_PAYMENTREQUEST_0_DESC{$item_num}" ] = mb_strcut( |
|
| 225 | + $this->gateway_data_formatter->formatLineItemDesc($line_item, $this->payment), |
|
| 226 | + 0, |
|
| 227 | + 127 |
|
| 228 | + ); |
|
| 229 | + // Cost of individual item. |
|
| 230 | + $this->order_items[ "L_PAYMENTREQUEST_0_AMT{$item_num}" ] = $unit_price; |
|
| 231 | + // Item Number. |
|
| 232 | + $this->order_items[ "L_PAYMENTREQUEST_0_NUMBER{$item_num}" ] = $item_num + 1; |
|
| 233 | + // Item quantity. |
|
| 234 | + $this->order_items[ "L_PAYMENTREQUEST_0_QTY{$item_num}" ] = $line_item_quantity; |
|
| 235 | + // Digital item is sold. |
|
| 236 | + $this->order_items[ "L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}" ] = 'Physical'; |
|
| 237 | + // add item total to order sum |
|
| 238 | + $this->itemized_order_sum += $unit_price * $line_item_quantity; |
|
| 239 | + ++$item_num; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + return $item_num; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * @param EE_Line_Item $total_line_item |
|
| 248 | - * @return void |
|
| 249 | - * @throws EE_Error |
|
| 250 | - * @throws ReflectionException |
|
| 251 | - */ |
|
| 252 | - private function addOrderItemsForAdditionalCharges(EE_Line_Item $total_line_item) |
|
| 253 | - { |
|
| 254 | - // Item's sales S/H and tax amount. |
|
| 255 | - $this->order_items['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_item->get_items_total(); |
|
| 256 | - $this->order_items['PAYMENTREQUEST_0_TAXAMT'] = $total_line_item->get_total_tax(); |
|
| 257 | - $this->order_items['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 258 | - $this->order_items['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 259 | - } |
|
| 246 | + /** |
|
| 247 | + * @param EE_Line_Item $total_line_item |
|
| 248 | + * @return void |
|
| 249 | + * @throws EE_Error |
|
| 250 | + * @throws ReflectionException |
|
| 251 | + */ |
|
| 252 | + private function addOrderItemsForAdditionalCharges(EE_Line_Item $total_line_item) |
|
| 253 | + { |
|
| 254 | + // Item's sales S/H and tax amount. |
|
| 255 | + $this->order_items['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_item->get_items_total(); |
|
| 256 | + $this->order_items['PAYMENTREQUEST_0_TAXAMT'] = $total_line_item->get_total_tax(); |
|
| 257 | + $this->order_items['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 258 | + $this->order_items['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * @param EE_Line_Item $total_line_item |
|
| 264 | - * @param int $item_num |
|
| 265 | - * @return void |
|
| 266 | - * @throws EE_Error |
|
| 267 | - * @throws ReflectionException |
|
| 268 | - */ |
|
| 269 | - private function handleItemizedOrderSumDifference(EE_Line_Item $total_line_item, int $item_num) |
|
| 270 | - { |
|
| 271 | - // calculate the difference between the TXN total and the itemized order sum |
|
| 272 | - $itemized_order_sum_difference = round( |
|
| 273 | - $this->transaction->total() |
|
| 274 | - - $this->itemized_order_sum |
|
| 275 | - - $total_line_item->get_total_tax(), |
|
| 276 | - $this->decimal_precision |
|
| 277 | - ); |
|
| 278 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 279 | - // add the difference as an extra line item. |
|
| 280 | - if (EEH_Money::compare_floats($itemized_order_sum_difference, 0, '!=')) { |
|
| 281 | - // Item Name. |
|
| 282 | - $this->order_items[ "L_PAYMENTREQUEST_0_NAME{$item_num}" ] = mb_strcut( |
|
| 283 | - esc_html__( |
|
| 284 | - 'Other (promotion/surcharge/cancellation)', |
|
| 285 | - 'event_espresso' |
|
| 286 | - ), |
|
| 287 | - 0, |
|
| 288 | - 127 |
|
| 289 | - ); |
|
| 290 | - // Item description. |
|
| 291 | - $this->order_items[ "L_PAYMENTREQUEST_0_DESC{$item_num}" ] = ''; |
|
| 292 | - // Cost of individual item. |
|
| 293 | - $this->order_items[ "L_PAYMENTREQUEST_0_AMT{$item_num}" ] = $this->gateway_data_formatter->formatCurrency( |
|
| 294 | - $itemized_order_sum_difference, |
|
| 295 | - $this->decimal_precision |
|
| 296 | - ); |
|
| 297 | - // Item Number. |
|
| 298 | - $this->order_items[ "L_PAYMENTREQUEST_0_NUMBER{$item_num}" ] = $item_num + 1; |
|
| 299 | - // Item quantity. |
|
| 300 | - $this->order_items[ "L_PAYMENTREQUEST_0_QTY{$item_num}" ] = 1; |
|
| 301 | - // Digital item is sold. |
|
| 302 | - $this->order_items[ "L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}" ] = 'Physical'; |
|
| 303 | - } |
|
| 304 | - } |
|
| 262 | + /** |
|
| 263 | + * @param EE_Line_Item $total_line_item |
|
| 264 | + * @param int $item_num |
|
| 265 | + * @return void |
|
| 266 | + * @throws EE_Error |
|
| 267 | + * @throws ReflectionException |
|
| 268 | + */ |
|
| 269 | + private function handleItemizedOrderSumDifference(EE_Line_Item $total_line_item, int $item_num) |
|
| 270 | + { |
|
| 271 | + // calculate the difference between the TXN total and the itemized order sum |
|
| 272 | + $itemized_order_sum_difference = round( |
|
| 273 | + $this->transaction->total() |
|
| 274 | + - $this->itemized_order_sum |
|
| 275 | + - $total_line_item->get_total_tax(), |
|
| 276 | + $this->decimal_precision |
|
| 277 | + ); |
|
| 278 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 279 | + // add the difference as an extra line item. |
|
| 280 | + if (EEH_Money::compare_floats($itemized_order_sum_difference, 0, '!=')) { |
|
| 281 | + // Item Name. |
|
| 282 | + $this->order_items[ "L_PAYMENTREQUEST_0_NAME{$item_num}" ] = mb_strcut( |
|
| 283 | + esc_html__( |
|
| 284 | + 'Other (promotion/surcharge/cancellation)', |
|
| 285 | + 'event_espresso' |
|
| 286 | + ), |
|
| 287 | + 0, |
|
| 288 | + 127 |
|
| 289 | + ); |
|
| 290 | + // Item description. |
|
| 291 | + $this->order_items[ "L_PAYMENTREQUEST_0_DESC{$item_num}" ] = ''; |
|
| 292 | + // Cost of individual item. |
|
| 293 | + $this->order_items[ "L_PAYMENTREQUEST_0_AMT{$item_num}" ] = $this->gateway_data_formatter->formatCurrency( |
|
| 294 | + $itemized_order_sum_difference, |
|
| 295 | + $this->decimal_precision |
|
| 296 | + ); |
|
| 297 | + // Item Number. |
|
| 298 | + $this->order_items[ "L_PAYMENTREQUEST_0_NUMBER{$item_num}" ] = $item_num + 1; |
|
| 299 | + // Item quantity. |
|
| 300 | + $this->order_items[ "L_PAYMENTREQUEST_0_QTY{$item_num}" ] = 1; |
|
| 301 | + // Digital item is sold. |
|
| 302 | + $this->order_items[ "L_PAYMENTREQUEST_0_ITEMCATEGORY{$item_num}" ] = 'Physical'; |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | 305 | } |
@@ -13,124 +13,124 @@ |
||
| 13 | 13 | class TokenRequest |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var GatewayDataFormatterInterface |
|
| 18 | - */ |
|
| 19 | - protected $gateway_data_formatter; |
|
| 16 | + /** |
|
| 17 | + * @var GatewayDataFormatterInterface |
|
| 18 | + */ |
|
| 19 | + protected $gateway_data_formatter; |
|
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 24 | - */ |
|
| 25 | - public function __construct(GatewayDataFormatterInterface $gateway_data_formatter) |
|
| 26 | - { |
|
| 27 | - $this->gateway_data_formatter = $gateway_data_formatter; |
|
| 28 | - } |
|
| 22 | + /** |
|
| 23 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 24 | + */ |
|
| 25 | + public function __construct(GatewayDataFormatterInterface $gateway_data_formatter) |
|
| 26 | + { |
|
| 27 | + $this->gateway_data_formatter = $gateway_data_formatter; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param EE_Payment $payment |
|
| 33 | - * @param array $itemized_order |
|
| 34 | - * @param string $return_url |
|
| 35 | - * @param string $cancel_url |
|
| 36 | - * @param string $logo_image_url |
|
| 37 | - * @param bool $request_shipping_address |
|
| 38 | - * @return array |
|
| 39 | - * @throws EE_Error |
|
| 40 | - * @throws ReflectionException |
|
| 41 | - */ |
|
| 42 | - public function generateDetails( |
|
| 43 | - EE_Payment $payment, |
|
| 44 | - array $itemized_order = [], |
|
| 45 | - string $return_url = '', |
|
| 46 | - string $cancel_url = '', |
|
| 47 | - string $logo_image_url = '', |
|
| 48 | - bool $request_shipping_address = false |
|
| 49 | - ): array { |
|
| 50 | - $locale = explode('-', get_bloginfo('language')); |
|
| 51 | - // Gather request parameters. |
|
| 52 | - $token_request_details = [ |
|
| 53 | - 'METHOD' => 'SetExpressCheckout', |
|
| 54 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 55 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 56 | - 'PAYMENTREQUEST_0_DESC' => mb_strcut( |
|
| 57 | - $this->gateway_data_formatter->formatOrderDescription($payment), |
|
| 58 | - 0, |
|
| 59 | - 127 |
|
| 60 | - ), |
|
| 61 | - 'RETURNURL' => $return_url, |
|
| 62 | - 'CANCELURL' => $cancel_url, |
|
| 63 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 64 | - // Buyer does not need to create a PayPal account to check out. |
|
| 65 | - // This is referred to as PayPal Account Optional. |
|
| 66 | - 'SOLUTIONTYPE' => 'Sole', |
|
| 67 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 68 | - 'LOCALECODE' => $locale[1], |
|
| 69 | - ]; |
|
| 70 | - $token_request_details = array_merge($token_request_details, $itemized_order); |
|
| 71 | - if (! $request_shipping_address) { |
|
| 72 | - // Do not request shipping details on the PP Checkout page. |
|
| 73 | - $token_request_details['NOSHIPPING'] = '1'; |
|
| 74 | - $token_request_details['REQCONFIRMSHIPPING'] = '0'; |
|
| 75 | - } else { |
|
| 76 | - // Automatically filling out shipping and contact information. |
|
| 77 | - $transaction = $payment->transaction(); |
|
| 78 | - $primary_registration = $transaction->primary_registration(); |
|
| 79 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 80 | - ? $primary_registration->attendee() |
|
| 81 | - : false; |
|
| 82 | - if ($primary_attendee instanceof EE_Attendee) { |
|
| 83 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 84 | - $token_request_details['NOSHIPPING'] = '2'; |
|
| 85 | - $token_request_details['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 86 | - $token_request_details['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 87 | - $token_request_details['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 88 | - $token_request_details['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 89 | - $token_request_details['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 90 | - $token_request_details['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 91 | - $token_request_details['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 92 | - $token_request_details['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - // Used a business/personal logo on the PayPal page. |
|
| 96 | - if (! empty($logo_image_url)) { |
|
| 97 | - $token_request_details['LOGOIMG'] = $logo_image_url; |
|
| 98 | - } |
|
| 99 | - return $token_request_details; |
|
| 100 | - } |
|
| 31 | + /** |
|
| 32 | + * @param EE_Payment $payment |
|
| 33 | + * @param array $itemized_order |
|
| 34 | + * @param string $return_url |
|
| 35 | + * @param string $cancel_url |
|
| 36 | + * @param string $logo_image_url |
|
| 37 | + * @param bool $request_shipping_address |
|
| 38 | + * @return array |
|
| 39 | + * @throws EE_Error |
|
| 40 | + * @throws ReflectionException |
|
| 41 | + */ |
|
| 42 | + public function generateDetails( |
|
| 43 | + EE_Payment $payment, |
|
| 44 | + array $itemized_order = [], |
|
| 45 | + string $return_url = '', |
|
| 46 | + string $cancel_url = '', |
|
| 47 | + string $logo_image_url = '', |
|
| 48 | + bool $request_shipping_address = false |
|
| 49 | + ): array { |
|
| 50 | + $locale = explode('-', get_bloginfo('language')); |
|
| 51 | + // Gather request parameters. |
|
| 52 | + $token_request_details = [ |
|
| 53 | + 'METHOD' => 'SetExpressCheckout', |
|
| 54 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 55 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 56 | + 'PAYMENTREQUEST_0_DESC' => mb_strcut( |
|
| 57 | + $this->gateway_data_formatter->formatOrderDescription($payment), |
|
| 58 | + 0, |
|
| 59 | + 127 |
|
| 60 | + ), |
|
| 61 | + 'RETURNURL' => $return_url, |
|
| 62 | + 'CANCELURL' => $cancel_url, |
|
| 63 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 64 | + // Buyer does not need to create a PayPal account to check out. |
|
| 65 | + // This is referred to as PayPal Account Optional. |
|
| 66 | + 'SOLUTIONTYPE' => 'Sole', |
|
| 67 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 68 | + 'LOCALECODE' => $locale[1], |
|
| 69 | + ]; |
|
| 70 | + $token_request_details = array_merge($token_request_details, $itemized_order); |
|
| 71 | + if (! $request_shipping_address) { |
|
| 72 | + // Do not request shipping details on the PP Checkout page. |
|
| 73 | + $token_request_details['NOSHIPPING'] = '1'; |
|
| 74 | + $token_request_details['REQCONFIRMSHIPPING'] = '0'; |
|
| 75 | + } else { |
|
| 76 | + // Automatically filling out shipping and contact information. |
|
| 77 | + $transaction = $payment->transaction(); |
|
| 78 | + $primary_registration = $transaction->primary_registration(); |
|
| 79 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
| 80 | + ? $primary_registration->attendee() |
|
| 81 | + : false; |
|
| 82 | + if ($primary_attendee instanceof EE_Attendee) { |
|
| 83 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 84 | + $token_request_details['NOSHIPPING'] = '2'; |
|
| 85 | + $token_request_details['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 86 | + $token_request_details['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 87 | + $token_request_details['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 88 | + $token_request_details['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 89 | + $token_request_details['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 90 | + $token_request_details['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 91 | + $token_request_details['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 92 | + $token_request_details['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + // Used a business/personal logo on the PayPal page. |
|
| 96 | + if (! empty($logo_image_url)) { |
|
| 97 | + $token_request_details['LOGOIMG'] = $logo_image_url; |
|
| 98 | + } |
|
| 99 | + return $token_request_details; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @param EE_Payment $payment |
|
| 105 | - * @param array $token_request_status |
|
| 106 | - * @param bool $is_in_sandbox_mode |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws ReflectionException |
|
| 109 | - */ |
|
| 110 | - public function processResponse(EE_Payment $payment, array $token_request_status, bool $is_in_sandbox_mode) |
|
| 111 | - { |
|
| 112 | - $response_args = (isset($token_request_status['args']) && is_array($token_request_status['args'])) |
|
| 113 | - ? $token_request_status['args'] |
|
| 114 | - : []; |
|
| 115 | - if ($token_request_status['status']) { |
|
| 116 | - // We got the Token so we may continue with the payment and redirect the client. |
|
| 117 | - $payment->set_details($response_args); |
|
| 118 | - $gateway_url = $is_in_sandbox_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 119 | - $token = $response_args['TOKEN']; |
|
| 120 | - $payment->set_redirect_url( |
|
| 121 | - "{$gateway_url}/checkoutnow?useraction=commit&cmd=_express-checkout&token={$token}" |
|
| 122 | - ); |
|
| 123 | - return; |
|
| 124 | - } |
|
| 125 | - $gateway_response = isset($response_args['L_ERRORCODE']) |
|
| 126 | - ? $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] |
|
| 127 | - : esc_html__( |
|
| 128 | - 'Error occurred while trying to setup the Express Checkout.', |
|
| 129 | - 'event_espresso' |
|
| 130 | - ); |
|
| 103 | + /** |
|
| 104 | + * @param EE_Payment $payment |
|
| 105 | + * @param array $token_request_status |
|
| 106 | + * @param bool $is_in_sandbox_mode |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws ReflectionException |
|
| 109 | + */ |
|
| 110 | + public function processResponse(EE_Payment $payment, array $token_request_status, bool $is_in_sandbox_mode) |
|
| 111 | + { |
|
| 112 | + $response_args = (isset($token_request_status['args']) && is_array($token_request_status['args'])) |
|
| 113 | + ? $token_request_status['args'] |
|
| 114 | + : []; |
|
| 115 | + if ($token_request_status['status']) { |
|
| 116 | + // We got the Token so we may continue with the payment and redirect the client. |
|
| 117 | + $payment->set_details($response_args); |
|
| 118 | + $gateway_url = $is_in_sandbox_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 119 | + $token = $response_args['TOKEN']; |
|
| 120 | + $payment->set_redirect_url( |
|
| 121 | + "{$gateway_url}/checkoutnow?useraction=commit&cmd=_express-checkout&token={$token}" |
|
| 122 | + ); |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | + $gateway_response = isset($response_args['L_ERRORCODE']) |
|
| 126 | + ? $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] |
|
| 127 | + : esc_html__( |
|
| 128 | + 'Error occurred while trying to setup the Express Checkout.', |
|
| 129 | + 'event_espresso' |
|
| 130 | + ); |
|
| 131 | 131 | |
| 132 | - $payment->set_gateway_response($gateway_response); |
|
| 133 | - $payment->set_details($response_args); |
|
| 134 | - $payment->set_status(EEM_Payment::instance()->failed_status()); |
|
| 135 | - } |
|
| 132 | + $payment->set_gateway_response($gateway_response); |
|
| 133 | + $payment->set_details($response_args); |
|
| 134 | + $payment->set_status(EEM_Payment::instance()->failed_status()); |
|
| 135 | + } |
|
| 136 | 136 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | 'LOCALECODE' => $locale[1], |
| 69 | 69 | ]; |
| 70 | 70 | $token_request_details = array_merge($token_request_details, $itemized_order); |
| 71 | - if (! $request_shipping_address) { |
|
| 71 | + if ( ! $request_shipping_address) { |
|
| 72 | 72 | // Do not request shipping details on the PP Checkout page. |
| 73 | 73 | $token_request_details['NOSHIPPING'] = '1'; |
| 74 | 74 | $token_request_details['REQCONFIRMSHIPPING'] = '0'; |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | // Used a business/personal logo on the PayPal page. |
| 96 | - if (! empty($logo_image_url)) { |
|
| 96 | + if ( ! empty($logo_image_url)) { |
|
| 97 | 97 | $token_request_details['LOGOIMG'] = $logo_image_url; |
| 98 | 98 | } |
| 99 | 99 | return $token_request_details; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | return; |
| 124 | 124 | } |
| 125 | 125 | $gateway_response = isset($response_args['L_ERRORCODE']) |
| 126 | - ? $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] |
|
| 126 | + ? $response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE'] |
|
| 127 | 127 | : esc_html__( |
| 128 | 128 | 'Error occurred while trying to setup the Express Checkout.', |
| 129 | 129 | 'event_espresso' |
@@ -1,18 +1,18 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (! function_exists('mb_strcut')) { |
| 4 | - /** |
|
| 5 | - * Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
|
| 6 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 7 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 8 | - * |
|
| 9 | - * @param $string |
|
| 10 | - * @param $start |
|
| 11 | - * @param $length |
|
| 12 | - * @return string |
|
| 13 | - */ |
|
| 14 | - function mb_strcut($string, $start, $length = null): string |
|
| 15 | - { |
|
| 16 | - return mb_substr($string, $start, $length); |
|
| 17 | - } |
|
| 4 | + /** |
|
| 5 | + * Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
|
| 6 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
| 7 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
| 8 | + * |
|
| 9 | + * @param $string |
|
| 10 | + * @param $start |
|
| 11 | + * @param $length |
|
| 12 | + * @return string |
|
| 13 | + */ |
|
| 14 | + function mb_strcut($string, $start, $length = null): string |
|
| 15 | + { |
|
| 16 | + return mb_substr($string, $start, $length); |
|
| 17 | + } |
|
| 18 | 18 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! function_exists('mb_strcut')) { |
|
| 3 | +if ( ! function_exists('mb_strcut')) { |
|
| 4 | 4 | /** |
| 5 | 5 | * Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 6 | 6 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
@@ -229,12 +229,12 @@ discard block |
||
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
| 232 | - if (! $payment instanceof EEI_Payment) { |
|
| 232 | + if ( ! $payment instanceof EEI_Payment) { |
|
| 233 | 233 | $payment = $transaction->last_payment(); |
| 234 | 234 | } |
| 235 | 235 | // ok, then validate the IPN. Even if we've already processed this payment, |
| 236 | 236 | // let PayPal know we don't want to hear from them anymore! |
| 237 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
| 237 | + if ( ! $this->validate_ipn($update_info, $payment)) { |
|
| 238 | 238 | return $payment; |
| 239 | 239 | } |
| 240 | 240 | // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | foreach ($raw_post_array as $keyval) { |
| 375 | 375 | $keyval = explode('=', $keyval); |
| 376 | 376 | if (count($keyval) === 2) { |
| 377 | - $update_info[ $keyval[0] ] = urldecode($keyval[1]); |
|
| 377 | + $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | 'timeout' => 60, |
| 394 | 394 | // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
| 395 | 395 | // plz see: https://github.com/websharks/s2member/issues/610 |
| 396 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
| 396 | + 'user-agent' => 'Event Espresso v'.EVENT_ESPRESSO_VERSION.'; '.home_url(), |
|
| 397 | 397 | 'httpversion' => '1.1' |
| 398 | 398 | ) |
| 399 | 399 | ); |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | /** @var EE_Transaction $transaction */ |
| 472 | 472 | $transaction = $payment->transaction(); |
| 473 | 473 | $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
| 474 | - if (! $transaction) { |
|
| 474 | + if ( ! $transaction) { |
|
| 475 | 475 | $this->log( |
| 476 | 476 | esc_html__( |
| 477 | 477 | // @codingStandardsIgnoreStart |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
| 547 | 547 | 1, |
| 548 | 548 | false, |
| 549 | - 'paypal_shipping_' . $transaction->ID() |
|
| 549 | + 'paypal_shipping_'.$transaction->ID() |
|
| 550 | 550 | ); |
| 551 | 551 | $grand_total_needs_resaving = true; |
| 552 | 552 | } |
@@ -19,554 +19,554 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class EEG_Paypal_Standard extends EE_Offsite_Gateway |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Name for the wp option used to save the itemized payment |
|
| 24 | - */ |
|
| 25 | - const itemized_payment_option_name = '_itemized_payment'; |
|
| 26 | - |
|
| 27 | - protected $_paypal_id; |
|
| 28 | - |
|
| 29 | - protected $_image_url; |
|
| 30 | - |
|
| 31 | - protected $_shipping_details; |
|
| 32 | - |
|
| 33 | - protected $_paypal_shipping; |
|
| 34 | - |
|
| 35 | - protected $_paypal_taxes; |
|
| 36 | - |
|
| 37 | - protected $_gateway_url; |
|
| 38 | - |
|
| 39 | - protected $_currencies_supported = array( |
|
| 40 | - 'USD', |
|
| 41 | - 'GBP', |
|
| 42 | - 'CAD', |
|
| 43 | - 'AUD', |
|
| 44 | - 'BRL', |
|
| 45 | - 'CHF', |
|
| 46 | - 'CZK', |
|
| 47 | - 'DKK', |
|
| 48 | - 'EUR', |
|
| 49 | - 'HKD', |
|
| 50 | - 'HUF', |
|
| 51 | - 'ILS', |
|
| 52 | - 'JPY', |
|
| 53 | - 'MXN', |
|
| 54 | - 'MYR', |
|
| 55 | - 'NOK', |
|
| 56 | - 'NZD', |
|
| 57 | - 'PHP', |
|
| 58 | - 'PLN', |
|
| 59 | - 'SEK', |
|
| 60 | - 'SGD', |
|
| 61 | - 'THB', |
|
| 62 | - 'TRY', |
|
| 63 | - 'TWD', |
|
| 64 | - 'RUB' |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var ItemizedOrder |
|
| 69 | - * @since $VID:$ |
|
| 70 | - */ |
|
| 71 | - protected $itemized_order; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * EEG_Paypal_Standard constructor. |
|
| 76 | - */ |
|
| 77 | - public function __construct() |
|
| 78 | - { |
|
| 79 | - $this->set_uses_separate_IPN_request(true); |
|
| 80 | - parent::__construct(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return mixed |
|
| 86 | - */ |
|
| 87 | - public function gatewayUrl() |
|
| 88 | - { |
|
| 89 | - return $this->_gateway_url; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @return mixed |
|
| 95 | - */ |
|
| 96 | - public function imageUrl() |
|
| 97 | - { |
|
| 98 | - return $this->_image_url; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return mixed |
|
| 104 | - */ |
|
| 105 | - public function paypalId() |
|
| 106 | - { |
|
| 107 | - return $this->_paypal_id; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return mixed |
|
| 113 | - */ |
|
| 114 | - public function paypalShipping() |
|
| 115 | - { |
|
| 116 | - return $this->_paypal_shipping; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @return mixed |
|
| 123 | - */ |
|
| 124 | - public function paypalTaxes() |
|
| 125 | - { |
|
| 126 | - return $this->_paypal_taxes; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return mixed |
|
| 132 | - */ |
|
| 133 | - public function shippingDetails() |
|
| 134 | - { |
|
| 135 | - return $this->_shipping_details; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
| 141 | - * |
|
| 142 | - * @param array $settings_array |
|
| 143 | - */ |
|
| 144 | - public function set_settings($settings_array) |
|
| 145 | - { |
|
| 146 | - parent::set_settings($settings_array); |
|
| 147 | - $this->_gateway_url = $this->_debug_mode |
|
| 148 | - ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
| 149 | - : 'https://www.paypal.com/cgi-bin/webscr'; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param EEI_Payment $payment the payment to process |
|
| 155 | - * @param array $billing_info but should be empty for this gateway |
|
| 156 | - * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
| 157 | - * @param string $notify_url URL to send the instant payment notification |
|
| 158 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
| 159 | - * on the payment provider's website |
|
| 160 | - * @return EEI_Payment |
|
| 161 | - * @throws EE_Error |
|
| 162 | - * @throws ReflectionException |
|
| 163 | - */ |
|
| 164 | - public function set_redirection_info( |
|
| 165 | - $payment, |
|
| 166 | - $billing_info = array(), |
|
| 167 | - $return_url = null, |
|
| 168 | - $notify_url = null, |
|
| 169 | - $cancel_url = null |
|
| 170 | - ) { |
|
| 171 | - $this->itemized_order = new ItemizedOrder($this->_get_gateway_formatter(), $this); |
|
| 172 | - $redirect_args = apply_filters( |
|
| 173 | - "FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", |
|
| 174 | - $this->itemized_order->generateItemizedOrderForPayment( |
|
| 175 | - $payment, |
|
| 176 | - $return_url, |
|
| 177 | - $notify_url, |
|
| 178 | - $cancel_url |
|
| 179 | - ), |
|
| 180 | - $this |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - $payment->set_redirect_url($this->_gateway_url); |
|
| 184 | - $payment->set_redirect_args($redirect_args); |
|
| 185 | - // log the results |
|
| 186 | - $this->log( |
|
| 187 | - [ |
|
| 188 | - 'message' => esc_html__('PayPal payment request initiated.', 'event_espresso'), |
|
| 189 | - 'transaction' => $payment->transaction()->model_field_array(), |
|
| 190 | - ], |
|
| 191 | - $payment |
|
| 192 | - ); |
|
| 193 | - return $payment; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Often used for IPNs. But applies the info in $update_info to the payment. |
|
| 199 | - * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
| 200 | - * the payment method passes in. |
|
| 201 | - * |
|
| 202 | - * @param array $update_info like $_POST |
|
| 203 | - * @param EEI_Transaction $transaction |
|
| 204 | - * @return EEI_Payment updated |
|
| 205 | - * @throws EE_Error, IpnException |
|
| 206 | - */ |
|
| 207 | - public function handle_payment_update($update_info, $transaction) |
|
| 208 | - { |
|
| 209 | - // verify there's payment data that's been sent |
|
| 210 | - if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
| 211 | - // log the results |
|
| 212 | - $this->log( |
|
| 213 | - array( |
|
| 214 | - 'message' => esc_html__( |
|
| 215 | - 'PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', |
|
| 216 | - 'event_espresso' |
|
| 217 | - ), |
|
| 218 | - 'update_info' => $update_info, |
|
| 219 | - ), |
|
| 220 | - $transaction |
|
| 221 | - ); |
|
| 222 | - // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
| 223 | - // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
| 224 | - if (isset($update_info['tx'])) { |
|
| 225 | - return $transaction->last_payment(); |
|
| 226 | - } else { |
|
| 227 | - return null; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
| 231 | - if (! $payment instanceof EEI_Payment) { |
|
| 232 | - $payment = $transaction->last_payment(); |
|
| 233 | - } |
|
| 234 | - // ok, then validate the IPN. Even if we've already processed this payment, |
|
| 235 | - // let PayPal know we don't want to hear from them anymore! |
|
| 236 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
| 237 | - return $payment; |
|
| 238 | - } |
|
| 239 | - // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
| 240 | - // registrations, ticket counts, etc) |
|
| 241 | - if ( |
|
| 242 | - ( |
|
| 243 | - $update_info['payment_status'] === 'Refunded' |
|
| 244 | - || $update_info['payment_status'] === 'Partially_Refunded' |
|
| 245 | - ) |
|
| 246 | - && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
| 247 | - ) { |
|
| 248 | - throw new EventEspresso\core\exceptions\IpnException( |
|
| 249 | - sprintf( |
|
| 250 | - esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
| 251 | - $update_info['payment_status'] |
|
| 252 | - ), |
|
| 253 | - EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
| 254 | - null, |
|
| 255 | - $payment, |
|
| 256 | - $update_info |
|
| 257 | - ); |
|
| 258 | - } |
|
| 259 | - // ok, well let's process this payment then! |
|
| 260 | - switch ($update_info['payment_status']) { |
|
| 261 | - case 'Completed': |
|
| 262 | - $status = $this->_pay_model->approved_status(); |
|
| 263 | - $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
| 264 | - break; |
|
| 265 | - |
|
| 266 | - case 'Pending': |
|
| 267 | - $status = $this->_pay_model->pending_status(); |
|
| 268 | - $gateway_response = esc_html__( |
|
| 269 | - 'The payment is in progress. Another message will be sent when payment is approved.', |
|
| 270 | - 'event_espresso' |
|
| 271 | - ); |
|
| 272 | - break; |
|
| 273 | - |
|
| 274 | - case 'Denied': |
|
| 275 | - $status = $this->_pay_model->declined_status(); |
|
| 276 | - $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
| 277 | - break; |
|
| 278 | - |
|
| 279 | - case 'Expired': |
|
| 280 | - case 'Failed': |
|
| 281 | - $status = $this->_pay_model->failed_status(); |
|
| 282 | - $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
| 283 | - break; |
|
| 284 | - |
|
| 285 | - case 'Refunded': |
|
| 286 | - case 'Partially_Refunded': |
|
| 287 | - // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
| 288 | - $status = $this->_pay_model->approved_status(); |
|
| 289 | - $gateway_response = esc_html__( |
|
| 290 | - 'The payment has been refunded. Please update registrations accordingly.', |
|
| 291 | - 'event_espresso' |
|
| 292 | - ); |
|
| 293 | - break; |
|
| 294 | - |
|
| 295 | - case 'Voided': |
|
| 296 | - case 'Reversed': |
|
| 297 | - case 'Canceled_Reversal': |
|
| 298 | - default: |
|
| 299 | - $status = $this->_pay_model->cancelled_status(); |
|
| 300 | - $gateway_response = esc_html__( |
|
| 301 | - 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
| 302 | - 'event_espresso' |
|
| 303 | - ); |
|
| 304 | - break; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // check if we've already processed this payment |
|
| 308 | - if ($payment instanceof EEI_Payment) { |
|
| 309 | - // payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
| 310 | - if ($payment->status() === $status && $payment->amount() === (float) $update_info['mc_gross']) { |
|
| 311 | - // DUPLICATED IPN! don't bother updating transaction |
|
| 312 | - throw new IpnException( |
|
| 313 | - sprintf( |
|
| 314 | - esc_html__( |
|
| 315 | - 'It appears we have received a duplicate IPN from PayPal for payment %d', |
|
| 316 | - 'event_espresso' |
|
| 317 | - ), |
|
| 318 | - $payment->ID() |
|
| 319 | - ), |
|
| 320 | - IpnException::DUPLICATE, |
|
| 321 | - null, |
|
| 322 | - $payment, |
|
| 323 | - $update_info |
|
| 324 | - ); |
|
| 325 | - } else { |
|
| 326 | - // new payment yippee !!! |
|
| 327 | - $payment->set_status($status); |
|
| 328 | - $payment->set_amount((float) $update_info['mc_gross']); |
|
| 329 | - $payment->set_gateway_response($gateway_response); |
|
| 330 | - $payment->set_details($update_info); |
|
| 331 | - $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
| 332 | - $this->log( |
|
| 333 | - array( |
|
| 334 | - 'message' => esc_html__( |
|
| 335 | - 'Updated payment either from IPN or as part of POST from PayPal', |
|
| 336 | - 'event_espresso' |
|
| 337 | - ), |
|
| 338 | - 'url' => $this->_process_response_url(), |
|
| 339 | - 'payment' => $payment->model_field_array(), |
|
| 340 | - 'IPN_data' => $update_info |
|
| 341 | - ), |
|
| 342 | - $payment |
|
| 343 | - ); |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
| 347 | - return $payment; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Validate the IPN notification. |
|
| 353 | - * |
|
| 354 | - * @param array $update_info like $_REQUEST |
|
| 355 | - * @param EE_Payment|EEI_Payment $payment |
|
| 356 | - * @return boolean |
|
| 357 | - * @throws EE_Error |
|
| 358 | - */ |
|
| 359 | - public function validate_ipn($update_info, $payment) |
|
| 360 | - { |
|
| 361 | - // allow us to skip validating IPNs with PayPal (useful for testing) |
|
| 362 | - if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
| 363 | - return true; |
|
| 364 | - } |
|
| 365 | - // ...otherwise, we actually don't care what the $update_info is, we need to look |
|
| 366 | - // at the request directly because we can't use $update_info because it has issues with quotes |
|
| 367 | - // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
| 368 | - // Instead, read raw POST data from the input stream. |
|
| 369 | - // @see https://gist.github.com/xcommerce-gists/3440401 |
|
| 370 | - $raw_post_data = file_get_contents('php://input'); |
|
| 371 | - $raw_post_array = explode('&', $raw_post_data); |
|
| 372 | - $update_info = array(); |
|
| 373 | - foreach ($raw_post_array as $keyval) { |
|
| 374 | - $keyval = explode('=', $keyval); |
|
| 375 | - if (count($keyval) === 2) { |
|
| 376 | - $update_info[ $keyval[0] ] = urldecode($keyval[1]); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
| 380 | - $req = 'cmd=_notify-validate'; |
|
| 381 | - $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1; |
|
| 382 | - foreach ($update_info as $key => $value) { |
|
| 383 | - $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
| 384 | - $req .= "&$key=$value"; |
|
| 385 | - } |
|
| 386 | - // HTTP POST the complete, unaltered IPN back to PayPal |
|
| 387 | - $response = wp_remote_post( |
|
| 388 | - $this->_gateway_url, |
|
| 389 | - array( |
|
| 390 | - 'body' => $req, |
|
| 391 | - 'sslverify' => false, |
|
| 392 | - 'timeout' => 60, |
|
| 393 | - // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
| 394 | - // plz see: https://github.com/websharks/s2member/issues/610 |
|
| 395 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
| 396 | - 'httpversion' => '1.1' |
|
| 397 | - ) |
|
| 398 | - ); |
|
| 399 | - // then check the response |
|
| 400 | - if ( |
|
| 401 | - array_key_exists('body', $response) |
|
| 402 | - && ! is_wp_error($response) |
|
| 403 | - && strcmp($response['body'], "VERIFIED") === 0 |
|
| 404 | - ) { |
|
| 405 | - return true; |
|
| 406 | - } |
|
| 407 | - // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
| 408 | - // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
| 409 | - if ($response instanceof WP_Error) { |
|
| 410 | - $error_msg = sprintf( |
|
| 411 | - esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
| 412 | - $response->get_error_code(), |
|
| 413 | - $response->get_error_message(), |
|
| 414 | - print_r($response->get_error_data(), true) |
|
| 415 | - ); |
|
| 416 | - } elseif (is_array($response) && isset($response['body'])) { |
|
| 417 | - $error_msg = $response['body']; |
|
| 418 | - } else { |
|
| 419 | - $error_msg = print_r($response, true); |
|
| 420 | - } |
|
| 421 | - $payment->set_gateway_response( |
|
| 422 | - sprintf( |
|
| 423 | - esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
| 424 | - $error_msg |
|
| 425 | - ) |
|
| 426 | - ); |
|
| 427 | - $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
| 428 | - $payment->set_status(EEM_Payment::status_id_failed); |
|
| 429 | - // log the results |
|
| 430 | - $this->log( |
|
| 431 | - array( |
|
| 432 | - 'url' => $this->_process_response_url(), |
|
| 433 | - 'message' => $payment->gateway_response(), |
|
| 434 | - 'details' => $payment->details(), |
|
| 435 | - ), |
|
| 436 | - $payment |
|
| 437 | - ); |
|
| 438 | - return false; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * _process_response_url |
|
| 444 | - * @return string |
|
| 445 | - */ |
|
| 446 | - protected function _process_response_url(): string |
|
| 447 | - { |
|
| 448 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 449 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
| 450 | - $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 451 | - $url .= EEH_URL::filter_input_server_url(); |
|
| 452 | - } else { |
|
| 453 | - $url = 'unknown'; |
|
| 454 | - } |
|
| 455 | - return $url; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
| 461 | - * like the taxes or shipping |
|
| 462 | - * |
|
| 463 | - * @param EEI_Payment $payment |
|
| 464 | - * @throws EE_Error |
|
| 465 | - * @throws ReflectionException |
|
| 466 | - */ |
|
| 467 | - public function update_txn_based_on_payment($payment) |
|
| 468 | - { |
|
| 469 | - $update_info = $payment->details(); |
|
| 470 | - /** @var EE_Transaction $transaction */ |
|
| 471 | - $transaction = $payment->transaction(); |
|
| 472 | - $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
| 473 | - if (! $transaction) { |
|
| 474 | - $this->log( |
|
| 475 | - esc_html__( |
|
| 476 | - // @codingStandardsIgnoreStart |
|
| 477 | - 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
| 478 | - // @codingStandardsIgnoreEnd |
|
| 479 | - 'event_espresso' |
|
| 480 | - ), |
|
| 481 | - $payment |
|
| 482 | - ); |
|
| 483 | - return; |
|
| 484 | - } |
|
| 485 | - if ( |
|
| 486 | - ! is_array($update_info) |
|
| 487 | - || ! isset($update_info['mc_shipping']) |
|
| 488 | - || ! isset($update_info['tax']) |
|
| 489 | - ) { |
|
| 490 | - $this->log( |
|
| 491 | - array( |
|
| 492 | - 'message' => esc_html__( |
|
| 493 | - // @codingStandardsIgnoreStart |
|
| 494 | - 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
| 495 | - // @codingStandardsIgnoreEnd |
|
| 496 | - 'event_espresso' |
|
| 497 | - ), |
|
| 498 | - 'url' => $this->_process_response_url(), |
|
| 499 | - 'payment' => $payment->model_field_array() |
|
| 500 | - ), |
|
| 501 | - $payment |
|
| 502 | - ); |
|
| 503 | - return; |
|
| 504 | - } |
|
| 505 | - if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
| 506 | - $this->log( |
|
| 507 | - array( |
|
| 508 | - 'message' => esc_html__( |
|
| 509 | - 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
| 510 | - 'event_espresso' |
|
| 511 | - ), |
|
| 512 | - 'url' => $this->_process_response_url(), |
|
| 513 | - 'payment' => $payment->model_field_array() |
|
| 514 | - ), |
|
| 515 | - $payment |
|
| 516 | - ); |
|
| 517 | - return; |
|
| 518 | - } |
|
| 519 | - $grand_total_needs_resaving = false; |
|
| 520 | - /** @var EE_Line_Item $transaction_total_line_item */ |
|
| 521 | - $transaction_total_line_item = $transaction->total_line_item(); |
|
| 522 | - |
|
| 523 | - // might paypal have changed the taxes? |
|
| 524 | - if ($this->_paypal_taxes && $payment_was_itemized) { |
|
| 525 | - // note that we're doing this BEFORE adding shipping; |
|
| 526 | - // we actually want PayPal's shipping to remain non-taxable |
|
| 527 | - $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
| 528 | - $this->_line_item->set_total_tax_to( |
|
| 529 | - $transaction_total_line_item, |
|
| 530 | - (float) $update_info['tax'], |
|
| 531 | - esc_html__('Taxes', 'event_espresso'), |
|
| 532 | - esc_html__('Calculated by Paypal', 'event_espresso'), |
|
| 533 | - 'paypal_tax' |
|
| 534 | - ); |
|
| 535 | - $grand_total_needs_resaving = true; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - $shipping_amount = (float) $update_info['mc_shipping']; |
|
| 539 | - // might paypal have added shipping? |
|
| 540 | - if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
| 541 | - $this->_line_item->add_unrelated_item( |
|
| 542 | - $transaction_total_line_item, |
|
| 543 | - sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
| 544 | - $shipping_amount, |
|
| 545 | - esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
| 546 | - 1, |
|
| 547 | - false, |
|
| 548 | - 'paypal_shipping_' . $transaction->ID() |
|
| 549 | - ); |
|
| 550 | - $grand_total_needs_resaving = true; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - if ($grand_total_needs_resaving) { |
|
| 554 | - $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 555 | - /** @var EE_Registration_Processor $registration_processor */ |
|
| 556 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 557 | - $registration_processor->update_registration_final_prices($transaction); |
|
| 558 | - } |
|
| 559 | - $this->log( |
|
| 560 | - array( |
|
| 561 | - 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
| 562 | - 'url' => $this->_process_response_url(), |
|
| 563 | - 'transaction (updated)' => $transaction->model_field_array(), |
|
| 564 | - 'payment (updated)' => $payment->model_field_array(), |
|
| 565 | - 'use_paypal_shipping' => $this->_paypal_shipping, |
|
| 566 | - 'use_paypal_tax' => $this->_paypal_taxes, |
|
| 567 | - 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
| 568 | - ), |
|
| 569 | - $payment |
|
| 570 | - ); |
|
| 571 | - } |
|
| 22 | + /** |
|
| 23 | + * Name for the wp option used to save the itemized payment |
|
| 24 | + */ |
|
| 25 | + const itemized_payment_option_name = '_itemized_payment'; |
|
| 26 | + |
|
| 27 | + protected $_paypal_id; |
|
| 28 | + |
|
| 29 | + protected $_image_url; |
|
| 30 | + |
|
| 31 | + protected $_shipping_details; |
|
| 32 | + |
|
| 33 | + protected $_paypal_shipping; |
|
| 34 | + |
|
| 35 | + protected $_paypal_taxes; |
|
| 36 | + |
|
| 37 | + protected $_gateway_url; |
|
| 38 | + |
|
| 39 | + protected $_currencies_supported = array( |
|
| 40 | + 'USD', |
|
| 41 | + 'GBP', |
|
| 42 | + 'CAD', |
|
| 43 | + 'AUD', |
|
| 44 | + 'BRL', |
|
| 45 | + 'CHF', |
|
| 46 | + 'CZK', |
|
| 47 | + 'DKK', |
|
| 48 | + 'EUR', |
|
| 49 | + 'HKD', |
|
| 50 | + 'HUF', |
|
| 51 | + 'ILS', |
|
| 52 | + 'JPY', |
|
| 53 | + 'MXN', |
|
| 54 | + 'MYR', |
|
| 55 | + 'NOK', |
|
| 56 | + 'NZD', |
|
| 57 | + 'PHP', |
|
| 58 | + 'PLN', |
|
| 59 | + 'SEK', |
|
| 60 | + 'SGD', |
|
| 61 | + 'THB', |
|
| 62 | + 'TRY', |
|
| 63 | + 'TWD', |
|
| 64 | + 'RUB' |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var ItemizedOrder |
|
| 69 | + * @since $VID:$ |
|
| 70 | + */ |
|
| 71 | + protected $itemized_order; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * EEG_Paypal_Standard constructor. |
|
| 76 | + */ |
|
| 77 | + public function __construct() |
|
| 78 | + { |
|
| 79 | + $this->set_uses_separate_IPN_request(true); |
|
| 80 | + parent::__construct(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return mixed |
|
| 86 | + */ |
|
| 87 | + public function gatewayUrl() |
|
| 88 | + { |
|
| 89 | + return $this->_gateway_url; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @return mixed |
|
| 95 | + */ |
|
| 96 | + public function imageUrl() |
|
| 97 | + { |
|
| 98 | + return $this->_image_url; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return mixed |
|
| 104 | + */ |
|
| 105 | + public function paypalId() |
|
| 106 | + { |
|
| 107 | + return $this->_paypal_id; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return mixed |
|
| 113 | + */ |
|
| 114 | + public function paypalShipping() |
|
| 115 | + { |
|
| 116 | + return $this->_paypal_shipping; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @return mixed |
|
| 123 | + */ |
|
| 124 | + public function paypalTaxes() |
|
| 125 | + { |
|
| 126 | + return $this->_paypal_taxes; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return mixed |
|
| 132 | + */ |
|
| 133 | + public function shippingDetails() |
|
| 134 | + { |
|
| 135 | + return $this->_shipping_details; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
| 141 | + * |
|
| 142 | + * @param array $settings_array |
|
| 143 | + */ |
|
| 144 | + public function set_settings($settings_array) |
|
| 145 | + { |
|
| 146 | + parent::set_settings($settings_array); |
|
| 147 | + $this->_gateway_url = $this->_debug_mode |
|
| 148 | + ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
| 149 | + : 'https://www.paypal.com/cgi-bin/webscr'; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param EEI_Payment $payment the payment to process |
|
| 155 | + * @param array $billing_info but should be empty for this gateway |
|
| 156 | + * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
| 157 | + * @param string $notify_url URL to send the instant payment notification |
|
| 158 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
| 159 | + * on the payment provider's website |
|
| 160 | + * @return EEI_Payment |
|
| 161 | + * @throws EE_Error |
|
| 162 | + * @throws ReflectionException |
|
| 163 | + */ |
|
| 164 | + public function set_redirection_info( |
|
| 165 | + $payment, |
|
| 166 | + $billing_info = array(), |
|
| 167 | + $return_url = null, |
|
| 168 | + $notify_url = null, |
|
| 169 | + $cancel_url = null |
|
| 170 | + ) { |
|
| 171 | + $this->itemized_order = new ItemizedOrder($this->_get_gateway_formatter(), $this); |
|
| 172 | + $redirect_args = apply_filters( |
|
| 173 | + "FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", |
|
| 174 | + $this->itemized_order->generateItemizedOrderForPayment( |
|
| 175 | + $payment, |
|
| 176 | + $return_url, |
|
| 177 | + $notify_url, |
|
| 178 | + $cancel_url |
|
| 179 | + ), |
|
| 180 | + $this |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + $payment->set_redirect_url($this->_gateway_url); |
|
| 184 | + $payment->set_redirect_args($redirect_args); |
|
| 185 | + // log the results |
|
| 186 | + $this->log( |
|
| 187 | + [ |
|
| 188 | + 'message' => esc_html__('PayPal payment request initiated.', 'event_espresso'), |
|
| 189 | + 'transaction' => $payment->transaction()->model_field_array(), |
|
| 190 | + ], |
|
| 191 | + $payment |
|
| 192 | + ); |
|
| 193 | + return $payment; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Often used for IPNs. But applies the info in $update_info to the payment. |
|
| 199 | + * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
| 200 | + * the payment method passes in. |
|
| 201 | + * |
|
| 202 | + * @param array $update_info like $_POST |
|
| 203 | + * @param EEI_Transaction $transaction |
|
| 204 | + * @return EEI_Payment updated |
|
| 205 | + * @throws EE_Error, IpnException |
|
| 206 | + */ |
|
| 207 | + public function handle_payment_update($update_info, $transaction) |
|
| 208 | + { |
|
| 209 | + // verify there's payment data that's been sent |
|
| 210 | + if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
| 211 | + // log the results |
|
| 212 | + $this->log( |
|
| 213 | + array( |
|
| 214 | + 'message' => esc_html__( |
|
| 215 | + 'PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', |
|
| 216 | + 'event_espresso' |
|
| 217 | + ), |
|
| 218 | + 'update_info' => $update_info, |
|
| 219 | + ), |
|
| 220 | + $transaction |
|
| 221 | + ); |
|
| 222 | + // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
| 223 | + // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
| 224 | + if (isset($update_info['tx'])) { |
|
| 225 | + return $transaction->last_payment(); |
|
| 226 | + } else { |
|
| 227 | + return null; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
| 231 | + if (! $payment instanceof EEI_Payment) { |
|
| 232 | + $payment = $transaction->last_payment(); |
|
| 233 | + } |
|
| 234 | + // ok, then validate the IPN. Even if we've already processed this payment, |
|
| 235 | + // let PayPal know we don't want to hear from them anymore! |
|
| 236 | + if (! $this->validate_ipn($update_info, $payment)) { |
|
| 237 | + return $payment; |
|
| 238 | + } |
|
| 239 | + // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
| 240 | + // registrations, ticket counts, etc) |
|
| 241 | + if ( |
|
| 242 | + ( |
|
| 243 | + $update_info['payment_status'] === 'Refunded' |
|
| 244 | + || $update_info['payment_status'] === 'Partially_Refunded' |
|
| 245 | + ) |
|
| 246 | + && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
| 247 | + ) { |
|
| 248 | + throw new EventEspresso\core\exceptions\IpnException( |
|
| 249 | + sprintf( |
|
| 250 | + esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
| 251 | + $update_info['payment_status'] |
|
| 252 | + ), |
|
| 253 | + EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
| 254 | + null, |
|
| 255 | + $payment, |
|
| 256 | + $update_info |
|
| 257 | + ); |
|
| 258 | + } |
|
| 259 | + // ok, well let's process this payment then! |
|
| 260 | + switch ($update_info['payment_status']) { |
|
| 261 | + case 'Completed': |
|
| 262 | + $status = $this->_pay_model->approved_status(); |
|
| 263 | + $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
| 264 | + break; |
|
| 265 | + |
|
| 266 | + case 'Pending': |
|
| 267 | + $status = $this->_pay_model->pending_status(); |
|
| 268 | + $gateway_response = esc_html__( |
|
| 269 | + 'The payment is in progress. Another message will be sent when payment is approved.', |
|
| 270 | + 'event_espresso' |
|
| 271 | + ); |
|
| 272 | + break; |
|
| 273 | + |
|
| 274 | + case 'Denied': |
|
| 275 | + $status = $this->_pay_model->declined_status(); |
|
| 276 | + $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
| 277 | + break; |
|
| 278 | + |
|
| 279 | + case 'Expired': |
|
| 280 | + case 'Failed': |
|
| 281 | + $status = $this->_pay_model->failed_status(); |
|
| 282 | + $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
| 283 | + break; |
|
| 284 | + |
|
| 285 | + case 'Refunded': |
|
| 286 | + case 'Partially_Refunded': |
|
| 287 | + // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
| 288 | + $status = $this->_pay_model->approved_status(); |
|
| 289 | + $gateway_response = esc_html__( |
|
| 290 | + 'The payment has been refunded. Please update registrations accordingly.', |
|
| 291 | + 'event_espresso' |
|
| 292 | + ); |
|
| 293 | + break; |
|
| 294 | + |
|
| 295 | + case 'Voided': |
|
| 296 | + case 'Reversed': |
|
| 297 | + case 'Canceled_Reversal': |
|
| 298 | + default: |
|
| 299 | + $status = $this->_pay_model->cancelled_status(); |
|
| 300 | + $gateway_response = esc_html__( |
|
| 301 | + 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
| 302 | + 'event_espresso' |
|
| 303 | + ); |
|
| 304 | + break; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // check if we've already processed this payment |
|
| 308 | + if ($payment instanceof EEI_Payment) { |
|
| 309 | + // payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
| 310 | + if ($payment->status() === $status && $payment->amount() === (float) $update_info['mc_gross']) { |
|
| 311 | + // DUPLICATED IPN! don't bother updating transaction |
|
| 312 | + throw new IpnException( |
|
| 313 | + sprintf( |
|
| 314 | + esc_html__( |
|
| 315 | + 'It appears we have received a duplicate IPN from PayPal for payment %d', |
|
| 316 | + 'event_espresso' |
|
| 317 | + ), |
|
| 318 | + $payment->ID() |
|
| 319 | + ), |
|
| 320 | + IpnException::DUPLICATE, |
|
| 321 | + null, |
|
| 322 | + $payment, |
|
| 323 | + $update_info |
|
| 324 | + ); |
|
| 325 | + } else { |
|
| 326 | + // new payment yippee !!! |
|
| 327 | + $payment->set_status($status); |
|
| 328 | + $payment->set_amount((float) $update_info['mc_gross']); |
|
| 329 | + $payment->set_gateway_response($gateway_response); |
|
| 330 | + $payment->set_details($update_info); |
|
| 331 | + $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
| 332 | + $this->log( |
|
| 333 | + array( |
|
| 334 | + 'message' => esc_html__( |
|
| 335 | + 'Updated payment either from IPN or as part of POST from PayPal', |
|
| 336 | + 'event_espresso' |
|
| 337 | + ), |
|
| 338 | + 'url' => $this->_process_response_url(), |
|
| 339 | + 'payment' => $payment->model_field_array(), |
|
| 340 | + 'IPN_data' => $update_info |
|
| 341 | + ), |
|
| 342 | + $payment |
|
| 343 | + ); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
| 347 | + return $payment; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Validate the IPN notification. |
|
| 353 | + * |
|
| 354 | + * @param array $update_info like $_REQUEST |
|
| 355 | + * @param EE_Payment|EEI_Payment $payment |
|
| 356 | + * @return boolean |
|
| 357 | + * @throws EE_Error |
|
| 358 | + */ |
|
| 359 | + public function validate_ipn($update_info, $payment) |
|
| 360 | + { |
|
| 361 | + // allow us to skip validating IPNs with PayPal (useful for testing) |
|
| 362 | + if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
| 363 | + return true; |
|
| 364 | + } |
|
| 365 | + // ...otherwise, we actually don't care what the $update_info is, we need to look |
|
| 366 | + // at the request directly because we can't use $update_info because it has issues with quotes |
|
| 367 | + // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
| 368 | + // Instead, read raw POST data from the input stream. |
|
| 369 | + // @see https://gist.github.com/xcommerce-gists/3440401 |
|
| 370 | + $raw_post_data = file_get_contents('php://input'); |
|
| 371 | + $raw_post_array = explode('&', $raw_post_data); |
|
| 372 | + $update_info = array(); |
|
| 373 | + foreach ($raw_post_array as $keyval) { |
|
| 374 | + $keyval = explode('=', $keyval); |
|
| 375 | + if (count($keyval) === 2) { |
|
| 376 | + $update_info[ $keyval[0] ] = urldecode($keyval[1]); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
| 380 | + $req = 'cmd=_notify-validate'; |
|
| 381 | + $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1; |
|
| 382 | + foreach ($update_info as $key => $value) { |
|
| 383 | + $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
| 384 | + $req .= "&$key=$value"; |
|
| 385 | + } |
|
| 386 | + // HTTP POST the complete, unaltered IPN back to PayPal |
|
| 387 | + $response = wp_remote_post( |
|
| 388 | + $this->_gateway_url, |
|
| 389 | + array( |
|
| 390 | + 'body' => $req, |
|
| 391 | + 'sslverify' => false, |
|
| 392 | + 'timeout' => 60, |
|
| 393 | + // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
| 394 | + // plz see: https://github.com/websharks/s2member/issues/610 |
|
| 395 | + 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
| 396 | + 'httpversion' => '1.1' |
|
| 397 | + ) |
|
| 398 | + ); |
|
| 399 | + // then check the response |
|
| 400 | + if ( |
|
| 401 | + array_key_exists('body', $response) |
|
| 402 | + && ! is_wp_error($response) |
|
| 403 | + && strcmp($response['body'], "VERIFIED") === 0 |
|
| 404 | + ) { |
|
| 405 | + return true; |
|
| 406 | + } |
|
| 407 | + // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
| 408 | + // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
| 409 | + if ($response instanceof WP_Error) { |
|
| 410 | + $error_msg = sprintf( |
|
| 411 | + esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
| 412 | + $response->get_error_code(), |
|
| 413 | + $response->get_error_message(), |
|
| 414 | + print_r($response->get_error_data(), true) |
|
| 415 | + ); |
|
| 416 | + } elseif (is_array($response) && isset($response['body'])) { |
|
| 417 | + $error_msg = $response['body']; |
|
| 418 | + } else { |
|
| 419 | + $error_msg = print_r($response, true); |
|
| 420 | + } |
|
| 421 | + $payment->set_gateway_response( |
|
| 422 | + sprintf( |
|
| 423 | + esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
| 424 | + $error_msg |
|
| 425 | + ) |
|
| 426 | + ); |
|
| 427 | + $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
| 428 | + $payment->set_status(EEM_Payment::status_id_failed); |
|
| 429 | + // log the results |
|
| 430 | + $this->log( |
|
| 431 | + array( |
|
| 432 | + 'url' => $this->_process_response_url(), |
|
| 433 | + 'message' => $payment->gateway_response(), |
|
| 434 | + 'details' => $payment->details(), |
|
| 435 | + ), |
|
| 436 | + $payment |
|
| 437 | + ); |
|
| 438 | + return false; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * _process_response_url |
|
| 444 | + * @return string |
|
| 445 | + */ |
|
| 446 | + protected function _process_response_url(): string |
|
| 447 | + { |
|
| 448 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 449 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
| 450 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 451 | + $url .= EEH_URL::filter_input_server_url(); |
|
| 452 | + } else { |
|
| 453 | + $url = 'unknown'; |
|
| 454 | + } |
|
| 455 | + return $url; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
| 461 | + * like the taxes or shipping |
|
| 462 | + * |
|
| 463 | + * @param EEI_Payment $payment |
|
| 464 | + * @throws EE_Error |
|
| 465 | + * @throws ReflectionException |
|
| 466 | + */ |
|
| 467 | + public function update_txn_based_on_payment($payment) |
|
| 468 | + { |
|
| 469 | + $update_info = $payment->details(); |
|
| 470 | + /** @var EE_Transaction $transaction */ |
|
| 471 | + $transaction = $payment->transaction(); |
|
| 472 | + $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
| 473 | + if (! $transaction) { |
|
| 474 | + $this->log( |
|
| 475 | + esc_html__( |
|
| 476 | + // @codingStandardsIgnoreStart |
|
| 477 | + 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
| 478 | + // @codingStandardsIgnoreEnd |
|
| 479 | + 'event_espresso' |
|
| 480 | + ), |
|
| 481 | + $payment |
|
| 482 | + ); |
|
| 483 | + return; |
|
| 484 | + } |
|
| 485 | + if ( |
|
| 486 | + ! is_array($update_info) |
|
| 487 | + || ! isset($update_info['mc_shipping']) |
|
| 488 | + || ! isset($update_info['tax']) |
|
| 489 | + ) { |
|
| 490 | + $this->log( |
|
| 491 | + array( |
|
| 492 | + 'message' => esc_html__( |
|
| 493 | + // @codingStandardsIgnoreStart |
|
| 494 | + 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
| 495 | + // @codingStandardsIgnoreEnd |
|
| 496 | + 'event_espresso' |
|
| 497 | + ), |
|
| 498 | + 'url' => $this->_process_response_url(), |
|
| 499 | + 'payment' => $payment->model_field_array() |
|
| 500 | + ), |
|
| 501 | + $payment |
|
| 502 | + ); |
|
| 503 | + return; |
|
| 504 | + } |
|
| 505 | + if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
| 506 | + $this->log( |
|
| 507 | + array( |
|
| 508 | + 'message' => esc_html__( |
|
| 509 | + 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
| 510 | + 'event_espresso' |
|
| 511 | + ), |
|
| 512 | + 'url' => $this->_process_response_url(), |
|
| 513 | + 'payment' => $payment->model_field_array() |
|
| 514 | + ), |
|
| 515 | + $payment |
|
| 516 | + ); |
|
| 517 | + return; |
|
| 518 | + } |
|
| 519 | + $grand_total_needs_resaving = false; |
|
| 520 | + /** @var EE_Line_Item $transaction_total_line_item */ |
|
| 521 | + $transaction_total_line_item = $transaction->total_line_item(); |
|
| 522 | + |
|
| 523 | + // might paypal have changed the taxes? |
|
| 524 | + if ($this->_paypal_taxes && $payment_was_itemized) { |
|
| 525 | + // note that we're doing this BEFORE adding shipping; |
|
| 526 | + // we actually want PayPal's shipping to remain non-taxable |
|
| 527 | + $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
| 528 | + $this->_line_item->set_total_tax_to( |
|
| 529 | + $transaction_total_line_item, |
|
| 530 | + (float) $update_info['tax'], |
|
| 531 | + esc_html__('Taxes', 'event_espresso'), |
|
| 532 | + esc_html__('Calculated by Paypal', 'event_espresso'), |
|
| 533 | + 'paypal_tax' |
|
| 534 | + ); |
|
| 535 | + $grand_total_needs_resaving = true; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + $shipping_amount = (float) $update_info['mc_shipping']; |
|
| 539 | + // might paypal have added shipping? |
|
| 540 | + if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
| 541 | + $this->_line_item->add_unrelated_item( |
|
| 542 | + $transaction_total_line_item, |
|
| 543 | + sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
| 544 | + $shipping_amount, |
|
| 545 | + esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
| 546 | + 1, |
|
| 547 | + false, |
|
| 548 | + 'paypal_shipping_' . $transaction->ID() |
|
| 549 | + ); |
|
| 550 | + $grand_total_needs_resaving = true; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + if ($grand_total_needs_resaving) { |
|
| 554 | + $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 555 | + /** @var EE_Registration_Processor $registration_processor */ |
|
| 556 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 557 | + $registration_processor->update_registration_final_prices($transaction); |
|
| 558 | + } |
|
| 559 | + $this->log( |
|
| 560 | + array( |
|
| 561 | + 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
| 562 | + 'url' => $this->_process_response_url(), |
|
| 563 | + 'transaction (updated)' => $transaction->model_field_array(), |
|
| 564 | + 'payment (updated)' => $payment->model_field_array(), |
|
| 565 | + 'use_paypal_shipping' => $this->_paypal_shipping, |
|
| 566 | + 'use_paypal_tax' => $this->_paypal_taxes, |
|
| 567 | + 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
| 568 | + ), |
|
| 569 | + $payment |
|
| 570 | + ); |
|
| 571 | + } |
|
| 572 | 572 | } |
@@ -14,282 +14,282 @@ |
||
| 14 | 14 | |
| 15 | 15 | class ItemizedOrder |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var float |
|
| 19 | - */ |
|
| 20 | - private $existing_shipping_charges = 0.00; |
|
| 17 | + /** |
|
| 18 | + * @var float |
|
| 19 | + */ |
|
| 20 | + private $existing_shipping_charges = 0.00; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * keeps track of exactly how much the itemized order amount equals |
|
| 24 | - * |
|
| 25 | - * @var float |
|
| 26 | - */ |
|
| 27 | - private $itemized_order_sum = 0.00; |
|
| 22 | + /** |
|
| 23 | + * keeps track of exactly how much the itemized order amount equals |
|
| 24 | + * |
|
| 25 | + * @var float |
|
| 26 | + */ |
|
| 27 | + private $itemized_order_sum = 0.00; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var GatewayDataFormatterInterface |
|
| 31 | - */ |
|
| 32 | - protected $gateway_data_formatter; |
|
| 29 | + /** |
|
| 30 | + * @var GatewayDataFormatterInterface |
|
| 31 | + */ |
|
| 32 | + protected $gateway_data_formatter; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - private $order_items; |
|
| 34 | + /** |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + private $order_items; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * the payment being processed |
|
| 41 | - * |
|
| 42 | - * @var EE_Payment |
|
| 43 | - */ |
|
| 44 | - protected $payment; |
|
| 39 | + /** |
|
| 40 | + * the payment being processed |
|
| 41 | + * |
|
| 42 | + * @var EE_Payment |
|
| 43 | + */ |
|
| 44 | + protected $payment; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var EEG_Paypal_Standard |
|
| 48 | - */ |
|
| 49 | - protected $paypal_gateway; |
|
| 46 | + /** |
|
| 47 | + * @var EEG_Paypal_Standard |
|
| 48 | + */ |
|
| 49 | + protected $paypal_gateway; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var float |
|
| 53 | - */ |
|
| 54 | - private $total_discounts = 0.00; |
|
| 51 | + /** |
|
| 52 | + * @var float |
|
| 53 | + */ |
|
| 54 | + private $total_discounts = 0.00; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var EE_Transaction |
|
| 58 | - */ |
|
| 59 | - private $transaction; |
|
| 56 | + /** |
|
| 57 | + * @var EE_Transaction |
|
| 58 | + */ |
|
| 59 | + private $transaction; |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 64 | - * @param EEG_Paypal_Standard $paypal_gateway |
|
| 65 | - */ |
|
| 66 | - public function __construct(GatewayDataFormatterInterface $gateway_data_formatter, EEG_Paypal_Standard $paypal_gateway) |
|
| 67 | - { |
|
| 68 | - $this->gateway_data_formatter = $gateway_data_formatter; |
|
| 69 | - $this->paypal_gateway = $paypal_gateway; |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
| 64 | + * @param EEG_Paypal_Standard $paypal_gateway |
|
| 65 | + */ |
|
| 66 | + public function __construct(GatewayDataFormatterInterface $gateway_data_formatter, EEG_Paypal_Standard $paypal_gateway) |
|
| 67 | + { |
|
| 68 | + $this->gateway_data_formatter = $gateway_data_formatter; |
|
| 69 | + $this->paypal_gateway = $paypal_gateway; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @param EE_Payment $payment |
|
| 75 | - * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
| 76 | - * @param string $notify_url URL to send the instant payment notification |
|
| 77 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
| 78 | - * on the payment provider's website |
|
| 79 | - * @return array |
|
| 80 | - * @throws EE_Error |
|
| 81 | - * @throws ReflectionException |
|
| 82 | - */ |
|
| 83 | - public function generateItemizedOrderForPayment( |
|
| 84 | - EE_Payment $payment, |
|
| 85 | - string $return_url = '', |
|
| 86 | - string $notify_url = '', |
|
| 87 | - string $cancel_url = '' |
|
| 88 | - ): array { |
|
| 89 | - $this->payment = $payment; |
|
| 90 | - $this->transaction = $this->payment->transaction(); |
|
| 91 | - $this->total_discounts = $this->transaction->paid(); |
|
| 92 | - $total_line_item = $this->transaction->total_line_item(); |
|
| 73 | + /** |
|
| 74 | + * @param EE_Payment $payment |
|
| 75 | + * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
| 76 | + * @param string $notify_url URL to send the instant payment notification |
|
| 77 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
| 78 | + * on the payment provider's website |
|
| 79 | + * @return array |
|
| 80 | + * @throws EE_Error |
|
| 81 | + * @throws ReflectionException |
|
| 82 | + */ |
|
| 83 | + public function generateItemizedOrderForPayment( |
|
| 84 | + EE_Payment $payment, |
|
| 85 | + string $return_url = '', |
|
| 86 | + string $notify_url = '', |
|
| 87 | + string $cancel_url = '' |
|
| 88 | + ): array { |
|
| 89 | + $this->payment = $payment; |
|
| 90 | + $this->transaction = $this->payment->transaction(); |
|
| 91 | + $this->total_discounts = $this->transaction->paid(); |
|
| 92 | + $total_line_item = $this->transaction->total_line_item(); |
|
| 93 | 93 | |
| 94 | - // only itemize the order if we're paying for the rest of the order's amount |
|
| 95 | - $item_num = 1; |
|
| 96 | - $item_num = $this->paymentIsForTransactionTotal() |
|
| 97 | - ? $this->itemizeOrderForFullPayment($total_line_item, $item_num) |
|
| 98 | - : $this->handlePartialPayment($item_num); |
|
| 94 | + // only itemize the order if we're paying for the rest of the order's amount |
|
| 95 | + $item_num = 1; |
|
| 96 | + $item_num = $this->paymentIsForTransactionTotal() |
|
| 97 | + ? $this->itemizeOrderForFullPayment($total_line_item, $item_num) |
|
| 98 | + : $this->handlePartialPayment($item_num); |
|
| 99 | 99 | |
| 100 | - if ($this->paypal_gateway->isInSandboxMode()) { |
|
| 101 | - $this->addSandboxModeArgs($item_num, $notify_url, $return_url); |
|
| 102 | - } |
|
| 103 | - $this->addGeneralOrderItems($cancel_url, $notify_url, $return_url); |
|
| 104 | - return $this->order_items; |
|
| 105 | - } |
|
| 100 | + if ($this->paypal_gateway->isInSandboxMode()) { |
|
| 101 | + $this->addSandboxModeArgs($item_num, $notify_url, $return_url); |
|
| 102 | + } |
|
| 103 | + $this->addGeneralOrderItems($cancel_url, $notify_url, $return_url); |
|
| 104 | + return $this->order_items; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @return bool |
|
| 110 | - * @throws ReflectionException |
|
| 111 | - * @throws EE_Error |
|
| 112 | - */ |
|
| 113 | - private function paymentIsForTransactionTotal(): bool |
|
| 114 | - { |
|
| 115 | - return EEH_Money::compare_floats($this->payment->amount(), $this->transaction->total(), '=='); |
|
| 116 | - } |
|
| 108 | + /** |
|
| 109 | + * @return bool |
|
| 110 | + * @throws ReflectionException |
|
| 111 | + * @throws EE_Error |
|
| 112 | + */ |
|
| 113 | + private function paymentIsForTransactionTotal(): bool |
|
| 114 | + { |
|
| 115 | + return EEH_Money::compare_floats($this->payment->amount(), $this->transaction->total(), '=='); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * if the payment is for the remaining transaction amount, |
|
| 121 | - * keep track of exactly how much the itemized order amount equals |
|
| 122 | - * |
|
| 123 | - * @param EE_Line_Item $total_line_item |
|
| 124 | - * @param int $item_num |
|
| 125 | - * @return int |
|
| 126 | - * @throws EE_Error |
|
| 127 | - * @throws ReflectionException |
|
| 128 | - */ |
|
| 129 | - private function itemizeOrderForFullPayment(EE_Line_Item $total_line_item, int $item_num): int |
|
| 130 | - { |
|
| 131 | - $this->payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
| 132 | - // this payment is for the remaining transaction amount, so let's show all the line items |
|
| 133 | - $item_num = $this->addOrderItemsForLineItems($total_line_item, $item_num); |
|
| 134 | - // and make adjustments as needed |
|
| 135 | - $item_num = $this->handleItemizedOrderSumDifference($total_line_item, $item_num); |
|
| 136 | - // add our taxes to the order if we're NOT using PayPal's |
|
| 137 | - if (! $this->paypal_gateway->paypalTaxes()) { |
|
| 138 | - $this->order_items['tax_cart'] = $total_line_item->get_total_tax(); |
|
| 139 | - } |
|
| 140 | - return $item_num; |
|
| 141 | - } |
|
| 119 | + /** |
|
| 120 | + * if the payment is for the remaining transaction amount, |
|
| 121 | + * keep track of exactly how much the itemized order amount equals |
|
| 122 | + * |
|
| 123 | + * @param EE_Line_Item $total_line_item |
|
| 124 | + * @param int $item_num |
|
| 125 | + * @return int |
|
| 126 | + * @throws EE_Error |
|
| 127 | + * @throws ReflectionException |
|
| 128 | + */ |
|
| 129 | + private function itemizeOrderForFullPayment(EE_Line_Item $total_line_item, int $item_num): int |
|
| 130 | + { |
|
| 131 | + $this->payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
| 132 | + // this payment is for the remaining transaction amount, so let's show all the line items |
|
| 133 | + $item_num = $this->addOrderItemsForLineItems($total_line_item, $item_num); |
|
| 134 | + // and make adjustments as needed |
|
| 135 | + $item_num = $this->handleItemizedOrderSumDifference($total_line_item, $item_num); |
|
| 136 | + // add our taxes to the order if we're NOT using PayPal's |
|
| 137 | + if (! $this->paypal_gateway->paypalTaxes()) { |
|
| 138 | + $this->order_items['tax_cart'] = $total_line_item->get_total_tax(); |
|
| 139 | + } |
|
| 140 | + return $item_num; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @param int $item_num |
|
| 146 | - * @return int |
|
| 147 | - * @throws EE_Error |
|
| 148 | - * @throws ReflectionException |
|
| 149 | - */ |
|
| 150 | - private function handlePartialPayment(int $item_num): int |
|
| 151 | - { |
|
| 152 | - $this->payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
| 153 | - // partial payment that's not for the remaining amount, so we can't send an itemized list |
|
| 154 | - $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 155 | - $this->gateway_data_formatter->formatPartialPaymentLineItemName($this->payment), |
|
| 156 | - 0, |
|
| 157 | - 127 |
|
| 158 | - ); |
|
| 159 | - $this->order_items[ "amount_{$item_num}" ] = $this->payment->amount(); |
|
| 160 | - $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 161 | - $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 162 | - $this->order_items['tax_cart'] = '0'; |
|
| 163 | - $item_num++; |
|
| 164 | - return $item_num; |
|
| 165 | - } |
|
| 144 | + /** |
|
| 145 | + * @param int $item_num |
|
| 146 | + * @return int |
|
| 147 | + * @throws EE_Error |
|
| 148 | + * @throws ReflectionException |
|
| 149 | + */ |
|
| 150 | + private function handlePartialPayment(int $item_num): int |
|
| 151 | + { |
|
| 152 | + $this->payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
| 153 | + // partial payment that's not for the remaining amount, so we can't send an itemized list |
|
| 154 | + $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 155 | + $this->gateway_data_formatter->formatPartialPaymentLineItemName($this->payment), |
|
| 156 | + 0, |
|
| 157 | + 127 |
|
| 158 | + ); |
|
| 159 | + $this->order_items[ "amount_{$item_num}" ] = $this->payment->amount(); |
|
| 160 | + $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 161 | + $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 162 | + $this->order_items['tax_cart'] = '0'; |
|
| 163 | + $item_num++; |
|
| 164 | + return $item_num; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * @param EE_Line_Item $total_line_item |
|
| 170 | - * @param int $item_num |
|
| 171 | - * @return int |
|
| 172 | - * @throws EE_Error |
|
| 173 | - * @throws ReflectionException |
|
| 174 | - */ |
|
| 175 | - private function addOrderItemsForLineItems(EE_Line_Item $total_line_item, int $item_num): int |
|
| 176 | - { |
|
| 177 | - foreach ($total_line_item->get_items() as $line_item) { |
|
| 178 | - if ($line_item instanceof EE_Line_Item) { |
|
| 179 | - // it's some kind of discount |
|
| 180 | - if (EEH_Money::compare_floats($line_item->pretaxTotal(), 0.00, '<')) { |
|
| 181 | - $this->total_discounts += abs($line_item->pretaxTotal()); |
|
| 182 | - $this->itemized_order_sum += $line_item->pretaxTotal(); |
|
| 183 | - continue; |
|
| 184 | - } |
|
| 185 | - // dont include shipping again. |
|
| 186 | - if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
| 187 | - $this->existing_shipping_charges = $line_item->pretaxTotal(); |
|
| 188 | - continue; |
|
| 189 | - } |
|
| 190 | - $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 191 | - $this->gateway_data_formatter->formatLineItemName($line_item, $this->payment), |
|
| 192 | - 0, |
|
| 193 | - 127 |
|
| 194 | - ); |
|
| 195 | - $this->order_items[ "amount_{$item_num}" ] = $line_item->unit_price(); |
|
| 196 | - $this->order_items[ "quantity_{$item_num}" ] = $line_item->quantity(); |
|
| 197 | - // if we're not letting PayPal calculate shipping, tell them its 0 |
|
| 198 | - if (! $this->paypal_gateway->paypalShipping()) { |
|
| 199 | - $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 200 | - $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 201 | - } |
|
| 202 | - $this->itemized_order_sum += $line_item->pretaxTotal(); |
|
| 203 | - $item_num++; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - return $item_num; |
|
| 207 | - } |
|
| 168 | + /** |
|
| 169 | + * @param EE_Line_Item $total_line_item |
|
| 170 | + * @param int $item_num |
|
| 171 | + * @return int |
|
| 172 | + * @throws EE_Error |
|
| 173 | + * @throws ReflectionException |
|
| 174 | + */ |
|
| 175 | + private function addOrderItemsForLineItems(EE_Line_Item $total_line_item, int $item_num): int |
|
| 176 | + { |
|
| 177 | + foreach ($total_line_item->get_items() as $line_item) { |
|
| 178 | + if ($line_item instanceof EE_Line_Item) { |
|
| 179 | + // it's some kind of discount |
|
| 180 | + if (EEH_Money::compare_floats($line_item->pretaxTotal(), 0.00, '<')) { |
|
| 181 | + $this->total_discounts += abs($line_item->pretaxTotal()); |
|
| 182 | + $this->itemized_order_sum += $line_item->pretaxTotal(); |
|
| 183 | + continue; |
|
| 184 | + } |
|
| 185 | + // dont include shipping again. |
|
| 186 | + if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
| 187 | + $this->existing_shipping_charges = $line_item->pretaxTotal(); |
|
| 188 | + continue; |
|
| 189 | + } |
|
| 190 | + $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 191 | + $this->gateway_data_formatter->formatLineItemName($line_item, $this->payment), |
|
| 192 | + 0, |
|
| 193 | + 127 |
|
| 194 | + ); |
|
| 195 | + $this->order_items[ "amount_{$item_num}" ] = $line_item->unit_price(); |
|
| 196 | + $this->order_items[ "quantity_{$item_num}" ] = $line_item->quantity(); |
|
| 197 | + // if we're not letting PayPal calculate shipping, tell them its 0 |
|
| 198 | + if (! $this->paypal_gateway->paypalShipping()) { |
|
| 199 | + $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 200 | + $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 201 | + } |
|
| 202 | + $this->itemized_order_sum += $line_item->pretaxTotal(); |
|
| 203 | + $item_num++; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + return $item_num; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * @param EE_Line_Item $total_line_item |
|
| 212 | - * @param int $item_num |
|
| 213 | - * @return int |
|
| 214 | - * @throws EE_Error |
|
| 215 | - * @throws ReflectionException |
|
| 216 | - */ |
|
| 217 | - private function handleItemizedOrderSumDifference(EE_Line_Item $total_line_item, int $item_num): int |
|
| 218 | - { |
|
| 219 | - $taxes_li = EEH_Line_Item::get_taxes_subtotal($total_line_item); |
|
| 220 | - // calculate the difference between the TXN total and the itemized order sum |
|
| 221 | - $itemized_order_sum_difference = round( |
|
| 222 | - $this->transaction->total() |
|
| 223 | - - $this->itemized_order_sum |
|
| 224 | - - $taxes_li->total() |
|
| 225 | - - $this->existing_shipping_charges, |
|
| 226 | - 2 |
|
| 227 | - ); |
|
| 228 | - // ideally the itemized order sum equals the transaction total, but if not (which is weird), |
|
| 229 | - // and the itemized sum is LESS than the transaction total... |
|
| 230 | - if (EEH_Money::compare_floats($itemized_order_sum_difference, 0.00, '<')) { |
|
| 231 | - // add the difference to the discounts |
|
| 232 | - $this->total_discounts += abs($itemized_order_sum_difference); |
|
| 233 | - } elseif (EEH_Money::compare_floats($itemized_order_sum_difference, 0.00, '>')) { |
|
| 234 | - // the itemized order sum is MORE than the transaction total |
|
| 235 | - $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 236 | - esc_html__('additional charges', 'event_espresso'), |
|
| 237 | - 0, |
|
| 238 | - 127 |
|
| 239 | - ); |
|
| 240 | - $this->order_items[ "amount_{$item_num}" ] = $this->gateway_data_formatter->formatCurrency( |
|
| 241 | - $itemized_order_sum_difference |
|
| 242 | - ); |
|
| 243 | - $this->order_items[ "quantity_{$item_num}" ] = 1; |
|
| 244 | - $item_num++; |
|
| 245 | - } |
|
| 246 | - if (EEH_Money::compare_floats($this->total_discounts, 0.00, '>')) { |
|
| 247 | - $this->order_items['discount_amount_cart'] = $this->gateway_data_formatter->formatCurrency( |
|
| 248 | - $this->total_discounts |
|
| 249 | - ); |
|
| 250 | - } |
|
| 251 | - return $item_num; |
|
| 252 | - } |
|
| 210 | + /** |
|
| 211 | + * @param EE_Line_Item $total_line_item |
|
| 212 | + * @param int $item_num |
|
| 213 | + * @return int |
|
| 214 | + * @throws EE_Error |
|
| 215 | + * @throws ReflectionException |
|
| 216 | + */ |
|
| 217 | + private function handleItemizedOrderSumDifference(EE_Line_Item $total_line_item, int $item_num): int |
|
| 218 | + { |
|
| 219 | + $taxes_li = EEH_Line_Item::get_taxes_subtotal($total_line_item); |
|
| 220 | + // calculate the difference between the TXN total and the itemized order sum |
|
| 221 | + $itemized_order_sum_difference = round( |
|
| 222 | + $this->transaction->total() |
|
| 223 | + - $this->itemized_order_sum |
|
| 224 | + - $taxes_li->total() |
|
| 225 | + - $this->existing_shipping_charges, |
|
| 226 | + 2 |
|
| 227 | + ); |
|
| 228 | + // ideally the itemized order sum equals the transaction total, but if not (which is weird), |
|
| 229 | + // and the itemized sum is LESS than the transaction total... |
|
| 230 | + if (EEH_Money::compare_floats($itemized_order_sum_difference, 0.00, '<')) { |
|
| 231 | + // add the difference to the discounts |
|
| 232 | + $this->total_discounts += abs($itemized_order_sum_difference); |
|
| 233 | + } elseif (EEH_Money::compare_floats($itemized_order_sum_difference, 0.00, '>')) { |
|
| 234 | + // the itemized order sum is MORE than the transaction total |
|
| 235 | + $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 236 | + esc_html__('additional charges', 'event_espresso'), |
|
| 237 | + 0, |
|
| 238 | + 127 |
|
| 239 | + ); |
|
| 240 | + $this->order_items[ "amount_{$item_num}" ] = $this->gateway_data_formatter->formatCurrency( |
|
| 241 | + $itemized_order_sum_difference |
|
| 242 | + ); |
|
| 243 | + $this->order_items[ "quantity_{$item_num}" ] = 1; |
|
| 244 | + $item_num++; |
|
| 245 | + } |
|
| 246 | + if (EEH_Money::compare_floats($this->total_discounts, 0.00, '>')) { |
|
| 247 | + $this->order_items['discount_amount_cart'] = $this->gateway_data_formatter->formatCurrency( |
|
| 248 | + $this->total_discounts |
|
| 249 | + ); |
|
| 250 | + } |
|
| 251 | + return $item_num; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * @param int $item_num |
|
| 257 | - * @param string $notify_url |
|
| 258 | - * @param string $return_url |
|
| 259 | - */ |
|
| 260 | - private function addSandboxModeArgs(int $item_num, string $notify_url, string $return_url) |
|
| 261 | - { |
|
| 262 | - $this->order_items[ "item_name_{$item_num}" ] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
| 263 | - $this->order_items[ "amount_{$item_num}" ] = 0; |
|
| 264 | - $this->order_items[ "on0_{$item_num}" ] = 'NOTIFY URL'; |
|
| 265 | - $this->order_items[ "os0_{$item_num}" ] = $notify_url; |
|
| 266 | - $this->order_items[ "on1_{$item_num}" ] = 'RETURN URL'; |
|
| 267 | - $this->order_items[ "os1_{$item_num}" ] = $return_url; |
|
| 268 | - $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 269 | - $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 270 | - // $this->order_items['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
|
| 271 | - } |
|
| 255 | + /** |
|
| 256 | + * @param int $item_num |
|
| 257 | + * @param string $notify_url |
|
| 258 | + * @param string $return_url |
|
| 259 | + */ |
|
| 260 | + private function addSandboxModeArgs(int $item_num, string $notify_url, string $return_url) |
|
| 261 | + { |
|
| 262 | + $this->order_items[ "item_name_{$item_num}" ] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
| 263 | + $this->order_items[ "amount_{$item_num}" ] = 0; |
|
| 264 | + $this->order_items[ "on0_{$item_num}" ] = 'NOTIFY URL'; |
|
| 265 | + $this->order_items[ "os0_{$item_num}" ] = $notify_url; |
|
| 266 | + $this->order_items[ "on1_{$item_num}" ] = 'RETURN URL'; |
|
| 267 | + $this->order_items[ "os1_{$item_num}" ] = $return_url; |
|
| 268 | + $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 269 | + $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 270 | + // $this->order_items['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * @param string $cancel_url |
|
| 276 | - * @param string $notify_url |
|
| 277 | - * @param string $return_url |
|
| 278 | - */ |
|
| 279 | - private function addGeneralOrderItems(string $cancel_url, string $notify_url, string $return_url) |
|
| 280 | - { |
|
| 281 | - $this->order_items['business'] = $this->paypal_gateway->paypalId(); |
|
| 282 | - $this->order_items['return'] = $return_url; |
|
| 283 | - $this->order_items['cancel_return'] = $cancel_url; |
|
| 284 | - $this->order_items['notify_url'] = $notify_url; |
|
| 285 | - $this->order_items['cmd'] = '_cart'; |
|
| 286 | - $this->order_items['upload'] = 1; |
|
| 287 | - $this->order_items['currency_code'] = $this->payment->currency_code(); |
|
| 288 | - $this->order_items['rm'] = 2;// makes the user return with method=POST |
|
| 289 | - $this->order_items['no_shipping'] = $this->paypal_gateway->shippingDetails(); |
|
| 290 | - $this->order_items['bn'] = 'EventEspresso_SP';// EE will blow up if you change this |
|
| 291 | - if ($this->paypal_gateway->imageUrl()) { |
|
| 292 | - $this->order_items['image_url'] = $this->paypal_gateway->imageUrl(); |
|
| 293 | - } |
|
| 294 | - } |
|
| 274 | + /** |
|
| 275 | + * @param string $cancel_url |
|
| 276 | + * @param string $notify_url |
|
| 277 | + * @param string $return_url |
|
| 278 | + */ |
|
| 279 | + private function addGeneralOrderItems(string $cancel_url, string $notify_url, string $return_url) |
|
| 280 | + { |
|
| 281 | + $this->order_items['business'] = $this->paypal_gateway->paypalId(); |
|
| 282 | + $this->order_items['return'] = $return_url; |
|
| 283 | + $this->order_items['cancel_return'] = $cancel_url; |
|
| 284 | + $this->order_items['notify_url'] = $notify_url; |
|
| 285 | + $this->order_items['cmd'] = '_cart'; |
|
| 286 | + $this->order_items['upload'] = 1; |
|
| 287 | + $this->order_items['currency_code'] = $this->payment->currency_code(); |
|
| 288 | + $this->order_items['rm'] = 2;// makes the user return with method=POST |
|
| 289 | + $this->order_items['no_shipping'] = $this->paypal_gateway->shippingDetails(); |
|
| 290 | + $this->order_items['bn'] = 'EventEspresso_SP';// EE will blow up if you change this |
|
| 291 | + if ($this->paypal_gateway->imageUrl()) { |
|
| 292 | + $this->order_items['image_url'] = $this->paypal_gateway->imageUrl(); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | 295 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | // and make adjustments as needed |
| 135 | 135 | $item_num = $this->handleItemizedOrderSumDifference($total_line_item, $item_num); |
| 136 | 136 | // add our taxes to the order if we're NOT using PayPal's |
| 137 | - if (! $this->paypal_gateway->paypalTaxes()) { |
|
| 137 | + if ( ! $this->paypal_gateway->paypalTaxes()) { |
|
| 138 | 138 | $this->order_items['tax_cart'] = $total_line_item->get_total_tax(); |
| 139 | 139 | } |
| 140 | 140 | return $item_num; |
@@ -151,15 +151,15 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | $this->payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
| 153 | 153 | // partial payment that's not for the remaining amount, so we can't send an itemized list |
| 154 | - $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 154 | + $this->order_items["item_name_{$item_num}"] = substr( |
|
| 155 | 155 | $this->gateway_data_formatter->formatPartialPaymentLineItemName($this->payment), |
| 156 | 156 | 0, |
| 157 | 157 | 127 |
| 158 | 158 | ); |
| 159 | - $this->order_items[ "amount_{$item_num}" ] = $this->payment->amount(); |
|
| 160 | - $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 161 | - $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 162 | - $this->order_items['tax_cart'] = '0'; |
|
| 159 | + $this->order_items["amount_{$item_num}"] = $this->payment->amount(); |
|
| 160 | + $this->order_items["shipping_{$item_num}"] = '0'; |
|
| 161 | + $this->order_items["shipping2_{$item_num}"] = '0'; |
|
| 162 | + $this->order_items['tax_cart'] = '0'; |
|
| 163 | 163 | $item_num++; |
| 164 | 164 | return $item_num; |
| 165 | 165 | } |
@@ -187,17 +187,17 @@ discard block |
||
| 187 | 187 | $this->existing_shipping_charges = $line_item->pretaxTotal(); |
| 188 | 188 | continue; |
| 189 | 189 | } |
| 190 | - $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 190 | + $this->order_items["item_name_{$item_num}"] = substr( |
|
| 191 | 191 | $this->gateway_data_formatter->formatLineItemName($line_item, $this->payment), |
| 192 | 192 | 0, |
| 193 | 193 | 127 |
| 194 | 194 | ); |
| 195 | - $this->order_items[ "amount_{$item_num}" ] = $line_item->unit_price(); |
|
| 196 | - $this->order_items[ "quantity_{$item_num}" ] = $line_item->quantity(); |
|
| 195 | + $this->order_items["amount_{$item_num}"] = $line_item->unit_price(); |
|
| 196 | + $this->order_items["quantity_{$item_num}"] = $line_item->quantity(); |
|
| 197 | 197 | // if we're not letting PayPal calculate shipping, tell them its 0 |
| 198 | - if (! $this->paypal_gateway->paypalShipping()) { |
|
| 199 | - $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 200 | - $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 198 | + if ( ! $this->paypal_gateway->paypalShipping()) { |
|
| 199 | + $this->order_items["shipping_{$item_num}"] = '0'; |
|
| 200 | + $this->order_items["shipping2_{$item_num}"] = '0'; |
|
| 201 | 201 | } |
| 202 | 202 | $this->itemized_order_sum += $line_item->pretaxTotal(); |
| 203 | 203 | $item_num++; |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | $this->total_discounts += abs($itemized_order_sum_difference); |
| 233 | 233 | } elseif (EEH_Money::compare_floats($itemized_order_sum_difference, 0.00, '>')) { |
| 234 | 234 | // the itemized order sum is MORE than the transaction total |
| 235 | - $this->order_items[ "item_name_{$item_num}" ] = substr( |
|
| 235 | + $this->order_items["item_name_{$item_num}"] = substr( |
|
| 236 | 236 | esc_html__('additional charges', 'event_espresso'), |
| 237 | 237 | 0, |
| 238 | 238 | 127 |
| 239 | 239 | ); |
| 240 | - $this->order_items[ "amount_{$item_num}" ] = $this->gateway_data_formatter->formatCurrency( |
|
| 240 | + $this->order_items["amount_{$item_num}"] = $this->gateway_data_formatter->formatCurrency( |
|
| 241 | 241 | $itemized_order_sum_difference |
| 242 | 242 | ); |
| 243 | - $this->order_items[ "quantity_{$item_num}" ] = 1; |
|
| 243 | + $this->order_items["quantity_{$item_num}"] = 1; |
|
| 244 | 244 | $item_num++; |
| 245 | 245 | } |
| 246 | 246 | if (EEH_Money::compare_floats($this->total_discounts, 0.00, '>')) { |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | private function addSandboxModeArgs(int $item_num, string $notify_url, string $return_url) |
| 261 | 261 | { |
| 262 | - $this->order_items[ "item_name_{$item_num}" ] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
| 263 | - $this->order_items[ "amount_{$item_num}" ] = 0; |
|
| 264 | - $this->order_items[ "on0_{$item_num}" ] = 'NOTIFY URL'; |
|
| 265 | - $this->order_items[ "os0_{$item_num}" ] = $notify_url; |
|
| 266 | - $this->order_items[ "on1_{$item_num}" ] = 'RETURN URL'; |
|
| 267 | - $this->order_items[ "os1_{$item_num}" ] = $return_url; |
|
| 268 | - $this->order_items[ "shipping_{$item_num}" ] = '0'; |
|
| 269 | - $this->order_items[ "shipping2_{$item_num}" ] = '0'; |
|
| 262 | + $this->order_items["item_name_{$item_num}"] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
| 263 | + $this->order_items["amount_{$item_num}"] = 0; |
|
| 264 | + $this->order_items["on0_{$item_num}"] = 'NOTIFY URL'; |
|
| 265 | + $this->order_items["os0_{$item_num}"] = $notify_url; |
|
| 266 | + $this->order_items["on1_{$item_num}"] = 'RETURN URL'; |
|
| 267 | + $this->order_items["os1_{$item_num}"] = $return_url; |
|
| 268 | + $this->order_items["shipping_{$item_num}"] = '0'; |
|
| 269 | + $this->order_items["shipping2_{$item_num}"] = '0'; |
|
| 270 | 270 | // $this->order_items['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
| 271 | 271 | } |
| 272 | 272 | |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | $this->order_items['cmd'] = '_cart'; |
| 286 | 286 | $this->order_items['upload'] = 1; |
| 287 | 287 | $this->order_items['currency_code'] = $this->payment->currency_code(); |
| 288 | - $this->order_items['rm'] = 2;// makes the user return with method=POST |
|
| 288 | + $this->order_items['rm'] = 2; // makes the user return with method=POST |
|
| 289 | 289 | $this->order_items['no_shipping'] = $this->paypal_gateway->shippingDetails(); |
| 290 | - $this->order_items['bn'] = 'EventEspresso_SP';// EE will blow up if you change this |
|
| 290 | + $this->order_items['bn'] = 'EventEspresso_SP'; // EE will blow up if you change this |
|
| 291 | 291 | if ($this->paypal_gateway->imageUrl()) { |
| 292 | 292 | $this->order_items['image_url'] = $this->paypal_gateway->imageUrl(); |
| 293 | 293 | } |
@@ -6,17 +6,17 @@ discard block |
||
| 6 | 6 | * @var EE_Ticket $ticket |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if (! function_exists('espressoSubtotalRow')) { |
|
| 9 | +if ( ! function_exists('espressoSubtotalRow')) { |
|
| 10 | 10 | function espressoSubtotalRow(float $running_total, bool $show = true): string |
| 11 | 11 | { |
| 12 | 12 | return $show |
| 13 | 13 | ? ' |
| 14 | 14 | <tr> |
| 15 | 15 | <td colspan="2" class="jst-rght small-text sbttl"> |
| 16 | - <b>' . esc_html__('subtotal', 'event_espresso') . '</b> |
|
| 16 | + <b>' . esc_html__('subtotal', 'event_espresso').'</b> |
|
| 17 | 17 | </td> |
| 18 | - <td data-th="' . esc_html__('subtotal', 'event_espresso') . '" class="jst-rght small-text"> |
|
| 19 | - <b>' . EEH_Template::format_currency($running_total) . '</b> |
|
| 18 | + <td data-th="' . esc_html__('subtotal', 'event_espresso').'" class="jst-rght small-text"> |
|
| 19 | + <b>' . EEH_Template::format_currency($running_total).'</b> |
|
| 20 | 20 | </td> |
| 21 | 21 | </tr> |
| 22 | 22 | ' |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | $new_sub_total = $price_mod->is_discount() |
| 81 | 81 | ? $new_sub_total * -1 |
| 82 | 82 | : $new_sub_total; |
| 83 | - $description = $price_mod->desc() . ' '; |
|
| 84 | - $description .= $price_mod->is_percent() |
|
| 85 | - ? $price_mod->amount() . '%' |
|
| 83 | + $description = $price_mod->desc().' '; |
|
| 84 | + $description .= $price_mod->is_percent() |
|
| 85 | + ? $price_mod->amount().'%' |
|
| 86 | 86 | : EEH_Template::format_currency($price_mod->amount()); |
| 87 | 87 | ?> |
| 88 | 88 | <tr> |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | if (! function_exists('espressoSubtotalRow')) { |
| 13 | - function espressoSubtotalRow(float $running_total, bool $show = true): string |
|
| 14 | - { |
|
| 15 | - return $show |
|
| 16 | - ? ' |
|
| 13 | + function espressoSubtotalRow(float $running_total, bool $show = true): string |
|
| 14 | + { |
|
| 15 | + return $show |
|
| 16 | + ? ' |
|
| 17 | 17 | <tr> |
| 18 | 18 | <td colspan="2" class="jst-rght small-text sbttl"> |
| 19 | 19 | <b>' . esc_html__('subtotal', 'event_espresso') . '</b> |
@@ -23,18 +23,18 @@ discard block |
||
| 23 | 23 | </td> |
| 24 | 24 | </tr> |
| 25 | 25 | ' |
| 26 | - : ''; |
|
| 27 | - } |
|
| 26 | + : ''; |
|
| 27 | + } |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | if ($display_ticket_price) { ?> |
| 31 | 31 | <section class="tckt-slctr-tkt-price-sctn"> |
| 32 | 32 | <h5><?php echo esc_html( |
| 33 | - apply_filters( |
|
| 34 | - 'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading', |
|
| 35 | - __('Price', 'event_espresso') |
|
| 36 | - ) |
|
| 37 | - ); ?></h5> |
|
| 33 | + apply_filters( |
|
| 34 | + 'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading', |
|
| 35 | + __('Price', 'event_espresso') |
|
| 36 | + ) |
|
| 37 | + ); ?></h5> |
|
| 38 | 38 | <div class="tckt-slctr-tkt-details-tbl-wrap-dv"> |
| 39 | 39 | <table class="tckt-slctr-tkt-details-tbl"> |
| 40 | 40 | <thead> |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | </thead> |
| 55 | 55 | <tbody> |
| 56 | 56 | <?php |
| 57 | - if ($ticket->base_price() instanceof EE_Price) { ?> |
|
| 57 | + if ($ticket->base_price() instanceof EE_Price) { ?> |
|
| 58 | 58 | <tr> |
| 59 | 59 | <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" class="small-text" colspan="2"> |
| 60 | 60 | <b> |
@@ -66,31 +66,31 @@ discard block |
||
| 66 | 66 | </td> |
| 67 | 67 | </tr> |
| 68 | 68 | <?php |
| 69 | - $running_total = $ticket->base_price()->amount(); |
|
| 70 | - } else { |
|
| 71 | - $running_total = 0; |
|
| 72 | - } |
|
| 73 | - $pretax_total = $running_total; |
|
| 74 | - $display_subtotal = true; |
|
| 75 | - // now add price modifiers |
|
| 76 | - foreach ($ticket->price_modifiers() as $price_mod) { |
|
| 77 | - if ($price_mod->is_tax()) { |
|
| 78 | - echo espressoSubtotalRow($running_total, $display_subtotal); |
|
| 79 | - $display_subtotal = false; |
|
| 80 | - $new_sub_total = $pretax_total * ($price_mod->amount() / 100); |
|
| 81 | - } elseif ($price_mod->is_percent()) { |
|
| 82 | - $new_sub_total = $running_total * ($price_mod->amount() / 100); |
|
| 83 | - } else { |
|
| 84 | - $new_sub_total = $price_mod->amount(); |
|
| 85 | - } |
|
| 86 | - $new_sub_total = $price_mod->is_discount() |
|
| 87 | - ? $new_sub_total * -1 |
|
| 88 | - : $new_sub_total; |
|
| 89 | - $description = $price_mod->desc() . ' '; |
|
| 90 | - $description .= $price_mod->is_percent() |
|
| 91 | - ? $price_mod->amount() . '%' |
|
| 92 | - : EEH_Template::format_currency($price_mod->amount()); |
|
| 93 | - ?> |
|
| 69 | + $running_total = $ticket->base_price()->amount(); |
|
| 70 | + } else { |
|
| 71 | + $running_total = 0; |
|
| 72 | + } |
|
| 73 | + $pretax_total = $running_total; |
|
| 74 | + $display_subtotal = true; |
|
| 75 | + // now add price modifiers |
|
| 76 | + foreach ($ticket->price_modifiers() as $price_mod) { |
|
| 77 | + if ($price_mod->is_tax()) { |
|
| 78 | + echo espressoSubtotalRow($running_total, $display_subtotal); |
|
| 79 | + $display_subtotal = false; |
|
| 80 | + $new_sub_total = $pretax_total * ($price_mod->amount() / 100); |
|
| 81 | + } elseif ($price_mod->is_percent()) { |
|
| 82 | + $new_sub_total = $running_total * ($price_mod->amount() / 100); |
|
| 83 | + } else { |
|
| 84 | + $new_sub_total = $price_mod->amount(); |
|
| 85 | + } |
|
| 86 | + $new_sub_total = $price_mod->is_discount() |
|
| 87 | + ? $new_sub_total * -1 |
|
| 88 | + : $new_sub_total; |
|
| 89 | + $description = $price_mod->desc() . ' '; |
|
| 90 | + $description .= $price_mod->is_percent() |
|
| 91 | + ? $price_mod->amount() . '%' |
|
| 92 | + : EEH_Template::format_currency($price_mod->amount()); |
|
| 93 | + ?> |
|
| 94 | 94 | <tr> |
| 95 | 95 | <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" |
| 96 | 96 | class="jst-rght small-text" |
@@ -102,17 +102,17 @@ discard block |
||
| 102 | 102 | </td> |
| 103 | 103 | <td data-th="<?php esc_html_e('Amount', 'event_espresso'); ?>" class="jst-rght small-text"> |
| 104 | 104 | <?php echo wp_kses( |
| 105 | - EEH_Template::format_currency($new_sub_total), |
|
| 106 | - AllowedTags::getAllowedTags() |
|
| 107 | - ); ?> |
|
| 105 | + EEH_Template::format_currency($new_sub_total), |
|
| 106 | + AllowedTags::getAllowedTags() |
|
| 107 | + ); ?> |
|
| 108 | 108 | </td> |
| 109 | 109 | <?php $pretax_total += ! $price_mod->is_tax() ? $new_sub_total : 0; ?> |
| 110 | 110 | <?php $running_total += $new_sub_total; ?> |
| 111 | 111 | </tr> |
| 112 | 112 | <?php } ?> |
| 113 | 113 | <?php if ($ticket->taxable()) { |
| 114 | - echo espressoSubtotalRow($running_total); |
|
| 115 | - foreach ($ticket->get_ticket_taxes_for_admin() as $tax) { ?> |
|
| 114 | + echo espressoSubtotalRow($running_total); |
|
| 115 | + foreach ($ticket->get_ticket_taxes_for_admin() as $tax) { ?> |
|
| 116 | 116 | <tr> |
| 117 | 117 | <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" |
| 118 | 118 | class="jst-rght small-text" |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | class="jst-rght small-text" |
| 130 | 130 | > |
| 131 | 131 | <?php echo wp_kses( |
| 132 | - EEH_Template::format_currency($tax_amount), |
|
| 133 | - AllowedTags::getAllowedTags() |
|
| 134 | - ); ?> |
|
| 132 | + EEH_Template::format_currency($tax_amount), |
|
| 133 | + AllowedTags::getAllowedTags() |
|
| 134 | + ); ?> |
|
| 135 | 135 | </td> |
| 136 | 136 | <?php $running_total += $tax_amount; ?> |
| 137 | 137 | </tr> |
@@ -141,24 +141,24 @@ discard block |
||
| 141 | 141 | <td colspan="2" class="jst-rght small-text ttl-lbl-td"> |
| 142 | 142 | <b> |
| 143 | 143 | <?php echo esc_html( |
| 144 | - apply_filters( |
|
| 145 | - 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 146 | - __('Total', 'event_espresso') |
|
| 147 | - ) |
|
| 148 | - ); ?> |
|
| 144 | + apply_filters( |
|
| 145 | + 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 146 | + __('Total', 'event_espresso') |
|
| 147 | + ) |
|
| 148 | + ); ?> |
|
| 149 | 149 | </b> |
| 150 | 150 | </td> |
| 151 | 151 | <td data-th="<?php echo esc_html( |
| 152 | - apply_filters( |
|
| 153 | - 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 154 | - __('Total', 'event_espresso') |
|
| 155 | - ) |
|
| 156 | - ); ?>" class="jst-rght small-text" |
|
| 152 | + apply_filters( |
|
| 153 | + 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 154 | + __('Total', 'event_espresso') |
|
| 155 | + ) |
|
| 156 | + ); ?>" class="jst-rght small-text" |
|
| 157 | 157 | > |
| 158 | 158 | <b><?php wp_kses( |
| 159 | - EEH_Template::format_currency($running_total), |
|
| 160 | - AllowedTags::getAllowedTags() |
|
| 161 | - ); ?></b> |
|
| 159 | + EEH_Template::format_currency($running_total), |
|
| 160 | + AllowedTags::getAllowedTags() |
|
| 161 | + ); ?></b> |
|
| 162 | 162 | </td> |
| 163 | 163 | </tr> |
| 164 | 164 | </tbody> |
@@ -118,13 +118,13 @@ |
||
| 118 | 118 | public function getHiddenInputs() |
| 119 | 119 | { |
| 120 | 120 | $html = '<input type="hidden" name="noheader" value="true"/>'; |
| 121 | - $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"'; |
|
| 122 | - $html .= ' value="' . EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>'; |
|
| 123 | - $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID(); |
|
| 124 | - $html .= '" value="' . $this->ticket_rows . '"/>'; |
|
| 125 | - $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID(); |
|
| 126 | - $html .= '" value="' . $this->template_args['max_atndz'] . '"/>'; |
|
| 127 | - $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>'; |
|
| 121 | + $html .= '<input type="hidden" name="tkt-slctr-return-url-'.$this->event->ID().'"'; |
|
| 122 | + $html .= ' value="'.EEH_URL::current_url().$this->template_args['anchor_id'].'"/>'; |
|
| 123 | + $html .= '<input type="hidden" name="tkt-slctr-rows-'.$this->event->ID(); |
|
| 124 | + $html .= '" value="'.$this->ticket_rows.'"/>'; |
|
| 125 | + $html .= '<input type="hidden" name="tkt-slctr-max-atndz-'.$this->event->ID(); |
|
| 126 | + $html .= '" value="'.$this->template_args['max_atndz'].'"/>'; |
|
| 127 | + $html .= '<input type="hidden" name="tkt-slctr-event-id" value="'.$this->event->ID().'"/>'; |
|
| 128 | 128 | return $html; |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -19,111 +19,111 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | abstract class TicketSelector |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var EE_Event |
|
| 24 | - */ |
|
| 25 | - protected $event; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var EE_Ticket[] |
|
| 29 | - */ |
|
| 30 | - protected $tickets; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - protected $max_attendees; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $template_args; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected $ticket_rows = 0; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * TicketSelectorSimple constructor. |
|
| 50 | - * |
|
| 51 | - * @param EE_Event $event |
|
| 52 | - * @param EE_Ticket[] $tickets |
|
| 53 | - * @param int $max_attendees |
|
| 54 | - * @param array $template_args |
|
| 55 | - */ |
|
| 56 | - public function __construct(EE_Event $event, array $tickets, $max_attendees, array $template_args) |
|
| 57 | - { |
|
| 58 | - $this->event = $event; |
|
| 59 | - $this->tickets = $tickets; |
|
| 60 | - $this->max_attendees = $max_attendees; |
|
| 61 | - $this->template_args = $template_args; |
|
| 62 | - $this->addTemplateArgs(); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * sets any and all template args that are required for this Ticket Selector |
|
| 68 | - * |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - abstract protected function addTemplateArgs(); |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * loadTicketSelectorTemplate |
|
| 76 | - * |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - protected function loadTicketSelectorTemplate() |
|
| 80 | - { |
|
| 81 | - try { |
|
| 82 | - $this->template_args['hidden_inputs'] = $this->getHiddenInputs(); |
|
| 83 | - return EEH_Template::locate_template( |
|
| 84 | - apply_filters( |
|
| 85 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
| 86 | - $this->template_args['template_path'], |
|
| 87 | - $this->event |
|
| 88 | - ), |
|
| 89 | - $this->template_args |
|
| 90 | - ); |
|
| 91 | - } catch (Exception $e) { |
|
| 92 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 93 | - } |
|
| 94 | - return ''; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * The __toString method allows a class to decide how it will react when it is converted to a string. |
|
| 100 | - * |
|
| 101 | - * @return string |
|
| 102 | - * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring |
|
| 103 | - */ |
|
| 104 | - public function __toString() |
|
| 105 | - { |
|
| 106 | - return $this->loadTicketSelectorTemplate(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * getHiddenInputs |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - * @throws EE_Error |
|
| 115 | - * @throws ReflectionException |
|
| 116 | - */ |
|
| 117 | - public function getHiddenInputs() |
|
| 118 | - { |
|
| 119 | - $html = '<input type="hidden" name="noheader" value="true"/>'; |
|
| 120 | - $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"'; |
|
| 121 | - $html .= ' value="' . EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>'; |
|
| 122 | - $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID(); |
|
| 123 | - $html .= '" value="' . $this->ticket_rows . '"/>'; |
|
| 124 | - $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID(); |
|
| 125 | - $html .= '" value="' . $this->template_args['max_atndz'] . '"/>'; |
|
| 126 | - $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>'; |
|
| 127 | - return $html; |
|
| 128 | - } |
|
| 22 | + /** |
|
| 23 | + * @var EE_Event |
|
| 24 | + */ |
|
| 25 | + protected $event; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var EE_Ticket[] |
|
| 29 | + */ |
|
| 30 | + protected $tickets; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + protected $max_attendees; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $template_args; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected $ticket_rows = 0; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * TicketSelectorSimple constructor. |
|
| 50 | + * |
|
| 51 | + * @param EE_Event $event |
|
| 52 | + * @param EE_Ticket[] $tickets |
|
| 53 | + * @param int $max_attendees |
|
| 54 | + * @param array $template_args |
|
| 55 | + */ |
|
| 56 | + public function __construct(EE_Event $event, array $tickets, $max_attendees, array $template_args) |
|
| 57 | + { |
|
| 58 | + $this->event = $event; |
|
| 59 | + $this->tickets = $tickets; |
|
| 60 | + $this->max_attendees = $max_attendees; |
|
| 61 | + $this->template_args = $template_args; |
|
| 62 | + $this->addTemplateArgs(); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * sets any and all template args that are required for this Ticket Selector |
|
| 68 | + * |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + abstract protected function addTemplateArgs(); |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * loadTicketSelectorTemplate |
|
| 76 | + * |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + protected function loadTicketSelectorTemplate() |
|
| 80 | + { |
|
| 81 | + try { |
|
| 82 | + $this->template_args['hidden_inputs'] = $this->getHiddenInputs(); |
|
| 83 | + return EEH_Template::locate_template( |
|
| 84 | + apply_filters( |
|
| 85 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', |
|
| 86 | + $this->template_args['template_path'], |
|
| 87 | + $this->event |
|
| 88 | + ), |
|
| 89 | + $this->template_args |
|
| 90 | + ); |
|
| 91 | + } catch (Exception $e) { |
|
| 92 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 93 | + } |
|
| 94 | + return ''; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * The __toString method allows a class to decide how it will react when it is converted to a string. |
|
| 100 | + * |
|
| 101 | + * @return string |
|
| 102 | + * @link http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring |
|
| 103 | + */ |
|
| 104 | + public function __toString() |
|
| 105 | + { |
|
| 106 | + return $this->loadTicketSelectorTemplate(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * getHiddenInputs |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + * @throws EE_Error |
|
| 115 | + * @throws ReflectionException |
|
| 116 | + */ |
|
| 117 | + public function getHiddenInputs() |
|
| 118 | + { |
|
| 119 | + $html = '<input type="hidden" name="noheader" value="true"/>'; |
|
| 120 | + $html .= '<input type="hidden" name="tkt-slctr-return-url-' . $this->event->ID() . '"'; |
|
| 121 | + $html .= ' value="' . EEH_URL::current_url() . $this->template_args['anchor_id'] . '"/>'; |
|
| 122 | + $html .= '<input type="hidden" name="tkt-slctr-rows-' . $this->event->ID(); |
|
| 123 | + $html .= '" value="' . $this->ticket_rows . '"/>'; |
|
| 124 | + $html .= '<input type="hidden" name="tkt-slctr-max-atndz-' . $this->event->ID(); |
|
| 125 | + $html .= '" value="' . $this->template_args['max_atndz'] . '"/>'; |
|
| 126 | + $html .= '<input type="hidden" name="tkt-slctr-event-id" value="' . $this->event->ID() . '"/>'; |
|
| 127 | + return $html; |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
| 85 | 85 | array() |
| 86 | 86 | ); |
| 87 | - if (! empty($shortcodes_to_register)) { |
|
| 87 | + if ( ! empty($shortcodes_to_register)) { |
|
| 88 | 88 | // cycle thru shortcode folders |
| 89 | 89 | foreach ($shortcodes_to_register as $shortcode_path) { |
| 90 | 90 | // add to list of installed shortcode modules |
@@ -128,44 +128,44 @@ discard block |
||
| 128 | 128 | // remove last segment |
| 129 | 129 | array_pop($shortcode_path); |
| 130 | 130 | // glue it back together |
| 131 | - $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
| 131 | + $shortcode_path = implode('/', $shortcode_path).'/'; |
|
| 132 | 132 | } else { |
| 133 | 133 | // we need to generate the filename based off of the folder name |
| 134 | 134 | // grab and sanitize shortcode directory name |
| 135 | 135 | $shortcode = sanitize_key(basename($shortcode_path)); |
| 136 | - $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
| 136 | + $shortcode_path = rtrim($shortcode_path, '/').'/'; |
|
| 137 | 137 | } |
| 138 | 138 | // create classname from shortcode directory or file name |
| 139 | 139 | $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
| 140 | 140 | // add class prefix |
| 141 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 141 | + $shortcode_class = 'EES_'.$shortcode; |
|
| 142 | 142 | // does the shortcode exist ? |
| 143 | - if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
| 143 | + if ( ! is_readable($shortcode_path.'/'.$shortcode_class.$shortcode_ext)) { |
|
| 144 | 144 | $msg = sprintf( |
| 145 | 145 | esc_html__( |
| 146 | 146 | 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
| 147 | 147 | 'event_espresso' |
| 148 | 148 | ), |
| 149 | 149 | $shortcode_class, |
| 150 | - $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
| 150 | + $shortcode_path.'/'.$shortcode_class.$shortcode_ext |
|
| 151 | 151 | ); |
| 152 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 152 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 153 | 153 | return false; |
| 154 | 154 | } |
| 155 | 155 | // load the shortcode class file |
| 156 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 156 | + require_once($shortcode_path.$shortcode_class.$shortcode_ext); |
|
| 157 | 157 | // verify that class exists |
| 158 | - if (! class_exists($shortcode_class)) { |
|
| 158 | + if ( ! class_exists($shortcode_class)) { |
|
| 159 | 159 | $msg = sprintf( |
| 160 | 160 | esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
| 161 | 161 | $shortcode_class |
| 162 | 162 | ); |
| 163 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 163 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 164 | 164 | return false; |
| 165 | 165 | } |
| 166 | 166 | $shortcode = strtoupper($shortcode); |
| 167 | 167 | // add to array of registered shortcodes |
| 168 | - $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 168 | + $this->registry->shortcodes->{$shortcode} = $shortcode_path.$shortcode_class.$shortcode_ext; |
|
| 169 | 169 | return true; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | // cycle thru shortcode folders |
| 182 | 182 | foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
| 183 | 183 | // add class prefix |
| 184 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 184 | + $shortcode_class = 'EES_'.$shortcode; |
|
| 185 | 185 | // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
| 186 | 186 | // which set hooks ? |
| 187 | 187 | if (is_admin()) { |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $shortcode_tag = strtoupper($shortcode); |
| 198 | 198 | // but first check if the shortcode has already |
| 199 | 199 | // been added before assigning 'fallback_shortcode_processor' |
| 200 | - if (! shortcode_exists($shortcode_tag)) { |
|
| 200 | + if ( ! shortcode_exists($shortcode_tag)) { |
|
| 201 | 201 | // NOTE: this shortcode declaration will get overridden if the shortcode |
| 202 | 202 | // is successfully detected in the post content in initializeShortcode() |
| 203 | 203 | add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | // one last test for an [espresso_*] shortcode |
| 315 | - if (! $has_shortcode) { |
|
| 315 | + if ( ! $has_shortcode) { |
|
| 316 | 316 | $has_shortcode = strpos($content, '[espresso_') !== false; |
| 317 | 317 | } |
| 318 | 318 | return $has_shortcode; |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public static function addShortcodeClassPrefix($class_name) |
| 420 | 420 | { |
| 421 | - return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
| 421 | + return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_'.$class_name; |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | |
@@ -25,444 +25,444 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class LegacyShortcodesManager |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * @type CurrentPage |
|
| 30 | - */ |
|
| 31 | - protected $current_page; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var EE_Registry $registry |
|
| 35 | - */ |
|
| 36 | - private $registry; |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * LegacyShortcodesManager constructor. |
|
| 41 | - * |
|
| 42 | - * @param EE_Registry $registry |
|
| 43 | - * @param CurrentPage $current_page |
|
| 44 | - */ |
|
| 45 | - public function __construct(EE_Registry $registry, CurrentPage $current_page) |
|
| 46 | - { |
|
| 47 | - $this->registry = $registry; |
|
| 48 | - $this->current_page = $current_page; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return EE_Registry |
|
| 54 | - */ |
|
| 55 | - public function registry() |
|
| 56 | - { |
|
| 57 | - return $this->registry; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * registerShortcodes |
|
| 63 | - * |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - public function registerShortcodes() |
|
| 67 | - { |
|
| 68 | - $this->registry->shortcodes = $this->getShortcodes(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * getShortcodes |
|
| 74 | - * |
|
| 75 | - * @return array |
|
| 76 | - */ |
|
| 77 | - public function getShortcodes() |
|
| 78 | - { |
|
| 79 | - // previously this method would glob the shortcodes directory |
|
| 80 | - // then filter that list of shortcodes to register, |
|
| 81 | - // but now we are going to just supply an empty array. |
|
| 82 | - // this allows any shortcodes that have not yet been converted to the new system |
|
| 83 | - // to still get loaded and processed, albeit using the same legacy logic as before |
|
| 84 | - $shortcodes_to_register = apply_filters( |
|
| 85 | - 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 86 | - array() |
|
| 87 | - ); |
|
| 88 | - if (! empty($shortcodes_to_register)) { |
|
| 89 | - // cycle thru shortcode folders |
|
| 90 | - foreach ($shortcodes_to_register as $shortcode_path) { |
|
| 91 | - // add to list of installed shortcode modules |
|
| 92 | - $this->registerShortcode($shortcode_path); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - // filter list of installed modules |
|
| 96 | - return apply_filters( |
|
| 97 | - 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
| 98 | - ! empty($this->registry->shortcodes) |
|
| 99 | - ? $this->registry->shortcodes |
|
| 100 | - : array() |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * register_shortcode - makes core aware of this shortcode |
|
| 107 | - * |
|
| 108 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 109 | - * @return bool |
|
| 110 | - */ |
|
| 111 | - public function registerShortcode($shortcode_path = null) |
|
| 112 | - { |
|
| 113 | - do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
| 114 | - $shortcode_ext = '.shortcode.php'; |
|
| 115 | - // make all separators match |
|
| 116 | - $shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path); |
|
| 117 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
| 118 | - if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
| 119 | - // grab shortcode file name from directory name and break apart at dots |
|
| 120 | - $shortcode_file = explode('.', basename($shortcode_path)); |
|
| 121 | - // take first segment from file name pieces and remove class prefix if it exists |
|
| 122 | - $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
| 123 | - ? substr($shortcode_file[0], 4) |
|
| 124 | - : $shortcode_file[0]; |
|
| 125 | - // sanitize shortcode directory name |
|
| 126 | - $shortcode = sanitize_key($shortcode); |
|
| 127 | - // now we need to rebuild the shortcode path |
|
| 128 | - $shortcode_path = explode('/', $shortcode_path); |
|
| 129 | - // remove last segment |
|
| 130 | - array_pop($shortcode_path); |
|
| 131 | - // glue it back together |
|
| 132 | - $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
| 133 | - } else { |
|
| 134 | - // we need to generate the filename based off of the folder name |
|
| 135 | - // grab and sanitize shortcode directory name |
|
| 136 | - $shortcode = sanitize_key(basename($shortcode_path)); |
|
| 137 | - $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
| 138 | - } |
|
| 139 | - // create classname from shortcode directory or file name |
|
| 140 | - $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
| 141 | - // add class prefix |
|
| 142 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 143 | - // does the shortcode exist ? |
|
| 144 | - if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
| 145 | - $msg = sprintf( |
|
| 146 | - esc_html__( |
|
| 147 | - 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
|
| 148 | - 'event_espresso' |
|
| 149 | - ), |
|
| 150 | - $shortcode_class, |
|
| 151 | - $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
| 152 | - ); |
|
| 153 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - // load the shortcode class file |
|
| 157 | - require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 158 | - // verify that class exists |
|
| 159 | - if (! class_exists($shortcode_class)) { |
|
| 160 | - $msg = sprintf( |
|
| 161 | - esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
| 162 | - $shortcode_class |
|
| 163 | - ); |
|
| 164 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - $shortcode = strtoupper($shortcode); |
|
| 168 | - // add to array of registered shortcodes |
|
| 169 | - $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 170 | - return true; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * _initialize_shortcodes |
|
| 176 | - * allow shortcodes to set hooks for the rest of the system |
|
| 177 | - * |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function addShortcodes() |
|
| 181 | - { |
|
| 182 | - // cycle thru shortcode folders |
|
| 183 | - foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
| 184 | - // add class prefix |
|
| 185 | - $shortcode_class = 'EES_' . $shortcode; |
|
| 186 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 187 | - // which set hooks ? |
|
| 188 | - if (is_admin()) { |
|
| 189 | - // fire immediately |
|
| 190 | - call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
| 191 | - } else { |
|
| 192 | - // delay until other systems are online |
|
| 193 | - add_action( |
|
| 194 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 195 | - array($shortcode_class, 'set_hooks') |
|
| 196 | - ); |
|
| 197 | - // convert classname to UPPERCASE and create WP shortcode. |
|
| 198 | - $shortcode_tag = strtoupper($shortcode); |
|
| 199 | - // but first check if the shortcode has already |
|
| 200 | - // been added before assigning 'fallback_shortcode_processor' |
|
| 201 | - if (! shortcode_exists($shortcode_tag)) { |
|
| 202 | - // NOTE: this shortcode declaration will get overridden if the shortcode |
|
| 203 | - // is successfully detected in the post content in initializeShortcode() |
|
| 204 | - add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * callback for the WP "get_header" hook point |
|
| 213 | - * checks posts for EE shortcodes, and initializes them, |
|
| 214 | - * then toggles filter switch that loads core default assets |
|
| 215 | - * |
|
| 216 | - * @param WP_Query $wp_query |
|
| 217 | - * @return void |
|
| 218 | - * @throws ReflectionException |
|
| 219 | - */ |
|
| 220 | - public function initializeShortcodes(WP_Query $wp_query) |
|
| 221 | - { |
|
| 222 | - if ( |
|
| 223 | - empty($this->registry->shortcodes) |
|
| 224 | - || defined('EE_TESTS_DIR') |
|
| 225 | - || ! $wp_query->is_main_query() |
|
| 226 | - || is_admin() |
|
| 227 | - ) { |
|
| 228 | - return; |
|
| 229 | - } |
|
| 230 | - // in case shortcode is loaded unexpectedly and deps haven't been set up correctly |
|
| 231 | - EE_Dependency_Map::register_dependencies( |
|
| 232 | - 'EE_Front_Controller', |
|
| 233 | - [ |
|
| 234 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 235 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 236 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 237 | - ] |
|
| 238 | - ); |
|
| 239 | - global $wp; |
|
| 240 | - /** @var EE_Front_controller $Front_Controller */ |
|
| 241 | - $Front_Controller = LoaderFactory::getLoader()->getShared('EE_Front_Controller'); |
|
| 242 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
| 243 | - $this->current_page->parseQueryVars(); |
|
| 244 | - // grab post_name from request |
|
| 245 | - $current_post = apply_filters( |
|
| 246 | - 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
| 247 | - $this->current_page->postName() |
|
| 248 | - ); |
|
| 249 | - $show_on_front = get_option('show_on_front'); |
|
| 250 | - // if it's not set, then check if frontpage is blog |
|
| 251 | - if (empty($current_post)) { |
|
| 252 | - // yup.. this is the posts page, prepare to load all shortcode modules |
|
| 253 | - $current_post = 'posts'; |
|
| 254 | - // unless.. |
|
| 255 | - if ($show_on_front === 'page') { |
|
| 256 | - // some other page is set as the homepage |
|
| 257 | - $page_on_front = get_option('page_on_front'); |
|
| 258 | - if ($page_on_front) { |
|
| 259 | - // k now we need to find the post_name for this page |
|
| 260 | - global $wpdb; |
|
| 261 | - $page_on_front = $wpdb->get_var( |
|
| 262 | - $wpdb->prepare( |
|
| 263 | - "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d", |
|
| 264 | - $page_on_front |
|
| 265 | - ) |
|
| 266 | - ); |
|
| 267 | - // set the current post slug to what it actually is |
|
| 268 | - $current_post = $page_on_front ?: $current_post; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - // in case $current_post is hierarchical like: /parent-page/current-page |
|
| 273 | - $current_post = basename($current_post); |
|
| 274 | - if ( |
|
| 275 | - // is current page/post the "blog" page ? |
|
| 276 | - $current_post === EE_Config::get_page_for_posts() |
|
| 277 | - // or are we on a category page? |
|
| 278 | - || ( |
|
| 279 | - is_array(term_exists($current_post, 'category')) |
|
| 280 | - || array_key_exists('category_name', $wp->query_vars) |
|
| 281 | - ) |
|
| 282 | - ) { |
|
| 283 | - // initialize all legacy shortcodes |
|
| 284 | - $load_assets = $this->parseContentForShortcodes('', true); |
|
| 285 | - } else { |
|
| 286 | - global $post; |
|
| 287 | - if ($post instanceof WP_Post) { |
|
| 288 | - $post_content = $post->post_content; |
|
| 289 | - } else { |
|
| 290 | - global $wpdb; |
|
| 291 | - $post_content = $wpdb->get_var( |
|
| 292 | - $wpdb->prepare( |
|
| 293 | - "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s", |
|
| 294 | - $current_post |
|
| 295 | - ) |
|
| 296 | - ); |
|
| 297 | - } |
|
| 298 | - $load_assets = $this->parseContentForShortcodes($post_content); |
|
| 299 | - } |
|
| 300 | - if ($load_assets) { |
|
| 301 | - $this->current_page->setEspressoPage(true); |
|
| 302 | - add_filter('FHEE_load_css', '__return_true'); |
|
| 303 | - add_filter('FHEE_load_js', '__return_true'); |
|
| 304 | - } |
|
| 305 | - do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * checks supplied content against list of legacy shortcodes, |
|
| 311 | - * then initializes any found shortcodes, and returns true. |
|
| 312 | - * returns false if no shortcodes found. |
|
| 313 | - * |
|
| 314 | - * @param string $content |
|
| 315 | - * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
| 316 | - * @return bool |
|
| 317 | - * @throws ReflectionException |
|
| 318 | - */ |
|
| 319 | - public function parseContentForShortcodes($content = '', $load_all = false) |
|
| 320 | - { |
|
| 321 | - $has_shortcode = false; |
|
| 322 | - foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
| 323 | - if ($load_all || has_shortcode($content, $shortcode_class)) { |
|
| 324 | - // load up the shortcode |
|
| 325 | - $this->initializeShortcode($shortcode_class); |
|
| 326 | - $has_shortcode = true; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - // one last test for an [espresso_*] shortcode |
|
| 330 | - if (! $has_shortcode) { |
|
| 331 | - $has_shortcode = strpos($content, '[espresso_') !== false; |
|
| 332 | - } |
|
| 333 | - return $has_shortcode; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
| 339 | - * |
|
| 340 | - * @param string $shortcode_class |
|
| 341 | - * @param WP $wp |
|
| 342 | - * @throws ReflectionException |
|
| 343 | - */ |
|
| 344 | - public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
| 345 | - { |
|
| 346 | - // don't do anything if shortcode is already initialized |
|
| 347 | - if ( |
|
| 348 | - empty($this->registry->shortcodes->{$shortcode_class}) |
|
| 349 | - || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
| 350 | - ) { |
|
| 351 | - return; |
|
| 352 | - } |
|
| 353 | - // let's pause to reflect on this... |
|
| 354 | - $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
| 355 | - // ensure that class is actually a shortcode |
|
| 356 | - if ( |
|
| 357 | - defined('WP_DEBUG') |
|
| 358 | - && WP_DEBUG === true |
|
| 359 | - && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
| 360 | - ) { |
|
| 361 | - EE_Error::add_error( |
|
| 362 | - sprintf( |
|
| 363 | - esc_html__( |
|
| 364 | - 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
| 365 | - 'event_espresso' |
|
| 366 | - ), |
|
| 367 | - $shortcode_class |
|
| 368 | - ), |
|
| 369 | - __FILE__, |
|
| 370 | - __FUNCTION__, |
|
| 371 | - __LINE__ |
|
| 372 | - ); |
|
| 373 | - add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 374 | - return; |
|
| 375 | - } |
|
| 376 | - global $wp; |
|
| 377 | - // and pass the request object to the run method |
|
| 378 | - $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
| 379 | - // fire the shortcode class's run method, so that it can activate resources |
|
| 380 | - $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * get classname, remove EES_prefix, and convert to UPPERCASE |
|
| 386 | - * |
|
| 387 | - * @param string $class_name |
|
| 388 | - * @return string |
|
| 389 | - */ |
|
| 390 | - public static function generateShortcodeTagFromClassName($class_name) |
|
| 391 | - { |
|
| 392 | - return strtoupper(str_replace('EES_', '', $class_name)); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * add EES_prefix and Capitalize words |
|
| 398 | - * |
|
| 399 | - * @param string $tag |
|
| 400 | - * @return string |
|
| 401 | - */ |
|
| 402 | - public static function generateShortcodeClassNameFromTag($tag) |
|
| 403 | - { |
|
| 404 | - // order of operation runs from inside to out |
|
| 405 | - // 5) maybe add prefix |
|
| 406 | - return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
| 407 | - // 4) find spaces, replace with underscores |
|
| 408 | - str_replace( |
|
| 409 | - ' ', |
|
| 410 | - '_', |
|
| 411 | - // 3) capitalize first letter of each word |
|
| 412 | - ucwords( |
|
| 413 | - // 2) also change to lowercase so ucwords() will work |
|
| 414 | - strtolower( |
|
| 415 | - // 1) find underscores, replace with spaces so ucwords() will work |
|
| 416 | - str_replace( |
|
| 417 | - '_', |
|
| 418 | - ' ', |
|
| 419 | - $tag |
|
| 420 | - ) |
|
| 421 | - ) |
|
| 422 | - ) |
|
| 423 | - ) |
|
| 424 | - ); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * maybe add EES_prefix |
|
| 430 | - * |
|
| 431 | - * @param string $class_name |
|
| 432 | - * @return string |
|
| 433 | - */ |
|
| 434 | - public static function addShortcodeClassPrefix($class_name) |
|
| 435 | - { |
|
| 436 | - return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @return array |
|
| 442 | - */ |
|
| 443 | - public function getEspressoShortcodeTags() |
|
| 444 | - { |
|
| 445 | - static $shortcode_tags = array(); |
|
| 446 | - if (empty($shortcode_tags)) { |
|
| 447 | - $shortcode_tags = array_keys((array) $this->registry->shortcodes); |
|
| 448 | - } |
|
| 449 | - return $shortcode_tags; |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * @param string $content |
|
| 455 | - * @return string |
|
| 456 | - * @throws ReflectionException |
|
| 457 | - */ |
|
| 458 | - public function doShortcode($content) |
|
| 459 | - { |
|
| 460 | - foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
| 461 | - if (strpos($content, $shortcode_tag) !== false) { |
|
| 462 | - $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
| 463 | - $this->initializeShortcode($shortcode_class); |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - return do_shortcode($content); |
|
| 467 | - } |
|
| 28 | + /** |
|
| 29 | + * @type CurrentPage |
|
| 30 | + */ |
|
| 31 | + protected $current_page; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var EE_Registry $registry |
|
| 35 | + */ |
|
| 36 | + private $registry; |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * LegacyShortcodesManager constructor. |
|
| 41 | + * |
|
| 42 | + * @param EE_Registry $registry |
|
| 43 | + * @param CurrentPage $current_page |
|
| 44 | + */ |
|
| 45 | + public function __construct(EE_Registry $registry, CurrentPage $current_page) |
|
| 46 | + { |
|
| 47 | + $this->registry = $registry; |
|
| 48 | + $this->current_page = $current_page; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return EE_Registry |
|
| 54 | + */ |
|
| 55 | + public function registry() |
|
| 56 | + { |
|
| 57 | + return $this->registry; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * registerShortcodes |
|
| 63 | + * |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + public function registerShortcodes() |
|
| 67 | + { |
|
| 68 | + $this->registry->shortcodes = $this->getShortcodes(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * getShortcodes |
|
| 74 | + * |
|
| 75 | + * @return array |
|
| 76 | + */ |
|
| 77 | + public function getShortcodes() |
|
| 78 | + { |
|
| 79 | + // previously this method would glob the shortcodes directory |
|
| 80 | + // then filter that list of shortcodes to register, |
|
| 81 | + // but now we are going to just supply an empty array. |
|
| 82 | + // this allows any shortcodes that have not yet been converted to the new system |
|
| 83 | + // to still get loaded and processed, albeit using the same legacy logic as before |
|
| 84 | + $shortcodes_to_register = apply_filters( |
|
| 85 | + 'FHEE__EE_Config__register_shortcodes__shortcodes_to_register', |
|
| 86 | + array() |
|
| 87 | + ); |
|
| 88 | + if (! empty($shortcodes_to_register)) { |
|
| 89 | + // cycle thru shortcode folders |
|
| 90 | + foreach ($shortcodes_to_register as $shortcode_path) { |
|
| 91 | + // add to list of installed shortcode modules |
|
| 92 | + $this->registerShortcode($shortcode_path); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + // filter list of installed modules |
|
| 96 | + return apply_filters( |
|
| 97 | + 'FHEE__EE_Config___register_shortcodes__installed_shortcodes', |
|
| 98 | + ! empty($this->registry->shortcodes) |
|
| 99 | + ? $this->registry->shortcodes |
|
| 100 | + : array() |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * register_shortcode - makes core aware of this shortcode |
|
| 107 | + * |
|
| 108 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
| 109 | + * @return bool |
|
| 110 | + */ |
|
| 111 | + public function registerShortcode($shortcode_path = null) |
|
| 112 | + { |
|
| 113 | + do_action('AHEE__EE_Config__register_shortcode__begin', $shortcode_path); |
|
| 114 | + $shortcode_ext = '.shortcode.php'; |
|
| 115 | + // make all separators match |
|
| 116 | + $shortcode_path = str_replace(array('\\', '/'), '/', $shortcode_path); |
|
| 117 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
| 118 | + if (strpos($shortcode_path, $shortcode_ext) !== false) { |
|
| 119 | + // grab shortcode file name from directory name and break apart at dots |
|
| 120 | + $shortcode_file = explode('.', basename($shortcode_path)); |
|
| 121 | + // take first segment from file name pieces and remove class prefix if it exists |
|
| 122 | + $shortcode = strpos($shortcode_file[0], 'EES_') === 0 |
|
| 123 | + ? substr($shortcode_file[0], 4) |
|
| 124 | + : $shortcode_file[0]; |
|
| 125 | + // sanitize shortcode directory name |
|
| 126 | + $shortcode = sanitize_key($shortcode); |
|
| 127 | + // now we need to rebuild the shortcode path |
|
| 128 | + $shortcode_path = explode('/', $shortcode_path); |
|
| 129 | + // remove last segment |
|
| 130 | + array_pop($shortcode_path); |
|
| 131 | + // glue it back together |
|
| 132 | + $shortcode_path = implode('/', $shortcode_path) . '/'; |
|
| 133 | + } else { |
|
| 134 | + // we need to generate the filename based off of the folder name |
|
| 135 | + // grab and sanitize shortcode directory name |
|
| 136 | + $shortcode = sanitize_key(basename($shortcode_path)); |
|
| 137 | + $shortcode_path = rtrim($shortcode_path, '/') . '/'; |
|
| 138 | + } |
|
| 139 | + // create classname from shortcode directory or file name |
|
| 140 | + $shortcode = str_replace(' ', '_', ucwords(str_replace('_', ' ', $shortcode))); |
|
| 141 | + // add class prefix |
|
| 142 | + $shortcode_class = 'EES_' . $shortcode; |
|
| 143 | + // does the shortcode exist ? |
|
| 144 | + if (! is_readable($shortcode_path . '/' . $shortcode_class . $shortcode_ext)) { |
|
| 145 | + $msg = sprintf( |
|
| 146 | + esc_html__( |
|
| 147 | + 'The requested %1$s shortcode file could not be found or is not readable due to file permissions. It should be in %2$s', |
|
| 148 | + 'event_espresso' |
|
| 149 | + ), |
|
| 150 | + $shortcode_class, |
|
| 151 | + $shortcode_path . '/' . $shortcode_class . $shortcode_ext |
|
| 152 | + ); |
|
| 153 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + // load the shortcode class file |
|
| 157 | + require_once($shortcode_path . $shortcode_class . $shortcode_ext); |
|
| 158 | + // verify that class exists |
|
| 159 | + if (! class_exists($shortcode_class)) { |
|
| 160 | + $msg = sprintf( |
|
| 161 | + esc_html__('The requested %s shortcode class does not exist.', 'event_espresso'), |
|
| 162 | + $shortcode_class |
|
| 163 | + ); |
|
| 164 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + $shortcode = strtoupper($shortcode); |
|
| 168 | + // add to array of registered shortcodes |
|
| 169 | + $this->registry->shortcodes->{$shortcode} = $shortcode_path . $shortcode_class . $shortcode_ext; |
|
| 170 | + return true; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * _initialize_shortcodes |
|
| 176 | + * allow shortcodes to set hooks for the rest of the system |
|
| 177 | + * |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function addShortcodes() |
|
| 181 | + { |
|
| 182 | + // cycle thru shortcode folders |
|
| 183 | + foreach ($this->registry->shortcodes as $shortcode => $shortcode_path) { |
|
| 184 | + // add class prefix |
|
| 185 | + $shortcode_class = 'EES_' . $shortcode; |
|
| 186 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
| 187 | + // which set hooks ? |
|
| 188 | + if (is_admin()) { |
|
| 189 | + // fire immediately |
|
| 190 | + call_user_func(array($shortcode_class, 'set_hooks_admin')); |
|
| 191 | + } else { |
|
| 192 | + // delay until other systems are online |
|
| 193 | + add_action( |
|
| 194 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
| 195 | + array($shortcode_class, 'set_hooks') |
|
| 196 | + ); |
|
| 197 | + // convert classname to UPPERCASE and create WP shortcode. |
|
| 198 | + $shortcode_tag = strtoupper($shortcode); |
|
| 199 | + // but first check if the shortcode has already |
|
| 200 | + // been added before assigning 'fallback_shortcode_processor' |
|
| 201 | + if (! shortcode_exists($shortcode_tag)) { |
|
| 202 | + // NOTE: this shortcode declaration will get overridden if the shortcode |
|
| 203 | + // is successfully detected in the post content in initializeShortcode() |
|
| 204 | + add_shortcode($shortcode_tag, array($shortcode_class, 'fallback_shortcode_processor')); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * callback for the WP "get_header" hook point |
|
| 213 | + * checks posts for EE shortcodes, and initializes them, |
|
| 214 | + * then toggles filter switch that loads core default assets |
|
| 215 | + * |
|
| 216 | + * @param WP_Query $wp_query |
|
| 217 | + * @return void |
|
| 218 | + * @throws ReflectionException |
|
| 219 | + */ |
|
| 220 | + public function initializeShortcodes(WP_Query $wp_query) |
|
| 221 | + { |
|
| 222 | + if ( |
|
| 223 | + empty($this->registry->shortcodes) |
|
| 224 | + || defined('EE_TESTS_DIR') |
|
| 225 | + || ! $wp_query->is_main_query() |
|
| 226 | + || is_admin() |
|
| 227 | + ) { |
|
| 228 | + return; |
|
| 229 | + } |
|
| 230 | + // in case shortcode is loaded unexpectedly and deps haven't been set up correctly |
|
| 231 | + EE_Dependency_Map::register_dependencies( |
|
| 232 | + 'EE_Front_Controller', |
|
| 233 | + [ |
|
| 234 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
| 235 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
| 236 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
| 237 | + ] |
|
| 238 | + ); |
|
| 239 | + global $wp; |
|
| 240 | + /** @var EE_Front_controller $Front_Controller */ |
|
| 241 | + $Front_Controller = LoaderFactory::getLoader()->getShared('EE_Front_Controller'); |
|
| 242 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__begin', $wp, $Front_Controller); |
|
| 243 | + $this->current_page->parseQueryVars(); |
|
| 244 | + // grab post_name from request |
|
| 245 | + $current_post = apply_filters( |
|
| 246 | + 'FHEE__EE_Front_Controller__initialize_shortcodes__current_post_name', |
|
| 247 | + $this->current_page->postName() |
|
| 248 | + ); |
|
| 249 | + $show_on_front = get_option('show_on_front'); |
|
| 250 | + // if it's not set, then check if frontpage is blog |
|
| 251 | + if (empty($current_post)) { |
|
| 252 | + // yup.. this is the posts page, prepare to load all shortcode modules |
|
| 253 | + $current_post = 'posts'; |
|
| 254 | + // unless.. |
|
| 255 | + if ($show_on_front === 'page') { |
|
| 256 | + // some other page is set as the homepage |
|
| 257 | + $page_on_front = get_option('page_on_front'); |
|
| 258 | + if ($page_on_front) { |
|
| 259 | + // k now we need to find the post_name for this page |
|
| 260 | + global $wpdb; |
|
| 261 | + $page_on_front = $wpdb->get_var( |
|
| 262 | + $wpdb->prepare( |
|
| 263 | + "SELECT post_name from {$wpdb->posts} WHERE post_type='page' AND post_status NOT IN ('auto-draft', 'inherit', 'trash') AND ID=%d", |
|
| 264 | + $page_on_front |
|
| 265 | + ) |
|
| 266 | + ); |
|
| 267 | + // set the current post slug to what it actually is |
|
| 268 | + $current_post = $page_on_front ?: $current_post; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + // in case $current_post is hierarchical like: /parent-page/current-page |
|
| 273 | + $current_post = basename($current_post); |
|
| 274 | + if ( |
|
| 275 | + // is current page/post the "blog" page ? |
|
| 276 | + $current_post === EE_Config::get_page_for_posts() |
|
| 277 | + // or are we on a category page? |
|
| 278 | + || ( |
|
| 279 | + is_array(term_exists($current_post, 'category')) |
|
| 280 | + || array_key_exists('category_name', $wp->query_vars) |
|
| 281 | + ) |
|
| 282 | + ) { |
|
| 283 | + // initialize all legacy shortcodes |
|
| 284 | + $load_assets = $this->parseContentForShortcodes('', true); |
|
| 285 | + } else { |
|
| 286 | + global $post; |
|
| 287 | + if ($post instanceof WP_Post) { |
|
| 288 | + $post_content = $post->post_content; |
|
| 289 | + } else { |
|
| 290 | + global $wpdb; |
|
| 291 | + $post_content = $wpdb->get_var( |
|
| 292 | + $wpdb->prepare( |
|
| 293 | + "SELECT post_content from {$wpdb->posts} WHERE post_status NOT IN ('auto-draft', 'inherit', 'trash') AND post_name=%s", |
|
| 294 | + $current_post |
|
| 295 | + ) |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | + $load_assets = $this->parseContentForShortcodes($post_content); |
|
| 299 | + } |
|
| 300 | + if ($load_assets) { |
|
| 301 | + $this->current_page->setEspressoPage(true); |
|
| 302 | + add_filter('FHEE_load_css', '__return_true'); |
|
| 303 | + add_filter('FHEE_load_js', '__return_true'); |
|
| 304 | + } |
|
| 305 | + do_action('AHEE__EE_Front_Controller__initialize_shortcodes__end', $Front_Controller); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * checks supplied content against list of legacy shortcodes, |
|
| 311 | + * then initializes any found shortcodes, and returns true. |
|
| 312 | + * returns false if no shortcodes found. |
|
| 313 | + * |
|
| 314 | + * @param string $content |
|
| 315 | + * @param bool $load_all if true, then ALL active legacy shortcodes will be initialized |
|
| 316 | + * @return bool |
|
| 317 | + * @throws ReflectionException |
|
| 318 | + */ |
|
| 319 | + public function parseContentForShortcodes($content = '', $load_all = false) |
|
| 320 | + { |
|
| 321 | + $has_shortcode = false; |
|
| 322 | + foreach ($this->registry->shortcodes as $shortcode_class => $shortcode) { |
|
| 323 | + if ($load_all || has_shortcode($content, $shortcode_class)) { |
|
| 324 | + // load up the shortcode |
|
| 325 | + $this->initializeShortcode($shortcode_class); |
|
| 326 | + $has_shortcode = true; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + // one last test for an [espresso_*] shortcode |
|
| 330 | + if (! $has_shortcode) { |
|
| 331 | + $has_shortcode = strpos($content, '[espresso_') !== false; |
|
| 332 | + } |
|
| 333 | + return $has_shortcode; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * given a shortcode name, will instantiate the shortcode and call it's run() method |
|
| 339 | + * |
|
| 340 | + * @param string $shortcode_class |
|
| 341 | + * @param WP $wp |
|
| 342 | + * @throws ReflectionException |
|
| 343 | + */ |
|
| 344 | + public function initializeShortcode($shortcode_class = '', WP $wp = null) |
|
| 345 | + { |
|
| 346 | + // don't do anything if shortcode is already initialized |
|
| 347 | + if ( |
|
| 348 | + empty($this->registry->shortcodes->{$shortcode_class}) |
|
| 349 | + || ! is_string($this->registry->shortcodes->{$shortcode_class}) |
|
| 350 | + ) { |
|
| 351 | + return; |
|
| 352 | + } |
|
| 353 | + // let's pause to reflect on this... |
|
| 354 | + $sc_reflector = new ReflectionClass(LegacyShortcodesManager::addShortcodeClassPrefix($shortcode_class)); |
|
| 355 | + // ensure that class is actually a shortcode |
|
| 356 | + if ( |
|
| 357 | + defined('WP_DEBUG') |
|
| 358 | + && WP_DEBUG === true |
|
| 359 | + && ! $sc_reflector->isSubclassOf('EES_Shortcode') |
|
| 360 | + ) { |
|
| 361 | + EE_Error::add_error( |
|
| 362 | + sprintf( |
|
| 363 | + esc_html__( |
|
| 364 | + 'The requested %s shortcode is not of the class "EES_Shortcode". Please check your files.', |
|
| 365 | + 'event_espresso' |
|
| 366 | + ), |
|
| 367 | + $shortcode_class |
|
| 368 | + ), |
|
| 369 | + __FILE__, |
|
| 370 | + __FUNCTION__, |
|
| 371 | + __LINE__ |
|
| 372 | + ); |
|
| 373 | + add_filter('FHEE_run_EE_the_content', '__return_true'); |
|
| 374 | + return; |
|
| 375 | + } |
|
| 376 | + global $wp; |
|
| 377 | + // and pass the request object to the run method |
|
| 378 | + $this->registry->shortcodes->{$shortcode_class} = $sc_reflector->newInstance(); |
|
| 379 | + // fire the shortcode class's run method, so that it can activate resources |
|
| 380 | + $this->registry->shortcodes->{$shortcode_class}->run($wp); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * get classname, remove EES_prefix, and convert to UPPERCASE |
|
| 386 | + * |
|
| 387 | + * @param string $class_name |
|
| 388 | + * @return string |
|
| 389 | + */ |
|
| 390 | + public static function generateShortcodeTagFromClassName($class_name) |
|
| 391 | + { |
|
| 392 | + return strtoupper(str_replace('EES_', '', $class_name)); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * add EES_prefix and Capitalize words |
|
| 398 | + * |
|
| 399 | + * @param string $tag |
|
| 400 | + * @return string |
|
| 401 | + */ |
|
| 402 | + public static function generateShortcodeClassNameFromTag($tag) |
|
| 403 | + { |
|
| 404 | + // order of operation runs from inside to out |
|
| 405 | + // 5) maybe add prefix |
|
| 406 | + return LegacyShortcodesManager::addShortcodeClassPrefix( |
|
| 407 | + // 4) find spaces, replace with underscores |
|
| 408 | + str_replace( |
|
| 409 | + ' ', |
|
| 410 | + '_', |
|
| 411 | + // 3) capitalize first letter of each word |
|
| 412 | + ucwords( |
|
| 413 | + // 2) also change to lowercase so ucwords() will work |
|
| 414 | + strtolower( |
|
| 415 | + // 1) find underscores, replace with spaces so ucwords() will work |
|
| 416 | + str_replace( |
|
| 417 | + '_', |
|
| 418 | + ' ', |
|
| 419 | + $tag |
|
| 420 | + ) |
|
| 421 | + ) |
|
| 422 | + ) |
|
| 423 | + ) |
|
| 424 | + ); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * maybe add EES_prefix |
|
| 430 | + * |
|
| 431 | + * @param string $class_name |
|
| 432 | + * @return string |
|
| 433 | + */ |
|
| 434 | + public static function addShortcodeClassPrefix($class_name) |
|
| 435 | + { |
|
| 436 | + return strpos($class_name, 'EES_') === 0 ? $class_name : 'EES_' . $class_name; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @return array |
|
| 442 | + */ |
|
| 443 | + public function getEspressoShortcodeTags() |
|
| 444 | + { |
|
| 445 | + static $shortcode_tags = array(); |
|
| 446 | + if (empty($shortcode_tags)) { |
|
| 447 | + $shortcode_tags = array_keys((array) $this->registry->shortcodes); |
|
| 448 | + } |
|
| 449 | + return $shortcode_tags; |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * @param string $content |
|
| 455 | + * @return string |
|
| 456 | + * @throws ReflectionException |
|
| 457 | + */ |
|
| 458 | + public function doShortcode($content) |
|
| 459 | + { |
|
| 460 | + foreach ($this->getEspressoShortcodeTags() as $shortcode_tag) { |
|
| 461 | + if (strpos($content, $shortcode_tag) !== false) { |
|
| 462 | + $shortcode_class = LegacyShortcodesManager::generateShortcodeClassNameFromTag($shortcode_tag); |
|
| 463 | + $this->initializeShortcode($shortcode_class); |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + return do_shortcode($content); |
|
| 467 | + } |
|
| 468 | 468 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | public function cancelTicketSelections() |
| 120 | 120 | { |
| 121 | 121 | // check nonce |
| 122 | - if (! $this->processTicketSelectorNonce()) { |
|
| 122 | + if ( ! $this->processTicketSelectorNonce()) { |
|
| 123 | 123 | return false; |
| 124 | 124 | } |
| 125 | 125 | $this->session->clear_session(__CLASS__, __FUNCTION__); |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | ); |
| 132 | 132 | } |
| 133 | 133 | EEH_URL::safeRedirectAndExit( |
| 134 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 134 | + site_url('/'.$this->core_config->event_cpt_slug.'/') |
|
| 135 | 135 | ); |
| 136 | 136 | return true; |
| 137 | 137 | } |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 213 | 213 | } |
| 214 | 214 | // check total tickets ordered vs max number of attendees that can register |
| 215 | - if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
| 215 | + if ( ! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
| 216 | 216 | $this->maxAttendeesViolation($valid); |
| 217 | 217 | } else { |
| 218 | 218 | // all data appears to be valid |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
| 226 | 226 | return false; |
| 227 | 227 | } |
| 228 | - if (! empty($valid['return_url'])) { |
|
| 228 | + if ( ! empty($valid['return_url'])) { |
|
| 229 | 229 | EEH_URL::safeRedirectAndExit($valid['return_url']); |
| 230 | 230 | } |
| 231 | 231 | // do we have an event id? |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | ) |
| 263 | 263 | ); |
| 264 | 264 | $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
| 265 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 265 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | { |
| 279 | 279 | $tickets_added = 0; |
| 280 | 280 | $tickets_selected = false; |
| 281 | - if (! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) { |
|
| 281 | + if ( ! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) { |
|
| 282 | 282 | // load cart using factory because we don't want to do so until actually needed |
| 283 | 283 | $this->cart = CartFactory::getCart(); |
| 284 | 284 | // if the user is an admin that can edit registrations, |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | // get ticket via the ticket id we put in the form |
| 294 | 294 | $ticket = $this->ticket_model->get_one_by_ID($ticket_id); |
| 295 | 295 | if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { |
| 296 | - $valid_ticket = true; |
|
| 296 | + $valid_ticket = true; |
|
| 297 | 297 | $tickets_added += $this->addTicketToCart($ticket, $qty); |
| 298 | 298 | } |
| 299 | 299 | if ($valid_ticket !== true) { |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | $this->cart, |
| 323 | 323 | $this |
| 324 | 324 | ); |
| 325 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 325 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 326 | 326 | // no ticket quantities were selected |
| 327 | 327 | EE_Error::add_error( |
| 328 | 328 | esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
| 391 | 391 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
| 392 | 392 | // make sure cart is loaded |
| 393 | - if (! $this->cart instanceof EE_Cart) { |
|
| 393 | + if ( ! $this->cart instanceof EE_Cart) { |
|
| 394 | 394 | $this->cart = CartFactory::getCart(); |
| 395 | 395 | } |
| 396 | 396 | do_action( |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | ) |
| 413 | 413 | ); |
| 414 | 414 | } |
| 415 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 415 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 416 | 416 | // nothing added to cart |
| 417 | 417 | EE_Error::add_attention( |
| 418 | 418 | esc_html__('No tickets were added for the event', 'event_espresso'), |
@@ -33,393 +33,393 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class ProcessTicketSelector |
| 35 | 35 | { |
| 36 | - /** |
|
| 37 | - * @var EE_Cart $cart |
|
| 38 | - */ |
|
| 39 | - private $cart; |
|
| 36 | + /** |
|
| 37 | + * @var EE_Cart $cart |
|
| 38 | + */ |
|
| 39 | + private $cart; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var EE_Core_Config $core_config |
|
| 43 | - */ |
|
| 44 | - private $core_config; |
|
| 41 | + /** |
|
| 42 | + * @var EE_Core_Config $core_config |
|
| 43 | + */ |
|
| 44 | + private $core_config; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var RequestInterface $request |
|
| 48 | - */ |
|
| 49 | - private $request; |
|
| 46 | + /** |
|
| 47 | + * @var RequestInterface $request |
|
| 48 | + */ |
|
| 49 | + private $request; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var EE_Session $session |
|
| 53 | - */ |
|
| 54 | - private $session; |
|
| 51 | + /** |
|
| 52 | + * @var EE_Session $session |
|
| 53 | + */ |
|
| 54 | + private $session; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var EEM_Ticket $ticket_model |
|
| 58 | - */ |
|
| 59 | - private $ticket_model; |
|
| 56 | + /** |
|
| 57 | + * @var EEM_Ticket $ticket_model |
|
| 58 | + */ |
|
| 59 | + private $ticket_model; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var TicketDatetimeAvailabilityTracker $tracker |
|
| 63 | - */ |
|
| 64 | - private $tracker; |
|
| 61 | + /** |
|
| 62 | + * @var TicketDatetimeAvailabilityTracker $tracker |
|
| 63 | + */ |
|
| 64 | + private $tracker; |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * ProcessTicketSelector constructor. |
|
| 69 | - * NOTE: PLZ use the Loader to instantiate this class if need be |
|
| 70 | - * so that all dependencies get injected correctly (which will happen automatically) |
|
| 71 | - * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
| 72 | - * |
|
| 73 | - * @param EE_Core_Config $core_config |
|
| 74 | - * @param RequestInterface $request |
|
| 75 | - * @param EE_Session $session |
|
| 76 | - * @param EEM_Ticket $ticket_model |
|
| 77 | - * @param TicketDatetimeAvailabilityTracker $tracker |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - * @throws InvalidDataTypeException |
|
| 80 | - * @throws InvalidInterfaceException |
|
| 81 | - */ |
|
| 82 | - public function __construct( |
|
| 83 | - EE_Core_Config $core_config = null, |
|
| 84 | - RequestInterface $request = null, |
|
| 85 | - EE_Session $session = null, |
|
| 86 | - EEM_Ticket $ticket_model = null, |
|
| 87 | - TicketDatetimeAvailabilityTracker $tracker = null |
|
| 88 | - ) { |
|
| 89 | - $loader = LoaderFactory::getLoader(); |
|
| 90 | - $this->core_config = $core_config instanceof EE_Core_Config |
|
| 91 | - ? $core_config |
|
| 92 | - : $loader->getShared('EE_Core_Config'); |
|
| 93 | - $this->request = $request instanceof RequestInterface |
|
| 94 | - ? $request |
|
| 95 | - : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 96 | - $this->session = $session instanceof EE_Session |
|
| 97 | - ? $session |
|
| 98 | - : $loader->getShared('EE_Session'); |
|
| 99 | - $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
| 100 | - ? $ticket_model |
|
| 101 | - : $loader->getShared('EEM_Ticket'); |
|
| 102 | - $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
| 103 | - ? $tracker |
|
| 104 | - : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
| 105 | - } |
|
| 67 | + /** |
|
| 68 | + * ProcessTicketSelector constructor. |
|
| 69 | + * NOTE: PLZ use the Loader to instantiate this class if need be |
|
| 70 | + * so that all dependencies get injected correctly (which will happen automatically) |
|
| 71 | + * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
| 72 | + * |
|
| 73 | + * @param EE_Core_Config $core_config |
|
| 74 | + * @param RequestInterface $request |
|
| 75 | + * @param EE_Session $session |
|
| 76 | + * @param EEM_Ticket $ticket_model |
|
| 77 | + * @param TicketDatetimeAvailabilityTracker $tracker |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + * @throws InvalidDataTypeException |
|
| 80 | + * @throws InvalidInterfaceException |
|
| 81 | + */ |
|
| 82 | + public function __construct( |
|
| 83 | + EE_Core_Config $core_config = null, |
|
| 84 | + RequestInterface $request = null, |
|
| 85 | + EE_Session $session = null, |
|
| 86 | + EEM_Ticket $ticket_model = null, |
|
| 87 | + TicketDatetimeAvailabilityTracker $tracker = null |
|
| 88 | + ) { |
|
| 89 | + $loader = LoaderFactory::getLoader(); |
|
| 90 | + $this->core_config = $core_config instanceof EE_Core_Config |
|
| 91 | + ? $core_config |
|
| 92 | + : $loader->getShared('EE_Core_Config'); |
|
| 93 | + $this->request = $request instanceof RequestInterface |
|
| 94 | + ? $request |
|
| 95 | + : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
| 96 | + $this->session = $session instanceof EE_Session |
|
| 97 | + ? $session |
|
| 98 | + : $loader->getShared('EE_Session'); |
|
| 99 | + $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
| 100 | + ? $ticket_model |
|
| 101 | + : $loader->getShared('EEM_Ticket'); |
|
| 102 | + $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
| 103 | + ? $tracker |
|
| 104 | + : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * cancelTicketSelections |
|
| 110 | - * |
|
| 111 | - * @return bool |
|
| 112 | - * @throws EE_Error |
|
| 113 | - * @throws InvalidArgumentException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws InvalidDataTypeException |
|
| 116 | - * @throws ReflectionException |
|
| 117 | - */ |
|
| 118 | - public function cancelTicketSelections() |
|
| 119 | - { |
|
| 120 | - // check nonce |
|
| 121 | - if (! $this->processTicketSelectorNonce()) { |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 125 | - if ($this->request->requestParamIsSet('event_id')) { |
|
| 126 | - EEH_URL::safeRedirectAndExit( |
|
| 127 | - EEH_Event_View::event_link_url( |
|
| 128 | - $this->request->getRequestParam('event_id', 0, 'int') |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - EEH_URL::safeRedirectAndExit( |
|
| 133 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 134 | - ); |
|
| 135 | - return true; |
|
| 136 | - } |
|
| 108 | + /** |
|
| 109 | + * cancelTicketSelections |
|
| 110 | + * |
|
| 111 | + * @return bool |
|
| 112 | + * @throws EE_Error |
|
| 113 | + * @throws InvalidArgumentException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws InvalidDataTypeException |
|
| 116 | + * @throws ReflectionException |
|
| 117 | + */ |
|
| 118 | + public function cancelTicketSelections() |
|
| 119 | + { |
|
| 120 | + // check nonce |
|
| 121 | + if (! $this->processTicketSelectorNonce()) { |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 125 | + if ($this->request->requestParamIsSet('event_id')) { |
|
| 126 | + EEH_URL::safeRedirectAndExit( |
|
| 127 | + EEH_Event_View::event_link_url( |
|
| 128 | + $this->request->getRequestParam('event_id', 0, 'int') |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + EEH_URL::safeRedirectAndExit( |
|
| 133 | + site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
| 134 | + ); |
|
| 135 | + return true; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * processTicketSelectorNonce |
|
| 141 | - * |
|
| 142 | - * @return bool |
|
| 143 | - */ |
|
| 144 | - private function processTicketSelectorNonce() |
|
| 145 | - { |
|
| 146 | - if ( |
|
| 147 | - ! $this->request->isAdmin() |
|
| 148 | - && ( |
|
| 149 | - ! $this->request->requestParamIsSet('cancel_ticket_selections_nonce') |
|
| 150 | - || ! wp_verify_nonce( |
|
| 151 | - $this->request->getRequestParam('cancel_ticket_selections_nonce'), |
|
| 152 | - 'cancel_ticket_selections' |
|
| 153 | - ) |
|
| 154 | - ) |
|
| 155 | - ) { |
|
| 156 | - EE_Error::add_error( |
|
| 157 | - sprintf( |
|
| 158 | - esc_html__( |
|
| 159 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 160 | - 'event_espresso' |
|
| 161 | - ), |
|
| 162 | - '<br/>' |
|
| 163 | - ), |
|
| 164 | - __FILE__, |
|
| 165 | - __FUNCTION__, |
|
| 166 | - __LINE__ |
|
| 167 | - ); |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - return true; |
|
| 171 | - } |
|
| 139 | + /** |
|
| 140 | + * processTicketSelectorNonce |
|
| 141 | + * |
|
| 142 | + * @return bool |
|
| 143 | + */ |
|
| 144 | + private function processTicketSelectorNonce() |
|
| 145 | + { |
|
| 146 | + if ( |
|
| 147 | + ! $this->request->isAdmin() |
|
| 148 | + && ( |
|
| 149 | + ! $this->request->requestParamIsSet('cancel_ticket_selections_nonce') |
|
| 150 | + || ! wp_verify_nonce( |
|
| 151 | + $this->request->getRequestParam('cancel_ticket_selections_nonce'), |
|
| 152 | + 'cancel_ticket_selections' |
|
| 153 | + ) |
|
| 154 | + ) |
|
| 155 | + ) { |
|
| 156 | + EE_Error::add_error( |
|
| 157 | + sprintf( |
|
| 158 | + esc_html__( |
|
| 159 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 160 | + 'event_espresso' |
|
| 161 | + ), |
|
| 162 | + '<br/>' |
|
| 163 | + ), |
|
| 164 | + __FILE__, |
|
| 165 | + __FUNCTION__, |
|
| 166 | + __LINE__ |
|
| 167 | + ); |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + return true; |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * process_ticket_selections |
|
| 176 | - * |
|
| 177 | - * @return bool |
|
| 178 | - * @throws EE_Error |
|
| 179 | - * @throws InvalidArgumentException |
|
| 180 | - * @throws InvalidDataTypeException |
|
| 181 | - * @throws InvalidInterfaceException |
|
| 182 | - * @throws ReflectionException |
|
| 183 | - */ |
|
| 184 | - public function processTicketSelections() |
|
| 185 | - { |
|
| 186 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 187 | - if ($this->request->isBot()) { |
|
| 188 | - EEH_URL::safeRedirectAndExit( |
|
| 189 | - apply_filters( |
|
| 190 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
| 191 | - site_url() |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - // we should really only have 1 registration in the works now |
|
| 196 | - // (ie, no MER) so unless otherwise requested, clear the session |
|
| 197 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 198 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 199 | - } |
|
| 200 | - // validate/sanitize/filter data |
|
| 201 | - $id = null; |
|
| 202 | - $valid = []; |
|
| 203 | - try { |
|
| 204 | - $post_data_validator = new ProcessTicketSelectorPostData($this->request); |
|
| 205 | - $id = $post_data_validator->getEventId(); |
|
| 206 | - $valid = apply_filters( |
|
| 207 | - 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
| 208 | - $post_data_validator->validatePostData() |
|
| 209 | - ); |
|
| 210 | - } catch (Exception $exception) { |
|
| 211 | - EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 212 | - } |
|
| 213 | - // check total tickets ordered vs max number of attendees that can register |
|
| 214 | - if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
| 215 | - $this->maxAttendeesViolation($valid); |
|
| 216 | - } else { |
|
| 217 | - // all data appears to be valid |
|
| 218 | - if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 223 | - // at this point, just return if registration is being made from admin |
|
| 224 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 225 | - return false; |
|
| 226 | - } |
|
| 227 | - if (! empty($valid['return_url'])) { |
|
| 228 | - EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
| 229 | - } |
|
| 230 | - // do we have an event id? |
|
| 231 | - if ($id) { |
|
| 232 | - EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
| 233 | - } |
|
| 234 | - echo EE_Error::get_notices(); // already escaped |
|
| 235 | - return false; |
|
| 236 | - } |
|
| 174 | + /** |
|
| 175 | + * process_ticket_selections |
|
| 176 | + * |
|
| 177 | + * @return bool |
|
| 178 | + * @throws EE_Error |
|
| 179 | + * @throws InvalidArgumentException |
|
| 180 | + * @throws InvalidDataTypeException |
|
| 181 | + * @throws InvalidInterfaceException |
|
| 182 | + * @throws ReflectionException |
|
| 183 | + */ |
|
| 184 | + public function processTicketSelections() |
|
| 185 | + { |
|
| 186 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 187 | + if ($this->request->isBot()) { |
|
| 188 | + EEH_URL::safeRedirectAndExit( |
|
| 189 | + apply_filters( |
|
| 190 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
| 191 | + site_url() |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + // we should really only have 1 registration in the works now |
|
| 196 | + // (ie, no MER) so unless otherwise requested, clear the session |
|
| 197 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 198 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
| 199 | + } |
|
| 200 | + // validate/sanitize/filter data |
|
| 201 | + $id = null; |
|
| 202 | + $valid = []; |
|
| 203 | + try { |
|
| 204 | + $post_data_validator = new ProcessTicketSelectorPostData($this->request); |
|
| 205 | + $id = $post_data_validator->getEventId(); |
|
| 206 | + $valid = apply_filters( |
|
| 207 | + 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
| 208 | + $post_data_validator->validatePostData() |
|
| 209 | + ); |
|
| 210 | + } catch (Exception $exception) { |
|
| 211 | + EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 212 | + } |
|
| 213 | + // check total tickets ordered vs max number of attendees that can register |
|
| 214 | + if (! empty($valid) && $valid['total_tickets'] > $valid['max_atndz']) { |
|
| 215 | + $this->maxAttendeesViolation($valid); |
|
| 216 | + } else { |
|
| 217 | + // all data appears to be valid |
|
| 218 | + if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 223 | + // at this point, just return if registration is being made from admin |
|
| 224 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 225 | + return false; |
|
| 226 | + } |
|
| 227 | + if (! empty($valid['return_url'])) { |
|
| 228 | + EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
| 229 | + } |
|
| 230 | + // do we have an event id? |
|
| 231 | + if ($id) { |
|
| 232 | + EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
| 233 | + } |
|
| 234 | + echo EE_Error::get_notices(); // already escaped |
|
| 235 | + return false; |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * @param array $valid |
|
| 241 | - */ |
|
| 242 | - private function maxAttendeesViolation(array $valid) |
|
| 243 | - { |
|
| 244 | - // ordering too many tickets !!! |
|
| 245 | - $total_tickets_string = esc_html( |
|
| 246 | - _n( |
|
| 247 | - 'You have attempted to purchase %s ticket.', |
|
| 248 | - 'You have attempted to purchase %s tickets.', |
|
| 249 | - $valid['total_tickets'], |
|
| 250 | - 'event_espresso' |
|
| 251 | - ) |
|
| 252 | - ); |
|
| 253 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 254 | - // dev only message |
|
| 255 | - $max_attendees_string = esc_html( |
|
| 256 | - _n( |
|
| 257 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 258 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 259 | - $valid['max_atndz'], |
|
| 260 | - 'event_espresso' |
|
| 261 | - ) |
|
| 262 | - ); |
|
| 263 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 264 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 265 | - } |
|
| 239 | + /** |
|
| 240 | + * @param array $valid |
|
| 241 | + */ |
|
| 242 | + private function maxAttendeesViolation(array $valid) |
|
| 243 | + { |
|
| 244 | + // ordering too many tickets !!! |
|
| 245 | + $total_tickets_string = esc_html( |
|
| 246 | + _n( |
|
| 247 | + 'You have attempted to purchase %s ticket.', |
|
| 248 | + 'You have attempted to purchase %s tickets.', |
|
| 249 | + $valid['total_tickets'], |
|
| 250 | + 'event_espresso' |
|
| 251 | + ) |
|
| 252 | + ); |
|
| 253 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 254 | + // dev only message |
|
| 255 | + $max_attendees_string = esc_html( |
|
| 256 | + _n( |
|
| 257 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 258 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 259 | + $valid['max_atndz'], |
|
| 260 | + 'event_espresso' |
|
| 261 | + ) |
|
| 262 | + ); |
|
| 263 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 264 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * @param array $valid |
|
| 270 | - * @return int |
|
| 271 | - * @throws EE_Error |
|
| 272 | - * @throws InvalidArgumentException |
|
| 273 | - * @throws InvalidDataTypeException |
|
| 274 | - * @throws InvalidInterfaceException |
|
| 275 | - */ |
|
| 276 | - private function addTicketsToCart(array $valid) |
|
| 277 | - { |
|
| 278 | - $tickets_added = 0; |
|
| 279 | - $tickets_selected = false; |
|
| 280 | - if (! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) { |
|
| 281 | - // load cart using factory because we don't want to do so until actually needed |
|
| 282 | - $this->cart = CartFactory::getCart(); |
|
| 283 | - // if the user is an admin that can edit registrations, |
|
| 284 | - // then we'll also allow them to add any tickets, even if they are expired |
|
| 285 | - $current_user_is_admin = current_user_can('ee_edit_registrations'); |
|
| 286 | - // cycle thru the number of data rows sent from the event listing |
|
| 287 | - foreach ($valid['ticket-selections'] as $ticket_id => $qty) { |
|
| 288 | - if ($qty) { |
|
| 289 | - // YES we have a ticket quantity |
|
| 290 | - $tickets_selected = true; |
|
| 291 | - $valid_ticket = false; |
|
| 292 | - // get ticket via the ticket id we put in the form |
|
| 293 | - $ticket = $this->ticket_model->get_one_by_ID($ticket_id); |
|
| 294 | - if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { |
|
| 295 | - $valid_ticket = true; |
|
| 296 | - $tickets_added += $this->addTicketToCart($ticket, $qty); |
|
| 297 | - } |
|
| 298 | - if ($valid_ticket !== true) { |
|
| 299 | - // nothing added to cart retrieved |
|
| 300 | - EE_Error::add_error( |
|
| 301 | - sprintf( |
|
| 302 | - esc_html__( |
|
| 303 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 304 | - 'event_espresso' |
|
| 305 | - ), |
|
| 306 | - '<br/>' |
|
| 307 | - ), |
|
| 308 | - __FILE__, |
|
| 309 | - __FUNCTION__, |
|
| 310 | - __LINE__ |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - if (EE_Error::has_error()) { |
|
| 314 | - break; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - do_action( |
|
| 320 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 321 | - $this->cart, |
|
| 322 | - $this |
|
| 323 | - ); |
|
| 324 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 325 | - // no ticket quantities were selected |
|
| 326 | - EE_Error::add_error( |
|
| 327 | - esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
| 328 | - __FILE__, |
|
| 329 | - __FUNCTION__, |
|
| 330 | - __LINE__ |
|
| 331 | - ); |
|
| 332 | - } |
|
| 333 | - return $tickets_added; |
|
| 334 | - } |
|
| 268 | + /** |
|
| 269 | + * @param array $valid |
|
| 270 | + * @return int |
|
| 271 | + * @throws EE_Error |
|
| 272 | + * @throws InvalidArgumentException |
|
| 273 | + * @throws InvalidDataTypeException |
|
| 274 | + * @throws InvalidInterfaceException |
|
| 275 | + */ |
|
| 276 | + private function addTicketsToCart(array $valid) |
|
| 277 | + { |
|
| 278 | + $tickets_added = 0; |
|
| 279 | + $tickets_selected = false; |
|
| 280 | + if (! empty($valid['ticket-selections']) && $valid['total_tickets'] > 0) { |
|
| 281 | + // load cart using factory because we don't want to do so until actually needed |
|
| 282 | + $this->cart = CartFactory::getCart(); |
|
| 283 | + // if the user is an admin that can edit registrations, |
|
| 284 | + // then we'll also allow them to add any tickets, even if they are expired |
|
| 285 | + $current_user_is_admin = current_user_can('ee_edit_registrations'); |
|
| 286 | + // cycle thru the number of data rows sent from the event listing |
|
| 287 | + foreach ($valid['ticket-selections'] as $ticket_id => $qty) { |
|
| 288 | + if ($qty) { |
|
| 289 | + // YES we have a ticket quantity |
|
| 290 | + $tickets_selected = true; |
|
| 291 | + $valid_ticket = false; |
|
| 292 | + // get ticket via the ticket id we put in the form |
|
| 293 | + $ticket = $this->ticket_model->get_one_by_ID($ticket_id); |
|
| 294 | + if ($ticket instanceof EE_Ticket && ($ticket->is_on_sale() || $current_user_is_admin)) { |
|
| 295 | + $valid_ticket = true; |
|
| 296 | + $tickets_added += $this->addTicketToCart($ticket, $qty); |
|
| 297 | + } |
|
| 298 | + if ($valid_ticket !== true) { |
|
| 299 | + // nothing added to cart retrieved |
|
| 300 | + EE_Error::add_error( |
|
| 301 | + sprintf( |
|
| 302 | + esc_html__( |
|
| 303 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 304 | + 'event_espresso' |
|
| 305 | + ), |
|
| 306 | + '<br/>' |
|
| 307 | + ), |
|
| 308 | + __FILE__, |
|
| 309 | + __FUNCTION__, |
|
| 310 | + __LINE__ |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + if (EE_Error::has_error()) { |
|
| 314 | + break; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + do_action( |
|
| 320 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 321 | + $this->cart, |
|
| 322 | + $this |
|
| 323 | + ); |
|
| 324 | + if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
| 325 | + // no ticket quantities were selected |
|
| 326 | + EE_Error::add_error( |
|
| 327 | + esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
| 328 | + __FILE__, |
|
| 329 | + __FUNCTION__, |
|
| 330 | + __LINE__ |
|
| 331 | + ); |
|
| 332 | + } |
|
| 333 | + return $tickets_added; |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | 336 | |
| 337 | - /** |
|
| 338 | - * adds a ticket to the cart |
|
| 339 | - * |
|
| 340 | - * @param EE_Ticket $ticket |
|
| 341 | - * @param int $qty |
|
| 342 | - * @return bool TRUE on success, FALSE on fail |
|
| 343 | - * @throws InvalidArgumentException |
|
| 344 | - * @throws InvalidInterfaceException |
|
| 345 | - * @throws InvalidDataTypeException |
|
| 346 | - * @throws EE_Error |
|
| 347 | - */ |
|
| 348 | - private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
| 349 | - { |
|
| 350 | - // get the number of spaces left for this datetime ticket |
|
| 351 | - $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
| 352 | - // compare available spaces against the number of tickets being purchased |
|
| 353 | - if ($available_spaces >= $qty) { |
|
| 354 | - // allow addons to prevent a ticket from being added to cart |
|
| 355 | - if ( |
|
| 356 | - ! apply_filters( |
|
| 357 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 358 | - true, |
|
| 359 | - $ticket, |
|
| 360 | - $qty, |
|
| 361 | - $available_spaces |
|
| 362 | - ) |
|
| 363 | - ) { |
|
| 364 | - return false; |
|
| 365 | - } |
|
| 366 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 367 | - // add event to cart |
|
| 368 | - if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
| 369 | - $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 370 | - return true; |
|
| 371 | - } |
|
| 372 | - return false; |
|
| 373 | - } |
|
| 374 | - $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
| 375 | - return false; |
|
| 376 | - } |
|
| 337 | + /** |
|
| 338 | + * adds a ticket to the cart |
|
| 339 | + * |
|
| 340 | + * @param EE_Ticket $ticket |
|
| 341 | + * @param int $qty |
|
| 342 | + * @return bool TRUE on success, FALSE on fail |
|
| 343 | + * @throws InvalidArgumentException |
|
| 344 | + * @throws InvalidInterfaceException |
|
| 345 | + * @throws InvalidDataTypeException |
|
| 346 | + * @throws EE_Error |
|
| 347 | + */ |
|
| 348 | + private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
| 349 | + { |
|
| 350 | + // get the number of spaces left for this datetime ticket |
|
| 351 | + $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
| 352 | + // compare available spaces against the number of tickets being purchased |
|
| 353 | + if ($available_spaces >= $qty) { |
|
| 354 | + // allow addons to prevent a ticket from being added to cart |
|
| 355 | + if ( |
|
| 356 | + ! apply_filters( |
|
| 357 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 358 | + true, |
|
| 359 | + $ticket, |
|
| 360 | + $qty, |
|
| 361 | + $available_spaces |
|
| 362 | + ) |
|
| 363 | + ) { |
|
| 364 | + return false; |
|
| 365 | + } |
|
| 366 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 367 | + // add event to cart |
|
| 368 | + if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
| 369 | + $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 370 | + return true; |
|
| 371 | + } |
|
| 372 | + return false; |
|
| 373 | + } |
|
| 374 | + $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
| 375 | + return false; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * @param $tickets_added |
|
| 381 | - * @return bool |
|
| 382 | - * @throws InvalidInterfaceException |
|
| 383 | - * @throws InvalidDataTypeException |
|
| 384 | - * @throws EE_Error |
|
| 385 | - * @throws InvalidArgumentException |
|
| 386 | - */ |
|
| 387 | - private function processSuccessfulCart($tickets_added) |
|
| 388 | - { |
|
| 389 | - // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 390 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 391 | - // make sure cart is loaded |
|
| 392 | - if (! $this->cart instanceof EE_Cart) { |
|
| 393 | - $this->cart = CartFactory::getCart(); |
|
| 394 | - } |
|
| 395 | - do_action( |
|
| 396 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 397 | - $this->cart, |
|
| 398 | - $this |
|
| 399 | - ); |
|
| 400 | - $this->cart->recalculate_all_cart_totals(); |
|
| 401 | - $this->cart->save_cart(false); |
|
| 402 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 403 | - // just return TRUE for registrations being made from admin |
|
| 404 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 405 | - return true; |
|
| 406 | - } |
|
| 407 | - EEH_URL::safeRedirectAndExit( |
|
| 408 | - apply_filters( |
|
| 409 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 410 | - $this->core_config->reg_page_url() |
|
| 411 | - ) |
|
| 412 | - ); |
|
| 413 | - } |
|
| 414 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 415 | - // nothing added to cart |
|
| 416 | - EE_Error::add_attention( |
|
| 417 | - esc_html__('No tickets were added for the event', 'event_espresso'), |
|
| 418 | - __FILE__, |
|
| 419 | - __FUNCTION__, |
|
| 420 | - __LINE__ |
|
| 421 | - ); |
|
| 422 | - } |
|
| 423 | - return false; |
|
| 424 | - } |
|
| 379 | + /** |
|
| 380 | + * @param $tickets_added |
|
| 381 | + * @return bool |
|
| 382 | + * @throws InvalidInterfaceException |
|
| 383 | + * @throws InvalidDataTypeException |
|
| 384 | + * @throws EE_Error |
|
| 385 | + * @throws InvalidArgumentException |
|
| 386 | + */ |
|
| 387 | + private function processSuccessfulCart($tickets_added) |
|
| 388 | + { |
|
| 389 | + // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 390 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 391 | + // make sure cart is loaded |
|
| 392 | + if (! $this->cart instanceof EE_Cart) { |
|
| 393 | + $this->cart = CartFactory::getCart(); |
|
| 394 | + } |
|
| 395 | + do_action( |
|
| 396 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 397 | + $this->cart, |
|
| 398 | + $this |
|
| 399 | + ); |
|
| 400 | + $this->cart->recalculate_all_cart_totals(); |
|
| 401 | + $this->cart->save_cart(false); |
|
| 402 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 403 | + // just return TRUE for registrations being made from admin |
|
| 404 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
| 405 | + return true; |
|
| 406 | + } |
|
| 407 | + EEH_URL::safeRedirectAndExit( |
|
| 408 | + apply_filters( |
|
| 409 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 410 | + $this->core_config->reg_page_url() |
|
| 411 | + ) |
|
| 412 | + ); |
|
| 413 | + } |
|
| 414 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
| 415 | + // nothing added to cart |
|
| 416 | + EE_Error::add_attention( |
|
| 417 | + esc_html__('No tickets were added for the event', 'event_espresso'), |
|
| 418 | + __FILE__, |
|
| 419 | + __FUNCTION__, |
|
| 420 | + __LINE__ |
|
| 421 | + ); |
|
| 422 | + } |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 425 | 425 | } |