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 feature to customize the Merchant Order Reference #22

Closed
remcotolsma opened this issue Jun 26, 2023 · 1 comment · Fixed by #23
Closed

Add feature to customize the Merchant Order Reference #22

remcotolsma opened this issue Jun 26, 2023 · 1 comment · Fixed by #23
Assignees

Comments

@remcotolsma
Copy link
Member

Request from customer:

Are we able to create a custom tag to be used as Merchant Order Reference in Adyen (like a dynamic invoice number)?

Internal Help Scout conversation: https://secure.helpscout.net/conversation/2282196531/25812?folderId=1425710

We'd like to add a custom reference (reference to a contract) to the Merchant Reference field, which currently consists of the Form ID and the entry ID.
Or we could use the Merchant Order Reference field (containing the entry ID right now) but that isn't the preferred field from the customers' perspective.

/**
* Merchant order reference.
*
* @link https://docs.adyen.com/api-explorer/#/CheckoutService/v68/post/payments__reqParam_merchantOrderReference
* @link https://docs.adyen.com/api-explorer/#/CheckoutService/v68/post/sessions__reqParam_merchantOrderReference
*/
$request->set_merchant_order_reference( $payment->format_string( $config->get_merchant_order_reference() ) );

@remcotolsma remcotolsma self-assigned this Jun 26, 2023
@remcotolsma
Copy link
Member Author

remcotolsma commented Jun 26, 2023

Added a filter in 783900b, could be used like this:

<?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
);

https://github.com/pronamic/wp-pronamic-pay-adyen/blob/783900b51c6a969fcb004bb0870d58492af8c23f/docs/hooks.md#pronamic_pay_adyen_merchant_order_reference

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 a pull request may close this issue.

1 participant