function pronamic_wp_pay_update_payment(Pronamic_WP_Pay_Payment $payment) { $post_id = $payment->get_id(); // Meta $prefix = '_pronamic_payment_'; $meta = array_merge(array('transaction_id' => $payment->get_transaction_id(), 'action_url' => $payment->get_action_url(), 'status' => $payment->status, 'consumer_name' => $payment->consumer_name, 'consumer_account_number' => $payment->consumer_account_number, 'consumer_iban' => $payment->consumer_iban, 'consumer_bic' => $payment->consumer_bic, 'consumer_city' => $payment->consumer_city), $payment->meta); foreach ($meta as $key => $value) { if (!empty($value)) { $meta_key = $prefix . $key; update_post_meta($post_id, $meta_key, $value); } } $status = get_post_meta($post_id, '_pronamic_payment_status', true); $post_status = null; switch ($status) { case Pronamic_WP_Pay_Statuses::CANCELLED: $post_status = 'payment_cancelled'; break; case Pronamic_WP_Pay_Statuses::EXPIRED: $post_status = 'payment_expired'; break; case Pronamic_WP_Pay_Statuses::FAILURE: $post_status = 'payment_failed'; break; case Pronamic_WP_Pay_Statuses::OPEN: $post_status = 'payment_pending'; break; case Pronamic_WP_Pay_Statuses::SUCCESS: $post_status = 'payment_completed'; break; } if (null !== $post_status) { wp_update_post(array('ID' => $payment->post->ID, 'post_status' => $post_status)); } }
/** * Entry post save * * @param array $lead * @param array $form */ public function entry_post_save($lead, $form) { if ($this->is_processing($form) && $this->payment) { // 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; }
/** * 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; }
/** * Payment redirect URL filter. * * @since unreleased * @param string $url * @param Pronamic_WP_Pay_Payment $payment * @return string */ public function redirect_url($url, $payment) { $lead_id = $payment->get_source_id(); $lead = RGFormsModel::get_lead($lead_id); if (!$lead) { return $url; } $form_id = $lead['form_id']; $form = RGFormsModel::get_form($form_id); $feed = get_pronamic_gf_pay_feed_by_entry_id($lead_id); if (!$feed) { return $url; } $data = new Pronamic_WP_Pay_Extensions_GravityForms_PaymentData($form, $lead, $feed); switch ($payment->status) { case Pronamic_WP_Pay_Statuses::CANCELLED: $url = $data->get_cancel_url(); break; case Pronamic_WP_Pay_Statuses::EXPIRED: $url = $feed->get_url(Pronamic_WP_Pay_Extensions_GravityForms_Links::EXPIRED); break; case Pronamic_WP_Pay_Statuses::FAILURE: $url = $data->get_error_url(); break; case Pronamic_WP_Pay_Statuses::SUCCESS: $url = $data->get_success_url(); break; case Pronamic_WP_Pay_Statuses::OPEN: default: $url = $data->get_normal_return_url(); break; } // Process Gravity Forms confirmations if link type is confirmation $link = Pronamic_WP_Pay_Extensions_GravityForms_Links::transform_status($payment->status); if (isset($feed->links[$link], $feed->links[$link]['type']) && Pronamic_WP_Pay_Extensions_GravityForms_PayFeed::LINK_TYPE_CONFIRMATION === $feed->links[$link]['type']) { $confirmation = $this->get_confirmation($lead, $payment->status); if (!empty($confirmation)) { if (is_array($confirmation) && isset($confirmation['redirect'])) { $url = $confirmation['redirect']; } else { $url = add_query_arg(array('pay_confirmation' => $payment->get_id(), '_wpnonce' => wp_create_nonce('gf_confirmation_payment_' . $payment->get_id())), $lead['source_url']); } } } return $url; }
/** * Payment redirect URL filter. * * @param string $url * @param Pronamic_WP_Pay_Payment $payment * @return string */ public static function redirect_url($url, $payment) { // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L492-L530 if (Pronamic_WP_Pay_Class::method_exists('MS_Model_Pages', 'get_page_url')) { // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L44-L55 $url = MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REGISTER); } elseif (function_exists('M_get_returnurl_permalink')) { // @see https://github.com/wp-plugins/membership/blob/3.4.4.3/membershipincludes/includes/functions.php#L598-L622 $url = M_get_returnurl_permalink(); } switch ($payment->get_status()) { case Pronamic_WP_Pay_Statuses::SUCCESS: // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L492-L530 if (Pronamic_WP_Pay_Class::method_exists('MS_Model_Pages', 'get_page_url')) { $invoice_id = get_post_meta($payment->get_id(), '_pronamic_payment_membership_invoice_id', true); $invoice = MS_Factory::load('MS_Model_Invoice', $invoice_id); $subscription = $invoice->get_subscription(); // @see https://github.com/wp-plugins/membership/blob/4.0.0.2/app/model/class-ms-model-pages.php#L44-L55 $url = add_query_arg('ms_relationship_id', $subscription->id, MS_Model_Pages::get_page_url(MS_Model_Pages::MS_PAGE_REG_COMPLETE)); } elseif (function_exists('M_get_registrationcompleted_permalink')) { // @see https://github.com/wp-plugins/membership/blob/3.4.4.3/membershipincludes/includes/functions.php#L576-L598 $url = M_get_registrationcompleted_permalink(); } break; } return $url; }