Skip to content

Commit

Permalink
Merge pull request #2987 from MaximilianoRicoTabo/bugfix/edit-custome…
Browse files Browse the repository at this point in the history
…r-in-stripe-button

Edit customer in Stripe button is present in Edit Member page despite…
  • Loading branch information
kimcoleman authored Jun 27, 2024
2 parents 8020fbf + a95a580 commit 230e18f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ class PMPro_Member_Edit_Panel_Subscriptions extends PMPro_Member_Edit_Panel {
public function __construct() {
$this->slug = 'subscriptions';
$this->title = __( 'Subscriptions', 'paid-memberships-pro' );

// Get the user's Stripe Customer if they have one.
$user = self::get_user();
$stripe = new PMProGateway_Stripe();
$customer = $stripe->get_customer_for_user( $user->ID );

// Link to the Stripe Customer if they have one.
// TODO: Eventually make this a hook or filter so other gateways can add their own links.
if ( ! empty( $customer ) ) {
$this->title_link = '<a target="_blank" class="page-title-action pmpro-has-icon pmpro-has-icon-admin-users" href="' . esc_url( 'https://dashboard.stripe.com/' . ( get_option( 'pmpro_gateway_environment' ) == 'sandbox' ? 'test/' : '' ) . 'customers/' . $customer->id ) . '">' . esc_html__( 'Edit customer in Stripe', 'paid-memberships-pro' ) . '</a>';
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public function __construct() {
$this->title_link = empty( $user->ID ) ? '' : '<a href="' . esc_url( add_query_arg( array( 'user_id' => intval( $user->ID ) ), admin_url( 'user-edit.php' ) ) ) . '" target="_blank" class="page-title-action pmpro-has-icon pmpro-has-icon-admin-users">' . esc_html__( 'Edit User', 'paid-memberships-pro' ) . '</a>';
$this->submit_text = empty( $user->ID ) ? __( 'Create User ') : __( 'Update User Info', 'paid-memberships-pro' );

// If this user has an associated Stripe Customer, add a link to edit that Stripe Customer as well.
$stripe = new PMProGateway_Stripe();
$customer = $stripe->get_customer_for_user( $user->ID );
if ( ! empty( $customer ) ) {
$this->title_link .= '<a target="_blank" class="page-title-action pmpro-has-icon pmpro-has-icon-admin-users" href="' . esc_url( 'https://dashboard.stripe.com/' . ( get_option( 'pmpro_gateway_environment' ) == 'sandbox' ? 'test/' : '' ) . 'customers/' . $customer->id ) . '">' . esc_html__( 'Edit Customer in Stripe', 'paid-memberships-pro' ) . '</a>';
}

// Show user updated or user created message if necessary.
if ( isset( $_REQUEST['user_id'] ) && ! empty( $_REQUEST['user_id'] && ! empty( $_REQUEST['user_info_action'] ) ) ) {
if ( 'updated' === $_REQUEST['user_info_action'] ) {
Expand Down
18 changes: 18 additions & 0 deletions adminpages/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ class="page-title-action pmpro-has-icon pmpro-has-icon-no"
<?php esc_html_e( 'Cancel Subscription', 'paid-memberships-pro' ); ?>
</a>

<?php
// If this is a Stripe subscription and we have a customer for the user, show a link to edit the customer in Stripe.
if ( 'stripe' === $subscription->get_gateway() ) {
$stripe = new PMProGateway_Stripe();
$customer = $stripe->get_customer_for_user( $sub_user->ID );
if ( ! empty( $customer ) ) {
?>
<a
target="_blank"
class="page-title-action pmpro-has-icon pmpro-has-icon-admin-users"
href="<?php echo esc_url( 'https://dashboard.stripe.com/' . ( get_option( 'pmpro_gateway_environment' ) == 'sandbox' ? 'test/' : '' ) . 'customers/' . $customer->id ) ?>">
<?php esc_html_e( 'Edit Customer in Stripe', 'paid-memberships-pro' ); ?>
</a>
<?php
}
}
?>

<?php
if ( $pmpro_msg ) {
?>
Expand Down

0 comments on commit 230e18f

Please sign in to comment.