Skip to content

Instantly share code, notes, and snippets.

@vanbo
Created September 18, 2023 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanbo/d1e2b6db71c482a4b0fbbff0f754956f to your computer and use it in GitHub Desktop.
Save vanbo/d1e2b6db71c482a4b0fbbff0f754956f to your computer and use it in GitHub Desktop.
wc-epaybg-change-request-description
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