pronamic / wp-pronamic-pay-adyen

Adyen driver for the WordPress payment processing library.
https://www.wp-pay.org/gateways/adyen/
6 stars 2 forks source link

Add filter for merchant order reference #23

Closed remcotolsma closed 1 year ago

remcotolsma commented 1 year ago

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