Add PayPal WPS payment payload information to Commerce admin e-mail I'm using Commerce with the Commerce E-mail module to customize the e-mail sent to admins whenever there is an order (a payment is received) at the store.  Payment is handled using PayPal WPS through the Commerce PayPal module.

On my site, buyers must input their e-mail addresses before moving on to PayPal, but these e-mail addresses (on my site) sometimes differ from the e-mail addresses registered on buyers' PayPal accounts.

For this reason, I want the admin e-mail (sent when an order is paid for) to include both the e-mail address that the buyer input on my Drupal site as well as their PayPal e-mail address.

Commerce E-mail provides a [commerce-email:order-items] token, but there is no token for the PayPal WPS information.  This information is stored within Drupal; in the Order Admin UI, if you click on the payment details of the transaction, under Payload there is a printout of an Array that includes [payer_email] =&gt; thepayeremail@example.com.

Payload array:

Array (
    [13775355555-ipn] =&gt; Array
        (
            [mc_gross] =&gt; 17.00
            [invoice] =&gt; 555-1377531555
            [protection_eligibility] =&gt; Eligible
            [payer_email] =&gt; thepayeremail@example.com


How can I add the buyer's PayPal registered e-mail address ([payer_email]) into the admin e-mail sent by Commerce?  It would be great if the solution would also allow use of other information in the payload array, such as the buyer's physical address.
You can extract those array and add them data object. After adding them to the token replace function you can use that to create custom tokens which will help you to get the tokens.
That custom tokens can now be used to get the buyer's email address

// Write a code for porting data to token_replace()
$data = new val();
$data-&gt;mc_gross = variable_get('mc_gross', '');
$data-&gt;invoice = variable_get('invoice', '');
$data-&gt;protection_eligibility = variable_get('protection_eligibility', '');
$data-&gt;invoice = variable_get('payer_email', '');
token_replace(['payload']', (array) $data);


--------write this in  module_name.tokens.inc file------------------------------------------

 function hook_token_info() {
      $info = array();

      // Add any new tokens.
      $info['tokens']['payload']['mc_gross'] = t('Gross');
      $info['tokens']['payload']['invoice'] = t('Invoice');
      $info['tokens']['payload']['protection_eligibility'] = t('Protection Eligibility');
      $info['tokens']['payload']['payer_email'] = t('Email');
      // Return them.
      return $info;
    }


    function hook_tokens($type, $tokens, array $data = array(), array $options = array()) {
     $replacements = array();


    if ($type == 'payload') {
    foreach ($tokens as $name =&gt; $original) {
          switch ($name) {
            case 'mc_gross':
              $replacements[$original] = $data['mc_gross'] ;
              break;
            case 'invoice':
              $replacements[$original] = $data['invoice'];
              break;
            case 'protection_eligibility':
              $replacements[$original] =  $data['protection_eligibility'];
              break;
            case 'payer_email':
              $replacements[$original] = $data['payer_email'];
              break;
          }
        }
      }

      return $replacements;
    }