From 9a52a9a1cee79e9b65f2152ad698f1cb9e076b08 Mon Sep 17 00:00:00 2001 From: Risto Niinemets Date: Wed, 13 Dec 2017 11:22:28 +0200 Subject: [PATCH] add filter to allow hooking into transaction data before signing --- includes/abstracts/class-wc-banklink-ipizza.php | 3 +++ includes/abstracts/class-wc-banklink-solo.php | 3 +++ includes/abstracts/class-wc-banklink.php | 11 +++++++++++ .../gateways/class-wc-banklink-estcard-gateway.php | 5 ++++- ...class-wc-banklink-maksekeskus-redirect-gateway.php | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) diff --git a/includes/abstracts/class-wc-banklink-ipizza.php b/includes/abstracts/class-wc-banklink-ipizza.php index 0644eaf..307930e 100644 --- a/includes/abstracts/class-wc-banklink-ipizza.php +++ b/includes/abstracts/class-wc-banklink-ipizza.php @@ -239,6 +239,9 @@ function generate_submit_form( $order_id ) { 'VK_DATETIME' => $datetime->format( DateTime::ISO8601 ) ); + // Allow hooking into the data + $mac_fields = $this->hookable_transaction_data( $mac_fields, $order ); + // Generate MAC string from the private key $key = openssl_pkey_get_private( $this->get_option( 'vk_privkey' ), $this->get_option( 'vk_pass' ) ); $signature = ''; diff --git a/includes/abstracts/class-wc-banklink-solo.php b/includes/abstracts/class-wc-banklink-solo.php index 92bca12..238f3f2 100644 --- a/includes/abstracts/class-wc-banklink-solo.php +++ b/includes/abstracts/class-wc-banklink-solo.php @@ -100,6 +100,9 @@ function generate_submit_form( $order_id ) { 'SOLOPMT_CUR' => get_woocommerce_currency(), ); + // Allow hooking into the data + $mac_fields = $this->hookable_transaction_data( $mac_fields, $order ); + // Generate MAC string $mac_fields['SOLOPMT_MAC'] = $this->generate_mac_string( $mac_fields ); diff --git a/includes/abstracts/class-wc-banklink.php b/includes/abstracts/class-wc-banklink.php index c63e76f..4e4464d 100644 --- a/includes/abstracts/class-wc-banklink.php +++ b/includes/abstracts/class-wc-banklink.php @@ -181,4 +181,15 @@ function debug( $data, $level = 'debug' ) { } } } + + /** + * Creates a filter for altering transaction data + * + * @param array $data Transaction data + * @param WC_Order $order Order + * @return array Modified transaction data + */ + function hookable_transaction_data( $data, $order ) { + return apply_filters( 'woocommerce_' . $this->id . '_gateway_transaction_fields', $data, $order ); + } } \ No newline at end of file diff --git a/includes/gateways/class-wc-banklink-estcard-gateway.php b/includes/gateways/class-wc-banklink-estcard-gateway.php index c3ee7bb..6bf8598 100644 --- a/includes/gateways/class-wc-banklink-estcard-gateway.php +++ b/includes/gateways/class-wc-banklink-estcard-gateway.php @@ -83,7 +83,7 @@ function generate_submit_form( $order_id ) { $lang_code = in_array( $lang, $accepted_lang_codes ) ? $lang : 'en'; // Set MAC fields - $mac_fields = array( + $mac_fields = array( 'action' => 'gaf', 'ver' => '004', 'id' => $this->get_option( 'merchant_id' ), @@ -98,6 +98,9 @@ function generate_submit_form( $order_id ) { 'charEncoding' => 'utf-8' ); + // Allow hooking into the data + $mac_fields = $this->hookable_transaction_data( $mac_fields, $order ); + $key = openssl_pkey_get_private( $this->get_option( 'private_key' ), $this->get_option( 'private_key_pass' ) ); $signature = ''; $mac_string = $this->generate_mac_string( $mac_fields ); diff --git a/includes/gateways/class-wc-banklink-maksekeskus-redirect-gateway.php b/includes/gateways/class-wc-banklink-maksekeskus-redirect-gateway.php index 6375f3f..d44adca 100644 --- a/includes/gateways/class-wc-banklink-maksekeskus-redirect-gateway.php +++ b/includes/gateways/class-wc-banklink-maksekeskus-redirect-gateway.php @@ -97,6 +97,9 @@ function generate_submit_form( $order_id ) { ) ); + // Allow hooking into the data + $request = $this->hookable_transaction_data( $request, $order ); + // Generate MAC code $mac_code = $this->get_signature( $request );