Last active
July 11, 2019 11:05
-
-
Save vanbo/92b3975a43e16ce0e0228fa17a270803 to your computer and use it in GitHub Desktop.
WooCommerce Paysafe Hosted API - Modify Payment 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
/** | |
* IMPORTANT: The filters only work for the Paysafe Hosted Payments API integration. | |
* Other integrations like Paysafe Checkout JS will have separate filters for the requests | |
*/ | |
// Normal order | |
add_filter( 'wc_paysafe_request_params', 'prefix_paysafe_modify_request', 10, 2 ); | |
// Subscriptions/Pre-Orders order | |
add_filter( 'wc_paysafe_addons_request_params', 'prefix_paysafe_modify_request', 10, 2 ); | |
/** | |
* @param array $params | |
* @param WC_Order $order | |
* | |
* @return mixed | |
*/ | |
function prefix_paysafe_modify_request( $params, $order ) { | |
/** | |
* $params - is an array containing all request parameters. To modify or add to the request, just modify or add to the array. | |
*/ | |
// Here is an example of appending text to the "merchantRefNum" parameter | |
if ( isset( $params['merchantRefNum'] ) ) { | |
$append_string = 'anything you want to append'; | |
$params['merchantRefNum'] = $params['merchantRefNum'] . $append_string; | |
} | |
// Here is an example of removing the customer IP parameter | |
if ( isset($params['customerIp']) ) { | |
unset($params['customerIp']); | |
} | |
// Removes the billing details from the request, if there is no billing address | |
// Note: You can also remove individual paramaters from within the "billingDetails" by unsetting those | |
if ( '' === WC_Compat_Paysafe::get_order_billing_address_1( $order ) ) { | |
unset($params['billingDetails']); | |
} | |
// Change the customer profile first and last name | |
$params['profile']['firstName'] = 'fake-first-name'; | |
$params['profile']['lastName'] = 'fake-last-name'; | |
// Remove the customer profile first and last name | |
if ( '' === WC_Compat_Paysafe::get_order_billing_first_name( $order ) ) { | |
unset( $params['profile']['firstName'] ); | |
} | |
if ( '' === WC_Compat_Paysafe::get_order_billing_last_name( $order ) ) { | |
unset( $params['profile']['lastName'] ); | |
} | |
// Always return the $params | |
return $params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment