Skip to content

Commit

Permalink
Updates to 1.11.23
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Jan 16, 2024
1 parent bb96190 commit e7459ca
Show file tree
Hide file tree
Showing 33 changed files with 1,079 additions and 638 deletions.
36 changes: 0 additions & 36 deletions app/controllers/MeprAddonsCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,6 @@ public function curr_plugin_info($main_file) {
return '';
}

public static function analytics() {
$plugin = array(
'active' => function_exists('MonsterInsights'),
'installed' => is_dir(WP_PLUGIN_DIR . '/google-analytics-for-wordpress'),
'url' => 'https://downloads.wordpress.org/plugin/google-analytics-for-wordpress.latest-stable.zip',
'slug' => 'google-analytics-for-wordpress/googleanalytics.php',
'activate_button_text' => __('Activate MonsterInsights', 'memberpress'),
'next_step_button_html' => sprintf(
'<a href="%s" class="button button-primary button-hero">%s</a>',
esc_url(admin_url('admin.php?page=monsterinsights-onboarding')),
esc_html__('Run Setup Wizard', 'memberpress')
)
);

$step = $plugin['active'] ? (function_exists('monsterinsights_get_ua') && monsterinsights_get_ua() ? 3 : 2) : 1;

MeprView::render('/admin/addons/analytics', get_defined_vars());
}

public function monsterinsights_shareasale_id($id) {
if(get_option('memberpress_installed_monsterinsights')) {
$id = '409876';
Expand All @@ -283,23 +264,6 @@ public function monsterinsights_shareasale_id($id) {
return $id;
}

public static function smtp() {
$plugin = array(
'active' => function_exists('wp_mail_smtp'),
'installed' => is_dir(WP_PLUGIN_DIR . '/wp-mail-smtp'),
'url' => 'https://downloads.wordpress.org/plugin/wp-mail-smtp.latest-stable.zip',
'slug' => 'wp-mail-smtp/wp_mail_smtp.php',
'activate_button_text' => __('Activate WP Mail SMTP', 'memberpress'),
'next_step_button_html' => sprintf(
'<a href="%s" class="button button-primary button-hero">%s</a>',
esc_url(admin_url('admin.php?page=wp-mail-smtp')),
esc_html__('Start Setup', 'memberpress')
)
);

MeprView::render('/admin/addons/smtp', get_defined_vars());
}

public function smtp_affiliate_link($link) {
if(get_option('memberpress_installed_wp_mail_smtp')) {
$link = 'https://shareasale.com/r.cfm?b=834775&u=409876&m=64312&urllink=wpmailsmtp%2Ecom%2Flite%2Dupgrade%2F&afftrack=MP%2DAnalytics%2DMenu%2DItem';
Expand Down
18 changes: 0 additions & 18 deletions app/controllers/MeprAppCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -1169,24 +1169,6 @@ public static function mepr_menu(){
add_submenu_page('memberpress', __('MemberPress Courses', 'memberpress'), $menu_title, $capability, 'memberpress-courses', 'MeprCoursesCtrl::route');
}

if(!get_option('mepr_disable_smtp_menu_item')) {
if(function_exists('wp_mail_smtp')) {
$submenu['memberpress'][998] = array(__('SMTP', 'memberpress'), $capability, admin_url('admin.php?page=wp-mail-smtp'));
}
else {
add_submenu_page('memberpress', __('SMTP', 'memberpress'), __('SMTP', 'memberpress'), $capability, 'memberpress-smtp', 'MeprAddonsCtrl::smtp');
}
}

if(!get_option('mepr_disable_analytics_menu_item')) {
if(class_exists('MonsterInsights_eCommerce')) {
$submenu['memberpress'][999] = array(__('Analytics', 'memberpress'), $capability, admin_url('admin.php?page=monsterinsights_reports#/ecommerce'));
}
else {
add_submenu_page('memberpress', __('Analytics', 'memberpress'), __('Analytics', 'memberpress'), $capability, 'memberpress-analytics', 'MeprAddonsCtrl::analytics');
}
}

add_submenu_page('', __('Support', 'memberpress'), __('Support', 'memberpress'), $capability, 'memberpress-support', 'MeprAppCtrl::render_admin_support');

MeprHooks::do_action('mepr_menu');
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/MeprGrowthToolsCtrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php if ( ! defined('ABSPATH')) {
die('You are not allowed to call this page directly.');
}

class MeprGrowthToolsCtrl extends MeprBaseCtrl
{
public function load_hooks()
{
if (class_exists('\MemberPress\Caseproof\GrowthTools\App')) {
add_action('admin_enqueue_scripts', function () {
$screen = get_current_screen();
if ($screen->id == 'memberpress_page_memberpress-growth-tools') {
wp_enqueue_style('memberpress-onboarding', MEPR_CSS_URL . '/admin-onboarding.css', [], MEPR_VERSION);
}
});
$config = new \MemberPress\Caseproof\GrowthTools\Config([
'parentMenuSlug' => 'memberpress',
'instanceId' => 'memberpress',
'menuSlug' => 'memberpress-growth-tools',
'buttonCSSClasses' => ['mepr-wizard-button-blue'],
]);
new \MemberPress\Caseproof\GrowthTools\App($config);
}
}
}
2 changes: 1 addition & 1 deletion app/controllers/MeprReadyLaunchCtrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public static function template_enabled( $template ) {
if ( 'checkout' === $template ) {
return isset( $options->$attribute_name ) &&
filter_var( $options->$attribute_name, FILTER_VALIDATE_BOOLEAN ) &&
( isset( $post ) && is_a( $post, 'WP_Post' ) && $post->post_type == MeprProduct::$cpt );
( isset( $post ) && is_a( $post, 'WP_Post' ) && is_singular( MeprProduct::$cpt ) );
}

if ( 'courses' === $template && is_array($courses_options) ) {
Expand Down
2 changes: 1 addition & 1 deletion app/data/taxes/vat_countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'CZ' => array( 'name' => __('Czech Republic', 'memberpress'), 'rate' => 21, 'reduced_rate' => 10, 'fmt' => '(CZ)?[0-9]{8,10}' ),
'DE' => array( 'name' => __('Germany', 'memberpress'), 'rate' => 19, 'reduced_rate' => 7, 'fmt' => '(DE)?[0-9]{9}' ),
'DK' => array( 'name' => __('Denmark', 'memberpress'), 'rate' => 25, 'reduced_rate' => 0, 'fmt' => '(DK)?[0-9]{8}' ),
'EE' => array( 'name' => __('Estonia', 'memberpress'), 'rate' => 20, 'reduced_rate' => 9, 'fmt' => '(EE)?[0-9]{9}' ),
'EE' => array( 'name' => __('Estonia', 'memberpress'), 'rate' => 22, 'reduced_rate' => 9, 'fmt' => '(EE)?[0-9]{9}' ),
'GR' => array( 'name' => __('Greece', 'memberpress'), 'rate' => 24, 'reduced_rate' => 6, 'fmt' => '(EL|GR)?[0-9]{9}' ),
'ES' => array( 'name' => __('Spain', 'memberpress'), 'rate' => 21, 'reduced_rate' => 4, 'fmt' => '(ES)?[0-9A-Z][0-9]{7}[0-9A-Z]' ),
'FI' => array( 'name' => __('Finland', 'memberpress'), 'rate' => 24, 'reduced_rate' => 10, 'fmt' => '(FI)?[0-9]{8}' ),
Expand Down
27 changes: 25 additions & 2 deletions app/gateways/MeprAuthorizeProfileGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@
class MeprAuthorizeProfileGateway extends MeprBaseRealGateway {
public static $order_invoice_str = '_mepr_authnet_order_invoice';

public $key;

/** @var MeprArtificialAuthorizeNetProfileHttpClient */
protected $client = null;

/**
* Mainly used in order bumps , so we only do 1$ validating transaction on the first bump
* In the following up bumps we know this card is good or not already so we don't need validation
*
* @var boolean
*/
protected $payment_validated;

/** Used in the view to identify the gateway */
public function __construct() {
$this->name = __( "Authorize.net Profile", 'memberpress' );
Expand Down Expand Up @@ -301,7 +311,7 @@ public function process_single_order($txn, $dataValue, $dataDescriptor) {

if ( $is_new_user || empty($dataDescriptor) || empty($dataValue) ) {
// wait some time for the customer to occupy on authorizenet server
sleep( 9 );
sleep( 14 );
}

if ( $txn->is_one_time_payment() ) {
Expand Down Expand Up @@ -339,7 +349,20 @@ public function process_single_order($txn, $dataValue, $dataDescriptor) {
$this->new_sub( $sub, true );
}

$subscr_id = $client->createSubscriptionFromCustomer( $authorizenet_customer, $txn, $sub, $dataDescriptor, $dataValue );
// Charge a 1 dollar to validate payment source
if ( apply_filters( 'mepr_authorize_profile_validation_txn_enabled', false ) && $this->payment_validated !== true ) {
$validationTxn = clone $txn;
$validationTxn->set_subtotal( 1 );
$validationTxn->trans_num = $client->chargeCustomer( $authorizenet_customer, $validationTxn, false );
}

$subscr_id = $client->createSubscriptionFromCustomer( $authorizenet_customer, $txn, $sub, $dataDescriptor,
$dataValue );

if ( isset( $validationTxn ) ) {
$client->voidTransaction( $validationTxn );
$this->payment_validated = true;
}

if ( $subscr_id ) {
$sub->subscr_id = $subscr_id;
Expand Down
2 changes: 2 additions & 0 deletions app/gateways/MeprPayPalProGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class MeprPayPalProGateway extends MeprBasePayPalGateway {
// This is stored with the user meta & the subscription meta
public static $paypal_token_str = '_mepr_paypal_pro_token';

public $key;

/** Used in the view to identify the gateway */
public function __construct() {
$this->name = __('PayPal Payments Pro', 'memberpress');
Expand Down
18 changes: 18 additions & 0 deletions app/gateways/MeprStripeGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@ public function handle_invoice_payment_succeeded_webhook($invoice) {
if(!$order->is_complete() && !$order->is_processing()) {
$order->update_meta('processing', true);

$this->record_cc_vars($sub, $payment_method);
$this->record_create_sub($sub);

if($sub->trial && $sub->trial_days > 0) {
Expand Down Expand Up @@ -1203,6 +1204,7 @@ public function handle_invoice_payment_succeeded_webhook($invoice) {
}
}

$this->record_cc_vars($sub, $payment_method);
$this->record_create_sub($sub);

if($payment_method && isset($customer->invoice_settings) && is_array($customer->invoice_settings)) {
Expand Down Expand Up @@ -1698,6 +1700,7 @@ public function process_stripe_checkout_session_completed($checkout_session) {
$sub->subscr_id = $checkout_session->subscription['id'];
}

$this->record_cc_vars($sub, $payment_method);
$this->record_create_sub($sub);

if($sub->trial && $sub->trial_days > 0) {
Expand Down Expand Up @@ -1761,6 +1764,7 @@ public function process_stripe_checkout_session_completed($checkout_session) {
$sub->subscr_id = $checkout_session->subscription['id'];
}

$this->record_cc_vars($sub, $payment_method);
$this->record_create_sub($sub);

if(isset($checkout_session->subscription['latest_invoice']['charge'])) {
Expand Down Expand Up @@ -4806,4 +4810,18 @@ public function create_test_payment_intent(array $payment_method_types) {

$this->send_stripe_request('payment_intents', $args);
}

/**
* Records CC Variables.
*
* @param object $sub
* @param mixed $payment_method
*/
private function record_cc_vars($sub, $payment_method) {
if( $sub instanceof MeprSubscription && isset($payment_method) && is_object($payment_method) && isset($payment_method->card) && is_array($payment_method->card)) {
$sub->cc_last4 = $payment_method->card['last4'];
$sub->cc_exp_month = $payment_method->card['exp_month'];
$sub->cc_exp_year = $payment_method->card['exp_year'];
}
}
}
75 changes: 69 additions & 6 deletions app/gateways/authorizenet/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public function refundTransaction( $txn ) {
$response = $this->parseAuthnetResponse( $response );
$this->log( $response );

if ( isset( $response['messages']['resultCode'] ) && $response['messages']['resultCode'] == 'Ok' ) {
if ( isset( $response['messages']['resultCode'] )
&& $response['messages']['resultCode'] == 'Ok'
) {
$trans_num = $response['transactionResponse']['transId'];

return $trans_num;
Expand All @@ -76,14 +78,61 @@ public function refundTransaction( $txn ) {
}
}

/**
* @param MeprTransaction $txn
*/
public function voidTransaction( $txn )
{
$xml = '<createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>' . $this->login_name . '</name>
<transactionKey>' . $this->transaction_key . '</transactionKey>
</merchantAuthentication>
<refId>v' . $txn->id . '</refId>
<transactionRequest>
<transactionType>voidTransaction</transactionType>
<refTransId>' . $txn->trans_num . '</refTransId>
</transactionRequest>
</createTransactionRequest>';
$this->log( $xml );
$response = wp_remote_post( $this->endpoint, $this->prepareOptions( $xml ) );
$response = wp_remote_retrieve_body( $response );
$response = $this->parseAuthnetResponse( $response );
$this->log( $response );

if ( isset( $response['messages']['resultCode'] )
&& $response['messages']['resultCode'] == 'Ok'
&& $response['transactionResponse']['responseCode'] == 1
&& isset( $response['transactionResponse']['transId'] )
&& ! isset( $response['transactionResponse']['errors'] )
) {
return $response['transactionResponse']['transId'];
}

$this->log( 'Could not complete the void transaction request' );
}

/**
* @param $authorize_net_customer
* @param MeprTransaction $txn
* @param bool $capture
*
* @throws Exception
*/
public function chargeCustomer( $authorize_net_customer, $txn ) {
public function chargeCustomer( $authorize_net_customer, $txn, $capture = true ) {
$this->log( $authorize_net_customer );
$paymentProfile = '';
$captureMode = $capture ? 'final' : 'pre';

// $captureMode = 'final';
if (isset($authorize_net_customer["paymentProfiles"]["customerPaymentProfileId"])) {
$paymentProfile = $authorize_net_customer["paymentProfiles"]["customerPaymentProfileId"];
}

if (empty($paymentProfile)) {
throw new MeprException(__('Profile does not have a payment source', 'memberpress'));
}

$xml = '<createTransactionRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">
<merchantAuthentication>
<name>' . $this->login_name . '</name>
Expand All @@ -96,7 +145,7 @@ public function chargeCustomer( $authorize_net_customer, $txn ) {
<profile>
<customerProfileId>' . $authorize_net_customer['customerProfileId'] . '</customerProfileId>
<paymentProfile>
<paymentProfileId>' . $authorize_net_customer["paymentProfiles"]["customerPaymentProfileId"] . '</paymentProfileId>
<paymentProfileId>' . $paymentProfile . '</paymentProfileId>
</paymentProfile>
</profile>
<poNumber>' . $txn->id . '</poNumber>
Expand All @@ -105,7 +154,7 @@ public function chargeCustomer( $authorize_net_customer, $txn ) {
</customer>
<customerIP>' . $_SERVER['REMOTE_ADDR'] . '</customerIP>
<authorizationIndicatorType>
<authorizationIndicator>final</authorizationIndicator>
<authorizationIndicator>' . $captureMode . '</authorizationIndicator>
</authorizationIndicatorType>
</transactionRequest>
</createTransactionRequest>';
Expand All @@ -115,13 +164,20 @@ public function chargeCustomer( $authorize_net_customer, $txn ) {
$response = $this->parseAuthnetResponse( $response );
$this->log( $response );

if ( isset( $response['messages']['resultCode'] ) && $response['messages']['resultCode'] == 'Ok' ) {
if ( isset( $response['messages']['resultCode'] )
&& $response['messages']['resultCode'] == 'Ok'
&& $response['transactionResponse']['responseCode'] == 1
&& ! isset($response['transactionResponse']['errors'])
) {
$trans_num = $response['transactionResponse']['transId'];
$last4 = substr( $response['transactionResponse']['accountNumber'], - 4 );
$txn->update_meta( 'cc_last4', $last4 );

return $trans_num;
} else {
if (isset($response['transactionResponse']['errors']['error']['errorText'])) {
throw new MeprException(__($response['transactionResponse']['errors']['error']['errorText'], 'memberpress'));
}
throw new MeprException( __( 'Can not complete the payment.', 'memberpress' ) );
}
}
Expand Down Expand Up @@ -417,13 +473,20 @@ public function chargeCustomerCard( $authorize_net_customer, $txn, $dataDesc, $d
$response = wp_remote_retrieve_body( $response );
$response = $this->parseAuthnetResponse( $response );

if ( isset( $response['messages']['resultCode'] ) && $response['messages']['resultCode'] == 'Ok' ) {
if ( isset( $response['messages']['resultCode'] )
&& $response['messages']['resultCode'] == 'Ok'
&& $response['transactionResponse']['responseCode'] == 1
&& ! isset($response['transactionResponse']['errors'])
) {
$trans_num = $response['transactionResponse']['transId'];
$last4 = substr( $response['transactionResponse']['accountNumber'], - 4 );
$txn->update_meta( 'cc_last4', $last4 );

return $trans_num;
} else {
if (isset($response['transactionResponse']['errors']['error']['errorText'])) {
throw new MeprException(__($response['transactionResponse']['errors']['error']['errorText'], 'memberpress'));
}
throw new MeprException( __( 'Can not complete the payment', 'memberpress' ) );
}
}
Expand Down

0 comments on commit e7459ca

Please sign in to comment.