Skip to content

Commit

Permalink
Merge branch 'epic/givewp-3.0' into feature/add-additional-fields-in-…
Browse files Browse the repository at this point in the history
…block-inserter
  • Loading branch information
JoshuaHungDinh committed Aug 23, 2023
2 parents fa7114e + a06c08d commit 3640720
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 74 deletions.
24 changes: 24 additions & 0 deletions give.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
use Give\Log\LogServiceProvider;
use Give\MigrationLog\MigrationLogServiceProvider;
use Give\MultiFormGoals\ServiceProvider as MultiFormGoalsServiceProvider;
use Give\PaymentGateways\Gateways\TestOffsiteGateway\TestOffsiteGateway;
use Give\PaymentGateways\ServiceProvider as PaymentGatewaysServiceProvider;
use Give\Promotions\ServiceProvider as PromotionsServiceProvider;
use Give\Revenue\RevenueServiceProvider;
Expand Down Expand Up @@ -257,6 +258,8 @@ public function boot()
{
$this->setup_constants();

$this->disableVisualDonationFormBuilderFeaturePlugin();

// Add compatibility notice for recurring and stripe support with Give 2.5.0.
add_action('admin_notices', [$this, 'display_old_recurring_compatibility_notice']);

Expand Down Expand Up @@ -515,6 +518,27 @@ private function setupExceptionHandler()
$handler = new UncaughtExceptionLogger();
$handler->setupExceptionHandler();
}

protected function disableVisualDonationFormBuilderFeaturePlugin()
{
// Include plugin.php to use is_plugin_active() below.
include_once ABSPATH . 'wp-admin/includes/plugin.php';

// Prevent fatal error due to a renamed class.
class_alias(TestOffsiteGateway::class, 'Give\PaymentGateways\Gateways\TestGateway\TestGatewayOffsite', true);

if ( is_plugin_active('givewp-next-gen/give-visual-form-builder.php' )) {
deactivate_plugins(['givewp-next-gen/give-visual-form-builder.php']);

add_action('admin_notices', function() {
Give()->notices->register_notice([
'id' => 'give-visual-donation-form-builder-feature-plugin-deactivated',
'description' => __('The Visual Form Builder Beta plugin is no longer needed, since the form builder is included in your current version of GiveWP. To prevent conflicts, the Beta plugin has been deactivated and can be safely deleted.', 'give'),
'type' => 'info',
]);
});
}
}
}

/**
Expand Down
41 changes: 4 additions & 37 deletions includes/gateways/stripe/includes/give-stripe-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,36 +630,6 @@ function give_stripe_get_application_fee_amount( $amount ) {
return round( $amount * give_stripe_get_application_fee_percentage() / 100, 0 );
}

/**
* This function is used to fetch the donation id by meta key.
*
* @param string $id Any String.
* @param string $type intent_id/client_secret
*
* @since 2.5.0
*
* @return void
*/
function give_stripe_get_donation_id_by( $id, $type ) {

global $wpdb;

$donation_id = 0;

switch ( $type ) {
case 'intent_id':
$donation_id = $wpdb->get_var( $wpdb->prepare( "SELECT donation_id FROM {$wpdb->donationmeta} WHERE meta_key = '_give_stripe_payment_intent_id' AND meta_value = %s LIMIT 1", $id ) );
break;

case 'client_secret':
$donation_id = $wpdb->get_var( $wpdb->prepare( "SELECT donation_id FROM {$wpdb->donationmeta} WHERE meta_key = '_give_stripe_payment_intent_client_secret' AND meta_value = %s LIMIT 1", $id ) );
break;
}

return $donation_id;

}

/**
* This function is used to set Stripe API Key.
*
Expand Down Expand Up @@ -874,11 +844,12 @@ function give_stripe_is_source_type( $id, $type = 'src' ) {
/**
* This helper function is used to process Stripe payments.
*
* @param array $donation_data Donation form data.
* @param object $stripe_gateway $this data.
*
* @unreleased no longer store the payment intent secret
* @since 2.5.0
*
* @param array $donation_data Donation form data.
* @param object $stripe_gateway $this data.
*
* @return void
*/
function give_stripe_process_payment( $donation_data, $stripe_gateway ) {
Expand Down Expand Up @@ -978,10 +949,6 @@ function give_stripe_process_payment( $donation_data, $stripe_gateway ) {

$intent = $stripe_gateway->payment_intent->create( $intent_args );

// Save Payment Intent Client Secret to donation note and DB.
give_insert_payment_note( $donation_id, 'Stripe Payment Intent Client Secret: ' . $intent->client_secret );
give_update_meta( $donation_id, '_give_stripe_payment_intent_client_secret', $intent->client_secret );

// Set Payment Intent ID as transaction ID for the donation.
give_set_payment_transaction_id( $donation_id, $intent->id );
give_insert_payment_note( $donation_id, 'Stripe Charge/Payment Intent ID: ' . $intent->id );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,15 @@ class="give-stripe-sepa-iban-field give-stripe-cc-field"
}

/**
* This function will be used for donation processing.
*
* @param array $donation_data List of donation data.
*
* @return void
* @since 2.6.1
* @access public
*/
* This function will be used for donation processing.
*
* @unreleased no longer store the intent secret in the database
* @since 2.6.1
*
* @param array $donation_data List of donation data.
*
* @return void
*/
public function process_payment( $donation_data ) {

// Bailout, if the current gateway and the posted gateway mismatched.
Expand Down Expand Up @@ -287,11 +288,6 @@ public function process_payment( $donation_data ) {
$intent = $this->payment_intent->create( $intent_args );

if ( ! empty( $intent->status ) && 'processing' === $intent->status ) {

// Save Payment Intent Client Secret to donation note and DB.
give_insert_payment_note( $donation_id, 'Stripe Payment Intent Client Secret: ' . $intent->client_secret );
give_update_meta( $donation_id, '_give_stripe_payment_intent_client_secret', $intent->client_secret );

// Set Payment Intent ID as transaction ID for the donation.
give_set_payment_transaction_id( $donation_id, $intent->id );
give_insert_payment_note( $donation_id, 'Stripe Charge/Payment Intent ID: ' . $intent->id );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {__} from '@wordpress/i18n';
import { __ } from "@wordpress/i18n";

/**
* @since 3.0.0
Expand Down Expand Up @@ -50,7 +50,7 @@ const subscriptionPeriodLabelLookup = {
/**
* @since 3.0.0
*/
export type subscriptionPeriod = keyof typeof subscriptionPeriodLabelLookup;
type subscriptionPeriod = keyof typeof subscriptionPeriodLabelLookup;

/**
* @since 3.0.0
Expand Down
8 changes: 7 additions & 1 deletion src/FormBuilder/resources/css/admin-form-builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
#adminmenumain,
#wpadminbar {
display: none;
}
}

/* Prevent classic admin theme layout issues */
html :where(.wp-block) {
margin: 0;
max-width: unset;
}
6 changes: 3 additions & 3 deletions src/FormMigration/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @return void Note: $formId is an "output argument" - not a return value.
*/
function give_redirect_form_id(&$formId, &...$extraReference) {
function _give_redirect_form_id(&$formId, &...$extraReference) {
global $wpdb;

$formId = absint(DB::get_var(
Expand All @@ -40,7 +40,7 @@ function give_redirect_form_id(&$formId, &...$extraReference) {
*
* @return bool
*/
function give_is_form_migrated($formId) {
function _give_is_form_migrated($formId) {
global $wpdb;

return (bool) DB::get_var(
Expand All @@ -63,7 +63,7 @@ function give_is_form_migrated($formId) {
*
* @return bool
*/
function give_is_form_donations_transferred($formId) {
function _give_is_form_donations_transferred($formId) {
global $wpdb;

return (bool) DB::get_var(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(array $paymentIntentArgs = [])
}

/**
* @unreleased no longer store the payment intent secret
* @since 2.19.0
*
* @throws InvalidPropertyName
Expand Down Expand Up @@ -71,17 +72,6 @@ public function __invoke(
'content' => sprintf(__('Stripe Charge/Payment Intent ID: %s', 'give'), $intent->id())
]);

DonationNote::create([
'donationId' => $donation->id,
'content' => sprintf(__('Stripe Payment Intent Client Secret: %s', 'give'), $intent->clientSecret())
]);

give_update_meta(
$donation->id,
'_give_stripe_payment_intent_client_secret',
$intent->clientSecret()
);

if ('requires_action' === $intent->status()) {
DonationNote::create([
'donationId' => $donation->id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Give\PaymentGateways\Gateways\Stripe\Migrations;

use Give\Framework\Database\DB;
use Give\Framework\Migrations\Contracts\Migration;

/**
* Removes the secret meta that was unnecessarily stored in the database for donations.
*
* @unreleased
*/
class RemovePaymentIntentSecretMeta extends Migration
{
/**
* @inheritDoc
*/
public static function id(): string
{
return 'remove_payment_intent_secret_meta';
}

/**
* @inheritDoc
*/
public static function title(): string
{
return __('Remove payment intent secret meta', 'give');
}

/**
* @inheritDoc
*/
public static function timestamp()
{
return strtotime('2023-06-29 00:00:00');
}

/**
* @inheritDoc
*/
public function run()
{
DB::delete(
DB::prefix('give_donationmeta'),
['meta_key' => '_give_stripe_payment_intent_client_secret'],
['%s']
);

$commentsTable = DB::prefix('give_comments');
DB::query(
DB::prepare(
"DELETE FROM {$commentsTable} WHERE comment_type = 'donation' AND comment_content LIKE %s",
'Stripe Payment Intent Client Secret:%'
)
);
}
}
5 changes: 4 additions & 1 deletion src/PaymentGateways/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Give\PaymentGateways\Gateways\Stripe\Controllers\UpdateStatementDescriptorAjaxRequestController;
use Give\PaymentGateways\Gateways\Stripe\Migrations\AddMissingTransactionIdForUncompletedDonations;
use Give\PaymentGateways\Gateways\Stripe\Migrations\AddStatementDescriptorToStripeAccounts;
use Give\PaymentGateways\Gateways\Stripe\Migrations\RemovePaymentIntentSecretMeta;
use Give\PaymentGateways\PayPalCommerce\Migrations\RegisterPayPalDonationsRefreshTokenCronJobByMode;
use Give\PaymentGateways\PayPalCommerce\Migrations\RemoveLogWithCardInfo;
use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface;
Expand Down Expand Up @@ -68,6 +69,7 @@ public function boot()
}

/**
* @unreleased add RemovePaymentIntentSecretMeta migration
* @since 2.19.6
*/
private function registerMigrations()
Expand All @@ -76,7 +78,8 @@ private function registerMigrations()
AddStatementDescriptorToStripeAccounts::class,
AddMissingTransactionIdForUncompletedDonations::class,
RemoveLogWithCardInfo::class,
RegisterPayPalDonationsRefreshTokenCronJobByMode::class
RemovePaymentIntentSecretMeta::class,
RegisterPayPalDonationsRefreshTokenCronJobByMode::class,
]);
}
}
12 changes: 6 additions & 6 deletions tests/Unit/FormMigration/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testIsFormRedirected()

$formId = $donationFormV2->id;

give_redirect_form_id($formId);
_give_redirect_form_id($formId);

$this->assertEquals($donationFormV3->id, $formId);
}
Expand All @@ -34,7 +34,7 @@ public function testIsFormRedirectedWithAdditionalReference()
$formId = $donationFormV2->id;
$atts['id'] = $donationFormV2->id;

give_redirect_form_id($formId, $atts['id']);
_give_redirect_form_id($formId, $atts['id']);

$this->assertEquals($donationFormV3->id, $formId);
$this->assertEquals($donationFormV3->id, $atts['id']);
Expand All @@ -46,14 +46,14 @@ public function testIsFormMigrated()
$donationFormV3 = DonationForm::factory()->create();
give_update_meta($donationFormV3->id, 'migratedFormId', $donationFormV2->id);

$this->assertTrue(give_is_form_migrated($donationFormV2->id));
$this->assertTrue(_give_is_form_migrated($donationFormV2->id));
}

public function testIsFormNotMigrated()
{
$donationFormV2 = $this->createSimpleDonationForm();

$this->assertFalse(give_is_form_migrated($donationFormV2->id));
$this->assertFalse(_give_is_form_migrated($donationFormV2->id));
}

public function testIsFormDonationsTransferred()
Expand All @@ -62,13 +62,13 @@ public function testIsFormDonationsTransferred()
$donationFormV3 = DonationForm::factory()->create();
give_update_meta($donationFormV3->id, 'transferredFormId', $donationFormV2->id);

$this->assertTrue(give_is_form_donations_transferred($donationFormV2->id));
$this->assertTrue(_give_is_form_donations_transferred($donationFormV2->id));
}

public function testIsFormDonationsNotTransferred()
{
$donationFormV2 = $this->createSimpleDonationForm();

$this->assertFalse(give_is_form_donations_transferred($donationFormV2->id));
$this->assertFalse(_give_is_form_donations_transferred($donationFormV2->id));
}
}

0 comments on commit 3640720

Please sign in to comment.