GithubHelp home page GithubHelp logo

pronamic / wp-pronamic-pay-contact-form-7 Goto Github PK

View Code? Open in Web Editor NEW
2.0 5.0 0.0 299 KB

Contact Form 7 driver for the WordPress payment processing library.

Home Page: http://www.wp-pay.org/extensions/contact-form-7/

JavaScript 0.50% PHP 99.50%
wordpress payment-integration contact-form-7 pronamic pay payment-form wp-pronamic-pay-extension

wp-pronamic-pay-contact-form-7's Introduction

WordPress Pay Extension: Contact Form 7

Contact Form 7 driver for the WordPress payment processing library.

Amount Field

The amount field can be a text, number, drop-down menu, checkboxes or radio buttons field, it requires the pronamic_pay_amount option:

[number pronamic_pay_amount]

WordPress environment for building and testing

npx wp-env start

For testing with wp-env you probably want to disable the default Contact Form 7 mail. You can achieve this by editing the form and including the following under 'Additional Settings':

skip_mail: on

Links

wp-pronamic-pay-contact-form-7's People

Contributors

remcotolsma avatar rvdsteege avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

wp-pronamic-pay-contact-form-7's Issues

Switch from Mollie to Buckaroo results in no option to choose iDEAL bank

Message from customer:

Een klant van mij zat bij Sisow en is dat is over gegaan naar Buckaroo, Ik gebruik voor een donatieformulier Contact From 7. Dit werkte bij Sisow prima, maar bij Buckaroo niet meer. Alle instellingen staan goed en de test gaat ook goed. Maar er is geen keuze meer zichtbaar om een bank te kiezen in het formulier (https://●●●●●●●●●●●●●●●●●●●●●●.nl/doneren/). Wat kan hier mis zijn?

Response from support:

Bedankt voor je bericht. Ik heb het gecontroleerd en kon inderdaad een probleem reproduceren in onze testomgeving in combinatie met Buckaroo. De oorzaak heeft te maken met dat Buckaroo de banken op land groepeert en Sisow deed dat niet.

We hebben het direct opgelost en zullen deze wijziging meenemen in de eerstvolgende update van de Pronamic Pay plugin. Voor nu kun je het veld voor de bankkeuze tijdelijk van het formulier verwijderen, zodat die keuze in een tussenscherm van Buckaroo gemaakt kan worden.

No amount from submission if select option contains single quote

Our integration is unable to get the amount from a select field option if the option name contains a quote (').

For example, the 2nd option of the following field would not work as expected:

[select* select-123 pronamic_pay_amount "Test|10" "Test's|20"]

The POST'ed value in https://github.com/pronamic/wp-pronamic-pay-contact-form-7/blob/3.0.1/src/Pronamic.php#L82 results in Test's, instead of Test's. This value is later checked against the option names, but with the encoded quotes there is no match with any of the options.

Internal Help Scout ticket: https://secure.helpscout.net/conversation/1891185446/23975

Use `$submission->add_result_props( ... )` instead of `feedback_args`?

In the Contact Form 7 Stripe integration i noticed the following code:

https://github.com/takayukister/contact-form-7/blob/6efa44cf62c055bbeb316290b66f405d4bf01946/modules/stripe/stripe.php#L177-L184

$submission->add_result_props( array(
	'stripe' => array(
		'payment_intent' => array(
			'id' => $payment_intent['id'],
			'client_secret' => $payment_intent['client_secret'],
		),
	),
) );

Can we use this to avoid the feedback_args and wpcf7_feedback_response filter?

$payment = Plugin::start_payment( $payment );
$this->payment = $payment;
$this->feedback_args = [
'status' => 'pronamic_pay_redirect',
'message' => __( 'Please wait while redirecting for payment', 'pronamic_ideal' ),
'pronamic_pay_redirect_url' => $payment->get_pay_redirect_url(),
];
} catch ( \Exception $e ) {
$this->feedback_args = [
'status' => 'pronamic_pay_error',
'message' => sprintf(
'%s' . str_repeat( \PHP_EOL, 2 ) . '%s',
Plugin::get_default_error_message(),
$e->getMessage()
),
];
$abort = true;
}
\add_filter( 'wpcf7_feedback_response', [ $this, 'feedback_response' ], 10, 2 );

Could also help to solve the following issue:

Use `$submission->get_posted_data()` to retrieve data?

Apart from this, I do think that we can improve the retrieval of the submitted data by using $submission->get_posted_data() for example:

/**
* Get Pronamic payment from Contact Form 7 form.
*
* @param WPCF7_Submission $submission Contact Form 7 form submission.
* @return Payment|null
*/
public static function get_submission_payment( WPCF7_Submission $submission ) {
$form = $submission->get_contact_form();
$payment = new Payment();
// Check amount.
$amount = self::get_submission_value( 'amount' );
if ( null === $amount ) {
return null;
}

This might save some code in handling the tags and pipes?

https://github.com/rocklobster-in/contact-form-7/blob/2cfaa472fa485c6d3366fcdd80701fdaf7f9e425/includes/submission.php#L370-L463

Originally posted by @remcotolsma in #13 (comment)

Use `wpcf7_submit` instead of `wpcf7_before_send_mail`?

I'm working on the review of the following pull request:

I use wp-env for testing and don't have a mail solution active. That's why I disabled the mail for Contact Form 7:

skip_mail: on

Scherm­afbeelding 2023-02-21 om 10 19 32

Payments are not working when users do this?

\add_action( 'wpcf7_before_send_mail', [ $this, 'before_send_mail' ], 10, 3 );

Should we use the wpcf7_submit action just like in Flamingo?

https://github.com/takayukister/contact-form-7/blob/6efa44cf62c055bbeb316290b66f405d4bf01946/modules/flamingo.php#L7

Amount editable

From customer:

I see that it is possible to adjust the amount (pronamic_pay_amount) via DevTools. This amount is then visible at Mollie's checkout. Wouldn't it be better to get the value for pronamic_pay_amount from the raw post_content of CF7? That way you can get the amount from the original field shortcode and pass that amount on to Mollie.

@LeoOosterloo asks in https://github.com/pronamic/pronamic-pay-with-mollie-for-contact-form-7/issues/14 if we can do something about this.

Internal Help Scout ticket: https://secure.helpscout.net/conversation/2325939497/26014/

Only first checked option added to total amount

A checkbox field can have multiple options in Contact Form 7, for example:

[checkbox checkbox-123 pronamic_pay_amount "Option 1|10" "Option 2|20" "Option 3|30"]

Currently, only the first checked option is added to the total amount. This value is retrieved with get_posted_string( $tag->name ), instead an array with all checked options is returned by get_posted_data( $tag->name ) (possibly related to #14).

/**
* Get value by tag.
*
* @param WPCF7_FormTag $tag Tag.
* @return string
*/
public function get_value_by_tag( $tag ) {
$value = $this->submission->get_posted_string( $tag->name );
/**
* Contact Form 7 concatenates the field option value with user input for free text fields. We
* are only interested in the input value as amount.
*
* @link https://github.com/rocklobster-in/contact-form-7/blob/2cfaa472fa485c6d3366fcdd80701fdaf7f9e425/includes/submission.php#L434-L437
*/
if ( \wpcf7_form_tag_supports( $tag->type, 'selectable-values' ) && $tag->has_option( 'free_text' ) ) {
$values = \WPCF7_USE_PIPE ? $tag->pipes->collect_afters() : $tag->values;
$last_value = \end( $values );
if ( \str_starts_with( $value, $last_value . ' ' ) ) {
$value = \substr( $value, \strlen( $last_value . ' ' ) );
}
}
/**
* Hidden fields.
*/
$hidden_fields = $this->get_hidden_fields();
if ( \in_array( $tag->name, $hidden_fields, true ) ) {
$value = '';
}
return $value;
}

No sum of multiple amount fields/tags with the `pronamic_pay_amount` option

This problem came to light due to a question from a potential customer:

I am interested in purchasing you plugin. However I have 1 question. I would like to use the plugin for a form with multiple products that have different prices. Is it possible to use the plugin to add up the chosen products and generate a total of the costs?

Internal HelpScout ticket: https://secure.helpscout.net/conversation/2450327829/26629?viewId=1425710

It's related to the following code:

/**
* Get submission value.
*
* @param WPCF7_Submission $submission Submission.
* @param string $type Type to search for.
* @return mixed
*/
public static function get_submission_value( WPCF7_Submission $submission, $type ) {
// phpcs:disable WordPress.Security.NonceVerification.Missing
$result = null;
$prefixed_type = 'pronamic_pay_' . $type;
// Hidden fields.
$hidden_fields = \filter_input( \INPUT_POST, '_wpcf7cf_hidden_group_fields' );
if ( ! empty( $hidden_fields ) ) {
$hidden_fields = \json_decode( stripslashes( $hidden_fields ) );
}
if ( ! \is_array( $hidden_fields ) ) {
$hidden_fields = [];
}
// @link https://contactform7.com/tag-syntax/
$tags = WPCF7_FormTagsManager::get_instance()->get_scanned_tags();
foreach ( $tags as $tag ) {
// Check if tag base type or name is requested type or tag has requested type as option.
if ( ! \in_array( $tag->basetype, [ $type, $prefixed_type ], true ) && ! $tag->has_option( $prefixed_type ) && $prefixed_type !== $tag->name ) {
continue;
}
// Check if field is not hidden.
if ( \in_array( $tag->name, $hidden_fields, true ) ) {
continue;
}
// Submission value.
$value = $submission->get_posted_string( $tag->name );
if ( empty( $value ) ) {
continue;
}
switch ( $type ) {
case 'amount':
/**
* Contact Form 7 concatenates the field option value with user input for free text fields. We
* are only interested in the input value as amount.
*
* @link https://github.com/rocklobster-in/contact-form-7/blob/2cfaa472fa485c6d3366fcdd80701fdaf7f9e425/includes/submission.php#L434-L437
*/
if ( \wpcf7_form_tag_supports( $tag->type, 'selectable-values' ) && $tag->has_option( 'free_text' ) ) {
$values = \WPCF7_USE_PIPE ? $tag->pipes->collect_afters() : $tag->values;
$last_value = end( $values );
if ( \str_starts_with( $value, $last_value . ' ' ) ) {
$value = substr( $value, strlen( $last_value . ' ' ) );
}
}
$value = Tags\AmountTag::parse_value( $value );
// Set parsed value as result or add to existing money result.
if ( null !== $value ) {
$result = ( $result instanceof Money ? $result->add( $value ) : $value );
}
break;
default:
$result = $value;
}
// Prefer tag with option (`pronamic_pay_email`) over tag name match (e.g. `email`).
if ( $tag->has_option( $prefixed_type ) ) {
return $result;
}
}
// phpcs:enable WordPress.Security.NonceVerification.Missing
return $result;
}

The problem is specifically in the next line:

// Prefer tag with option (`pronamic_pay_email`) over tag name match (e.g. `email`).
if ( $tag->has_option( $prefixed_type ) ) {
return $result;
}

In the Pronamic Pay plugin we currently support 3 custom tags:

  • pronamic_pay_amount
  • pronamic_pay_issuer
  • pronamic_pay_method

The processing of these custom tags, the custom tag options and the amount to be paid (sum) is now in one function: Pronamic::get_submission_value( WPCF7_Submission $submission, $type ).

We can probably rewrite this a bit so that it works simpler and better:

  • get_submission_value_by_tag_name_or_tag_option
  • get_submission_values_by_tag_name_or_tag_option
  • get_submission_amount_by_tag_name_or_tag_option
  • get_submission_value_by_tag_option
  • get_submission_values_by_tag_option

Uncaught Error: Call to a member function get_result() on null

An error occurs on a contact form with the mail extension enabled (full stacktrace below). The error occurs when simply loading the page with the form, and nothing has been POSTed yet.

On https://github.com/pronamic/wp-pronamic-pay-contact-form-7/blob/main/src/Extension.php#L241 it appears the WPCF7_Submission::get_instance() result is null...

I do not know Contact Form 7, but it seems this callback isn't supposed to be run yet - as there's nothing in POST data, WPCF7_Submission is supposed to be null.

The stacktrace:

PHP Fatal error:  Uncaught Error: Call to a member function get_result() on null in /home/.../public_html/staging/wp-content/plugins/pronamic-pay-with-mollie-for-contact-form-7/packages/wp-pay-extensions/contact-form-7/src/Extension.php:241
Stack trace:
#0 /home/.../public_html/staging/wp-includes/class-wp-hook.php(308): Pronamic\WordPress\Pay\Extensions\ContactForm7\Extension->replace_mail_tags()
#1 /home/.../public_html/staging/wp-includes/plugin.php(205): WP_Hook->apply_filters()
#2 /home/.../public_html/staging/wp-content/plugins/contact-form-7/includes/mail.php(519): apply_filters()
#3 [internal function]: WPCF7_MailTaggedText->replace_tags_callback()
#4 /home/.../public_html/staging/wp-content/plugins/contact-form-7/includes/mail.php(451): preg_replace_callback()
#5 /home/.../public_html/staging/wp-content/plugins/contact-form-7/includes/mail.php(346): WPCF7_MailTaggedText->replace_tags()
#6 /home/.../public_html/staging/wp-content/plugins/send-pdf-for-contact-form-7/classes/send-pdf.php(421): wpcf7_mail_replace_tags()
#7 /home/.../public_html/staging/wp-content/plugins/send-pdf-for-contact-form-7/classes/send-pdf.php(2083): cf7_sendpdf->wpcf7pdf_name_pdf()
#8 /home/.../public_html/staging/wp-includes/class-wp-hook.php(308): cf7_sendpdf->wpcf7_add_footer()
#9 /home/.../public_html/staging/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters()
#10 /home/.../public_html/staging/wp-includes/plugin.php(517): WP_Hook->do_action()
#11 /home/.../public_html/staging/wp-includes/general-template.php(3065): do_action()
#12 /home/.../public_html/staging/wp-content/themes/sydney/footer.php(42): wp_footer()
#13 /home/.../public_html/staging/wp-includes/template.php(783): require_once('/home/.../...')
#14 /home/.../public_html/staging/wp-includes/template.php(718): load_template()
#15 /home/.../public_html/staging/wp-includes/general-template.php(92): locate_template()
#16 /home/.../public_html/staging/wp-content/themes/sydney/page.php(45): get_footer()
#17 /home/.../public_html/staging/wp-includes/template-loader.php(106): include('/home/.../...')
#18 /home/.../public_html/staging/wp-blog-header.php(19): require_once('/home/.../...')
#19 /home/.../public_html/staging/index.php(17): require('/home/.../...')
#20 {main}
  thrown in /home/.../public_html/staging/wp-content/plugins/pronamic-pay-with-mollie-for-contact-form-7/packages/wp-pay-extensions/contact-form-7/src/Extension.php on line 241

Status page settings per form

From customer:

We're using Pronamic Pay for donations on this website and also for merchandise orders. We would like to show different confirmation pages based on which form is submitted. For donations we want to show ‘thank you for your donation’ and for orders ‘thank you for your order’. The same goes for the other status pages. Is this possible?

Currently there are no form settings to select which status pages to use.

Internal Help Scout ticket: https://secure.helpscout.net/conversation/2189870915/25375

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.