Payment Token API in 2.6

WooCommerce 2.6 will ship with a payment tokenization API. This makes it easier to store, manipulate, and retrieve payment info in a standardized way. Payment methods saved using the API can be managed from the user’s account settings and are displayed as options during checkout. The Simplify gateway also now has support for tokens meaning users can save their payment information for future purchases.

Sound good? Check out the docs to learn more and get started.

What are Payment Tokens?

Payment tokens in WooCommerce allow you to save the tokens/keys you use for communicating with various payment processors. They also store the other meta information needed to process a payment. For example, credit card tokens store the four digits of a card, the card brand/type, and expiration information. eChecks store their last four digits. New types of tokens can be easily built and used with WooCommerce.

When can I use it?

The Payment Token API will ship with WooCommerce 2.6 which is due for release in Q2 2016.

Please feel free to experiment and test with this functionality from Github master branch and provide feedback on GitHub. The Payment Token API documentation should contain everything you need to know. You can also look at examples in the unit tests, or by looking at the Simplify Commerce gateway code.

Can you give me an example?

The Payment Token API docs cover examples and the available classes comprehensively, but here is an example of how easy it is to build and save a token to a user’s account:

[code language=”php”]
// Build the token
$token = new WC_Payment_Token_CC();
$token->set_token( $payment_token_from_gateway ); // Token comes from payment processor
$token->set_gateway_id( ‘paypal’ );
$token->set_last4( ‘1517’ );
$token->set_expiry_year( ‘2018’ );
$token->set_expiry_month( ’06’ );
$token->set_card_type( ‘visa’ );
$token->set_user_id( get_current_user_id() );
// Save the new token to the database
$token->save();
// Set this token as the users new default token
WC_Payment_Tokens::set_users_default( get_current_user_id(), $token->get_id() );
[/code]


3 responses to “Payment Token API in 2.6”

  1. slash.andy Avatar
    slash.andy

    Reblogged this on Me. (Andrew) and commented:
    This is a really exciting development in WooCommerce.

  2. […] WooCommerce developer blog has details on the new payment token API coming in version 2.6 for […]

  3. […] will have access to our new Payment Tokens API which standardized the way in which tokens are stored and displayed. This wiki article explains […]

Leave a Reply

Your email address will not be published. Required fields are marked *