There is an action hook processed just before any successful transaction that can be used to add (for example) a receipt_email to the current charge :

Tha action is ‘direct_stripe_before_success_redirection’

Its parameters are :

  1. Charge ID – ID of the Charge that was just created with Stripe API
  2. Post ID – ID of the log created for the current transaction
  3. Button ID – ID set with the shortcode parameter “button_id”
  4. User ID – ID of the Stripe User

Here we go :

function my_direct_stripe_action($chargeID, $post_id, $button_id, $user_id) {
 // Add the action for a precise button setting a button_id
 if( $button_id === '1') {
 // Retrieve the user to identify its email address
 $user = get_user_by( 'ID', $user_id );
 $email_address = $user->user_email;
 //Retrieve Stripe Charge and update it
 $ch = \Stripe\Charge::retrieve($chargeID);
 $ch->receipt_email = $email_address;

// Pass the function 'my_direct_stripe_action' through the action with priority 10 and 4 parameters
add_action( 'direct_stripe_before_success_redirection', 'my_direct_stripe_action', 10, 4 );

If you are in a testing environment, stripe don’t send the receipt but you can check in the logs that the charge was updated.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *