Use new code style
This commit is contained in:
@ -151,8 +151,7 @@ abstract class Base_Gateway {
|
||||
* Calls the init code.
|
||||
*/
|
||||
$this->init();
|
||||
|
||||
} // end __construct;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an order.
|
||||
@ -169,10 +168,8 @@ abstract class Base_Gateway {
|
||||
public function set_order($order) {
|
||||
|
||||
if ($order === null) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* The only thing we do is to set the order.
|
||||
@ -188,8 +185,7 @@ abstract class Base_Gateway {
|
||||
$this->membership = $this->order->get_membership();
|
||||
$this->payment = $this->order->get_payment();
|
||||
$this->discount_code = $this->order->get_discount_code();
|
||||
|
||||
} // end set_order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the gateway.
|
||||
@ -197,11 +193,10 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return string
|
||||
*/
|
||||
public final function get_id() {
|
||||
final public function get_id() {
|
||||
|
||||
return $this->id;
|
||||
|
||||
} // end get_id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Required Methods.
|
||||
@ -307,7 +302,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function init() {} // end init;
|
||||
public function init() {}
|
||||
|
||||
/**
|
||||
* Adds Settings.
|
||||
@ -322,7 +317,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function settings() {} // end settings;
|
||||
public function settings() {}
|
||||
|
||||
/**
|
||||
* Checkout fields.
|
||||
@ -336,7 +331,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function fields() {} // end fields;
|
||||
public function fields() {}
|
||||
|
||||
/**
|
||||
* Declares support for recurring payments.
|
||||
@ -358,8 +353,7 @@ abstract class Base_Gateway {
|
||||
public function supports_recurring() {
|
||||
|
||||
return false;
|
||||
|
||||
} // end supports_recurring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares support for free trials.
|
||||
@ -383,8 +377,7 @@ abstract class Base_Gateway {
|
||||
public function supports_free_trials() {
|
||||
|
||||
return false;
|
||||
|
||||
} // end supports_free_trials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares support for recurring amount updates.
|
||||
@ -403,8 +396,7 @@ abstract class Base_Gateway {
|
||||
public function supports_amount_update() {
|
||||
|
||||
return false;
|
||||
|
||||
} // end supports_amount_update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles payment method updates.
|
||||
@ -412,7 +404,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function update_payment_method() {} // end update_payment_method;
|
||||
public function update_payment_method() {}
|
||||
|
||||
/**
|
||||
* Defines a public title.
|
||||
@ -435,18 +427,15 @@ abstract class Base_Gateway {
|
||||
|
||||
$registered_gateway = wu_get_isset($gateways, $this->get_id());
|
||||
|
||||
if (!$registered_gateway) {
|
||||
|
||||
if ( ! $registered_gateway) {
|
||||
$default = $this->get_id();
|
||||
$default = str_replace('-', ' ', $default);
|
||||
|
||||
return ucwords($default);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $registered_gateway['title'];
|
||||
|
||||
} // end get_public_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds additional hooks.
|
||||
@ -460,7 +449,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function hooks() {} // end hooks;
|
||||
public function hooks() {}
|
||||
|
||||
/**
|
||||
* Run preparations before checkout processing.
|
||||
@ -481,7 +470,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void|array
|
||||
*/
|
||||
public function run_preflight() {} // end run_preflight;
|
||||
public function run_preflight() {}
|
||||
|
||||
/**
|
||||
* Registers and Enqueue scripts.
|
||||
@ -494,7 +483,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function register_scripts() {} // end register_scripts;
|
||||
public function register_scripts() {}
|
||||
|
||||
/**
|
||||
* Gives gateways a chance to run things before backwards compatible webhooks are run.
|
||||
@ -502,7 +491,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.7
|
||||
* @return void
|
||||
*/
|
||||
public function before_backwards_compatible_webhook() {} // end before_backwards_compatible_webhook;
|
||||
public function before_backwards_compatible_webhook() {}
|
||||
|
||||
/**
|
||||
* Handles webhook calls.
|
||||
@ -518,7 +507,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function process_webhooks() {} // end process_webhooks;
|
||||
public function process_webhooks() {}
|
||||
|
||||
/**
|
||||
* Handles confirmation windows and extra processing.
|
||||
@ -532,7 +521,7 @@ abstract class Base_Gateway {
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function process_confirmation() {} // end process_confirmation;
|
||||
public function process_confirmation() {}
|
||||
|
||||
/**
|
||||
* Returns the external link to view the payment on the payment gateway.
|
||||
@ -544,7 +533,7 @@ abstract class Base_Gateway {
|
||||
* @param string $gateway_payment_id The gateway payment id.
|
||||
* @return void|string
|
||||
*/
|
||||
public function get_payment_url_on_gateway($gateway_payment_id) {} // end get_payment_url_on_gateway;
|
||||
public function get_payment_url_on_gateway($gateway_payment_id) {}
|
||||
|
||||
/**
|
||||
* Returns the external link to view the membership on the membership gateway.
|
||||
@ -556,7 +545,7 @@ abstract class Base_Gateway {
|
||||
* @param string $gateway_subscription_id The gateway subscription id.
|
||||
* @return void|string.
|
||||
*/
|
||||
public function get_subscription_url_on_gateway($gateway_subscription_id) {} // end get_subscription_url_on_gateway;
|
||||
public function get_subscription_url_on_gateway($gateway_subscription_id) {}
|
||||
|
||||
/**
|
||||
* Returns the external link to view the membership on the membership gateway.
|
||||
@ -568,7 +557,7 @@ abstract class Base_Gateway {
|
||||
* @param string $gateway_customer_id The gateway customer id.
|
||||
* @return void|string.
|
||||
*/
|
||||
public function get_customer_url_on_gateway($gateway_customer_id) {} // end get_customer_url_on_gateway;
|
||||
public function get_customer_url_on_gateway($gateway_customer_id) {}
|
||||
|
||||
/**
|
||||
* Reflects membership changes on the gateway.
|
||||
@ -589,20 +578,16 @@ abstract class Base_Gateway {
|
||||
$has_duration_change = $membership->get_duration() !== absint(wu_get_isset($original, 'duration')) || $membership->get_duration_unit() !== wu_get_isset($original, 'duration_unit');
|
||||
|
||||
// If there is no change in amount or duration, we don't do anything here.
|
||||
if (!$has_amount_change && !$has_duration_change) {
|
||||
|
||||
if ( ! $has_amount_change && ! $has_duration_change) {
|
||||
return true;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// Cancel the current gateway integration.
|
||||
$cancellation = $this->process_cancellation($membership, $customer);
|
||||
|
||||
if (is_wp_error($cancellation)) {
|
||||
|
||||
return $cancellation;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// Reset the gateway in the membership object.
|
||||
$membership->set_gateway('');
|
||||
@ -611,8 +596,7 @@ abstract class Base_Gateway {
|
||||
$membership->set_auto_renew(false);
|
||||
|
||||
return true;
|
||||
|
||||
} // end process_membership_update;
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper methods
|
||||
@ -629,27 +613,20 @@ abstract class Base_Gateway {
|
||||
*/
|
||||
public function get_amount_update_message($to_customer = false) {
|
||||
|
||||
if (!$this->supports_amount_update()) {
|
||||
|
||||
if ( ! $this->supports_amount_update()) {
|
||||
$message = __('The current payment integration will be cancelled.', 'wp-ultimo');
|
||||
|
||||
if ($to_customer) {
|
||||
|
||||
$message .= ' ' . __('You will receive a new invoice on the next billing cycle.', 'wp-ultimo');
|
||||
|
||||
} else {
|
||||
|
||||
$message .= ' ' . __('The customer will receive a new invoice on the next billing cycle.', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $message;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return __('The current payment integration will be updated.', 'wp-ultimo');
|
||||
|
||||
} // end get_amount_update_message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the return URL.
|
||||
@ -660,39 +637,37 @@ abstract class Base_Gateway {
|
||||
public function get_return_url() {
|
||||
|
||||
if (empty($this->return_url)) {
|
||||
|
||||
$this->return_url = wu_get_current_url();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$return_url = is_admin() ? admin_url('admin.php') : $this->return_url;
|
||||
|
||||
$return_url = remove_query_arg(array(
|
||||
'wu-confirm',
|
||||
'token',
|
||||
'PayerID',
|
||||
), $return_url);
|
||||
$return_url = remove_query_arg(
|
||||
array(
|
||||
'wu-confirm',
|
||||
'token',
|
||||
'PayerID',
|
||||
),
|
||||
$return_url
|
||||
);
|
||||
|
||||
if (is_admin()) {
|
||||
|
||||
$args = array('page' => 'account');
|
||||
|
||||
if ($this->order) {
|
||||
|
||||
$args['updated'] = $this->order->get_cart_type();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$return_url = add_query_arg($args, $return_url);
|
||||
|
||||
} else {
|
||||
|
||||
$return_url = add_query_arg(array(
|
||||
'payment' => $this->payment->get_hash(),
|
||||
'status' => 'done',
|
||||
), $return_url);
|
||||
|
||||
} // end if;
|
||||
$return_url = add_query_arg(
|
||||
array(
|
||||
'payment' => $this->payment->get_hash(),
|
||||
'status' => 'done',
|
||||
),
|
||||
$return_url
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow developers to change the gateway return URL used after checkout processes.
|
||||
@ -703,11 +678,10 @@ abstract class Base_Gateway {
|
||||
* @param self $gateway the gateway instance.
|
||||
* @param \WP_Ultimo\Models\Payment $payment the WP Multisite WaaS payment instance.
|
||||
* @param \WP_Ultimo\Checkout\Cart $cart the current WP Multisite WaaS cart order.
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
return apply_filters('wu_return_url', $return_url, $this, $this->payment, $this->order);
|
||||
|
||||
} // end get_return_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cancel URL.
|
||||
@ -718,16 +692,16 @@ abstract class Base_Gateway {
|
||||
public function get_cancel_url() {
|
||||
|
||||
if (empty($this->cancel_url)) {
|
||||
|
||||
$this->cancel_url = wu_get_current_url();
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return add_query_arg(array(
|
||||
'payment' => $this->payment->get_hash(),
|
||||
), $this->cancel_url);
|
||||
|
||||
} // end get_cancel_url;
|
||||
return add_query_arg(
|
||||
array(
|
||||
'payment' => $this->payment->get_hash(),
|
||||
),
|
||||
$this->cancel_url
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the confirm URL.
|
||||
@ -738,17 +712,17 @@ abstract class Base_Gateway {
|
||||
public function get_confirm_url() {
|
||||
|
||||
if (empty($this->confirm_url)) {
|
||||
|
||||
$this->confirm_url = wu_get_current_url();
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return add_query_arg(array(
|
||||
'payment' => $this->payment->get_hash(),
|
||||
'wu-confirm' => $this->get_id(),
|
||||
), $this->confirm_url);
|
||||
|
||||
} // end get_confirm_url;
|
||||
return add_query_arg(
|
||||
array(
|
||||
'payment' => $this->payment->get_hash(),
|
||||
'wu-confirm' => $this->get_id(),
|
||||
),
|
||||
$this->confirm_url
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the webhook url for the listener of this gateway events.
|
||||
@ -761,8 +735,7 @@ abstract class Base_Gateway {
|
||||
$site_url = defined('WU_GATEWAY_LISTENER_URL') ? WU_GATEWAY_LISTENER_URL : get_site_url(wu_get_main_site_id(), '/');
|
||||
|
||||
return add_query_arg('wu-gateway', $this->get_id(), $site_url);
|
||||
|
||||
} // end get_webhook_listener_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the payment.
|
||||
@ -774,8 +747,7 @@ abstract class Base_Gateway {
|
||||
public function set_payment($payment) {
|
||||
|
||||
$this->payment = $payment;
|
||||
|
||||
} // end set_payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the membership.
|
||||
@ -787,8 +759,7 @@ abstract class Base_Gateway {
|
||||
public function set_membership($membership) {
|
||||
|
||||
$this->membership = $membership;
|
||||
|
||||
} // end set_membership;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the customer.
|
||||
@ -800,8 +771,7 @@ abstract class Base_Gateway {
|
||||
public function set_customer($customer) {
|
||||
|
||||
$this->customer = $customer;
|
||||
|
||||
} // end set_customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the events related to processing a payment.
|
||||
@ -815,14 +785,11 @@ abstract class Base_Gateway {
|
||||
public function trigger_payment_processed($payment, $membership = null) {
|
||||
|
||||
if ($membership === null) {
|
||||
|
||||
$membership = $payment->get_membership();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
do_action('wu_gateway_payment_processed', $payment, $membership, $this);
|
||||
|
||||
} // end trigger_payment_processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a cart for a future swap.
|
||||
@ -839,8 +806,7 @@ abstract class Base_Gateway {
|
||||
set_site_transient($swap_id, $cart, DAY_IN_SECONDS);
|
||||
|
||||
return $swap_id;
|
||||
|
||||
} // end save_swap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a saved swap based on the id.
|
||||
@ -853,8 +819,7 @@ abstract class Base_Gateway {
|
||||
public function get_saved_swap($swap_id) {
|
||||
|
||||
return get_site_transient($swap_id);
|
||||
|
||||
} // end get_saved_swap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the compatibility ids for this gateway.
|
||||
@ -867,8 +832,7 @@ abstract class Base_Gateway {
|
||||
$all_ids = array_merge(array($this->get_id()), (array) $this->other_ids);
|
||||
|
||||
return array_unique($all_ids);
|
||||
|
||||
} // end get_all_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the backwards compatibility id of the gateway from v1.
|
||||
@ -879,7 +843,5 @@ abstract class Base_Gateway {
|
||||
public function get_backwards_compatibility_v1_id() {
|
||||
|
||||
return $this->backwards_compatibility_v1_id;
|
||||
|
||||
} // end get_backwards_compatibility_v1_id;
|
||||
|
||||
} // end class Base_Gateway;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -12,8 +12,8 @@
|
||||
namespace WP_Ultimo\Gateways;
|
||||
|
||||
use WP_Ultimo\Gateways\Base_Gateway;
|
||||
use \WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
use \WP_Ultimo\Database\Payments\Payment_Status;
|
||||
use WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
use WP_Ultimo\Database\Payments\Payment_Status;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
@ -79,7 +79,6 @@ class Free_Gateway extends Base_Gateway {
|
||||
$status = $membership->save();
|
||||
|
||||
return;
|
||||
|
||||
} elseif ($type === 'upgrade' || $type === 'downgrade' || $type === 'addon') {
|
||||
/*
|
||||
* A change to another free membership
|
||||
@ -89,16 +88,14 @@ class Free_Gateway extends Base_Gateway {
|
||||
$membership->swap($cart);
|
||||
|
||||
$membership->set_status(Membership_Status::ACTIVE);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$membership->save();
|
||||
|
||||
$payment->set_status(Payment_Status::COMPLETED);
|
||||
|
||||
$payment->save();
|
||||
|
||||
} // end process_checkout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a cancellation.
|
||||
@ -120,7 +117,7 @@ class Free_Gateway extends Base_Gateway {
|
||||
* @param \WP_Ultimo\Models\Customer $customer The customer checking out.
|
||||
* @return void
|
||||
*/
|
||||
public function process_cancellation($membership, $customer) {} // end process_cancellation;
|
||||
public function process_cancellation($membership, $customer) {}
|
||||
|
||||
/**
|
||||
* Process a refund.
|
||||
@ -144,6 +141,5 @@ class Free_Gateway extends Base_Gateway {
|
||||
* @param \WP_Ultimo\Models\Customer $customer The customer checking out.
|
||||
* @return void
|
||||
*/
|
||||
public function process_refund($amount, $payment, $membership, $customer) {} // end process_refund;
|
||||
|
||||
} // end class Free_Gateway;
|
||||
public function process_refund($amount, $payment, $membership, $customer) {}
|
||||
}
|
||||
|
@ -14,4 +14,4 @@ namespace WP_Ultimo\Gateways;
|
||||
*
|
||||
* @since 2.0.7
|
||||
*/
|
||||
class Ignorable_Exception extends \Exception {} // end class Ignorable_Exception;
|
||||
class Ignorable_Exception extends \Exception {}
|
||||
|
@ -15,9 +15,9 @@
|
||||
|
||||
namespace WP_Ultimo\Gateways;
|
||||
|
||||
use \WP_Ultimo\Gateways\Base_Gateway;
|
||||
use \WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
use \WP_Ultimo\Database\Payments\Payment_Status;
|
||||
use WP_Ultimo\Gateways\Base_Gateway;
|
||||
use WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
use WP_Ultimo\Database\Payments\Payment_Status;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
@ -48,8 +48,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* Adds payment instructions to the thank you page.
|
||||
*/
|
||||
add_action('wu_thank_you_before_info_blocks', array($this, 'add_payment_instructions_block'), 10, 3);
|
||||
|
||||
} // end hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares support to recurring payments.
|
||||
@ -63,8 +62,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
public function supports_recurring(): bool {
|
||||
|
||||
return false;
|
||||
|
||||
} // end supports_recurring;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares support to free trials
|
||||
@ -75,8 +73,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
public function supports_free_trials(): bool {
|
||||
|
||||
return false;
|
||||
|
||||
} // end supports_free_trials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Stripe Gateway settings to the settings screen.
|
||||
@ -86,28 +83,35 @@ class Manual_Gateway extends Base_Gateway {
|
||||
*/
|
||||
public function settings() {
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'manual_header', array(
|
||||
'title' => __('Manual', 'wp-ultimo'),
|
||||
'desc' => __('Use the settings section below to configure the manual payment method. This method allows your customers to manually pay for their memberships, but those payments require manual confirmation on your part.', 'wp-ultimo'),
|
||||
'type' => 'header',
|
||||
'show_as_submenu' => true,
|
||||
'require' => array(
|
||||
'active_gateways' => 'manual',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'manual_header',
|
||||
array(
|
||||
'title' => __('Manual', 'wp-ultimo'),
|
||||
'desc' => __('Use the settings section below to configure the manual payment method. This method allows your customers to manually pay for their memberships, but those payments require manual confirmation on your part.', 'wp-ultimo'),
|
||||
'type' => 'header',
|
||||
'show_as_submenu' => true,
|
||||
'require' => array(
|
||||
'active_gateways' => 'manual',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'manual_payment_instructions', array(
|
||||
'title' => __('Payment Instructions', 'wp-ultimo'),
|
||||
'desc' => __('This instructions will be shown to the customer on the thank you page, as well as be sent via email.', 'wp-ultimo'),
|
||||
'type' => 'wp_editor',
|
||||
'allow_html' => true,
|
||||
'default' => __('Payment instructions here.', 'wp-ultimo'),
|
||||
'require' => array(
|
||||
'active_gateways' => 'manual',
|
||||
),
|
||||
));
|
||||
|
||||
} // end settings;
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'manual_payment_instructions',
|
||||
array(
|
||||
'title' => __('Payment Instructions', 'wp-ultimo'),
|
||||
'desc' => __('This instructions will be shown to the customer on the thank you page, as well as be sent via email.', 'wp-ultimo'),
|
||||
'type' => 'wp_editor',
|
||||
'allow_html' => true,
|
||||
'default' => __('Payment instructions here.', 'wp-ultimo'),
|
||||
'require' => array(
|
||||
'active_gateways' => 'manual',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reflects membership changes on the gateway.
|
||||
@ -123,8 +127,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
public function process_membership_update(&$membership, $customer) {
|
||||
|
||||
return true;
|
||||
|
||||
} // end process_membership_update;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a message about what will happen to the gateway subscription
|
||||
@ -138,18 +141,13 @@ class Manual_Gateway extends Base_Gateway {
|
||||
public function get_amount_update_message($to_customer = false) {
|
||||
|
||||
if ($to_customer) {
|
||||
|
||||
$message = __('You will receive a updated invoice on the next billing cycle.', 'wp-ultimo');
|
||||
|
||||
} else {
|
||||
|
||||
$message = __('The customer will receive a updated invoice on the next billing cycle.', 'wp-ultimo');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $message;
|
||||
|
||||
} // end get_amount_update_message;
|
||||
}
|
||||
/**
|
||||
* Process a checkout.
|
||||
*
|
||||
@ -220,11 +218,9 @@ class Manual_Gateway extends Base_Gateway {
|
||||
if ($type === 'new') {
|
||||
|
||||
// Your logic here.
|
||||
|
||||
} elseif ($type === 'renewal') {
|
||||
|
||||
// Your logic here.
|
||||
|
||||
} elseif ($type === 'downgrade') {
|
||||
/*
|
||||
* When downgrading, we need to schedule a swap for the end of the
|
||||
@ -242,7 +238,6 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* Saves the membership with the changes.
|
||||
*/
|
||||
$status = $membership->save();
|
||||
|
||||
} elseif ($type === 'upgrade' || $type === 'addon') {
|
||||
/*
|
||||
* After everything is said and done,
|
||||
@ -271,8 +266,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* Saves the membership with the changes.
|
||||
*/
|
||||
$status = $membership->save();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* We want to check the status
|
||||
@ -288,19 +282,15 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* will be undone, including the swap above.
|
||||
*/
|
||||
if (is_wp_error($status)) {
|
||||
|
||||
throw new \Exception($status->get_error_message(), $status->get_error_code());
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// In case of trials with payment method
|
||||
if ($payment->get_total() === 0.00) {
|
||||
|
||||
$payment->set_status(Payment_Status::COMPLETED);
|
||||
|
||||
$payment->save();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* You don't need to return anything,
|
||||
@ -312,8 +302,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* extra redirects.
|
||||
*/
|
||||
return true;
|
||||
|
||||
} // end process_checkout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a cancellation.
|
||||
@ -327,7 +316,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* @param \WP_Ultimo\Models\Customer $customer The customer checking out.
|
||||
* @return void|bool
|
||||
*/
|
||||
public function process_cancellation($membership, $customer) {} // end process_cancellation;
|
||||
public function process_cancellation($membership, $customer) {}
|
||||
|
||||
/**
|
||||
* Process a checkout.
|
||||
@ -348,29 +337,25 @@ class Manual_Gateway extends Base_Gateway {
|
||||
$status = $payment->refund($amount);
|
||||
|
||||
if (is_wp_error($status)) {
|
||||
|
||||
throw new \Exception($status->get_error_code(), $status->get_error_message());
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_refund;
|
||||
/**
|
||||
* Adds additional fields to the checkout form for a particular gateway.
|
||||
*
|
||||
* In this method, you can either return an array of fields (that we will display
|
||||
* using our form display methods) or you can return plain HTML in a string,
|
||||
* which will get outputted to the gateway section of the checkout.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return mixed[]|string
|
||||
*/
|
||||
public function fields() {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds additional fields to the checkout form for a particular gateway.
|
||||
*
|
||||
* In this method, you can either return an array of fields (that we will display
|
||||
* using our form display methods) or you can return plain HTML in a string,
|
||||
* which will get outputted to the gateway section of the checkout.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return mixed[]|string
|
||||
*/
|
||||
public function fields() {
|
||||
|
||||
$message = __('After you finish signing up, we will send you an email with instructions to finalize the payment. Your account will be pending until the payment is finalized and confirmed.', 'wp-ultimo');
|
||||
|
||||
return sprintf('<p v-if="!order.has_trial" class="wu-p-4 wu-bg-yellow-200">%s</p>', $message);
|
||||
|
||||
} // end fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the payment instruction block.
|
||||
@ -385,10 +370,8 @@ class Manual_Gateway extends Base_Gateway {
|
||||
public function add_payment_instructions_block($payment, $membership, $customer) {
|
||||
|
||||
if ($payment->get_gateway() !== $this->id) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
// phpcs:disable
|
||||
|
||||
@ -427,7 +410,5 @@ class Manual_Gateway extends Base_Gateway {
|
||||
<?php endif;
|
||||
|
||||
// phpcs:enable
|
||||
|
||||
} // end add_payment_instructions_block;
|
||||
|
||||
} // end class Manual_Gateway;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -11,9 +11,9 @@
|
||||
|
||||
namespace WP_Ultimo\Gateways;
|
||||
|
||||
use \WP_Ultimo\Gateways\Base_Stripe_Gateway;
|
||||
use \Stripe;
|
||||
use \WP_Ultimo\Checkout\Cart;
|
||||
use WP_Ultimo\Gateways\Base_Stripe_Gateway;
|
||||
use Stripe;
|
||||
use WP_Ultimo\Checkout\Cart;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
@ -26,11 +26,11 @@ defined('ABSPATH') || exit;
|
||||
class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
/**
|
||||
* Holds the ID of a given gateway.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
* Holds the ID of a given gateway.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'stripe-checkout';
|
||||
|
||||
/**
|
||||
@ -43,121 +43,152 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
$error_message_wrap = '<span class="wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>';
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_header', array(
|
||||
'title' => __('Stripe Checkout', 'wp-ultimo'),
|
||||
'desc' => __('Use the settings section below to configure Stripe Checkout as a payment method.', 'wp-ultimo'),
|
||||
'type' => 'header',
|
||||
'show_as_submenu' => true,
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_header',
|
||||
array(
|
||||
'title' => __('Stripe Checkout', 'wp-ultimo'),
|
||||
'desc' => __('Use the settings section below to configure Stripe Checkout as a payment method.', 'wp-ultimo'),
|
||||
'type' => 'header',
|
||||
'show_as_submenu' => true,
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_public_title', array(
|
||||
'title' => __('Stripe Public Name', 'wp-ultimo'),
|
||||
'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => __('Credit Card', 'wp-ultimo'),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_public_title',
|
||||
array(
|
||||
'title' => __('Stripe Public Name', 'wp-ultimo'),
|
||||
'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => __('Credit Card', 'wp-ultimo'),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_sandbox_mode', array(
|
||||
'title' => __('Stripe Checkout Sandbox Mode', 'wp-ultimo'),
|
||||
'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'default' => 1,
|
||||
'html_attr' => array(
|
||||
'v-model' => 'stripe_checkout_sandbox_mode',
|
||||
),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_sandbox_mode',
|
||||
array(
|
||||
'title' => __('Stripe Checkout Sandbox Mode', 'wp-ultimo'),
|
||||
'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'default' => 1,
|
||||
'html_attr' => array(
|
||||
'v-model' => 'stripe_checkout_sandbox_mode',
|
||||
),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$pk_test_status = wu_get_setting('stripe_checkout_test_pk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_test_pk_key', array(
|
||||
'title' => __('Stripe Test Publishable Key', 'wp-ultimo'),
|
||||
'desc' => !empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 1,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_test_pk_key',
|
||||
array(
|
||||
'title' => __('Stripe Test Publishable Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 1,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sk_test_status = wu_get_setting('stripe_checkout_test_sk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_test_sk_key', array(
|
||||
'title' => __('Stripe Test Secret Key', 'wp-ultimo'),
|
||||
'desc' => !empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 1,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_test_sk_key',
|
||||
array(
|
||||
'title' => __('Stripe Test Secret Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 1,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$pk_status = wu_get_setting('stripe_checkout_live_pk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_live_pk_key', array(
|
||||
'title' => __('Stripe Live Publishable Key', 'wp-ultimo'),
|
||||
'desc' => !empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 0,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_live_pk_key',
|
||||
array(
|
||||
'title' => __('Stripe Live Publishable Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 0,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sk_status = wu_get_setting('stripe_checkout_live_sk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_live_sk_key', array(
|
||||
'title' => __('Stripe Live Secret Key', 'wp-ultimo'),
|
||||
'desc' => !empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 0,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_live_sk_key',
|
||||
array(
|
||||
'title' => __('Stripe Live Secret Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
'stripe_checkout_sandbox_mode' => 0,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$webhook_message = sprintf('<span class="wu-p-2 wu-bg-blue-100 wu-text-blue-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>', __('Whenever you change your Stripe settings, WP Multisite WaaS will automatically check the webhook URLs on your Stripe account to make sure we get notified about changes in subscriptions and payments.', 'wp-ultimo'));
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_checkout_webhook_listener_explanation', array(
|
||||
'title' => __('Webhook Listener URL', 'wp-ultimo'),
|
||||
'desc' => $webhook_message,
|
||||
'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'),
|
||||
'type' => 'text-display',
|
||||
'copy' => true,
|
||||
'default' => $this->get_webhook_listener_url(),
|
||||
'wrapper_classes' => '',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_checkout_webhook_listener_explanation',
|
||||
array(
|
||||
'title' => __('Webhook Listener URL', 'wp-ultimo'),
|
||||
'desc' => $webhook_message,
|
||||
'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'),
|
||||
'type' => 'text-display',
|
||||
'copy' => true,
|
||||
'default' => $this->get_webhook_listener_url(),
|
||||
'wrapper_classes' => '',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe-checkout',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
parent::settings();
|
||||
|
||||
} // end settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run preparations before checkout processing.
|
||||
@ -211,9 +242,13 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
* For those to work, you'll need to activate them on your
|
||||
* Stripe account, and you should also be in live mode.
|
||||
*/
|
||||
$allowed_payment_method_types = apply_filters('wu_stripe_checkout_allowed_payment_method_types', array(
|
||||
'card',
|
||||
), $this);
|
||||
$allowed_payment_method_types = apply_filters(
|
||||
'wu_stripe_checkout_allowed_payment_method_types',
|
||||
array(
|
||||
'card',
|
||||
),
|
||||
$this
|
||||
);
|
||||
|
||||
$metadata = array(
|
||||
'payment_id' => $this->payment->get_id(),
|
||||
@ -230,9 +265,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
* Verify the card type
|
||||
*/
|
||||
if ($this->order->get_cart_type() === 'new') {
|
||||
|
||||
$redirect_url = $this->get_return_url();
|
||||
|
||||
} else {
|
||||
/*
|
||||
* Saves cart for later swap.
|
||||
@ -242,8 +275,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
$redirect_url = add_query_arg('swap', $swap_id, $this->get_confirm_url());
|
||||
|
||||
$metadata['swap_id'] = $swap_id;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$subscription_data = array(
|
||||
'payment_method_types' => $allowed_payment_method_types,
|
||||
@ -256,7 +288,6 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
);
|
||||
|
||||
if ($this->order->should_auto_renew()) {
|
||||
|
||||
$stripe_cart = $this->build_stripe_cart($this->order);
|
||||
$stripe_non_recurring_cart = $this->build_non_recurring_cart($this->order);
|
||||
|
||||
@ -266,14 +297,12 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
$subscription_data['subscription_data'] = array(
|
||||
'items' => array_values($stripe_cart),
|
||||
);
|
||||
|
||||
} else {
|
||||
/*
|
||||
* Create non-recurring only cart.
|
||||
*/
|
||||
$stripe_non_recurring_cart = $this->build_non_recurring_cart($this->order, true);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add non-recurring line items
|
||||
@ -287,12 +316,10 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
$s_coupon = $this->get_credit_coupon($this->order);
|
||||
|
||||
if ($s_coupon) {
|
||||
|
||||
$subscription_data['discounts'] = array(
|
||||
array('coupon' => $s_coupon),
|
||||
);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/**
|
||||
* If its a downgrade, we need to set as a trial,
|
||||
@ -300,7 +327,6 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
* (https://stripe.com/docs/api/checkout/sessions/create)
|
||||
*/
|
||||
if ($this->order->get_cart_type() === 'downgrade') {
|
||||
|
||||
$next_charge = $this->order->get_billing_next_charge_date();
|
||||
$next_charge_date = \DateTime::createFromFormat('U', $next_charge);
|
||||
$current_time = new \DateTime();
|
||||
@ -311,19 +337,15 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
$next_charge = $next_charge_date->diff($current_time)->days > 2 ? $next_charge : strtotime('+2 days');
|
||||
|
||||
$subscription_data['subscription_data']['trial_end'] = $next_charge;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle trial periods.
|
||||
*/
|
||||
if ($this->order->has_trial() && $this->order->has_recurring()) {
|
||||
|
||||
$subscription_data['subscription_data']['trial_end'] = $this->order->get_billing_start_date();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$session = Stripe\Checkout\Session::create($subscription_data);
|
||||
|
||||
@ -331,8 +353,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
return array(
|
||||
'stripe_session_id' => sanitize_text_field($session->id),
|
||||
);
|
||||
|
||||
} // end run_preflight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles confirmation windows and extra processing.
|
||||
@ -353,16 +374,11 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
$membership = $this->payment ? $this->payment->get_membership() : wu_get_membership_by_hash(wu_request('membership'));
|
||||
|
||||
if ($saved_swap && $membership) {
|
||||
|
||||
if ($saved_swap->get_cart_type() === 'downgrade') {
|
||||
|
||||
$membership->schedule_swap($saved_swap);
|
||||
|
||||
} else {
|
||||
|
||||
$membership->swap($saved_swap);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$membership->save();
|
||||
|
||||
@ -371,10 +387,8 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
wp_redirect($redirect_url);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_confirmation;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add credit card fields.
|
||||
*
|
||||
@ -385,8 +399,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
$message = __('You will be redirected to a checkout to complete the purchase.', 'wp-ultimo');
|
||||
|
||||
return sprintf('<p class="wu-p-4 wu-bg-yellow-200">%s</p>', $message);
|
||||
|
||||
} // end fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment methods.
|
||||
@ -401,24 +414,19 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
$card_options = $this->get_saved_card_options();
|
||||
|
||||
if ($card_options) {
|
||||
|
||||
foreach ($card_options as $payment_method => $card) {
|
||||
|
||||
$fields = array(
|
||||
"payment_method_{$payment_method}" => array(
|
||||
'type' => 'text-display',
|
||||
'title' => __('Saved Cards', 'wp-ultimo'),
|
||||
'display_value' => $card,
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
|
||||
} // end payment_methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the saved Stripe payment methods for a given user ID.
|
||||
@ -433,11 +441,9 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
$customer = wu_get_current_customer();
|
||||
|
||||
if (!$customer) {
|
||||
|
||||
if ( ! $customer) {
|
||||
return array();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$customer_id = $customer->get_id();
|
||||
|
||||
@ -447,19 +453,19 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
*/
|
||||
static $existing_payment_methods;
|
||||
|
||||
if (!is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) {
|
||||
|
||||
return $existing_payment_methods[$customer_id];
|
||||
|
||||
} // end if;
|
||||
if ( ! is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) {
|
||||
return $existing_payment_methods[ $customer_id ];
|
||||
}
|
||||
|
||||
$customer_payment_methods = array();
|
||||
|
||||
$stripe_customer_id = \WP_Ultimo\Models\Membership::query(array(
|
||||
'customer_id' => $customer_id,
|
||||
'search' => 'cus_*',
|
||||
'fields' => array('gateway_customer_id'),
|
||||
));
|
||||
$stripe_customer_id = \WP_Ultimo\Models\Membership::query(
|
||||
array(
|
||||
'customer_id' => $customer_id,
|
||||
'search' => 'cus_*',
|
||||
'fields' => array('gateway_customer_id'),
|
||||
)
|
||||
);
|
||||
|
||||
$stripe_customer_id = current(array_column($stripe_customer_id, 'gateway_customer_id'));
|
||||
|
||||
@ -468,27 +474,22 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
*/
|
||||
$this->setup_api_keys();
|
||||
|
||||
$payment_methods = Stripe\PaymentMethod::all(array(
|
||||
'customer' => $stripe_customer_id,
|
||||
'type' => 'card'
|
||||
));
|
||||
$payment_methods = Stripe\PaymentMethod::all(
|
||||
array(
|
||||
'customer' => $stripe_customer_id,
|
||||
'type' => 'card',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($payment_methods->data as $payment_method) {
|
||||
$customer_payment_methods[ $payment_method->id ] = $payment_method;
|
||||
}
|
||||
|
||||
$customer_payment_methods[$payment_method->id] = $payment_method;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
$existing_payment_methods[$customer_id] = $customer_payment_methods;
|
||||
|
||||
return $existing_payment_methods[$customer_id];
|
||||
$existing_payment_methods[ $customer_id ] = $customer_payment_methods;
|
||||
|
||||
return $existing_payment_methods[ $customer_id ];
|
||||
} catch (\Throwable $exception) {
|
||||
|
||||
return array();
|
||||
|
||||
} // end try;
|
||||
|
||||
} // end get_user_saved_payment_methods;
|
||||
|
||||
} // end class Stripe_Checkout_Gateway;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@
|
||||
|
||||
namespace WP_Ultimo\Gateways;
|
||||
|
||||
use \WP_Ultimo\Database\Payments\Payment_Status;
|
||||
use \WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
use \WP_Ultimo\Gateways\Base_Stripe_Gateway;
|
||||
use \Stripe;
|
||||
use WP_Ultimo\Database\Payments\Payment_Status;
|
||||
use WP_Ultimo\Database\Memberships\Membership_Status;
|
||||
use WP_Ultimo\Gateways\Base_Stripe_Gateway;
|
||||
use Stripe;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
@ -27,11 +27,11 @@ defined('ABSPATH') || exit;
|
||||
class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
/**
|
||||
* Holds the ID of a given gateway.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
* Holds the ID of a given gateway.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @var string
|
||||
*/
|
||||
protected $id = 'stripe';
|
||||
|
||||
/**
|
||||
@ -44,17 +44,20 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
parent::hooks();
|
||||
|
||||
add_filter('wu_customer_payment_methods', function($fields, $customer): array {
|
||||
add_filter(
|
||||
'wu_customer_payment_methods',
|
||||
function ($fields, $customer): array {
|
||||
|
||||
$this->customer = $customer;
|
||||
$this->customer = $customer;
|
||||
|
||||
$extra_fields = $this->payment_methods();
|
||||
$extra_fields = $this->payment_methods();
|
||||
|
||||
return array_merge($fields, $extra_fields);
|
||||
|
||||
}, 10, 2);
|
||||
|
||||
} // end hooks;
|
||||
return array_merge($fields, $extra_fields);
|
||||
},
|
||||
10,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Stripe Gateway settings to the settings screen.
|
||||
@ -66,121 +69,152 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
$error_message_wrap = '<span class="wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>';
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_header', array(
|
||||
'title' => __('Stripe', 'wp-ultimo'),
|
||||
'desc' => __('Use the settings section below to configure Stripe as a payment method.', 'wp-ultimo'),
|
||||
'type' => 'header',
|
||||
'show_as_submenu' => true,
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_header',
|
||||
array(
|
||||
'title' => __('Stripe', 'wp-ultimo'),
|
||||
'desc' => __('Use the settings section below to configure Stripe as a payment method.', 'wp-ultimo'),
|
||||
'type' => 'header',
|
||||
'show_as_submenu' => true,
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_public_title', array(
|
||||
'title' => __('Stripe Public Name', 'wp-ultimo'),
|
||||
'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => __('Credit Card', 'wp-ultimo'),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_public_title',
|
||||
array(
|
||||
'title' => __('Stripe Public Name', 'wp-ultimo'),
|
||||
'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => __('Credit Card', 'wp-ultimo'),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_sandbox_mode', array(
|
||||
'title' => __('Stripe Sandbox Mode', 'wp-ultimo'),
|
||||
'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'default' => 1,
|
||||
'html_attr' => array(
|
||||
'v-model' => 'stripe_sandbox_mode',
|
||||
),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_sandbox_mode',
|
||||
array(
|
||||
'title' => __('Stripe Sandbox Mode', 'wp-ultimo'),
|
||||
'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'default' => 1,
|
||||
'html_attr' => array(
|
||||
'v-model' => 'stripe_sandbox_mode',
|
||||
),
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$pk_test_status = wu_get_setting('stripe_test_pk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_test_pk_key', array(
|
||||
'title' => __('Stripe Test Publishable Key', 'wp-ultimo'),
|
||||
'desc' => !empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 1,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_test_pk_key',
|
||||
array(
|
||||
'title' => __('Stripe Test Publishable Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 1,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sk_test_status = wu_get_setting('stripe_test_sk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_test_sk_key', array(
|
||||
'title' => __('Stripe Test Secret Key', 'wp-ultimo'),
|
||||
'desc' => !empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 1,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_test_sk_key',
|
||||
array(
|
||||
'title' => __('Stripe Test Secret Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_test_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 1,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$pk_status = wu_get_setting('stripe_live_pk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_live_pk_key', array(
|
||||
'title' => __('Stripe Live Publishable Key', 'wp-ultimo'),
|
||||
'desc' => !empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 0,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_live_pk_key',
|
||||
array(
|
||||
'title' => __('Stripe Live Publishable Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('pk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 0,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$sk_status = wu_get_setting('stripe_live_sk_key_status', '');
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_live_sk_key', array(
|
||||
'title' => __('Stripe Live Secret Key', 'wp-ultimo'),
|
||||
'desc' => !empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 0,
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_live_sk_key',
|
||||
array(
|
||||
'title' => __('Stripe Live Secret Key', 'wp-ultimo'),
|
||||
'desc' => ! empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '',
|
||||
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
|
||||
'placeholder' => __('sk_live_***********', 'wp-ultimo'),
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
'capability' => 'manage_api_keys',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
'stripe_sandbox_mode' => 0,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$webhook_message = sprintf('<span class="wu-p-2 wu-bg-blue-100 wu-text-blue-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>', __('Whenever you change your Stripe settings, WP Multisite WaaS will automatically check the webhook URLs on your Stripe account to make sure we get notified about changes in subscriptions and payments.', 'wp-ultimo'));
|
||||
|
||||
wu_register_settings_field('payment-gateways', 'stripe_webhook_listener_explanation', array(
|
||||
'title' => __('Webhook Listener URL', 'wp-ultimo'),
|
||||
'desc' => $webhook_message,
|
||||
'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'),
|
||||
'type' => 'text-display',
|
||||
'copy' => true,
|
||||
'default' => $this->get_webhook_listener_url(),
|
||||
'wrapper_classes' => '',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
));
|
||||
wu_register_settings_field(
|
||||
'payment-gateways',
|
||||
'stripe_webhook_listener_explanation',
|
||||
array(
|
||||
'title' => __('Webhook Listener URL', 'wp-ultimo'),
|
||||
'desc' => $webhook_message,
|
||||
'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'),
|
||||
'type' => 'text-display',
|
||||
'copy' => true,
|
||||
'default' => $this->get_webhook_listener_url(),
|
||||
'wrapper_classes' => '',
|
||||
'require' => array(
|
||||
'active_gateways' => 'stripe',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
parent::settings();
|
||||
|
||||
} // end settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run preparations before checkout processing.
|
||||
@ -224,8 +258,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
// translators: %s is the error message.
|
||||
return new \WP_Error($s_customer->get_error_code(), sprintf(__('Error creating Stripe customer: %s', 'wp-ultimo'), $s_customer->get_error_message()));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$this->membership->set_gateway_customer_id($s_customer->id);
|
||||
$this->membership->set_gateway($this->get_id());
|
||||
@ -239,14 +272,10 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
* a membership swap.
|
||||
*/
|
||||
if ($type === 'upgrade' || $type === 'addon') {
|
||||
|
||||
$this->membership->swap($this->order);
|
||||
|
||||
} elseif ($type === 'downgrade') {
|
||||
|
||||
$this->membership->schedule_swap($this->order);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$this->membership->save();
|
||||
|
||||
@ -260,10 +289,8 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
* Maybe use an existing payment method.
|
||||
*/
|
||||
if (wu_request('payment_method', 'add-new') !== 'add-new') {
|
||||
|
||||
$intent_args['payment_method'] = sanitize_text_field(wu_request('payment_method'));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Let's start with the intent options.
|
||||
@ -298,31 +325,26 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
* payment attached to the membership. Those start with a pi_
|
||||
* id.
|
||||
*/
|
||||
if (!empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'pi_', strlen('pi_')) === 0) {
|
||||
|
||||
if ( ! empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'pi_', strlen('pi_')) === 0) {
|
||||
$existing_intent = Stripe\PaymentIntent::retrieve($payment_intent_id);
|
||||
|
||||
/*
|
||||
* Setup intents are created with the intent
|
||||
* of future charging. This is what we use
|
||||
* when we set up a subscription without a
|
||||
* initial amount.
|
||||
*/
|
||||
} elseif (!empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) {
|
||||
|
||||
/*
|
||||
* Setup intents are created with the intent
|
||||
* of future charging. This is what we use
|
||||
* when we set up a subscription without a
|
||||
* initial amount.
|
||||
*/
|
||||
} elseif ( ! empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) {
|
||||
$existing_intent = Stripe\SetupIntent::retrieve($payment_intent_id);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* We can't use cancelled intents
|
||||
* for obvious reasons...
|
||||
*/
|
||||
if (!empty($existing_intent) && 'canceled' === $existing_intent->status) {
|
||||
|
||||
if ( ! empty($existing_intent) && 'canceled' === $existing_intent->status) {
|
||||
$existing_intent = false;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we have a initial payment,
|
||||
@ -331,14 +353,16 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
* If we have a trial, we need to deal with that via a setup intent.
|
||||
*/
|
||||
if ($this->order->get_total() && $this->order->has_trial() === false) {
|
||||
|
||||
$intent_args = wp_parse_args($intent_args, array(
|
||||
'amount' => $this->order->get_total() * wu_stripe_get_currency_multiplier(),
|
||||
'confirmation_method' => 'automatic',
|
||||
'setup_future_usage' => 'off_session',
|
||||
'currency' => strtolower((string) wu_get_setting('currency_symbol', 'USD')),
|
||||
'confirm' => false,
|
||||
));
|
||||
$intent_args = wp_parse_args(
|
||||
$intent_args,
|
||||
array(
|
||||
'amount' => $this->order->get_total() * wu_stripe_get_currency_multiplier(),
|
||||
'confirmation_method' => 'automatic',
|
||||
'setup_future_usage' => 'off_session',
|
||||
'currency' => strtolower((string) wu_get_setting('currency_symbol', 'USD')),
|
||||
'confirm' => false,
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the payment intent arguments.
|
||||
@ -351,8 +375,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
*/
|
||||
$intent_args = apply_filters('wu_stripe_create_payment_intent_args', $intent_args, $this);
|
||||
|
||||
if (!empty($existing_intent) && 'payment_intent' === $existing_intent->object) {
|
||||
|
||||
if ( ! empty($existing_intent) && 'payment_intent' === $existing_intent->object) {
|
||||
$idempotency_args = $intent_args;
|
||||
$idempotency_args['update'] = true;
|
||||
|
||||
@ -370,75 +393,56 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$unset_args = array('confirmation_method', 'confirm');
|
||||
|
||||
foreach ($unset_args as $unset_arg) {
|
||||
|
||||
if (isset($intent_args[$unset_arg])) {
|
||||
|
||||
unset($intent_args[$unset_arg]);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
if (isset($intent_args[ $unset_arg ])) {
|
||||
unset($intent_args[ $unset_arg ]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tries to update the payment intent.
|
||||
*/
|
||||
$intent = Stripe\PaymentIntent::update($existing_intent->id, $intent_args, $intent_options);
|
||||
|
||||
} else {
|
||||
|
||||
$intent_options['idempotency_key'] = wu_stripe_generate_idempotency_key($intent_args);
|
||||
|
||||
$intent = Stripe\PaymentIntent::create($intent_args, $intent_options);
|
||||
|
||||
} // end if;
|
||||
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Create a setup intent instead.
|
||||
*/
|
||||
$intent_args = wp_parse_args($intent_args, array(
|
||||
'usage' => 'off_session'
|
||||
));
|
||||
$intent_args = wp_parse_args(
|
||||
$intent_args,
|
||||
array(
|
||||
'usage' => 'off_session',
|
||||
)
|
||||
);
|
||||
|
||||
if (empty($existing_intent) || 'setup_intent' !== $existing_intent->object) {
|
||||
|
||||
$intent_options['idempotency_key'] = wu_stripe_generate_idempotency_key($intent_args);
|
||||
|
||||
/*
|
||||
* Tries to create in Stripe.
|
||||
*/
|
||||
$intent = Stripe\SetupIntent::create($intent_args, $intent_options);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
}
|
||||
}
|
||||
} catch (Stripe\Stripe\Error\Base $e) {
|
||||
|
||||
return $this->get_stripe_error($e);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$error_code = $e->getCode();
|
||||
|
||||
// WP Error did not handle empty error code
|
||||
if (empty($error_code)) {
|
||||
|
||||
if (method_exists($e, 'getHttpStatus')) {
|
||||
|
||||
$error_code = $e->getHttpStatus();
|
||||
|
||||
} else {
|
||||
|
||||
$error_code = 500;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return new \WP_Error($error_code, $e->getMessage());
|
||||
|
||||
} // end try;
|
||||
}
|
||||
|
||||
/*
|
||||
* To prevent re-doing all this
|
||||
@ -463,8 +467,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
'stripe_client_secret' => sanitize_text_field($intent->client_secret),
|
||||
'stripe_intent_type' => sanitize_text_field($intent->object),
|
||||
);
|
||||
|
||||
} // end run_preflight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a checkout.
|
||||
@ -506,10 +509,8 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$payment_intent_id = $payment->get_meta('stripe_payment_intent_id');
|
||||
|
||||
if (empty($payment_intent_id)) {
|
||||
|
||||
throw new \Exception(__('Missing Stripe payment intent, please try again or contact support if the issue persists.', 'wp-ultimo'), 'missing_stripe_payment_intent');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the correct api keys are set
|
||||
@ -529,16 +530,12 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
* type depending on the intent ID
|
||||
*/
|
||||
if (strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) {
|
||||
|
||||
$is_setup_intent = true;
|
||||
|
||||
$payment_intent = Stripe\SetupIntent::retrieve($payment_intent_id);
|
||||
|
||||
} else {
|
||||
|
||||
$payment_intent = Stripe\PaymentIntent::retrieve($payment_intent_id);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves the Stripe Customer
|
||||
@ -550,25 +547,26 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$description = sprintf(__('Customer ID: %1$d - User Email: %2$s', 'wp-ultimo'), $customer->get_id(), $customer->get_email_address());
|
||||
|
||||
if (strlen($description) > 350) {
|
||||
|
||||
$description = substr($description, 0, 350);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates the customer on Stripe
|
||||
* to make sure it always has the most
|
||||
* up-to-date info.
|
||||
*/
|
||||
Stripe\Customer::update($s_customer->id, array(
|
||||
'address' => $this->convert_to_stripe_address($customer->get_billing_address()),
|
||||
'description' => sanitize_text_field($description),
|
||||
'metadata' => array(
|
||||
'email' => $customer->get_email_address(),
|
||||
'user_id' => $customer->get_user_id(),
|
||||
'customer_id' => $customer->get_id(),
|
||||
),
|
||||
));
|
||||
Stripe\Customer::update(
|
||||
$s_customer->id,
|
||||
array(
|
||||
'address' => $this->convert_to_stripe_address($customer->get_billing_address()),
|
||||
'description' => sanitize_text_field($description),
|
||||
'metadata' => array(
|
||||
'email' => $customer->get_email_address(),
|
||||
'user_id' => $customer->get_user_id(),
|
||||
'customer_id' => $customer->get_id(),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/*
|
||||
* Persist payment methods.
|
||||
@ -580,26 +578,22 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
*/
|
||||
$payment_method = $this->save_payment_method($payment_intent, $s_customer);
|
||||
|
||||
$payment_completed = $is_setup_intent || (!empty($payment_intent->charges->data[0]['id']) && 'succeeded' === $payment_intent->charges->data[0]['status']);
|
||||
$payment_completed = $is_setup_intent || (! empty($payment_intent->charges->data[0]['id']) && 'succeeded' === $payment_intent->charges->data[0]['status']);
|
||||
|
||||
$subscription = false;
|
||||
|
||||
if ($payment_completed && $should_auto_renew && $is_recurring) {
|
||||
|
||||
$subscription = $this->create_recurring_payment($membership, $cart, $payment_method, $s_customer);
|
||||
|
||||
if (!$subscription) {
|
||||
if ( ! $subscription) {
|
||||
/**
|
||||
* Another process is already taking care of this (webhook).
|
||||
*/
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
if ($payment_completed) {
|
||||
|
||||
$payment_id = $is_setup_intent ? $payment_intent->id : sanitize_text_field($payment_intent->charges->data[0]['id']);
|
||||
|
||||
$payment->set_status(Payment_Status::COMPLETED);
|
||||
@ -608,11 +602,9 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$payment->save();
|
||||
|
||||
$this->trigger_payment_processed($payment, $membership);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if ($subscription) {
|
||||
|
||||
$membership->set_gateway($this->get_id());
|
||||
$membership->set_gateway_customer_id($s_customer->id);
|
||||
$membership->set_gateway_subscription_id($subscription->id);
|
||||
@ -620,7 +612,6 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$membership->should_auto_renew(true);
|
||||
|
||||
if ($type !== 'downgrade') {
|
||||
|
||||
$membership_status = $cart->has_trial() ? Membership_Status::TRIALING : Membership_Status::ACTIVE;
|
||||
|
||||
$renewal_date = new \DateTime();
|
||||
@ -630,24 +621,17 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$stripe_estimated_charge_timestamp = $subscription->current_period_end + (2 * HOUR_IN_SECONDS);
|
||||
|
||||
if ($stripe_estimated_charge_timestamp > $renewal_date->getTimestamp()) {
|
||||
|
||||
$renewal_date->setTimestamp($stripe_estimated_charge_timestamp);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$expiration = $renewal_date->format('Y-m-d H:i:s');
|
||||
|
||||
$membership->renew(true, $membership_status, $expiration);
|
||||
|
||||
} else {
|
||||
|
||||
$membership->save();
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end process_checkout;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add credit card fields.
|
||||
@ -662,7 +646,6 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$card_options = $this->get_saved_card_options();
|
||||
|
||||
if ($card_options) {
|
||||
|
||||
$card_options['add-new'] = __('Add new card', 'wp-ultimo');
|
||||
|
||||
$fields = array(
|
||||
@ -674,19 +657,22 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
'html_attr' => array(
|
||||
'v-model' => 'payment_method',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} // end if;
|
||||
|
||||
$stripe_form = new \WP_Ultimo\UI\Form('billing-address-fields', $fields, array(
|
||||
'views' => 'checkout/fields',
|
||||
'variables' => array(
|
||||
'step' => (object) array(
|
||||
'classes' => '',
|
||||
),
|
||||
),
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
$stripe_form = new \WP_Ultimo\UI\Form(
|
||||
'billing-address-fields',
|
||||
$fields,
|
||||
array(
|
||||
'views' => 'checkout/fields',
|
||||
'variables' => array(
|
||||
'step' => (object) array(
|
||||
'classes' => '',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
ob_start();
|
||||
|
||||
@ -716,8 +702,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
// phpcs:enable
|
||||
|
||||
return ob_get_clean();
|
||||
|
||||
} // end fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the payment methods.
|
||||
@ -732,24 +717,19 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$card_options = $this->get_saved_card_options();
|
||||
|
||||
if ($card_options) {
|
||||
|
||||
foreach ($card_options as $payment_method => $card) {
|
||||
|
||||
$fields = array(
|
||||
"payment_method_{$payment_method}" => array(
|
||||
'type' => 'text-display',
|
||||
'title' => __('Saved Cards', 'wp-ultimo'),
|
||||
'display_value' => $card,
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
|
||||
} // end payment_methods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the saved Stripe payment methods for a given user ID.
|
||||
@ -764,11 +744,9 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
|
||||
$customer = wu_get_current_customer();
|
||||
|
||||
if (!$customer) {
|
||||
|
||||
if ( ! $customer) {
|
||||
return array();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$customer_id = $customer->get_id();
|
||||
|
||||
@ -778,19 +756,19 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
*/
|
||||
static $existing_payment_methods;
|
||||
|
||||
if (!is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) {
|
||||
|
||||
return $existing_payment_methods[$customer_id];
|
||||
|
||||
} // end if;
|
||||
if ( ! is_null($existing_payment_methods) && array_key_exists($customer_id, $existing_payment_methods)) {
|
||||
return $existing_payment_methods[ $customer_id ];
|
||||
}
|
||||
|
||||
$customer_payment_methods = array();
|
||||
|
||||
$stripe_customer_id = \WP_Ultimo\Models\Membership::query(array(
|
||||
'customer_id' => $customer_id,
|
||||
'search' => 'cus_*',
|
||||
'fields' => array('gateway_customer_id'),
|
||||
));
|
||||
$stripe_customer_id = \WP_Ultimo\Models\Membership::query(
|
||||
array(
|
||||
'customer_id' => $customer_id,
|
||||
'search' => 'cus_*',
|
||||
'fields' => array('gateway_customer_id'),
|
||||
)
|
||||
);
|
||||
|
||||
$stripe_customer_id = current(array_column($stripe_customer_id, 'gateway_customer_id'));
|
||||
|
||||
@ -799,27 +777,22 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
*/
|
||||
$this->setup_api_keys();
|
||||
|
||||
$payment_methods = Stripe\PaymentMethod::all(array(
|
||||
'customer' => $stripe_customer_id,
|
||||
'type' => 'card'
|
||||
));
|
||||
$payment_methods = Stripe\PaymentMethod::all(
|
||||
array(
|
||||
'customer' => $stripe_customer_id,
|
||||
'type' => 'card',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($payment_methods->data as $payment_method) {
|
||||
$customer_payment_methods[ $payment_method->id ] = $payment_method;
|
||||
}
|
||||
|
||||
$customer_payment_methods[$payment_method->id] = $payment_method;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
$existing_payment_methods[$customer_id] = $customer_payment_methods;
|
||||
|
||||
return $existing_payment_methods[$customer_id];
|
||||
$existing_payment_methods[ $customer_id ] = $customer_payment_methods;
|
||||
|
||||
return $existing_payment_methods[ $customer_id ];
|
||||
} catch (\Throwable $exception) {
|
||||
|
||||
return array();
|
||||
|
||||
} // end try;
|
||||
|
||||
} // end get_user_saved_payment_methods;
|
||||
|
||||
} // end class Stripe_Gateway;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user