Skip to content

Instantly share code, notes, and snippets.

@messica
Last active June 18, 2019 02:23
Show Gist options
  • Save messica/d2a7f4ef66fe68182ee4c1c3bb6616ac to your computer and use it in GitHub Desktop.
Save messica/d2a7f4ef66fe68182ee4c1c3bb6616ac to your computer and use it in GitHub Desktop.
Save PayPal payer email in usermeta.
<?php
/**
* Save PayPal payer email in usermeta.
*/
function my_http_api_debug( $response, $context, $class, $r, $url ) {
global $current_user;
// Only continue for PayPal requests.
if ( false === strpos( $url, 'paypal.com' ) ) {
return;
}
// Only continue for GetExpressCheckoutDetails requests.
// We use GetExpressCheckoutDetails to confirm the payment after returning from PayPal.
$request = array();
parse_str( wp_remote_retrieve_body( $r ), $request );
if ( 'GetExpressCheckoutDetails' == $request['METHOD'] ) {
// Get the payer email.
parse_str( wp_remote_retrieve_body( $response ), $response );
$email = $response['EMAIL'];
// Save it in usermeta.
update_user_meta( $current_user, 'pmpro_paypal_payer_email', $email );
}
}
add_action( 'http_api_debug', 'my_http_api_debug', 10, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment