Created
September 18, 2023 19:53
-
-
Save vanbo/d1e2b6db71c482a4b0fbbff0f754956f to your computer and use it in GitHub Desktop.
wc-epaybg-change-request-description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'wc_epaybg_request_parameters', 'vanbodevelops_epaybg_add_order_number_to_description', 10, 4 ); | |
/** | |
* @param $epaybg_args | |
* @param $payment_type | |
* @param $order | |
* @param \WC_Gateway_Epaybg $gateway | |
* | |
* @return array | |
*/ | |
function vanbodevelops_epaybg_add_order_number_to_description( $epaybg_args, $payment_type, $order, $gateway ) { | |
$desc = '#' . $order->get_id() . ' '; | |
if ( sizeof( $order->get_items() ) > 0 ) { | |
foreach ( $order->get_items() as $item ) { | |
if ( \WcEpaybg\Compatibility\WC_Compatibility::get_item_quantity( $item ) ) { | |
$item_meta = \WcEpaybg\Compatibility\WC_Compatibility::wc_display_item_meta( $item ); | |
$item_name = \WcEpaybg\Compatibility\WC_Compatibility::get_item_name( $item ); | |
if ( $item_meta ) { | |
$item_name .= ' (' . $item_meta . ')'; | |
} | |
$desc .= \WcEpaybg\Compatibility\WC_Compatibility::get_item_quantity( $item ) . ' x ' . $item_name . ', '; | |
} | |
} | |
//Add the description | |
$desc = substr( $desc, 0, - 2 ); | |
// Cut description to the 100th character | |
$desc = substr( mb_convert_encoding( $desc, 'windows-1251', 'utf-8' ), 0, 100 ); | |
} | |
// Change the security checksum with the new description | |
$data = "MIN={$epaybg_args['MIN']} | |
INVOICE={$epaybg_args['INVOICE']} | |
AMOUNT={$epaybg_args['AMOUNT']} | |
CURRENCY={$epaybg_args['CURRENCY']} | |
EXP_TIME={$epaybg_args['EXP_TIME']} | |
DESCR={$desc} | |
"; | |
$encoded = base64_encode( $data ); | |
$checksum = $gateway->hmac( 'sha1', $encoded, $gateway->secret_word ); | |
$epaybg_args['DESCR'] = $desc; | |
$epaybg_args['ENCODED'] = $encoded; | |
$epaybg_args['CHECKSUM'] = $checksum; | |
return $epaybg_args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment