/** * Acquirrer field input * * @param string $field_content * @param string $field * @param string $value * @param string $lead_id * @param string $form_id */ public static function acquirer_field_input($field_content, $field, $value, $lead_id, $form_id) { $type = RGFormsModel::get_input_type($field); if (Pronamic_WP_Pay_Extensions_GravityForms_IssuerDropDown::TYPE === $type) { $id = $field['id']; $field_id = IS_ADMIN || 0 === $form_id ? "input_{$id}" : 'input_' . $form_id . "_{$id}"; $class_suffix = RG_CURRENT_VIEW === 'entry' ? '_admin' : ''; $size = rgar($field, 'size'); $class = $size . $class_suffix; $css_class = trim(esc_attr($class) . ' gfield_ideal_acquirer_select'); $tab_index = GFCommon::get_tabindex(); $disabled_text = IS_ADMIN && 'entry' !== RG_CURRENT_VIEW ? "disabled='disabled'" : ''; $html = ''; $feed = get_pronamic_gf_pay_conditioned_feed_by_form_id($form_id, true); /** * Developing warning: * Don't use single quotes in the HTML you output, it is buggy in combination with SACK */ if (IS_ADMIN) { if (null === $feed) { $html .= sprintf("<a class='ideal-edit-link' href='%s' target='_blank'>%s</a>", add_query_arg('post_type', 'pronamic_pay_gf', admin_url('post-new.php')), __('Create iDEAL feed', 'pronamic_ideal')); } else { $html .= sprintf("<a class='ideal-edit-link' href='%s' target='_blank'>%s</a>", get_edit_post_link($feed->id), __('Edit iDEAL feed', 'pronamic_ideal')); } } $html_input = ''; $html_error = ''; if (null !== $feed) { $gateway = Pronamic_WP_Pay_Plugin::get_gateway($feed->config_id); if ($gateway) { $issuer_field = $gateway->get_issuer_field(); $error = $gateway->get_error(); if (is_wp_error($error)) { $html_error .= Pronamic_WP_Pay_Plugin::get_default_error_message(); $html_error .= '<br /><em>' . $error->get_error_message() . '</em>'; } elseif ($issuer_field) { $choices = $issuer_field['choices']; $options = Pronamic_WP_HTML_Helper::select_options_grouped($choices, $value); // Double quotes are not working, se we replace them with an single quote $options = str_replace('"', '\'', $options); $html_input = ''; $html_input .= sprintf("<select name='input_%d' id='%s' class='%s' %s %s>", $id, $field_id, $css_class, $tab_index, $disabled_text); $html_input .= sprintf('%s', $options); $html_input .= sprintf('</select>'); } } } if ($html_error) { $html .= sprintf("<div class='gfield_description validation_message'>"); $html .= sprintf('%s', $html_error); $html .= sprintf('</div>'); } else { $html .= sprintf("<div class='ginput_container ginput_ideal'>"); $html .= sprintf('%s', $html_input); $html .= sprintf('</div>'); } $field_content = $html; } return $field_content; }
function info_fields($form_id) { $payment_mode = give_get_chosen_gateway($form_id); if ($this->id === $payment_mode) { // Errors if (filter_has_var(INPUT_GET, 'payment-error')) { printf('<div class="give_error">%s</div>', Pronamic_WP_Pay_Plugin::get_default_error_message()); } // Gateway $config_id = give_get_option(sprintf('give_%s_configuration', $this->id)); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $gateway->set_payment_method($this->payment_method); echo $gateway->get_input_html(); } } }
/** * Set redirection info * * @see https://github.com/eventespresso/event-espresso-core/blob/4.6.17.p/core/libraries/payment_methods/EE_Offsite_Gateway.lib.php#L51-L59 * * @param EEI_Payment $payment * @param type $billing_info * @param type $return_url * @param type $cancel_url */ public function set_redirection_info($ee_payment, $billing_info = array(), $return_url = null, $notify_url = null, $cancel_url = null) { $pronamic_gateway = Pronamic_WP_Pay_Plugin::get_gateway($this->_config_id); if ($pronamic_gateway) { $transaction = $ee_payment->transaction(); $total_line_item = $transaction->total_line_item(); $data = new Pronamic_WP_Pay_Extensions_EventEspresso_PaymentData($this, $total_line_item, $transaction); $pronamic_payment = Pronamic_WP_Pay_Plugin::start($this->_config_id, $pronamic_gateway, $data); $error = $pronamic_gateway->get_error(); if (is_wp_error($error)) { // @see https://github.com/eventespresso/event-espresso-core/blob/4.6.18.p/caffeinated/payment_methods/Mijireh/EEG_Mijireh.gateway.php#L147 $error_message = sprintf(__('Errors communicating with gateway: %s', 'pronamic_ideal'), implode(',', $error->get_error_messages())); EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__); throw new EE_Error($error_message); } else { update_post_meta($pronamic_payment->get_id(), '_pronamic_payment_url_return', $return_url); update_post_meta($pronamic_payment->get_id(), '_pronamic_payment_url_success', $return_url); update_post_meta($pronamic_payment->get_id(), '_pronamic_payment_url_cancel', $cancel_url); update_post_meta($pronamic_payment->get_id(), '_pronamic_payment_url_error', $cancel_url); $redirect_url = $pronamic_payment->get_action_url(); $redirect_args = $pronamic_gateway->get_output_fields(); /* * Since Event Espresso uses an HTML form to redirect users to the payment gateway * we have to make sure an POST method is used when the redirect URL has query arguments. * Otheriwse the URL query arguments will be stripped by the users webbrowser. * Herefor we have to make sure the redirect arguments array is not empty. * * @see https://github.com/eventespresso/event-espresso-core/blob/4.6.18.p/core/db_classes/EE_Payment.class.php#L547 * @see http://stackoverflow.com/q/1116019 */ if (false !== strpos($redirect_url, '?') && empty($redirect_args)) { $redirect_args[] = ''; } $ee_payment->set_redirect_url($redirect_url); $ee_payment->set_redirect_args($redirect_args); } } else { $error = Pronamic_WP_Pay_Plugin::get_default_error_message(); // @see https://github.com/eventespresso/event-espresso-core/blob/4.6.18.p/caffeinated/payment_methods/Mijireh/EEG_Mijireh.gateway.php#L147 throw new EE_Error($error); } return $ee_payment; }
private function process_gateway_http_redirect($order, $gateway) { $data = new Pronamic_WP_Pay_Extensions_Jigoshop_PaymentData($order); $payment = Pronamic_WP_Pay_Plugin::start($this->config_id, $gateway, $data); $error = $gateway->get_error(); if (is_wp_error($error)) { jigoshop::add_error(Pronamic_WP_Pay_Plugin::get_default_error_message()); if (current_user_can('administrator')) { foreach ($error->get_error_codes() as $code) { jigoshop::add_error($error->get_error_message($code)); } } // see https://github.com/jigoshop/jigoshop/blob/1.4.9/shortcodes/pay.php#L55 return array('result' => 'failed'); } else { // We can't redirect directly to the action URL because of Jigoshop wp_safe_redirect() usage. // $url = $payment->get_action_url(); $url = add_query_arg('payment_redirect', $payment->get_id(), home_url('/')); return array('result' => 'success', 'redirect' => $url); } }
/** * Render field. * * @param array $field */ private function render_field($field) { $config_id = get_option('pronamic_pay_config_id'); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { // Always use iDEAL payment method for issuer field $payment_method = $gateway->get_payment_method(); $gateway->set_payment_method(Pronamic_WP_Pay_PaymentMethods::IDEAL); $issuer_field = $gateway->get_issuer_field(); $error = $gateway->get_error(); if (is_wp_error($error)) { $html_error .= Pronamic_WP_Pay_Plugin::get_default_error_message(); $html_error .= '<br /><em>' . $error->get_error_message() . '</em>'; } elseif ($issuer_field) { $choices = $issuer_field['choices']; $options = Pronamic_WP_HTML_Helper::select_options_grouped($choices); printf('<select name="%s" id="%s">', esc_attr(sprintf('item_meta[%s]', $field['id'])), esc_attr(sprintf('field_%s', $field['field_key']))); echo $options; echo '</select>'; } // Reset payment method to original value $gateway->set_payment_method($payment_method); } }
/** * Confirmation * * @see http://www.gravityhelp.com/documentation/page/Gform_confirmation */ public function confirmation($confirmation, $form, $lead, $ajax) { if ($this->is_processing($form) && $this->gateway && $this->payment && $this->payment->get_amount() > 0) { if (is_wp_error($this->error)) { $html = ''; $html .= '<ul>'; $html .= '<li>' . Pronamic_WP_Pay_Plugin::get_default_error_message() . '</li>'; foreach ($this->error->get_error_messages() as $message) { $html .= '<li>' . $message . '</li>'; } $html .= '</ul>'; $confirmation = $html; } else { $confirmation = array('redirect' => $this->payment->get_pay_redirect_url()); } if ((headers_sent() || $ajax) && is_array($confirmation) && isset($confirmation['redirect'])) { $url = $confirmation['redirect']; // Using esc_js() and esc_url() on the URL is causing problems, the & in the URL is modified to & or & $confirmation = sprintf('<script>function gformRedirect(){document.location.href = %s;}', json_encode($url)); if (!$ajax) { $confirmation .= 'gformRedirect();'; } $confirmation .= '</script>'; } } return $confirmation; }
/** * The $purchase_data array consists of the following data: * * $purchase_data = array( * 'downloads' => array of download IDs, * 'tax' => taxed amount on shopping cart * 'subtotal' => total price before tax * 'price' => total price of cart contents after taxes, * 'purchase_key' => Random key * 'user_email' => $user_email, * 'date' => date( 'Y-m-d H:i:s' ), * 'user_id' => $user_id, * 'post_data' => $_POST, * 'user_info' => array of user's information and used discount code * 'cart_details' => array of cart details, * ); */ public function process_purchase($purchase_data) { $config_id = edd_get_option($this->id . '_config_id'); // Collect payment data $payment_data = array('price' => $purchase_data['price'], 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => edd_get_currency(), 'downloads' => $purchase_data['downloads'], 'user_info' => $purchase_data['user_info'], 'cart_details' => $purchase_data['cart_details'], 'gateway' => $this->id, 'status' => 'pending'); // Record the pending payment $payment_id = edd_insert_payment($payment_data); // Check payment if (!$payment_id) { // Log error edd_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to the payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $payment_id); edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } else { $data = new Pronamic_WP_Pay_Extensions_EDD_PaymentData($payment_id, $payment_data); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { // Start $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $this->payment_method); $error = $gateway->get_error(); if (is_wp_error($error)) { edd_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to the payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $payment_id); edd_set_error('pronamic_pay_error', Pronamic_WP_Pay_Plugin::get_default_error_message()); foreach ($error->get_error_messages() as $i => $message) { edd_set_error('pronamic_pay_error_' . $i, $message); } edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } else { // Transaction ID // @see https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/2.3/includes/payments/functions.php#L1400-L1416 edd_set_payment_transaction_id($payment_id, $payment->get_transaction_id()); // Payment note $payment_link = add_query_arg(array('post' => $payment->get_id(), 'action' => 'edit'), admin_url('post.php')); $note = sprintf(__('Payment %s pending.', 'pronamic_ideal'), sprintf('<a href="%s">#%s</a>', $payment_link, $payment->get_id())); edd_insert_payment_note($payment_id, $note); $gateway->redirect($payment); exit; } } else { edd_set_error('pronamic_pay_error', Pronamic_WP_Pay_Plugin::get_default_error_message()); edd_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['edd-gateway']); } } }
/** * Process iDEAL advanced payment * * @param WC_Order $order * @return array */ private function process_gateway_http_redirect($order, $gateway) { $data = new Pronamic_WP_Pay_Extensions_WooCommerce_PaymentData($order, $this, $this->payment_description); $payment = Pronamic_WP_Pay_Plugin::start($this->config_id, $gateway, $data, $this->payment_method); $error = $gateway->get_error(); if (is_wp_error($error)) { Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::add_notice(Pronamic_WP_Pay_Plugin::get_default_error_message(), 'error'); foreach ($error->get_error_messages() as $message) { Pronamic_WP_Pay_Extensions_WooCommerce_WooCommerce::add_notice($message, 'error'); } // @see https://github.com/woothemes/woocommerce/blob/v1.6.6/woocommerce-functions.php#L518 // @see https://github.com/woothemes/woocommerce/blob/v2.1.5/includes/class-wc-checkout.php#L669 return array('result' => 'failure'); } else { $url = $payment->get_action_url(); return array('result' => 'success', 'redirect' => $url); } }
/** * Handle payment */ public function handle_payment() { if (filter_has_var(INPUT_POST, 'pronamic_pay_s2member')) { $index = filter_input(INPUT_POST, 'pronamic_pay_s2member_index', FILTER_SANITIZE_STRING); $hash = filter_input(INPUT_POST, 'pronamic_pay_s2member_hash', FILTER_SANITIZE_STRING); $data = filter_input(INPUT_POST, 'pronamic_pay_s2member_data', FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY); if ($hash === $this->create_hash($data)) { // Config $config_id = get_option('pronamic_pay_s2member_config_id'); // Gateway $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); // Data $data = new Pronamic_WP_Pay_Extensions_S2Member_PaymentData($data); $email = $data->get_email(); if (!empty($email)) { // Start $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); update_post_meta($payment->get_id(), '_pronamic_payment_s2member_period', $data->get_period()); update_post_meta($payment->get_id(), '_pronamic_payment_s2member_level', $data->get_level()); update_post_meta($payment->get_id(), '_pronamic_payment_s2member_ccaps', $data->get_ccaps()); $error = $gateway->get_error(); if (is_wp_error($error)) { // Set error message $this->error[$index] = array(Pronamic_WP_Pay_Plugin::get_default_error_message()); foreach ($error->get_error_messages() as $message) { $this->error[$index][] = $message; } } else { // Redirect $gateway->redirect($payment); } } } } }
/** * Confirmation * * @see http://www.gravityhelp.com/documentation/page/Gform_confirmation */ public function confirmation($confirmation, $form, $lead, $ajax) { if ($this->is_processing($form) && $this->gateway && $this->payment && $this->payment->get_amount() > 0) { if (is_wp_error($this->error)) { $html = ''; $html .= '<ul>'; $html .= '<li>' . Pronamic_WP_Pay_Plugin::get_default_error_message() . '</li>'; foreach ($this->error->get_error_messages() as $message) { $html .= '<li>' . $message . '</li>'; } $html .= '</ul>'; $confirmation = $html; } else { if ($this->gateway->is_http_redirect()) { // Redirect user to the issuer $confirmation = array('redirect' => $this->payment->get_action_url()); } if ($this->gateway->is_html_form()) { $auto_submit = true; if ($ajax) { // On AJAX enabled forms we can't auto submit, this will auto submit in a hidden iframe $auto_submit = false; } // HTML $html = ''; $html .= '<div id="gforms_confirmation_message">'; $html .= GFCommon::replace_variables($form['confirmation']['message'], $form, $lead, false, true, true); $html .= $this->gateway->get_form_html($this->payment, $auto_submit); $html .= '</div>'; // Extend the confirmation with the iDEAL form $confirmation = $html; } } if ((headers_sent() || $ajax) && is_array($confirmation) && isset($confirmation['redirect'])) { $url = $confirmation['redirect']; // Using esc_js() and esc_url() on the URL is causing problems, the & in the URL is modified to & or & $confirmation = sprintf('<script>function gformRedirect(){document.location.href = %s;}', json_encode($url)); if (!$ajax) { $confirmation .= 'gformRedirect();'; } $confirmation .= '</script>'; } } return $confirmation; }