Last active
May 16, 2019 14:21
-
-
Save vanbo/099a16f05a92d76e6f72b302c0fabed6 to your computer and use it in GitHub Desktop.
WooCommerce Paytrace - Add Discretionary data field to the request
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_paytrace_transaction_request', 'prefix_filter_paytrace_transaction_request', 10, 5 ); | |
/** | |
* @param array $request_parameters | |
* @param WC_Order $order The order to be charged | |
* @param float $amount Amount to be charged | |
* @param bool $is_subscription Is this a subscription | |
* @param bool $is_paid_with_profile Is this a profile payment(true) or new card is used(false) | |
* | |
* @return array | |
*/ | |
function prefix_filter_paytrace_transaction_request( $request_parameters, $order, $amount, $is_subscription, $is_paid_with_profile ) { | |
// To add a parameter just add the key => value to the $request_parameters | |
/** | |
* IMPORTANT: Adding the Discretionary Data depends on the integration you use. | |
* | |
* Remove the parts that you do not use | |
*/ | |
//******************************************** | |
// Start: POST API Integration | |
// If the parameter is submitted from the checkout page | |
$request_parameters['name of the Discretionary Data Field'] = wc_clean( $_POST['name_of_the_account_number_field'] ); | |
// If the parameter is saved to the order | |
$request_parameters['name of the Discretionary Data Field'] = wc_clean( $order->get_meta( 'name_of_the_account_number_meta_field', true ) ); | |
// END: POST API Integration | |
//******************************************** | |
// Start: JSON API Integration | |
// If the parameter is submitted from the checkout page | |
$request_parameters['discretionary_data']['name of the Discretionary Data Field'] = wc_clean( $_POST['name_of_the_account_number_field'] ); | |
// If the parameter is saved to the order | |
$request_parameters['discretionary_data']['name of the Discretionary Data Field'] = wc_clean( $order->get_meta( 'name_of_the_account_number_meta_field', true ) ); | |
// END: JSON API Integration | |
//******************************************** | |
return $request_parameters; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment