/** * Maybe pay */ public function maybe_pay() { if (filter_has_var(INPUT_POST, 'pronamic_pay_membership')) { // Data $subscription_id = filter_input(INPUT_POST, 'subscription_id', FILTER_SANITIZE_STRING); $user_id = filter_input(INPUT_POST, 'user_id', FILTER_SANITIZE_STRING); $subscription = Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Membership::get_subscription($subscription_id); $membership = Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Membership::get_membership($user_id); if (isset($subscription, $membership)) { $config_id = get_option(Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_Extension::OPTION_CONFIG_ID); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); $data = new Pronamic_WP_Pay_Extensions_WPMUDEV_Membership_PaymentData($subscription, $membership); // Start $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); // Meta update_post_meta($payment->get_id(), '_pronamic_payment_membership_user_id', $user_id); update_post_meta($payment->get_id(), '_pronamic_payment_membership_subscription_id', $data->get_subscription_id()); // Membership record transaction // @see http://plugins.trac.wordpress.org/browser/membership/tags/3.4.4.1/membershipincludes/classes/class.gateway.php#L176 $this->pronamic_record_transaction($user_id, $data->get_subscription_id(), $data->get_amount(), $data->get_currency(), time(), $payment->get_id(), '', ''); // Error $error = $gateway->get_error(); if (is_wp_error($error)) { $this->error = $error; } else { // Redirect $gateway->redirect($payment); } } } }
/** * Processes a payment using this Gateway */ public function process($order, $options) { if (isset($options['config_id'])) { $config_id = $options['config_id']; $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $data = new Pronamic_WP_Pay_Extensions_AppThemes_PaymentData($order); if (filter_has_var(INPUT_POST, 'appthemes_pronamic_ideal')) { $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); $error = $gateway->get_error(); if (is_wp_error($error)) { foreach ($error->get_error_messages() as $message) { echo $message; } } else { $gateway->redirect($payment); } } else { ?> <form method="post" action=""> <?php echo $gateway->get_input_html(); ?> <p> <?php printf('<input class="ideal-button" type="submit" name="appthemes_pronamic_ideal" value="%s" />', __('Pay with iDEAL', 'pronamic_ideal')); ?> </p> </form> <?php } } } }
/** * Process gateway */ public static function process_gateway() { if (filter_has_var(INPUT_POST, 'event_espresso_pronamic_ideal')) { $config_id = get_option(self::OPTION_CONFIG_ID); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $payment_data = array('attendee_id' => apply_filters('filter_hook_espresso_transactions_get_attendee_id', '')); $data = new Pronamic_WP_Pay_Extensions_EventEspressoLegacy_PaymentData($payment_data); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); $error = $gateway->get_error(); if (is_wp_error($error)) { Pronamic_WP_Pay_Plugin::render_errors($error); } else { $gateway->redirect($payment); } } } }
/** * Process donation. * * @since 1.0.0 * @param mixed $return * @param int $donation_id * @param Charitable_Donation_Processor $processor * @param string $gateway * @return mixed array or boolean */ public static function pronamic_process_donation($return, $donation_id, $processor, $charitable_gateway) { $payment_method = $charitable_gateway->payment_method; $config_id = $charitable_gateway->get_value('config_id'); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if (!$gateway) { return false; } // Data $data = new Pronamic_WP_Pay_Extensions_Charitable_PaymentData($donation_id, $processor, $charitable_gateway); $gateway->set_payment_method($payment_method); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $payment_method); $error = $gateway->get_error(); if (is_wp_error($error)) { charitable_get_notices()->add_error($error->get_error_message()); return false; } return array('redirect' => $payment->get_pay_redirect_url(), 'safe' => false); }
/** * 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; }
/** * Initialize */ public function init() { global $pronamic_pay_errors; $pronamic_pay_errors = array(); if (filter_has_var(INPUT_POST, 'pronamic_pay_nonce')) { $nonce = filter_input(INPUT_POST, 'pronamic_pay_nonce', FILTER_SANITIZE_STRING); if (wp_verify_nonce($nonce, 'pronamic_pay')) { $id = filter_input(INPUT_POST, 'pronamic_pay_form_id', FILTER_VALIDATE_INT); $config_id = get_post_meta($id, '_pronamic_payment_form_config_id', true); $valid = $this->validate(); if ($valid) { $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $data = new Pronamic_WP_Pay_PaymentFormData(); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); $error = $gateway->get_error(); if (is_wp_error($error)) { Pronamic_WP_Pay_Plugin::render_errors($error); } else { // @see https://github.com/WordImpress/Give/blob/1.1/includes/payments/functions.php#L172-L178 // @see https://github.com/woothemes/woocommerce/blob/2.4.3/includes/wc-user-functions.php#L36-L118 $first_name = filter_input(INPUT_POST, 'pronamic_pay_first_name', FILTER_SANITIZE_STRING); $last_name = filter_input(INPUT_POST, 'pronamic_pay_last_name', FILTER_SANITIZE_STRING); $email = filter_input(INPUT_POST, 'pronamic_pay_email', FILTER_VALIDATE_EMAIL); $user = get_user_by('email', $email); if (!$user) { // Make a random string for password $password = wp_generate_password(10); // Make a user with the username as the email $user_id = wp_insert_user(array('user_login' => $email, 'user_pass' => $password, 'user_email' => $email, 'role' => 'payer', 'first_name' => $first_name, 'last_name' => $last_name)); // User $user = new WP_User($user_id); } wp_update_post(array('ID' => $payment->post->ID, 'post_author' => $user->ID)); $gateway->redirect($payment); } exit; } } } } }
/** * Submit to gateway */ public function submit() { $config_id = get_option(Pronamic_WP_Pay_Extensions_WPeCommerce_Extension::OPTION_CONFIG_ID); // Set process to 'order_received' (2) // @see http://plugins.trac.wordpress.org/browser/wp-e-commerce/tags/3.8.7.6.2/wpsc-includes/merchant.class.php#L301 // @see http://plugins.trac.wordpress.org/browser/wp-e-commerce/tags/3.8.7.6.2/wpsc-core/wpsc-functions.php#L115 $this->set_purchase_processed_by_purchid(Pronamic_WP_Pay_Extensions_WPeCommerce_WPeCommerce::PURCHASE_STATUS_ORDER_RECEIVED); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $data = new Pronamic_WP_Pay_Extensions_WPeCommerce_PaymentData($this); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); update_post_meta($payment->get_id(), '_pronamic_payment_wpsc_purchase_id', $data->get_purchase_id()); update_post_meta($payment->get_id(), '_pronamic_payment_wpsc_session_id', $data->get_session_id()); $error = $gateway->get_error(); if (is_wp_error($error)) { // @todo what todo? } else { $gateway->redirect($payment); } } }
/** * Process donation. * * @param int $donation_id * @param Charitable_Donation_Processor $processor * @param string $gateway * @since 1.0.0 */ public static function process_donation($donation_id, $processor, $gateway = null) { if (null === $gateway) { $gateway = new self(); } else { $gateway = new $gateway(); } $payment_method = $gateway->payment_method; $config_id = $gateway->get_value('config_id'); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { // Data $data = new Pronamic_WP_Pay_Extensions_Charitable_PaymentData($donation_id, $processor); $gateway->set_payment_method($payment_method); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $payment_method); $error = $gateway->get_error(); if (!is_wp_error($error)) { // Redirect $gateway->redirect($payment); } } }
/** * Entry created * * @param array $lead * @param array $form */ public function entry_created($lead, $form) { if ($this->is_processing($form)) { $this->gateway = Pronamic_WP_Pay_Plugin::get_gateway($this->feed->config_id); if ($this->gateway) { $data = new Pronamic_WP_Pay_Extensions_GravityForms_PaymentData($form, $lead, $this->feed); $this->payment = Pronamic_WP_Pay_Plugin::start($this->feed->config_id, $this->gateway, $data); $this->error = $this->gateway->get_error(); } } }
/** * Check if an iDEAL payment needs to be processed. */ public static function process_payment() { $do_process_payment = filter_input(INPUT_POST, 'pronamic_ideal_process_payment', FILTER_SANITIZE_STRING); if (strlen($do_process_payment) <= 0) { return; } // Prepare transaction data $unique_hash = it_exchange_create_unique_hash(); $current_customer = it_exchange_get_current_customer(); $transaction_object = it_exchange_generate_transaction_object(); if (!$transaction_object instanceof stdClass) { return; } it_exchange_add_transient_transaction(self::$slug, $unique_hash, $current_customer->ID, $transaction_object); $configuration_id = self::get_gateway_configuration_id(); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($configuration_id); if ($gateway) { $data = new Pronamic_WP_Pay_Extensions_IThemesExchange_PaymentData($unique_hash, $transaction_object); $payment = Pronamic_WP_Pay_Plugin::start($configuration_id, $gateway, $data); $gateway->redirect($payment); exit; } }
/** * Process payment start * * @param EE_Line_Item $total_line_item * @param $transaction */ public function process_payment_start(EE_Line_Item $total_line_item, $transaction = null) { if (!$transaction) { $transaction = $total_line_item->transaction(); } $config_id = $this->_payment_settings['config_id']; $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $data = new Pronamic_WP_Pay_Extensions_EventEspresso_PaymentData($this, $total_line_item, $transaction); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); $error = $gateway->get_error(); if (!is_wp_error($error)) { $offsite_form = $this->submitPayment(); $offsite_form['form'] = $gateway->get_form_html($payment, true); $this->_EEM_Gateways->set_off_site_form($offsite_form); $this->redirect_after_reg_step_3(); } } }
/** * 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); } } } } }
/** * Process purchase. * * @since 1.0.0 * * @param array $purchase_data Purchase Data * * @return void */ function process_purchase($purchase_data) { if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'give-gateway')) { wp_die(__('Nonce verification has failed', 'pronamic_ideal'), __('Error', 'pronamic_ideal'), array('response' => 403)); } $form_id = intval($purchase_data['post_data']['give-form-id']); // Collect payment data $payment_data = array('price' => $purchase_data['price'], 'give_form_title' => $purchase_data['post_data']['give-form-title'], 'give_form_id' => $form_id, 'date' => $purchase_data['date'], 'user_email' => $purchase_data['user_email'], 'purchase_key' => $purchase_data['purchase_key'], 'currency' => give_get_currency(), 'user_info' => $purchase_data['user_info'], 'status' => 'pending', 'gateway' => $this->id); // Record the pending payment $donation_id = give_insert_payment($payment_data); if (!$donation_id) { // Record the error // /wp-admin/edit.php?post_type=give_forms&page=give-reports&tab=logs&view=gateway_errors // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/gateways/functions.php#L267-L285 give_record_gateway_error(__('Payment Error', 'pronamic_ideal'), sprintf(__('Payment creation failed before sending buyer to payment provider. Payment data: %s', 'pronamic_ideal'), json_encode($payment_data)), $donation_id); // Problems? send back // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/forms/functions.php#L150-L184 give_send_back_to_checkout(array('payment-error' => true, 'payment-mode' => $purchase_data['post_data']['give-gateway'])); } else { $config_id = give_get_option(sprintf('give_%s_configuration', $this->id)); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { // Data $data = new Pronamic_WP_Pay_Extensions_Give_PaymentData($donation_id, $this); $gateway->set_payment_method($this->payment_method); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $this->payment_method); $error = $gateway->get_error(); if (is_wp_error($error)) { // Record the error // /wp-admin/edit.php?post_type=give_forms&page=give-reports&tab=logs&view=gateway_errors // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/gateways/functions.php#L267-L285 give_record_gateway_error(__('Payment Error', 'pronamic_ideal'), implode('<br />', $error->get_error_messages()), $donation_id); // Problems? send back // @see https://github.com/WordImpress/Give/blob/1.3.6/includes/forms/functions.php#L150-L184 give_send_back_to_checkout(array('payment-error' => true, 'payment-mode' => $purchase_data['post_data']['give-gateway'])); } else { // Redirect $gateway->redirect($payment); } } } }
/** * Maybe test payment */ public function maybe_test_payment() { if (filter_has_var(INPUT_POST, 'test_pay_gateway') && check_admin_referer('test_pay_gateway', 'pronamic_pay_test_nonce')) { $id = filter_input(INPUT_POST, 'post_ID', FILTER_SANITIZE_NUMBER_INT); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($id); if ($gateway) { $amount = filter_input(INPUT_POST, 'test_amount', FILTER_VALIDATE_FLOAT, array('flags' => FILTER_FLAG_ALLOW_THOUSAND, 'options' => array('decimal' => pronamic_pay_get_decimal_separator()))); $data = new Pronamic_WP_Pay_PaymentTestData(wp_get_current_user(), $amount); $payment = Pronamic_WP_Pay_Plugin::start($id, $gateway, $data); $error = $gateway->get_error(); if (is_wp_error($error)) { Pronamic_WP_Pay_Plugin::render_errors($error); } else { $gateway->redirect($payment); } exit; } } }
/** * 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); } }
/** * Order success * * In Shopp version 1.1.9 the 'shopp_order_success' the purchase is given as first parameter, * in Shopp version 1.2+ the 'shopp_order_success' the purchase is not passed as parameter anymore */ public function order_success($purchase = null) { // Check if the purchases is passed as first parameter, if not we // will load the purchase from the global Shopp variable if (empty($purchase)) { global $Shopp; $purchase = $Shopp->Purchase; } // Check gateway $gateway = Pronamic_WP_Pay_Plugin::get_gateway($this->config_id); if ($gateway) { $gateway->set_payment_method($this->payment_method); $data = new Pronamic_WP_Pay_Extensions_Shopp_PaymentData($purchase, $this); $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_Plugin::render_errors($error); exit; } else { $gateway->redirect($payment); } } }
/** * Redirect for payment. * * @see https://github.com/wp-premium/formidable-paypal/blob/3.02/controllers/FrmPaymentsController.php#L274-L311 */ public function redirect_for_payment($entry_id, $form_id) { $config_id = get_option('pronamic_pay_config_id'); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $data = new Pronamic_WP_Pay_Extensions_FormidableForms_PaymentData($entry_id, $form_id, $this->action); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, Pronamic_WP_Pay_PaymentMethods::IDEAL); $error = $gateway->get_error(); if (!is_wp_error($error)) { // Redirect $gateway->redirect($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); } }
/** * Process gateway */ public static function gateway_process($order_values) { // If gateway wasn't selected then immediately return if ('pronamic_ideal' !== $order_values['cp_payment_method']) { return; } // Add transaction entry $transaction_id = Pronamic_WP_Pay_Extensions_ClassiPress_ClassiPress::add_transaction_entry($order_values); // Handle gateway global $app_abbr; $config_id = get_option($app_abbr . '_pronamic_ideal_config_id'); $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { $data = new Pronamic_WP_Pay_Extensions_ClassiPress_PaymentData($order_values); if ($gateway->is_html_form()) { $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data); echo $gateway->get_form_html($payment, $auto_submit = true); } if ($gateway->is_http_redirect()) { // Hide the checkout page container HTML element echo '<style type="text/css">.thankyou center { display: none; }</style>'; ?> <form class="form_step" method="post" action=""> <?php echo Pronamic_IDeal_IDeal::htmlHiddenFields(array('cp_payment_method' => 'pronamic_ideal', 'oid' => $data->get_order_id())); echo $gateway->get_input_html(); ?> <p class="btn1"> <?php printf('<input class="ideal-button" type="submit" name="classipress_pronamic_ideal" value="%s" />', __('Pay with iDEAL', 'pronamic_ideal')); ?> </p> </form> <?php } } }
/** * Payment redirect. * * @since 1.0.2 * @param $txn */ public function payment_redirect($txn) { $txn = new MeprTransaction($txn->id); $invoice = MeprTransactionsHelper::get_invoice($txn); echo $invoice; // WPCS: XSS ok. // Gateway $config_id = $this->settings->config_id; $gateway = Pronamic_WP_Pay_Plugin::get_gateway($config_id); if ($gateway) { // Data $data = new Pronamic_WP_Pay_Extensions_MemberPress_PaymentData($txn); $payment = Pronamic_WP_Pay_Plugin::start($config_id, $gateway, $data, $this->payment_method); $error = $gateway->get_error(); if (!is_wp_error($error)) { // Redirect $gateway->redirect($payment); } } }
/** * Entry post save * * @param array $lead * @param array $form */ public function entry_post_save($lead, $form) { if ($this->is_processing($form)) { // Payment ID $payment_id = gform_get_meta($lead['id'], 'pronamic_payment_id'); if (!empty($payment_id)) { return $lead; } // Gateway $this->gateway = Pronamic_WP_Pay_Plugin::get_gateway($this->feed->config_id); if (!$this->gateway) { return $lead; } // New payment $data = new Pronamic_WP_Pay_Extensions_GravityForms_PaymentData($form, $lead, $this->feed); $payment_method = $data->get_payment_method(); // Set payment method to iDEAL if issuer_id is set if (null === $data->get_payment_method() && null !== $data->get_issuer_id()) { $payment_method = Pronamic_WP_Pay_PaymentMethods::IDEAL; } $this->payment = Pronamic_WP_Pay_Plugin::start($this->feed->config_id, $this->gateway, $data, $payment_method); $this->error = $this->gateway->get_error(); // Updating lead's payment_status to Processing $lead[Pronamic_WP_Pay_Extensions_GravityForms_LeadProperties::PAYMENT_STATUS] = Pronamic_WP_Pay_Extensions_GravityForms_PaymentStatuses::PROCESSING; $lead[Pronamic_WP_Pay_Extensions_GravityForms_LeadProperties::PAYMENT_AMOUNT] = $this->payment->get_amount(); $lead[Pronamic_WP_Pay_Extensions_GravityForms_LeadProperties::PAYMENT_DATE] = gmdate('y-m-d H:i:s'); $lead[Pronamic_WP_Pay_Extensions_GravityForms_LeadProperties::TRANSACTION_TYPE] = Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::TRANSACTION_TYPE_PAYMENT; $lead[Pronamic_WP_Pay_Extensions_GravityForms_LeadProperties::TRANSACTION_ID] = $this->payment->get_transaction_id(); // Update entry meta with payment ID gform_update_meta($lead['id'], 'pronamic_payment_id', $this->payment->get_id()); // Update entry meta with feed ID gform_update_meta($lead['id'], 'ideal_feed_id', $this->feed->id); // Update entry meta with current payment gateway gform_update_meta($lead['id'], 'payment_gateway', 'pronamic_pay'); // Update lead Pronamic_WP_Pay_Extensions_GravityForms_GravityForms::update_entry($lead); } return $lead; }
/** * 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']); } } }