@@ -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 | } |
@@ -7,10 +7,10 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | if (! function_exists('espressoSubtotalRow')) { |
| 10 | - function espressoSubtotalRow(float $running_total, bool $show = true): string |
|
| 11 | - { |
|
| 12 | - return $show |
|
| 13 | - ? ' |
|
| 10 | + function espressoSubtotalRow(float $running_total, bool $show = true): string |
|
| 11 | + { |
|
| 12 | + return $show |
|
| 13 | + ? ' |
|
| 14 | 14 | <tr> |
| 15 | 15 | <td colspan="2" class="jst-rght small-text sbttl"> |
| 16 | 16 | <b>' . esc_html__('subtotal', 'event_espresso') . '</b> |
@@ -20,18 +20,18 @@ discard block |
||
| 20 | 20 | </td> |
| 21 | 21 | </tr> |
| 22 | 22 | ' |
| 23 | - : ''; |
|
| 24 | - } |
|
| 23 | + : ''; |
|
| 24 | + } |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | if ($display_ticket_price) { ?> |
| 28 | 28 | <section class="tckt-slctr-tkt-price-sctn"> |
| 29 | 29 | <h5><?php echo esc_html( |
| 30 | - apply_filters( |
|
| 31 | - 'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading', |
|
| 32 | - __('Price', 'event_espresso') |
|
| 33 | - ) |
|
| 34 | - ); ?></h5> |
|
| 30 | + apply_filters( |
|
| 31 | + 'FHEE__ticket_selector_chart_template__ticket_details_price_breakdown_heading', |
|
| 32 | + __('Price', 'event_espresso') |
|
| 33 | + ) |
|
| 34 | + ); ?></h5> |
|
| 35 | 35 | <div class="tckt-slctr-tkt-details-tbl-wrap-dv"> |
| 36 | 36 | <table class="tckt-slctr-tkt-details-tbl"> |
| 37 | 37 | <thead> |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | </thead> |
| 52 | 52 | <tbody> |
| 53 | 53 | <?php |
| 54 | - if ($ticket->base_price() instanceof EE_Price) { ?> |
|
| 54 | + if ($ticket->base_price() instanceof EE_Price) { ?> |
|
| 55 | 55 | <tr> |
| 56 | 56 | <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" class="small-text" colspan="2"> |
| 57 | 57 | <b><?php echo $ticket->base_price()->name(); ?></b></td> |
@@ -60,31 +60,31 @@ discard block |
||
| 60 | 60 | </td> |
| 61 | 61 | </tr> |
| 62 | 62 | <?php |
| 63 | - $running_total = $ticket->base_price()->amount(); |
|
| 64 | - } else { |
|
| 65 | - $running_total = 0; |
|
| 66 | - } |
|
| 67 | - $pretax_total = $running_total; |
|
| 68 | - $display_subtotal = true; |
|
| 69 | - // now add price modifiers |
|
| 70 | - foreach ($ticket->price_modifiers() as $price_mod) { |
|
| 71 | - if ($price_mod->is_tax()) { |
|
| 72 | - echo espressoSubtotalRow($running_total, $display_subtotal); |
|
| 73 | - $display_subtotal = false; |
|
| 74 | - $new_sub_total = $pretax_total * ($price_mod->amount() / 100); |
|
| 75 | - } elseif ($price_mod->is_percent()) { |
|
| 76 | - $new_sub_total = $running_total * ($price_mod->amount() / 100); |
|
| 77 | - } else { |
|
| 78 | - $new_sub_total = $price_mod->amount(); |
|
| 79 | - } |
|
| 80 | - $new_sub_total = $price_mod->is_discount() |
|
| 81 | - ? $new_sub_total * -1 |
|
| 82 | - : $new_sub_total; |
|
| 83 | - $description = $price_mod->desc() . ' '; |
|
| 84 | - $description .= $price_mod->is_percent() |
|
| 85 | - ? $price_mod->amount() . '%' |
|
| 86 | - : EEH_Template::format_currency($price_mod->amount()); |
|
| 87 | - ?> |
|
| 63 | + $running_total = $ticket->base_price()->amount(); |
|
| 64 | + } else { |
|
| 65 | + $running_total = 0; |
|
| 66 | + } |
|
| 67 | + $pretax_total = $running_total; |
|
| 68 | + $display_subtotal = true; |
|
| 69 | + // now add price modifiers |
|
| 70 | + foreach ($ticket->price_modifiers() as $price_mod) { |
|
| 71 | + if ($price_mod->is_tax()) { |
|
| 72 | + echo espressoSubtotalRow($running_total, $display_subtotal); |
|
| 73 | + $display_subtotal = false; |
|
| 74 | + $new_sub_total = $pretax_total * ($price_mod->amount() / 100); |
|
| 75 | + } elseif ($price_mod->is_percent()) { |
|
| 76 | + $new_sub_total = $running_total * ($price_mod->amount() / 100); |
|
| 77 | + } else { |
|
| 78 | + $new_sub_total = $price_mod->amount(); |
|
| 79 | + } |
|
| 80 | + $new_sub_total = $price_mod->is_discount() |
|
| 81 | + ? $new_sub_total * -1 |
|
| 82 | + : $new_sub_total; |
|
| 83 | + $description = $price_mod->desc() . ' '; |
|
| 84 | + $description .= $price_mod->is_percent() |
|
| 85 | + ? $price_mod->amount() . '%' |
|
| 86 | + : EEH_Template::format_currency($price_mod->amount()); |
|
| 87 | + ?> |
|
| 88 | 88 | <tr> |
| 89 | 89 | <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" |
| 90 | 90 | class="jst-rght small-text" |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | </tr> |
| 102 | 102 | <?php } ?> |
| 103 | 103 | <?php if ($ticket->taxable()) { |
| 104 | - echo espressoSubtotalRow($running_total); |
|
| 105 | - foreach ($ticket->get_ticket_taxes_for_admin() as $tax) { ?> |
|
| 104 | + echo espressoSubtotalRow($running_total); |
|
| 105 | + foreach ($ticket->get_ticket_taxes_for_admin() as $tax) { ?> |
|
| 106 | 106 | <tr> |
| 107 | 107 | <td data-th="<?php esc_html_e('Name', 'event_espresso'); ?>" |
| 108 | 108 | class="jst-rght small-text" |
@@ -125,19 +125,19 @@ discard block |
||
| 125 | 125 | <td colspan="2" class="jst-rght small-text ttl-lbl-td"> |
| 126 | 126 | <b> |
| 127 | 127 | <?php echo esc_html( |
| 128 | - apply_filters( |
|
| 129 | - 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 130 | - __('Total', 'event_espresso') |
|
| 131 | - ) |
|
| 132 | - ); ?> |
|
| 128 | + apply_filters( |
|
| 129 | + 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 130 | + __('Total', 'event_espresso') |
|
| 131 | + ) |
|
| 132 | + ); ?> |
|
| 133 | 133 | </b> |
| 134 | 134 | </td> |
| 135 | 135 | <td data-th="<?php echo esc_html( |
| 136 | - apply_filters( |
|
| 137 | - 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 138 | - __('Total', 'event_espresso') |
|
| 139 | - ) |
|
| 140 | - ); ?>" class="jst-rght small-text" |
|
| 136 | + apply_filters( |
|
| 137 | + 'FHEE__ticket_selector_chart_template__ticket_details_total_price', |
|
| 138 | + __('Total', 'event_espresso') |
|
| 139 | + ) |
|
| 140 | + ); ?>" class="jst-rght small-text" |
|
| 141 | 141 | > |
| 142 | 142 | <b><?php echo EEH_Template::format_currency($running_total); ?></b> |
| 143 | 143 | </td> |
@@ -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> |