Title: Forced Saved Card &#8211; Token Process
Last modified: June 29, 2020

---

# Forced Saved Card – Token Process

 *  Resolved [crackajax](https://wordpress.org/support/users/crackajax/)
 * (@crackajax)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/)
 * [@dougaitken](https://wordpress.org/support/users/dougaitken/) I have had the
   client check her Stripe for the actual customer account creation and if they 
   see the credit card on the account. As it turns out the customer account was 
   created and a credit card is present for the two customers whose accounts failed
   on the automated order. Their accounts were created on the day they setup their
   Woocommerce accounts on the site. The automated orders take place on the 1st 
   of each month thereafter.
 * For the existing customer in the program prior to these two new ones, their card
   gets charged and the order created. But the new customers who are buying in (
   simply by buying a tagged product in the Woocommerce shop – nothing custom going
   other than setting a user capability when purchasing a certain item), even though
   their customer account is created in Stripe, and the credit card associated, 
   the _stripe_customer_id is not being set in the WordPress user_meta table.
 * I am checking in my custom code for the Stripe token before hitting the API and
   if not found for the customer ID, it logs the error, User has no credit card 
   on file, and returns. So, does the filter, add_filter( ‘wc_stripe_force_save_source’,‘
   __return_true’ );, trigger the creation of the Stripe token? Should it be stored
   by the plugin as part of the transaction?
 * Thanks.
    Crack-Ajax
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fforced-saved-card-token-process%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Thread Starter [crackajax](https://wordpress.org/support/users/crackajax/)
 * (@crackajax)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/#post-13101730)
 * So, is there a bug with the plugin not saving the token when using the force 
   save filter?
 * Is there a way to add the token after the fact given that the customer account
   is created in the Stripe account as is the credit card stored, but the token 
   is not entered into the WordPress database?
 * Or, do I not need the token in order to auto charge the customer now?
 * I currently have:
 * //Charge user via Stripe API
    $charge = \Stripe\Charge::create([ ‘amount’ => 
   $totalNoDec, ‘currency’ => ‘usd’, ‘customer’ => $tokenString, ‘description’ =
   > ‘Tiffany Andersen Brands – Order ‘ . $order->get_id()] [‘idempotency_key’ =
   > $order->get_id(), ]);
 * But, before I hit the API, I am checking for the token in the WordPress database:
 * //Get Stripe customer token that was created when the card was saved in woo
    
   $tokenString = get_user_meta($user_id, ‘_stripe_customer_id’, true);
 * //If no token string, then user does not have a credit card on file
    if ( empty(
   $tokenString ) ) { $this->record_error_to_log( ‘User has no credit card on file
   for VIP Order #’ . $order->get_id() . ‘ for User ID #’ . $user_id ); return; }
 * Is this even necessary now? Will the order go through without the token?
 *  Thread Starter [crackajax](https://wordpress.org/support/users/crackajax/)
 * (@crackajax)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/#post-13123110)
 * Is anybody home? This issue has been active for 6 weeks now without resolution.
   [@dougaitken](https://wordpress.org/support/users/dougaitken/) was helping until
   he closed the [https://wordpress.org/support/topic/forced-save-card-customer-creation-not-working/#post-12998349](https://wordpress.org/support/topic/forced-save-card-customer-creation-not-working/#post-12998349)
   ticket and said to open a new one. Can someone please help?
 * The issue has been narrowed down to the Stripe token, and the WC Stripe plugin
   is not putting it in the database recently – but it was prior. Id this still 
   necessary to do the automated orders or no longer required?
 *  Plugin Support [dougaitken](https://wordpress.org/support/users/dougaitken/)
 * (@dougaitken)
 * Automattic Happiness Engineer
 * [5 years, 10 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/#post-13194881)
 * Hey [@crackajax](https://wordpress.org/support/users/crackajax/)
 * This thread has fallen by the side without a response, I’m sorry about that.
 * With the extra information and context you’ve given here, this is into the area
   of very custom code that I’m not able to offer support for.
 * On a general level, using wc_stripe_force_save_source on checkout will save a
   payment token for a customer as long as that customer is either registered or
   is being registered as a Customer user on the site during checkout.
 * As I mentioned, if the customer is a guest this won’t work since there is no 
   account to save the card details to.
 * > and the WC Stripe plugin is not putting it in the database recently – but it
   > was prior.
 * Were you able to narrow down a timeline here? From the time you brought this 
   up, I have been able to have this filter work as expected so if this stopped 
   working, it is possible a conflict from another plugin or other custom code.
 * > Id this still necessary to do the automated orders or no longer required?
 * It depends on what you’re wanting to achieve and how you’re “generating” these
   automated orders.
 * I know for the premium [WooCommerce Subscriptions](https://woocommerce.com/products/woocommerce-subscriptions/)
   this isn’t used and within the Stripe plugin itself it is only mentioned once
   in the filter creation – [https://github.com/woocommerce/woocommerce-gateway-stripe/blob/c7cd02dcb6a7b641070da1a10d585b369af9c930/includes/abstracts/abstract-wc-stripe-payment-gateway.php#L597](https://github.com/woocommerce/woocommerce-gateway-stripe/blob/c7cd02dcb6a7b641070da1a10d585b369af9c930/includes/abstracts/abstract-wc-stripe-payment-gateway.php#L597)
 * The need for this filter to be used is so that a payment token is saved even 
   if the registered customer doesn’t use the standard _“Save payment information
   to my account for future purchases.”_ option within the Stripe payment fields.
   Or like in your scenario, if you are creating orders programmatically and adding
   payment information with that order creation.
 * Thanks,
 *  Thread Starter [crackajax](https://wordpress.org/support/users/crackajax/)
 * (@crackajax)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/#post-13196466)
 * [@dougaitken](https://wordpress.org/support/users/dougaitken/) thanks for getting
   back to me. The cron job will run again overnight and I hope to resolve this 
   for my client.
 * But, I want to be clear, that the issue regarding the token is strictly the plugin
   code and not affected by any other customization outside of the filter: add_filter(‘
   wc_stripe_force_save_source’, ‘__return_true’ ); The custom code creates and 
   charges orders in a script that only runs on the 1st day of the month via a cron
   job.
 * That being said, I deactivated ALL plugins except Woocommerce and Woocommerce
   Stripe and activated the Twenty Twenty theme just to be sure. I added the filter:
   add_filter( ‘wc_stripe_force_save_source’, ‘__return_true’ ); to the top line
   of the Twenty twenty functions.php file as the only customization in the system.
   With this minimal setup, I created an order with my Stripe sandbox settings to
   test. The transaction does go through and I can see the user in my Stripe Test
   Data, but it did not save the card it appears, nor did it add the _stripe_customer_id
   to the wp_usermeta table. From My Stripe Dashboard:
 * EMAIL DESCRIPTION DEFAULT SOURCE CREATED
 * [donnie+testytesty@crack-ajax.com](https://wordpress.org/support/topic/forced-saved-card-token-process/donnie+testytesty@crack-ajax.com?output_format=md)
   
   Name: Testy Testy, Username: Testy — Jul 31, 1:04 PM
 * So, with the minimal setup two important pieces of data do not seem to be occurring
   as expected. I know this was working correctly at one time as the customers who
   bought into the system prior to March 2020 do have the tokens and the cards are
   saved. Since March 2020, the clients that have bought in are in Stripe and it
   appears their cards are as well (even though I don’t see the cards in my test
   today) AND the stripe id is in the wp_usermeta table. So, it is clear that something
   has changed in the WC Stripe plugin given this result – totally independent of
   any custom code other than the force save card filter.
 * As a hunch, I just searched the meta key filed in the wp_usemeta table for anything%
   stripe% and lo and behold, I see my three test customers I have created during
   the troubleshooting we have done over the last 3 months, and sure enough there
   is a meta key with the token, but the meta key is no longer:
 * _stripe_customer_id
 * it is now:
 * wp__stripe_customer_id
 * This is the source of the entire issue and one that I would have hoped you could
   have provided in support of your plugin 3 months ago. This token is necessary
   to do an auto charge because how else do you identify the Stripe user in order
   to charge their crd for a given order?
 * Anyway, this turns out to be the answer to this question on two tickets, and 
   hopefully any developer in the future will find this useful if they encounter
   the same issue. I would also suggest that the documentation for the plugin is
   also updated with this information as well.
 * Thanks for all your help,
    Donnie
 *  Thread Starter [crackajax](https://wordpress.org/support/users/crackajax/)
 * (@crackajax)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/#post-13196487)
 * I am marking this as resolved. I will update my code to check both meta keys 
   for the token and I am thinking it will fire perfectly in tonights cron job. 
   If any further issues, I will open a new ticket.
 * Thanks again [@dougaitken](https://wordpress.org/support/users/dougaitken/) !!
 *  Thread Starter [crackajax](https://wordpress.org/support/users/crackajax/)
 * (@crackajax)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/#post-13198301)
 * To be clear, it is not just a generic appendage of “wp_” to the old _stripe_customer_id
   key, but it is actually an appendage of the database prefix to the old key.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Forced Saved Card – Token Process’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-gateway-stripe/assets/icon-256x256.png?rev=3177277)
 * [WooCommerce Stripe Payment Gateway](https://wordpress.org/plugins/woocommerce-gateway-stripe/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-gateway-stripe/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-gateway-stripe/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-gateway-stripe/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-gateway-stripe/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-gateway-stripe/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [crackajax](https://wordpress.org/support/users/crackajax/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/forced-saved-card-token-process/#post-13198301)
 * Status: resolved