Advertisement
verygoodplugins

Untitled

Oct 22nd, 2021
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.29 KB | None | 0 0
  1.  
  2.                 // Create the MemberPress transaction
  3.                 $txn             = new MeprTransaction();
  4.                 $txn->user_id    = $user_id;
  5.                 $txn->product_id = $product_id;
  6.                 $txn->txn_type   = 'subscription_confirmation';
  7.                 $txn->gateway    = 'manual';
  8.                 $txn->created_at = current_time( 'mysql' );
  9.  
  10.                 $product = new MeprProduct( $txn->product_id );
  11.  
  12.                 // Can't use $txn->create_free_transaction( $txn ); since it forces a redirect, so copied the code from MeprTransaction
  13.                 if ( $product->period_type != 'lifetime' ) { // A free recurring subscription? Nope - let's make it lifetime for free here folks
  14.  
  15.                     $expires_at = MeprUtils::db_lifetime();
  16.  
  17.                 } else {
  18.                     $product_expiration = $product->get_expires_at( strtotime( $txn->created_at ) );
  19.  
  20.                     if ( is_null( $product_expiration ) ) {
  21.                         $expires_at = MeprUtils::db_lifetime();
  22.                     } else {
  23.                         $expires_at = MeprUtils::ts_to_mysql_date( $product_expiration, 'Y-m-d 23:59:59' );
  24.                     }
  25.                 }
  26.  
  27.                 $txn->trans_num  = MeprTransaction::generate_trans_num();
  28.                 $txn->status     = 'pending';
  29.                 $txn->txn_type   = 'payment';
  30.                 $txn->gateway    = 'free';
  31.                 $txn->expires_at = $expires_at;
  32.  
  33.                 // This will only work before maybe_cancel_old_sub is run
  34.                 $upgrade   = $txn->is_upgrade();
  35.                 $downgrade = $txn->is_downgrade();
  36.  
  37.                 $event_txn   = $txn->maybe_cancel_old_sub();
  38.                 $txn->status = 'complete';
  39.                 $txn->store();
  40.  
  41.                 $free_gateway = new MeprBaseStaticGateway( 'free', __( 'Free', 'memberpress' ), __( 'Free', 'memberpress' ) );
  42.  
  43.                 if ( $upgrade ) {
  44.  
  45.                     $free_gateway->upgraded_sub( $txn, $event_txn );
  46.  
  47.                 } elseif ( $downgrade ) {
  48.  
  49.                     $free_gateway->downgraded_sub( $txn, $event_txn );
  50.  
  51.                 }
  52.  
  53.                 MeprUtils::send_signup_notices( $txn );
  54.                 MeprEvent::record( 'transaction-completed', $txn ); // Delete this if we use $free_gateway->send_transaction_receipt_notices later
  55.                 MeprEvent::record( 'non-recurring-transaction-completed', $txn ); // Delete this if we use $free_gateway->send_transaction_receipt_notices later
  56.  
  57.                 remove_action( 'mepr-signup', array( $this, 'apply_tags_checkout' ) );
  58.  
  59.                 MeprHooks::do_action( 'mepr-signup', $txn ); // This lets the Corportate Accounts addon know there's been a new signup
  60.  
  61.                 add_action( 'mepr-signup', array( $this, 'apply_tags_checkout' ) );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement