Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for merchant order reference #23

Merged

Conversation

remcotolsma
Copy link
Member

@remcotolsma remcotolsma commented Jun 26, 2023

Awaiting response from customer in https://secure.helpscout.net/conversation/2282196531/25812?folderId=1425710.

<?php

add_filter(
	'pronamic_pay_adyen_merchant_order_reference',
	function( $merchant_order_reference, $payment ) {
		// Check if payment source is Gravity Forms.
		if ( 'gravityformsideal' !== $payment->get_source() ) {
			return $merchant_order_reference;
		}

		// Check if Gravity Forms API is available.
		if ( ! method_exists( 'GFAPI', 'get_entry' ) ) {
			return $merchant_order_reference;
		}

		// Check if Gravity Forms entry exists.
		$entry = GFAPI::get_entry( $payment->get_source_id() );

		if ( false === $entry ) {
			return $merchant_order_reference;
		}

		// Format merchant order reference.
		$merchant_order_reference = strtr(
			$merchant_order_reference,
			[
				'{gf_form_id}'  => $entry['form_id'],
				'{gf_entry_id}' => $entry['id'],
			]
		);

		return $merchant_order_reference;
	},
	10,
	2
);

@remcotolsma remcotolsma self-assigned this Jun 26, 2023
@remcotolsma remcotolsma linked an issue Jun 26, 2023 that may be closed by this pull request
Copy link
Member

@rvdsteege rvdsteege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this with the merchant order reference setting set to GF form #{gf_form_id} + entry #{gf_entry_id}, but this resulted in GF form #2 + entry #278242912 for Gravity Forms entry ID 2782. It appears the payment ID (42912) is appended by Payment::format_string() as the setting does not contain {order_id} nor {payment_id}.

In case of Gravity Forms, the user could also set the order ID setting in the payment feed of the form. This setting supports all Gravity Forms merge tags. The value of GF form #{form_id} + entry #{entry_id} there will result in the expected merchant order reference Gravity Forms form #2 + entry #2783. We don't need the filter for this case.

Scherm­afbeelding 2023-06-26 om 16 40 39

The user provided the below sample code, which I think this will result in the payment ID being appended to the contract ID. I'm not sure how we can improve this — in the Payment::format_string() method?

$merchant_order_reference = rgar( $entry, strval( self::CONTRACT_ID_FIELD ) );

rvdsteege added a commit to pronamic/wp-pronamic-pay-ems-e-commerce that referenced this pull request Jul 3, 2023
rvdsteege added a commit to pronamic/wp-pronamic-pay-icepay that referenced this pull request Jul 3, 2023
rvdsteege added a commit to pronamic/wp-pronamic-pay-ideal-advanced-v3 that referenced this pull request Jul 3, 2023
rvdsteege added a commit to pronamic/wp-pronamic-pay-ideal-basic that referenced this pull request Jul 3, 2023
rvdsteege added a commit to pronamic/wp-pronamic-pay-ingenico that referenced this pull request Jul 3, 2023
rvdsteege added a commit to pronamic/wp-pronamic-pay-rabo-smart-pay that referenced this pull request Jul 3, 2023
Copy link
Member

@rvdsteege rvdsteege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved the issue with forced adding of a dynamic part (payment ID). I think this PR can now be merged.

@remcotolsma remcotolsma merged commit 9ccc95a into main Jul 6, 2023
9 of 20 checks passed
@remcotolsma remcotolsma deleted the 22-add-feature-to-customize-the-merchant-order-reference branch July 6, 2023 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add feature to customize the Merchant Order Reference
2 participants