| @@ -83,9 +83,9 @@ | ||
| 83 | 83 | if ( ! $actions ) { |
| 84 | 84 | wp_send_json_error( __( 'No Square actions found for this form', 'formidable' ) ); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $action = reset( $actions ); | |
| 87 | + $action = self::get_action_for_verification( $actions ); | |
| 88 | 88 | $verification_details = array( |
| 89 | 89 | 'amount' => self::get_amount_value_for_verification( $action ), |
| 90 | 90 | 'billingContact' => self::get_billing_contact( $action ), |
| 91 | 91 | 'currencyCode' => strtoupper( $action->post_content['currency'] ), |
| @@ -100,10 +100,45 @@ | ||
| 100 | 100 | ); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | + * Get the action that the submission will actually trigger. | |
| 105 | + * | |
| 106 | + * Square verifies a single amount, so when a form has more than one Square action, | |
| 107 | + * the conditional logic of each action is checked against the posted values. Without | |
| 108 | + * this, the first action always wins and the buyer gets verified for an amount that | |
| 109 | + * a different action is going to charge. | |
| 110 | + * | |
| 111 | + * @since 6.35 | |
| 112 | + * | |
| 113 | + * @param array $actions Payment actions from FrmSquareLiteActionsController::get_actions_before_submit. Never empty. | |
| 114 | + * | |
| 115 | + * @return WP_Post | |
| 116 | + */ | |
| 117 | + private static function get_action_for_verification( $actions ) { | |
| 118 | + if ( count( $actions ) > 1 ) { | |
| 119 | + $entry = self::generate_false_entry(); | |
| 120 | + | |
| 121 | + foreach ( $actions as $action ) { | |
| 122 | + if ( ! FrmFormAction::action_conditions_met( $action, $entry ) ) { | |
| 123 | + // Conditions were met, so this is the action that will charge the buyer. | |
| 124 | + return $action; | |
| 125 | + } | |
| 126 | + } | |
| 127 | + } | |
| 128 | + | |
| 129 | + // Either there is a single action, or no action passed its conditional logic. | |
| 130 | + return reset( $actions ); | |
| 131 | + } | |
| 132 | + | |
| 133 | + /** | |
| 104 | 134 | * Get the amount value for verification. |
| 105 | 135 | * |
| 136 | + * Square's verifyBuyer expects the amount as a decimal string in the currency's | |
| 137 | + * major units ("20.00" for twenty pounds), not the smallest denomination that the | |
| 138 | + * Payments API uses. FrmSquareLiteActionsController::prepare_amount returns the | |
| 139 | + * smallest denomination, so the parent is called here instead. | |
| 140 | + * | |
| 106 | 141 | * @param WP_Post $action |
| 107 | 142 | * |
| 108 | 143 | * @return string |
| 109 | 144 | */ |
| @@ -110,9 +145,10 @@ | ||
| 110 | 145 | private static function get_amount_value_for_verification( $action ) { |
| 111 | 146 | $amount = $action->post_content['amount']; |
| 112 | 147 | |
| 113 | 148 | if ( ! str_contains( $amount, '[' ) ) { |
| 114 | - return $amount; | |
| 149 | + $currency = $action->post_content['currency']; | |
| 150 | + return FrmTransLiteActionsController::prepare_amount( $amount, compact( 'currency' ) ); | |
| 115 | 151 | } |
| 116 | 152 | |
| 117 | 153 | $form = FrmForm::getOne( $action->menu_order ); |
| 118 | 154 | |
| @@ -122,9 +158,9 @@ | ||
| 122 | 158 | |
| 123 | 159 | // Update amount based on field shortcodes. |
| 124 | 160 | $entry = self::generate_false_entry(); |
| 125 | 161 | |
| 126 | - return FrmSquareLiteActionsController::prepare_amount( $amount, compact( 'form', 'entry', 'action' ) ); | |
| 162 | + return FrmTransLiteActionsController::prepare_amount( $amount, compact( 'form', 'entry', 'action' ) ); | |
| 127 | 163 | } |
| 128 | 164 | |
| 129 | 165 | /** |
| 130 | 166 | * Show a warning in the payment action settings when the selected address field |
| @@ -276,9 +312,11 @@ | ||
| 276 | 312 | $entry = new stdClass(); |
| 277 | 313 | $entry->post_id = 0; |
| 278 | 314 | $entry->id = 0; |
| 279 | 315 | $entry->item_key = ''; |
| 280 | - $entry->metas = array(); | |
| 316 | + // Shortcode replacement reads ip off of the entry, so it cannot be left unset. | |
| 317 | + $entry->ip = ''; | |
| 318 | + $entry->metas = array(); | |
| 281 | 319 | |
| 282 | 320 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 283 | 321 | foreach ( $_POST as $k => $v ) { |
| 284 | 322 | $k = sanitize_text_field( stripslashes( $k ) ); |