Skip to content

Commit

Permalink
add filter to allow hooking into transaction data before signing
Browse files Browse the repository at this point in the history
  • Loading branch information
RistoNiinemets committed Dec 13, 2017
1 parent 80465ea commit 9a52a9a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions includes/abstracts/class-wc-banklink-ipizza.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
3 changes: 3 additions & 0 deletions includes/abstracts/class-wc-banklink-solo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
11 changes: 11 additions & 0 deletions includes/abstracts/class-wc-banklink.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
5 changes: 4 additions & 1 deletion includes/gateways/class-wc-banklink-estcard-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand All @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down

0 comments on commit 9a52a9a

Please sign in to comment.